* src/modest-ui-actions.c:
[modest] / src / modest-ui-actions.c
index 17633f1..811b72c 100644 (file)
@@ -184,7 +184,7 @@ remote_folder_is_pop (const TnyFolderStore *folder)
                 account = tny_folder_get_account(TNY_FOLDER(folder));
         }
 
-       if (!account && !TNY_IS_ACCOUNT(account)) {
+       if (!TNY_IS_ACCOUNT(account)) {
                g_warning ("%s: could not get account", __FUNCTION__);
                return FALSE;
        }
@@ -395,10 +395,8 @@ void
 modest_ui_actions_refresh_message_window_after_delete (ModestMsgViewWindow* win)
 {
        /* Close msg view window or select next */
-       if (modest_msg_view_window_last_message_selected (win) &&
-               modest_msg_view_window_first_message_selected (win)) {
-               modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (win));
-       } else if (!modest_msg_view_window_select_next_message (win)) {
+       if (!modest_msg_view_window_select_next_message (win) &&
+           !modest_msg_view_window_select_previous_message (win)) {
                gboolean ret_value;
                g_signal_emit_by_name (G_OBJECT (win), "delete-event", NULL, &ret_value);       
        }
@@ -560,9 +558,9 @@ modest_ui_actions_on_delete_message (GtkAction *action, ModestWindow *win)
                                gtk_tree_path_free (prev_path);                         
                }
                
-               /* Update window dimming state */
+               /* Update toolbar dimming state */
                if (main_window)
-                       modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window));
+                       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 
                /* Free */
                g_list_foreach (sel_list, (GFunc) gtk_tree_path_free, NULL);
@@ -597,8 +595,6 @@ modest_ui_actions_on_delete_message_or_folder (GtkAction *action, ModestWindow *
        modest_ui_actions_on_delete_message (action, win);
 }
 
-
-
 void
 modest_ui_actions_on_quit (GtkAction *action, ModestWindow *win)
 {      
@@ -813,6 +809,7 @@ modest_ui_actions_on_new_msg (GtkAction *action, ModestWindow *win)
        modest_ui_actions_compose_msg(win, NULL, NULL, NULL, NULL, NULL, NULL);
 }
 
+
 gboolean 
 modest_ui_actions_msg_retrieval_check (ModestMailOperation *mail_op,
                                       TnyHeader *header,
@@ -982,9 +979,9 @@ open_msg_cb (ModestMailOperation *mail_op,
                gtk_widget_show_all (GTK_WIDGET(win));
        }
 
-       /* Update window dimming state */
+       /* Update toolbar dimming state */
        if (MODEST_IS_MAIN_WINDOW (parent_win)) {
-               modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (parent_win));
+               modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (parent_win));
        }
 
 cleanup:
