#include <modest-debug.h>
#include <modest-header-window.h>
#include <modest-account-protocol.h>
+#include <tny-camel-msg.h>
#define MYDOCS_ENV "MYDOCSDIR"
#define DOCS_FOLDER ".documents"
typedef struct {
ModestMsgViewWindow *self;
gchar *file_path;
+ gchar *attachment_uid;
} DecodeAsyncHelper;
static void
gpointer user_data)
{
DecodeAsyncHelper *helper = (DecodeAsyncHelper *) user_data;
+ const gchar *content_type;
/* It could happen that the window was closed */
if (GTK_WIDGET_VISIBLE (helper->self))
goto free;
}
- /* make the file read-only */
- g_chmod(helper->file_path, 0444);
+ content_type = tny_mime_part_get_content_type (mime_part);
+ if ((g_str_has_prefix (content_type, "message/rfc822") ||
+ g_str_has_prefix (content_type, "multipart/") ||
+ g_str_has_prefix (content_type, "text/"))) {
+ ModestWindowMgr *mgr;
+ ModestWindow *msg_win = NULL;
+ TnyMsg * msg;
+ gchar *account;
+ const gchar *mailbox;
+ TnyStream *file_stream;
+ gint fd;
+
+ fd = g_open (helper->file_path, O_RDONLY, 0644);
+ if (fd != -1) {
+ file_stream = tny_fs_stream_new (fd);
+
+ mgr = modest_runtime_get_window_mgr ();
+
+ account = g_strdup (modest_window_get_active_account (MODEST_WINDOW (helper->self)));
+ mailbox = modest_window_get_active_mailbox (MODEST_WINDOW (helper->self));
- /* Activate the file */
- modest_platform_activate_file (helper->file_path, tny_mime_part_get_content_type (mime_part));
+ if (!account)
+ account = modest_account_mgr_get_default_account (modest_runtime_get_account_mgr ());
+
+ msg = tny_camel_msg_new ();
+ tny_camel_msg_parse (msg, file_stream);
+ msg_win = modest_msg_view_window_new_for_attachment (TNY_MSG (msg), account, mailbox, helper->attachment_uid);
+ modest_window_set_zoom (MODEST_WINDOW (msg_win),
+ modest_window_get_zoom (MODEST_WINDOW (helper->self)));
+ if (modest_window_mgr_register_window (mgr, msg_win, MODEST_WINDOW (helper->self)))
+ gtk_widget_show_all (GTK_WIDGET (msg_win));
+ else
+ gtk_widget_destroy (GTK_WIDGET (msg_win));
+ g_object_unref (file_stream);
+ }
+
+ } else {
+
+ /* make the file read-only */
+ g_chmod(helper->file_path, 0444);
+
+ /* Activate the file */
+ modest_platform_activate_file (helper->file_path, tny_mime_part_get_content_type (mime_part));
+ }
free:
/* Frees */
g_object_unref (helper->self);
g_free (helper->file_path);
+ g_free (helper->attachment_uid);
g_slice_free (DecodeAsyncHelper, helper);
}
helper = g_slice_new0 (DecodeAsyncHelper);
helper->self = g_object_ref (window);
helper->file_path = g_strdup (filepath);
+ helper->attachment_uid = g_strdup (attachment_uid);
decode_in_provider = FALSE;
mgr = modest_runtime_get_account_mgr ();
account = modest_window_get_active_account (MODEST_WINDOW (window));
if (modest_account_mgr_account_is_multimailbox (mgr, account, &protocol)) {
if (MODEST_IS_ACCOUNT_PROTOCOL (protocol)) {
+ gchar *uri;
+ uri = g_strconcat ("file://", filepath, NULL);
decode_in_provider =
modest_account_protocol_decode_part_to_stream_async (
MODEST_ACCOUNT_PROTOCOL (protocol),
mime_part,
- NULL,
+ filepath,
TNY_STREAM (temp_stream),
on_decode_to_stream_async_handler,
NULL,
helper);
+ g_free (uri);
}
}