+ 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);
+ }
+ if (folder) {
+ TnyDevice *device;
+ gboolean device_online;
+
+ device = modest_runtime_get_device();
+ device_online = tny_device_is_online (device);
+ if (device_online) {
+ info->connect = TRUE;
+ } else {
+ TnyMsg *msg = tny_folder_find_msg (folder, uri, NULL);
+ if (msg) {
+ info->connect = FALSE;
+ g_object_unref (msg);
+ } else {
+ info->connect = TRUE;
+ }
+ }
+ g_object_unref (folder);
+ }
+
+ /* We need to call it into an idle to get
+ modest_platform_connect_and_perform into the main
+ loop */
+ g_idle_add (on_idle_open_message_performer, info);
+ osso_retval = OSSO_OK;
+ } else {
+ g_free (uri);
+ osso_retval = OSSO_ERROR;
+ g_idle_add (notify_error_in_dbus_callback, NULL);
+ }
+
+ if (account)
+ g_object_unref (account);
+ return osso_retval;
+}
+
+static void
+on_remove_msgs_finished (ModestMailOperation *mail_op,
+ gpointer user_data)
+{
+ TnyHeader *header;
+ ModestWindow *main_win = NULL, *msg_view = NULL;
+ ModestHeaderView *header_view;
+
+ header = (TnyHeader *) user_data;
+
+ /* Get the main window if exists */
+ main_win = modest_window_mgr_get_main_window (modest_runtime_get_window_mgr(),
+ FALSE); /* don't create */
+ if (!main_win) {
+ g_object_unref (header);
+ return;
+ }
+
+ if (modest_window_mgr_find_registered_header (modest_runtime_get_window_mgr(),
+ header, &msg_view)) {
+ if (MODEST_IS_MSG_VIEW_WINDOW (msg_view))
+ modest_ui_actions_refresh_message_window_after_delete (MODEST_MSG_VIEW_WINDOW (msg_view));
+ }
+ g_object_unref (header);
+
+ /* Refilter the header view explicitly */
+ header_view = (ModestHeaderView *)
+ modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(main_win),
+ MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+ if (header_view && MODEST_IS_HEADER_VIEW (header_view))
+ modest_header_view_refilter (header_view);