@@ -1000,19 +997,21 @@ modest_ui_actions_get_msgs_full_error_handler (ModestMailOperation *mail_op,
 {
        const GError *error;
        GObject *win = NULL;
-       const gchar *err_msg;
 
        win = modest_mail_operation_get_source (mail_op);
        error = modest_mail_operation_get_error (mail_op);
-       /* Select error message */
-       if (error->code == MODEST_MAIL_OPERATION_ERROR_MESSAGE_SIZE_LIMIT)
-               err_msg = _("emev_ni_ui_imap_msg_size_exceed_error");
-       else
-               err_msg = (const gchar *) user_data;
 
        /* Show error */
-       modest_platform_run_information_dialog ((GtkWindow *) win, err_msg);
+       if (error->code == TNY_SYSTEM_ERROR_MEMORY ||
+           error->code == TNY_IO_ERROR_WRITE ||
+           error->code == TNY_IO_ERROR_READ) {
+               modest_platform_information_banner ((GtkWidget *) win, 
+                                                   NULL, dgettext("ke-recv", 
+                                                                  "cerm_device_memory_full"));
+       } else if (user_data) {
+               modest_platform_information_banner ((GtkWidget *) win, 
+                                                   NULL, user_data);
+       }
 
        if (win)
                g_object_unref (win);
@@ -1039,6 +1038,16 @@ get_account_from_header_list (TnyList *headers)
        return account;
 }
 
+static void 
+foreach_unregister_headers (gpointer data,
+                           gpointer user_data)
+{
+       ModestWindowMgr *mgr = (ModestWindowMgr *) user_data;
+       TnyHeader *header = TNY_HEADER (data);
+
+       modest_window_mgr_unregister_header (mgr, header);
+}
+
 static void
 open_msgs_performer(gboolean canceled, 
                    GError *err,
@@ -1057,6 +1066,9 @@ open_msgs_performer(gboolean canceled,
 
        status = tny_account_get_connection_status (account);
        if (err || canceled) {
+               /* Unregister the already registered headers */
+               tny_list_foreach (not_opened_headers, foreach_unregister_headers, 
+                                 modest_runtime_get_window_mgr ());
                goto clean;
        }
 
@@ -1220,7 +1232,7 @@ open_msgs_from_headers (TnyList *headers, ModestWindow *win)
 
        /* Connect to the account and perform */
        if (uncached_msgs > 0) {
-               modest_platform_connect_and_perform ((GtkWindow *) win, g_object_ref (account), 
+               modest_platform_connect_and_perform ((GtkWindow *) win, TRUE, g_object_ref (account), 
                                                     open_msgs_performer, g_object_ref (not_opened_headers));
        } else {
                /* Call directly the performer, do not need to connect */
@@ -1299,19 +1311,23 @@ reply_forward_cb (ModestMailOperation *mail_op,
        switch (rf_helper->action) {
        case ACTION_REPLY:
                new_msg = 
-                       modest_tny_msg_create_reply_msg (msg, header, from, signature,
+                       modest_tny_msg_create_reply_msg (msg, header, from, 
+                                                        (use_signature) ? signature : NULL,
                                                         rf_helper->reply_forward_type,
                                                         MODEST_TNY_MSG_REPLY_MODE_SENDER);
                break;
        case ACTION_REPLY_TO_ALL:
                new_msg = 
-                       modest_tny_msg_create_reply_msg (msg, header, from, signature, rf_helper->reply_forward_type,
+                       modest_tny_msg_create_reply_msg (msg, header, from, 
+                                                        (use_signature) ? signature : NULL, 
+                                                        rf_helper->reply_forward_type,
                                                         MODEST_TNY_MSG_REPLY_MODE_ALL);
                edit_type = MODEST_EDIT_TYPE_REPLY;
                break;
        case ACTION_FORWARD:
                new_msg = 
-                       modest_tny_msg_create_forward_msg (msg, from, signature, rf_helper->reply_forward_type);
+                       modest_tny_msg_create_forward_msg (msg, from, (use_signature) ? signature : NULL, 
+                                                          rf_helper->reply_forward_type);
                edit_type = MODEST_EDIT_TYPE_FORWARD;
                break;
        default:
@@ -1647,7 +1663,7 @@ new_messages_arrived (ModestMailOperation *self,
           send&receive was invoked by the user then do not show any
           visual notification, only play a sound and activate the LED
           (for the Maemo version) */
-       if ((new_headers != NULL) && (tny_list_get_length (new_headers) > 0))
+       if (TNY_IS_LIST(new_headers) && (tny_list_get_length (new_headers)) > 0)
                modest_platform_on_new_headers_received (new_headers, 
                                                         show_visual_notifications);
 
@@ -1738,6 +1754,7 @@ do_send_receive_performer (gboolean canceled,
  */
 void
 modest_ui_actions_do_send_receive (const gchar *account_name, 
+                                  gboolean force_connection,
                                   ModestWindow *win)
 {
        gchar *acc_name = NULL;
@@ -1769,7 +1786,8 @@ modest_ui_actions_do_send_receive (const gchar *account_name,
                                                                     TNY_ACCOUNT_TYPE_STORE);
 
        /* Invoke the connect and perform */
-       modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, info->account, 
+       modest_platform_connect_and_perform ((win) ? GTK_WINDOW (win) : NULL, 
+                                            force_connection, info->account, 
                                             do_send_receive_performer, info);
 }
 
@@ -1800,9 +1818,12 @@ modest_ui_actions_do_cancel_send (const gchar *account_name,
                             MODEST_MAIL_OPERATION_ERROR_ITEM_NOT_FOUND,
                             "modest: could not find send queue for account\n");
        } else {
-               /* Keeep messages in outbox folder */
-               tny_send_queue_cancel (send_queue, FALSE, &error);
-       }       
+               /* Cancel the current send */
+               tny_account_cancel (TNY_ACCOUNT (transport_account));
+
+               /* Suspend all pending messages */
+               tny_send_queue_cancel (send_queue, TNY_SEND_QUEUE_CANCEL_ACTION_SUSPEND, &error);
+       }
 
  frees:
        if (transport_account != NULL) 
@@ -1848,7 +1869,8 @@ modest_ui_actions_cancel_send (GtkAction *action,  ModestWindow *win)
  * updates
  */
 void
-modest_ui_actions_do_send_receive_all (ModestWindow *win)
+modest_ui_actions_do_send_receive_all (ModestWindow *win, 
+                                      gboolean force_connection)
 {
        GSList *account_names, *iter;
 
@@ -1857,7 +1879,7 @@ modest_ui_actions_do_send_receive_all (ModestWindow *win)
 
        iter = account_names;
        while (iter) {                  
-               modest_ui_actions_do_send_receive ((const char*) iter->data, win);
+               modest_ui_actions_do_send_receive ((const char*) iter->data, force_connection, win);
                iter = g_slist_next (iter);
        }
 
@@ -1898,8 +1920,8 @@ modest_ui_actions_on_send_receive (GtkAction *action, ModestWindow *win)
                        g_object_unref (folder_store);
        }       
        
-       /* Refresh the active account */
-       modest_ui_actions_do_send_receive (NULL, win);
+       /* Refresh the active account. Force the connection if needed */
+       modest_ui_actions_do_send_receive (NULL, TRUE, win);
 }
 
 
@@ -1966,8 +1988,8 @@ modest_ui_actions_on_header_selected (ModestHeaderView *header_view,
        if (!gtk_widget_is_focus (GTK_WIDGET(header_view)))
            gtk_widget_grab_focus (GTK_WIDGET(header_view));
 
-       /* Update window dimming state */
-       modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window));
+       /* Update toolbar dimming state */
+       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 }
 
 void
@@ -2130,8 +2152,8 @@ modest_ui_actions_on_folder_selection_changed (ModestFolderView *folder_view,
                }
        }
 
-       /* Update window dimming state */
-       modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (main_window));
+       /* Update toolbar dimming state */
+       modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (main_window));
 }
 
 void 
@@ -2245,13 +2267,13 @@ on_save_to_drafts_cb (ModestMailOperation *mail_op,
        if (modest_mail_operation_get_error (mail_op) != NULL) {
                g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_op))->message);
                modest_platform_information_banner (NULL, NULL, _("mail_ib_file_operation_failed"));
-               return;
+       } else {
+               modest_msg_edit_window_set_draft (edit_window, saved_draft);
        }
-
-       modest_msg_edit_window_set_draft (edit_window, saved_draft);
+       g_object_unref(edit_window);
 }
 
-void
+gboolean
 modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edit_window)
 {
        TnyTransportAccount *transport_account;
@@ -2259,12 +2281,31 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        MsgData *data;
        gchar *account_name, *from;
        ModestAccountMgr *account_mgr;
-       char *info_text;
+/*     char *info_text; */
+       gboolean had_error = FALSE;
+       guint64 available_disk, expected_size;
+       gint parts_count;
+       guint64 parts_size;
 
-       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
+       g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), FALSE);
        
        data = modest_msg_edit_window_get_msg_data (edit_window);
 
+       /* Check size */
+       available_disk = modest_folder_available_space (NULL);
+       modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
+       expected_size = modest_tny_msg_estimate_size (data->plain_body,
+                                                data->html_body,
+                                                parts_count,
+                                                parts_size);
+
+       if ((available_disk != -1) && expected_size > available_disk) {
+               modest_msg_edit_window_free_msg_data (edit_window, data);
+
+               modest_platform_information_banner (NULL, NULL, dgettext("ke-recv", "cerm_device_memory_full"));
+               return FALSE;
+       }
+
        account_name = g_strdup (data->account_name);
        account_mgr = modest_runtime_get_account_mgr();
        if (!account_name)
