+ }
+
+cleanup:
+ g_object_unref (header);
+
+end:
+ on_find_msg_async_destroy (info);
+}
+
+
+static void
+on_open_message_performer (gboolean canceled,
+ GError *err,
+ GtkWindow *parent_window,
+ TnyAccount *account,
+ gpointer user_data)
+{
+ OpenMsgPerformerInfo *info;
+ TnyFolder *folder = NULL;
+
+ info = (OpenMsgPerformerInfo *) user_data;
+ if (canceled || err) {
+ modest_platform_run_information_dialog (NULL, _("mail_ni_ui_folder_get_msg_folder_error"), TRUE);
+ g_idle_add (notify_error_in_dbus_callback, NULL);
+ on_find_msg_async_destroy (info);
+ return;
+ }
+
+ /* Get folder */
+ if (!account) {
+ ModestTnyAccountStore *account_store;
+ ModestTnyLocalFoldersAccount *local_folders_account;
+
+ account_store = modest_runtime_get_account_store ();
+ local_folders_account = MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (
+ modest_tny_account_store_get_local_folders_account (account_store));
+ folder = modest_tny_local_folders_account_get_merged_outbox (local_folders_account);
+ g_object_unref (local_folders_account);
+ } else {
+ folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account), info->uri, NULL);
+ }
+ if (!folder) {
+ modest_platform_run_information_dialog (NULL, _("mail_ni_ui_folder_get_msg_folder_error"), TRUE);
+ g_idle_add (notify_error_in_dbus_callback, NULL);
+ on_find_msg_async_destroy (info);
+ return;
+ }
+#ifndef MODEST_TOOLKIT_HILDON2
+ info->animation_timeout = g_timeout_add (1000, on_show_opening_animation, info);
+#endif
+ /* Get message */
+ tny_folder_find_msg_async (folder, info->uri, find_msg_async_cb, NULL, info);
+ g_object_unref (folder);
+}
+
+static gboolean
+on_idle_open_message_performer (gpointer user_data)
+{
+ ModestWindow *top_win = NULL;
+ OpenMsgPerformerInfo *info = (OpenMsgPerformerInfo *) user_data;
+
+ top_win = modest_window_mgr_get_current_top (modest_runtime_get_window_mgr());
+
+ /* Lock before the call as we're in an idle handler */
+ gdk_threads_enter ();
+ if (info->connect) {
+ modest_platform_connect_and_perform (GTK_WINDOW (top_win), TRUE,
+ info->account,
+ on_open_message_performer, info);
+ } else {
+ on_open_message_performer (FALSE, NULL, GTK_WINDOW (top_win),
+ info->account, info);
+ }
+ gdk_threads_leave ();
+
+ return FALSE;
+}
+
+static gint
+on_open_message (GArray * arguments, gpointer data, osso_rpc_t * retval)
+{
+ osso_rpc_t val;
+ gchar *uri;
+ TnyAccount *account = NULL;
+ gint osso_retval;
+ gboolean is_merge;
+
+ /* Get the arguments: */
+ val = g_array_index(arguments, osso_rpc_t, MODEST_DBUS_OPEN_MESSAGE_ARG_URI);
+ uri = g_strdup (val.value.s);
+
+ is_merge = g_str_has_prefix (uri, "merge:");
+
+ /* Get the account */
+ if (!is_merge)
+ account = tny_account_store_find_account (TNY_ACCOUNT_STORE (modest_runtime_get_account_store ()),
+ uri);
+
+
+ if (is_merge || account) {
+ OpenMsgPerformerInfo *info;
+ TnyFolder *folder = NULL;
+
+ info = g_slice_new0 (OpenMsgPerformerInfo);
+ if (account)
+ info->account = g_object_ref (account);
+ info->uri = uri;
+ info->connect = TRUE;
+ info->animation = NULL;
+ info->animation_timeout = 0;
+
+ /* Try to get the message, if it's already downloaded
+ we don't need to connect */
+ if (account) {
+ folder = tny_store_account_find_folder (TNY_STORE_ACCOUNT (account), uri, NULL);
+ } else {
+ ModestTnyAccountStore *account_store;
+ ModestTnyLocalFoldersAccount *local_folders_account;
+
+ account_store = modest_runtime_get_account_store ();
+ local_folders_account = MODEST_TNY_LOCAL_FOLDERS_ACCOUNT (
+ modest_tny_account_store_get_local_folders_account (account_store));
+ folder = modest_tny_local_folders_account_get_merged_outbox (local_folders_account);
+ g_object_unref (local_folders_account);