@@ -2274,7 +2315,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
        if (!account_name) {
                g_printerr ("modest: no account found\n");
                modest_msg_edit_window_free_msg_data (edit_window, data);
-               return;
+               return FALSE;
        }
 
        if (!strcmp (account_name, MODEST_LOCAL_FOLDERS_ACCOUNT_ID)) {
@@ -2290,12 +2331,12 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                g_printerr ("modest: no transport account found for '%s'\n", account_name);
                g_free (account_name);
                modest_msg_edit_window_free_msg_data (edit_window, data);
-               return;
+               return FALSE;
        }
        from = modest_account_mgr_get_from_string (account_mgr, account_name);
 
        /* Create the mail operation */         
-       mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
+       mail_operation = modest_mail_operation_new (NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
 
        modest_mail_operation_save_to_drafts (mail_operation,
@@ -2312,19 +2353,19 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                                              data->images,
                                              data->priority_flags,
                                              on_save_to_drafts_cb,
-                                             edit_window);
-       info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts"));
-       modest_platform_information_banner (NULL, NULL, info_text);
+                                             g_object_ref(edit_window));
+
+/*     info_text = g_strdup_printf (_("mail_va_saved_to_drafts"), _("mcen_me_folder_drafts")); */
+       modest_platform_information_banner (NULL, NULL, _CS("sfil_ib_saving"));
+       modest_msg_edit_window_reset_modified (edit_window);
 
        /* Frees */
-       g_free (info_text);
        g_free (from);
        g_free (account_name);
        g_object_unref (G_OBJECT (transport_account));
        g_object_unref (G_OBJECT (mail_operation));
 
        modest_msg_edit_window_free_msg_data (edit_window, data);
-       modest_msg_edit_window_reset_modified (edit_window);
 
        /* ** FIXME **
         * If the drafts folder is selected then make the header view
@@ -2343,7 +2384,7 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
         */
        ModestMainWindow *win = MODEST_MAIN_WINDOW(modest_window_mgr_get_main_window(
                modest_runtime_get_window_mgr(), FALSE));
-       if (win != NULL) {
+       if (!had_error && win != NULL) {
                ModestFolderView *view = MODEST_FOLDER_VIEW(modest_main_window_get_child_widget(
                        win, MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW));
                if (view != NULL) {
@@ -2362,28 +2403,49 @@ modest_ui_actions_on_save_to_drafts (GtkWidget *widget, ModestMsgEditWindow *edi
                        if (folder != NULL) g_object_unref(folder);
                }
        }
+
+       return !had_error;
 }
 
 /* For instance, when clicking the Send toolbar button when editing a message: */
-void
+gboolean
 modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
 {
        TnyTransportAccount *transport_account = NULL;
+       gboolean had_error = FALSE;
+       guint64 available_disk, expected_size;
+       gint parts_count;
+       guint64 parts_size;
 
-       g_return_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window));
+       g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW(edit_window), TRUE);
 
        if (!modest_msg_edit_window_check_names (edit_window, TRUE))
-               return;
+               return TRUE;
        
        /* FIXME: Code added just for testing. The final version will
           use the send queue provided by tinymail and some
           classifier */
        MsgData *data = modest_msg_edit_window_get_msg_data (edit_window);
 
+       /* Check size */
+       available_disk = modest_folder_available_space (NULL);
+       modest_msg_edit_window_get_parts_size (edit_window, &parts_count, &parts_size);
+       expected_size = modest_tny_msg_estimate_size (data->plain_body,
+                                                data->html_body,
+                                                parts_count,
+                                                parts_size);
+
+       if ((available_disk != -1) && expected_size > available_disk) {
+               modest_msg_edit_window_free_msg_data (edit_window, data);
+
+               modest_platform_information_banner (NULL, NULL, dgettext("ke-recv", "cerm_device_memory_full"));
+               return FALSE;
+       }
+
        ModestAccountMgr *account_mgr = modest_runtime_get_account_mgr();
        gchar *account_name = g_strdup (data->account_name);
        if (!account_name)
-               g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
+               account_name = g_strdup(modest_window_get_active_account (MODEST_WINDOW(edit_window)));
 
        if (!account_name) 
                account_name = modest_account_mgr_get_default_account (account_mgr);
@@ -2391,8 +2453,9 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        if (!account_name) {
                modest_msg_edit_window_free_msg_data (edit_window, data);
                /* Run account setup wizard */
-               if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window)))
-                       return;
+               if (!modest_ui_actions_run_account_setup_wizard (MODEST_WINDOW(edit_window))) {
+                       return TRUE;
+               }
        }
        
        /* Get the currently-active transport account for this modest account: */
@@ -2403,15 +2466,16 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        }
        
        if (!transport_account) {
+               modest_msg_edit_window_free_msg_data (edit_window, data);
                /* Run account setup wizard */
                if (!modest_ui_actions_run_account_setup_wizard(MODEST_WINDOW(edit_window)))
-                       return;
+                       return TRUE;
        }
        
        gchar *from = modest_account_mgr_get_from_string (account_mgr, account_name);
 
        /* Create the mail operation */
-       ModestMailOperation *mail_operation = modest_mail_operation_new (G_OBJECT(edit_window));
+       ModestMailOperation *mail_operation = modest_mail_operation_new (NULL);
        modest_mail_operation_queue_add (modest_runtime_get_mail_operation_queue (), mail_operation);
 
        modest_mail_operation_send_new_mail (mail_operation,
@@ -2431,6 +2495,15 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        if (modest_mail_operation_get_status (mail_operation) == MODEST_MAIL_OPERATION_STATUS_IN_PROGRESS)
                modest_platform_information_banner (NULL, NULL, _("mcen_ib_outbox_waiting_to_be_sent"));
 
+
+       if (modest_mail_operation_get_error (mail_operation) != NULL) {
+               const GError *error = modest_mail_operation_get_error (mail_operation);
+               if (error->code == MODEST_MAIL_OPERATION_ERROR_INSTANCE_CREATION_FAILED) {
+                       g_warning ("%s failed: %s\n", __FUNCTION__, (modest_mail_operation_get_error (mail_operation))->message);
+                       modest_platform_information_banner (NULL, NULL, _CS("sfil_ni_not_enough_memory"));
+                       had_error = TRUE;
+               }
+       }
                                             
        /* Free data: */
        g_free (from);
@@ -2439,10 +2512,15 @@ modest_ui_actions_on_send (GtkWidget *widget, ModestMsgEditWindow *edit_window)
        g_object_unref (G_OBJECT (mail_operation));
 
        modest_msg_edit_window_free_msg_data (edit_window, data);
-       modest_msg_edit_window_set_sent (edit_window, TRUE);
 
-       /* Save settings and close the window: */
-       modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
+       if (!had_error) {
+               modest_msg_edit_window_set_sent (edit_window, TRUE);
+
+               /* Save settings and close the window: */
+               modest_ui_actions_on_close_window (NULL, MODEST_WINDOW (edit_window));
+       }
+
+       return !had_error;
 }
 
 void 
@@ -2598,7 +2676,7 @@ do_create_folder_cb (ModestMailOperation *mail_op,
 {
        gchar *suggested_name = (gchar *) user_data;
        GtkWindow *source_win = (GtkWindow *) modest_mail_operation_get_source (mail_op);
-               
+
        if (modest_mail_operation_get_error (mail_op)) {
                /* Show an error */
                modest_platform_information_banner (GTK_WIDGET (source_win), NULL,
@@ -2689,6 +2767,7 @@ modest_ui_actions_create_folder(GtkWidget *parent_window,
        if (parent_folder) {
                /* The parent folder will be freed in the callback */
                modest_platform_connect_if_remote_and_perform (GTK_WINDOW (parent_window), 
+                                                              TRUE,
                                                               parent_folder,
                                                               create_folder_performer, 
                                                               parent_folder);
@@ -2742,8 +2821,21 @@ typedef struct {
 } RenameFolderInfo;
 
 static void
-on_rename_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window, 
-               TnyAccount *account, gpointer user_data)
+on_rename_folder_cb (ModestMailOperation *mail_op, 
+                    TnyFolder *new_folder,
+                    gpointer user_data)
+{
+       /* Select now */
+       modest_folder_view_select_folder (MODEST_FOLDER_VIEW (user_data),
+                                         new_folder, FALSE);
+}
+
+static void
+on_rename_folder_performer (gboolean canceled, 
+                           GError *err, 
+                           GtkWindow *parent_window, 
+                           TnyAccount *account, 
+                           gpointer user_data)
 {
        ModestMailOperation *mail_op = NULL;
        GtkTreeSelection *sel = NULL;
@@ -2768,20 +2860,12 @@ on_rename_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
                sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (folder_view));
                gtk_tree_selection_unselect_all (sel);
 
-               /* Select *after* the changes */
-               modest_folder_view_select_folder (MODEST_FOLDER_VIEW(folder_view),
-                               TNY_FOLDER(data->folder), TRUE);
-
                /* Actually rename the folder */
                modest_mail_operation_rename_folder (mail_op,
-                               TNY_FOLDER (data->folder),
-                               (const gchar *) (data->new_name));
-               
-               /* TODO folder view filter refilter */
-               /* 
-               GtkTreeModel *tree_model = gtk_tree_view_get_model (GTK_TREE_VIEW (folder_view));
-               if (GTK_IS_TREE_MODEL_FILTER (tree_model))
-                       gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (tree_model)); */
+                                                    TNY_FOLDER (data->folder),
+                                                    (const gchar *) (data->new_name),
+                                                    on_rename_folder_cb,
+                                                    folder_view);
        }
 
        g_object_unref (mail_op);
@@ -2835,8 +2919,8 @@ modest_ui_actions_on_rename_folder (GtkAction *action,
                        RenameFolderInfo *rename_folder_data = g_new0 (RenameFolderInfo, 1);
                        rename_folder_data->folder = folder;
                        rename_folder_data->new_name = folder_name;
-                       modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), 
-                                       folder, on_rename_folder_cb, rename_folder_data);
+                       modest_platform_connect_if_remote_and_perform (GTK_WINDOW(main_window), TRUE,
+                                       folder, on_rename_folder_performer, rename_folder_data);
                }
        }
        g_object_unref (folder);
@@ -2873,6 +2957,7 @@ on_delete_folder_cb (gboolean canceled,
        if (!MODEST_IS_MAIN_WINDOW(parent_window) || canceled || (err!=NULL)) {
                g_object_unref (G_OBJECT (info->folder));
                g_free (info);
+               return;
        }
        
        folder_view = modest_main_window_get_child_widget (
@@ -2938,9 +3023,11 @@ delete_folder (ModestMainWindow *main_window, gboolean move_to_trash)
                info->folder = folder;
                info->move_to_trash = move_to_trash;
                g_object_ref (G_OBJECT (info->folder));
-               TnyAccount *account = tny_folder_get_account(TNY_FOLDER(folder));
-               modest_platform_connect_and_perform (GTK_WINDOW (main_window), 
-                               account, on_delete_folder_cb, info);
+               TnyAccount *account = tny_folder_get_account (TNY_FOLDER (folder));
+               modest_platform_connect_if_remote_and_perform (GTK_WINDOW (main_window), 
+                                                              TRUE,
+                                                              TNY_FOLDER_STORE (account), 
+                                                              on_delete_folder_cb, info);
                g_object_unref (account);
        }
        g_object_unref (G_OBJECT (folder));
@@ -3185,9 +3272,11 @@ modest_ui_actions_on_cut (GtkAction *action,
                GtkTextBuffer *buffer;
 
                buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
-               gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
-               gtk_clipboard_set_can_store (clipboard, NULL, 0);
-               gtk_clipboard_store (clipboard);
+               if (modest_text_utils_buffer_selection_is_valid (buffer)) {
+                       gtk_text_buffer_cut_clipboard (buffer, clipboard, TRUE);
+                       gtk_clipboard_set_can_store (clipboard, NULL, 0);
+                       gtk_clipboard_store (clipboard);
+               }
        } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
                TnyList *header_list = modest_header_view_get_selected_headers (
                                MODEST_HEADER_VIEW (focused_widget));
@@ -3227,7 +3316,10 @@ modest_ui_actions_on_copy (GtkAction *action,
        focused_widget = gtk_window_get_focus (GTK_WINDOW (window));
 
        if (GTK_IS_LABEL (focused_widget)) {
-               gtk_clipboard_set_text (clipboard, gtk_label_get_text (GTK_LABEL (focused_widget)), -1);
+               gchar *selection;
+               selection = modest_text_utils_label_get_selection (GTK_LABEL (focused_widget));
+               gtk_clipboard_set_text (clipboard, selection, -1);
+               g_free (selection);
                gtk_clipboard_set_can_store (clipboard, NULL, 0);
                gtk_clipboard_store (clipboard);
        } else if (GTK_IS_EDITABLE (focused_widget)) {
@@ -3241,9 +3333,11 @@ modest_ui_actions_on_copy (GtkAction *action,
        } else if (GTK_IS_TEXT_VIEW (focused_widget)) {
                GtkTextBuffer *buffer;
                buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (focused_widget));
-               gtk_text_buffer_copy_clipboard (buffer, clipboard);
-               gtk_clipboard_set_can_store (clipboard, NULL, 0);
-               gtk_clipboard_store (clipboard);
+               if (modest_text_utils_buffer_selection_is_valid (buffer)) {
+                       gtk_text_buffer_copy_clipboard (buffer, clipboard);
+                       gtk_clipboard_set_can_store (clipboard, NULL, 0);
+                       gtk_clipboard_store (clipboard);
+               }
        } else if (MODEST_IS_HEADER_VIEW (focused_widget)) {
                TnyList *header_list = modest_header_view_get_selected_headers (
                                MODEST_HEADER_VIEW (focused_widget));
@@ -3310,7 +3404,17 @@ modest_ui_actions_on_redo (GtkAction *action,
 
 
 static void
-destroy_information_note (ModestMailOperation *mail_op, gpointer user_data)
+destroy_information_note (ModestMailOperation *mail_op, 
+                         gpointer user_data)
+{
+       /* destroy information note */
+       gtk_widget_destroy (GTK_WIDGET(user_data));
+}
+
+static void
+destroy_folder_information_note (ModestMailOperation *mail_op, 
+                                TnyFolder *new_folder,
+                                gpointer user_data)
 {
        /* destroy information note */
        gtk_widget_destroy (GTK_WIDGET(user_data));
@@ -3455,7 +3559,7 @@ modest_ui_actions_on_paste (GtkAction *action,
                                                           src_folder,
                                                           folder_store,
                                                           delete,
-                                                          destroy_information_note,
+                                                          destroy_folder_information_note,
                                                           inf_note);
                }
 
@@ -3515,7 +3619,7 @@ modest_ui_actions_on_select_all (GtkAction *action,
 
                /* Enable window dimming management */
                modest_window_enable_dimming (MODEST_WINDOW(window));
-               modest_ui_actions_check_window_dimming_rules (MODEST_WINDOW (window));
+               modest_ui_actions_check_toolbar_dimming_rules (MODEST_WINDOW (window));
        }
 
 }
@@ -3807,16 +3911,16 @@ modest_ui_actions_on_folder_display_name_changed (ModestFolderView *folder_view,
         * updating the display name apparently is expensive */
        const gchar* old_name = gtk_window_get_title (window);
 
+       if (display_name == NULL)
+               display_name = " ";
+
        if (old_name && display_name && strcmp (old_name, display_name) == 0)
                return; /* don't do anything */
 
        /* This is usually used to change the title of the main window, which
         * is the one that holds the folder view. Note that this change can
         * happen even when the widget doesn't have the focus. */
-       if (display_name)
-               gtk_window_set_title (window, display_name);
-       else
-               gtk_window_set_title (window, " ");
+       gtk_window_set_title (window, display_name);
 
 }
 
@@ -3864,9 +3968,11 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
        GtkWidget *folder_view = NULL;
        ModestTnyFolderRules rules;
 
+       g_return_if_fail (MODEST_IS_FOLDER_VIEW(self));
+       
        if (!selected)
                return;
-
+       
        /* Get the OK button */
        dialog = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_DIALOG);
        if (!dialog)
@@ -3889,10 +3995,15 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
 
                if ((gpointer) local_account != (gpointer) folder_store &&
                    (gpointer) mmc_account != (gpointer) folder_store) {
+                       const char *proto_name = tny_account_get_proto (TNY_ACCOUNT (folder_store));
+                       ModestTransportStoreProtocol proto = MODEST_PROTOCOL_STORE_MAILDIR;
+                       if (proto_name != NULL) {
+                               proto = modest_protocol_info_get_transport_store_protocol (proto_name);
+                       }
                        is_local_account = FALSE;
                        /* New button should be dimmed on remote
-                          account root */
-                       new_sensitive = FALSE;
+                          POP account root */
+                       new_sensitive = (proto != MODEST_PROTOCOL_STORE_POP);
                }
                g_object_unref (local_account);
        }
@@ -3943,25 +4054,36 @@ on_move_to_dialog_folder_selection_changed (ModestFolderView* self,
                }
                g_object_unref (moved_folder);
        } else {
-               TnyHeader *header = NULL;
                TnyFolder *src_folder = NULL;
 
                /* Moving a message */
                if (MODEST_IS_MSG_VIEW_WINDOW (user_data)) {
-                       header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (user_data));
-                       src_folder = tny_header_get_folder (header);
-                       g_object_unref (header);
+
+                       TnyHeader *header = NULL;
+                       header = modest_msg_view_window_get_header
+                               (MODEST_MSG_VIEW_WINDOW (user_data));
+                       if (!TNY_IS_HEADER(header))
+                               g_warning ("%s: could not get source header", __FUNCTION__);
+                       else
+                               src_folder = tny_header_get_folder (header);
+
+                       if (header)
+                               g_object_unref (header);
                } else {
                        src_folder = 
-                               TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
+                               TNY_FOLDER (modest_folder_view_get_selected
+                                           (MODEST_FOLDER_VIEW (folder_view)));
                }
 
-               /* Do not allow to move the msg to the same folder */
-               /* Do not allow to move the msg to an account */
-               if ((gpointer) src_folder == (gpointer) folder_store ||
-                   TNY_IS_ACCOUNT (folder_store))
-                       ok_sensitive = FALSE;
-               g_object_unref (src_folder);
+               if (TNY_IS_FOLDER(src_folder)) {
+                       /* Do not allow to move the msg to the same folder */
+                       /* Do not allow to move the msg to an account */
+                       if ((gpointer) src_folder == (gpointer) folder_store ||
+                           TNY_IS_ACCOUNT (folder_store))
+                               ok_sensitive = FALSE;
+                       g_object_unref (src_folder);
+               } else
+                       g_warning ("%s: could not get source folder", __FUNCTION__);
        }
 
  end:
@@ -4188,10 +4310,9 @@ modest_ui_actions_msgs_move_to_confirmation (ModestWindow *win,
        return response;
 }
 
-
-
 static void
-move_to_cb (ModestMailOperation *mail_op, gpointer user_data)
+move_to_cb (ModestMailOperation *mail_op, 
+           gpointer user_data)
 {
        MoveToHelper *helper = (MoveToHelper *) user_data;
 
@@ -4204,10 +4325,11 @@ move_to_cb (ModestMailOperation *mail_op, gpointer user_data)
                if (MODEST_IS_MSG_VIEW_WINDOW (object)) {
                        ModestMsgViewWindow *self = MODEST_MSG_VIEW_WINDOW (object);
 
-                       if (!modest_msg_view_window_select_next_message (self))
-                               if (!modest_msg_view_window_select_previous_message (self))
-                                       /* No more messages to view, so close this window */
-                                       modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
+                       if (!modest_msg_view_window_select_next_message (self) &&
+                           !modest_msg_view_window_select_previous_message (self)) {
+                               /* No more messages to view, so close this window */
+                               modest_ui_actions_on_close_window (NULL, MODEST_WINDOW(self));
+                       }
                } else if (MODEST_IS_MAIN_WINDOW (object) && helper->reference != NULL) {
                        GtkWidget *header_view;
                        GtkTreePath *path;
@@ -4230,6 +4352,31 @@ move_to_cb (ModestMailOperation *mail_op, gpointer user_data)
        g_free (helper);
 }
 
+static void
+folder_move_to_cb (ModestMailOperation *mail_op, 
+                  TnyFolder *new_folder,
+                  gpointer user_data)
+{
+       GtkWidget *folder_view;
+       GObject *object;
+
+       object = modest_mail_operation_get_source (mail_op);
+       folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(object),
+                                                          MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+       g_object_ref (folder_view);
+       g_object_unref (object);
+       move_to_cb (mail_op, user_data);
+       modest_folder_view_select_folder (MODEST_FOLDER_VIEW (folder_view), new_folder, FALSE);
+       g_object_unref (folder_view);
+}
+
+static void
+msgs_move_to_cb (ModestMailOperation *mail_op, 
+                gpointer user_data)
+{
+       move_to_cb (mail_op, user_data);
+}
+
 void
 modest_ui_actions_move_folder_error_handler (ModestMailOperation *mail_op, 
                                             gpointer user_data)
@@ -4348,6 +4495,7 @@ open_msg_for_purge_cb (ModestMailOperation *mail_op,
 
                                tny_iterator_next (iter);
                        }
+                       g_object_unref (iter);
                        
                        tny_msg_rewrite_cache (msg);
                }
@@ -4355,7 +4503,6 @@ open_msg_for_purge_cb (ModestMailOperation *mail_op,
                /* This string no longer exists, refer to NB#75415 for more info */
                /* modest_platform_information_banner (NULL, NULL, _("mail_ib_attachment_already_purged")); */
        }
-       g_object_unref (iter);
 
        modest_window_mgr_unregister_header (mgr, header);
 
@@ -4368,7 +4515,6 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
 {
        GtkWidget *header_view;
        TnyList *header_list;
-       TnyIterator *iter;
        TnyHeader *header;
        TnyHeaderFlags flags;
        ModestWindow *msg_view_window =  NULL;
@@ -4386,7 +4532,7 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
        }
        
        if (tny_list_get_length (header_list) == 1) {
-               iter = tny_list_create_iterator (header_list);
+               TnyIterator *iter = tny_list_create_iterator (header_list);
                header = TNY_HEADER (tny_iterator_get_current (iter));
                g_object_unref (iter);
        } else
@@ -4432,8 +4578,8 @@ modest_ui_actions_on_main_window_remove_attachments (GtkAction *action,
  */
 static void
 xfer_messages_from_move_to_cb  (gboolean canceled, GError *err,
-               GtkWindow *parent_window, 
-               TnyAccount *account, gpointer user_data)
+                               GtkWindow *parent_window, 
+                               TnyAccount *account, gpointer user_data)
 {
        TnyFolderStore *dst_folder = TNY_FOLDER_STORE (user_data);
        ModestWindow *win = MODEST_WINDOW (parent_window);
@@ -4446,13 +4592,6 @@ xfer_messages_from_move_to_cb  (gboolean canceled, GError *err,
                g_object_unref (dst_folder);
                return;
        }
-       
-       if (!TNY_IS_FOLDER (dst_folder)) {
-               modest_platform_information_banner (GTK_WIDGET (win),
-                                                   NULL,
-                                                   _CS("ckdg_ib_unable_to_move_to_current_location"));
-               return;
-       }
 
        dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
        proto_str = tny_account_get_proto (dst_account);
@@ -4508,7 +4647,7 @@ xfer_messages_from_move_to_cb  (gboolean canceled, GError *err,
                                         headers,
                                         TNY_FOLDER (dst_folder),
                                         TRUE,
-                                        move_to_cb,
+                                        msgs_move_to_cb,
                                         helper);
 
        g_object_unref (G_OBJECT (mail_op));
@@ -4574,11 +4713,13 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
                        TNY_FOLDER (info->src_folder),
                        info->dst_folder,
                        info->delete_original, 
-                       move_to_cb, 
+                       folder_move_to_cb, 
                        helper);
-       
-       modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
-                       TNY_FOLDER (info->dst_folder), TRUE);
+
+       if (modest_mail_operation_get_status (mail_op) == MODEST_MAIL_OPERATION_STATUS_SUCCESS) {       
+               modest_folder_view_select_folder (MODEST_FOLDER_VIEW(info->folder_view),
+                                                 TNY_FOLDER (info->dst_folder), TRUE);
+       }
        
        /* Unref mail operation */
        g_object_unref (G_OBJECT (mail_op));
@@ -4587,6 +4728,15 @@ on_move_folder_cb (gboolean canceled, GError *err, GtkWindow *parent_window,
        g_free (user_data);
 }
 
+static TnyAccount *
+get_account_from_folder_store (TnyFolderStore *folder_store) 
+{
+       if (TNY_IS_ACCOUNT (folder_store))
+               return g_object_ref (folder_store);
+       else
+               return tny_folder_get_account (TNY_FOLDER (folder_store));
+}
+
 /*
  * UI handler for the "Move to" action when invoked from the
  * ModestMainWindow
@@ -4615,51 +4765,74 @@ modest_ui_actions_on_main_window_move_to (GtkAction *action,
 
                /* Allow only to transfer folders to the local root folder */
                if (TNY_IS_ACCOUNT (dst_folder) && 
-                               !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder)) {
-                                       do_xfer = FALSE;
+                   !MODEST_IS_TNY_LOCAL_FOLDERS_ACCOUNT (dst_folder) &&
+                   !modest_tny_account_is_memory_card_account (TNY_ACCOUNT (dst_folder))) {
+                       do_xfer = FALSE;
                } else if (!TNY_IS_FOLDER (src_folder)) {
                        g_warning ("%s: src_folder is not a TnyFolder.\n", __FUNCTION__);
                        do_xfer = FALSE;
-               } /* else if (!online && modest_tny_folder_store_is_remote(src_folder)) {
-                       guint num_headers = tny_folder_get_all_count(TNY_FOLDER (src_folder));
-                       TnyAccount *account = tny_folder_get_account (TNY_FOLDER (src_folder));
-                       if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
-                               do_xfer = FALSE;
-                       g_object_unref (account);
-               }*/
+               }
 
-               if (do_xfer) {
+               if (do_xfer) {                  
                        MoveFolderInfo *info = g_new0 (MoveFolderInfo, 1);
-                       info->src_folder = TNY_FOLDER (src_folder);
-                       info->dst_folder = dst_folder;
+                       DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
+
+                       info->src_folder = g_object_ref (src_folder);
+                       info->dst_folder = g_object_ref (dst_folder);
                        info->delete_original = TRUE;
                        info->folder_view = folder_view;
-                       g_object_ref (G_OBJECT (info->src_folder));
-                       g_object_ref (G_OBJECT (info->dst_folder));
-                       modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), 
-                                   TNY_FOLDER_STORE (dst_folder), on_move_folder_cb, info);
+
+                       connect_info->callback = on_move_folder_cb;
+                       connect_info->dst_account = get_account_from_folder_store (TNY_FOLDER_STORE (dst_folder));
+                       connect_info->data = info;
+
+                       modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
+                                                                  TNY_FOLDER_STORE (src_folder), 
+                                                                  connect_info);
                }
        } else if (gtk_widget_is_focus (GTK_WIDGET(header_view))) {
                gboolean do_xfer = TRUE;
+
+               /* Show an error when trying to move msgs to an account */      
+               if (!TNY_IS_FOLDER (dst_folder)) {
+                       modest_platform_information_banner (GTK_WIDGET (win),
+                                                           NULL,
+                                                           _CS("ckdg_ib_unable_to_move_to_current_location"));
+                       goto free;
+               }
+
                /* Ask for confirmation if the source folder is remote and we're not connected */
                if (!online && modest_tny_folder_store_is_remote(src_folder)) {
                        TnyList *headers = modest_header_view_get_selected_headers(header_view);
                        if (!msgs_already_deleted_from_server(headers, src_folder)) {
                                guint num_headers = tny_list_get_length(headers);
                                TnyAccount *account = get_account_from_header_list (headers);
-                               if (!connect_to_get_msg(MODEST_WINDOW (win), num_headers, account))
+                               GtkResponseType response;
+
+                               response = modest_platform_run_confirmation_dialog (GTK_WINDOW (win),
+                                                                                   ngettext("mcen_nc_get_msg",
+                                                                                            "mcen_nc_get_msgs",
+                                                                                            num_headers));
+                               if (response == GTK_RESPONSE_CANCEL)
                                        do_xfer = FALSE;
+                               
                                g_object_unref (account);
                        }
                        g_object_unref(headers);
                }
                if (do_xfer) /* Transfer messages */ {
-                       g_object_ref (dst_folder);
-                       modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), 
-                                       TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
+                       DoubleConnectionInfo *connect_info = g_slice_new (DoubleConnectionInfo);
+                       connect_info->callback = xfer_messages_from_move_to_cb;
+                       connect_info->dst_account = tny_folder_get_account (TNY_FOLDER (dst_folder));
+                       connect_info->data = g_object_ref (dst_folder);
+                       
+                       modest_platform_double_connect_and_perform(GTK_WINDOW (win), TRUE,
+                                                                  TNY_FOLDER_STORE (src_folder), 
+                                                                  connect_info);
                }
        }
 
+ free:
        if (src_folder)
                g_object_unref (src_folder);
 }
@@ -4699,7 +4872,7 @@ modest_ui_actions_on_msg_view_window_move_to (GtkAction *action,
 
        if (do_xfer) {
                g_object_ref (dst_folder);
-               modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), 
+               modest_platform_connect_if_remote_and_perform(GTK_WINDOW (win), TRUE,
                                TNY_FOLDER_STORE (dst_folder), xfer_messages_from_move_to_cb, dst_folder);
         }
        g_object_unref (account);
@@ -4930,7 +5103,7 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
        g_object_unref (iter);
 
        /* Connect and perform the message retrieval */
-       modest_platform_connect_and_perform ((GtkWindow *) window, 
+       modest_platform_connect_and_perform ((GtkWindow *) window, TRUE,
                                             g_object_ref (account), 
                                             retrieve_msg_contents_performer, 
                                             g_object_ref (headers));
@@ -4941,12 +5114,111 @@ modest_ui_actions_on_retrieve_msg_contents (GtkAction *action,
 }
 
 void
-modest_ui_actions_check_window_dimming_rules (ModestWindow *window)
+modest_ui_actions_check_toolbar_dimming_rules (ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_TOOLBAR);
+}
+
+void
+modest_ui_actions_check_menu_dimming_rules (ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_window_check_dimming_rules_group (window, MODEST_DIMMING_RULES_MENU);
+}
+
+void
+modest_ui_actions_on_email_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+       
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_edit_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
 {
        g_return_if_fail (MODEST_IS_WINDOW (window));
 
-       /* Update dimmed */     
-       modest_window_check_dimming_rules_group (window, "ModestWindowDimmingRules");   
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_view_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_format_menu_activated (GtkAction *action,
+                                           ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_tools_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_attachment_menu_activated (GtkAction *action,
+                                         ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_toolbar_csm_menu_activated (GtkAction *action,
+                                                ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_folder_view_csm_menu_activated (GtkAction *action,
+                                                    ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
+}
+
+void
+modest_ui_actions_on_header_view_csm_menu_activated (GtkAction *action,
+                                                    ModestWindow *window)
+{
+       g_return_if_fail (MODEST_IS_WINDOW (window));
+
+       /* Update dimmed */
+       modest_ui_actions_check_menu_dimming_rules (window);
 }
 
 void
@@ -5040,7 +5312,7 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
        gchar *message = NULL;
 
        /* Don't show anything if the user cancelled something */
-       if (err->code == TNY_TRANSPORT_ACCOUNT_ERROR_SEND_USER_CANCEL)
+       if (err->code == TNY_SYSTEM_ERROR_CANCEL)
                return;
 
        /* Get the server name: */
@@ -5057,20 +5329,17 @@ modest_ui_actions_on_send_queue_error_happened (TnySendQueue *self,
 
        /* Show the appropriate message text for the GError: */
        switch (err->code) {
-       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_HOST_LOOKUP_FAILED:
+       case TNY_SERVICE_ERROR_CONNECT:
                message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
                break;
-       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_SERVICE_UNAVAILABLE:
-               message = g_strdup_printf (_("emev_ib_ui_smtp_server_invalid"), server_name);
-               break;
-       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND_AUTHENTICATION_NOT_SUPPORTED:
+       case TNY_SERVICE_ERROR_AUTHENTICATE:
                message = g_strdup_printf (_("emev_ni_ui_smtp_authentication_fail_error"), server_name);
                break;
-       case TNY_TRANSPORT_ACCOUNT_ERROR_SEND:
+       case TNY_SERVICE_ERROR_SEND:
                message = g_strdup (_("emev_ib_ui_smtp_send_error"));
                break;
        default:
-               g_warning ("%s: unexpected TNY_TRANSPORT_ACCOUNT_ERROR %d",
+               g_warning ("%s: unexpected ERROR %d",
                           __FUNCTION__, err->code);
                message = g_strdup (_("emev_ib_ui_smtp_send_error"));
                break;  
@@ -5125,6 +5394,10 @@ modest_ui_actions_on_send_queue_status_changed (ModestTnySendQueue *send_queue,
 #else
        gtk_widget_queue_draw (header_view);
 #endif         
+
+       /* Rerun dimming rules, because the message could become deletable for example */
+       modest_window_check_dimming_rules_group (MODEST_WINDOW (main_window), 
+                                                MODEST_DIMMING_RULES_TOOLBAR);
        
        /* Free */
  frees:
@@ -5165,3 +5438,54 @@ modest_ui_actions_on_account_connection_error (GtkWindow *parent_window,
                g_free (error_note);
        }
 }
+
+gchar *
+modest_ui_actions_get_msg_already_deleted_error_msg (ModestWindow *win)
+{
+       gchar *msg = NULL;
+       TnyFolderStore *folder = NULL;
+       TnyAccount *account = NULL;
+       ModestTransportStoreProtocol proto;
+       TnyHeader *header = NULL;
+
+       if (MODEST_IS_MAIN_WINDOW (win)) {
+               GtkWidget *header_view;
+               TnyList* headers = NULL;
+               TnyIterator *iter;
+               header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                                  MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+               headers = modest_header_view_get_selected_headers (MODEST_HEADER_VIEW (header_view));
+               if (!headers || tny_list_get_length (headers) == 0) {
+                       if (headers)
+                               g_object_unref (headers);
+                       return NULL;
+               }
+               iter = tny_list_create_iterator (headers);
+               header = TNY_HEADER (tny_iterator_get_current (iter));
+               folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
+               g_object_unref (iter);
+               g_object_unref (headers);
+       } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
+               header = modest_msg_view_window_get_header (MODEST_MSG_VIEW_WINDOW (win));
+               folder = TNY_FOLDER_STORE (tny_header_get_folder (header));
+       }
+
+       /* Get the account type */
+       account = tny_folder_get_account (TNY_FOLDER (folder));
+       proto = modest_protocol_info_get_transport_store_protocol (tny_account_get_proto (account));
+       if (proto == MODEST_PROTOCOL_STORE_POP) {
+               msg = g_strdup (_("emev_ni_ui_pop3_msg_recv_error"));
+       } else if (proto == MODEST_PROTOCOL_STORE_IMAP) {
+               msg = g_strdup_printf (_("emev_ni_ui_imap_message_not_available_in_server"), 
+                                      tny_header_get_subject (header));
+       } else {
+               msg = g_strdup_printf (_("mail_ni_ui_folder_get_msg_folder_error"));
+       }
+
+       /* Frees */
+       g_object_unref (account);
+       g_object_unref (folder);
+       g_object_unref (header);
+
+       return msg;
+}