* Reworked attachments mime type detection and body detection, to work
[modest] / src / modest-ui-dimming-rules.c
index b1e5274..af08d11 100644 (file)
@@ -38,6 +38,7 @@
 #include "modest-debug.h"
 #include "modest-tny-folder.h"
 #include "modest-tny-account.h"
+#include "modest-tny-mime-part.h"
 #include "modest-text-utils.h"
 #include <widgets/modest-attachments-view.h>
 #include <modest-runtime.h>
@@ -60,7 +61,6 @@ static gboolean _selected_folder_not_renameable (ModestMainWindow *win);
 static gboolean _selected_folder_not_deletable (ModestMainWindow *win);
 static gboolean _selected_folder_is_any_of_type (ModestWindow *win, TnyFolderType types[], guint ntypes);
 static gboolean _selected_folder_is_root_or_inbox (ModestMainWindow *win);
-static gboolean _selected_folder_is_MMC_or_POP_root (ModestMainWindow *win);
 static gboolean _selected_folder_is_root (ModestMainWindow *win);
 static gboolean _header_view_is_all_selected (ModestMainWindow *win);
 static gboolean _selected_folder_is_empty (ModestMainWindow *win);
@@ -69,8 +69,6 @@ static gboolean _selected_folder_is_same_as_source (ModestWindow *win);
 static gboolean _msg_download_in_progress (ModestWindow *win);
 static gboolean _msg_download_completed (ModestMainWindow *win);
 static gboolean _selected_msg_sent_in_progress (ModestWindow *win);
-static gboolean _sending_in_progress (ModestWindow *win);
-static gboolean _invalid_account_for_purge (ModestWindow *win, ModestDimmingRule *rule);
 static gboolean _invalid_folder_for_purge (ModestWindow *win, ModestDimmingRule *rule);
 static gboolean _transfer_mode_enabled (ModestWindow *win);
 static gboolean _selected_folder_has_subfolder_with_same_name (ModestWindow *win);
@@ -99,6 +97,7 @@ _define_main_window_dimming_state (ModestMainWindow *window)
        gboolean all_seen = TRUE;
        gboolean all_cached = TRUE;
        gboolean all_has_attach = TRUE;
+       TnyFolder *folder = NULL;
 
        g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(window), NULL);
 
@@ -173,23 +172,28 @@ _define_main_window_dimming_state (ModestMainWindow *window)
                        state->any_has_attachments = flags & TNY_HEADER_FLAG_ATTACHMENTS;
        
                /* sent in progress */
-               msg_uid = modest_tny_send_queue_get_msg_id (header);
-               if (!state->sent_in_progress) {
-                       cache_mgr = modest_runtime_get_cache_mgr ();
-                       send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
-                                                                      MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
-                       
-                       g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues);
+               folder = tny_header_get_folder (header);
+               if (folder) {
+                       if (modest_tny_folder_guess_folder_type (folder) == TNY_FOLDER_TYPE_OUTBOX) {
+                               msg_uid = modest_tny_send_queue_get_msg_id (header);
+                               if (!state->sent_in_progress) {
+                                       cache_mgr = modest_runtime_get_cache_mgr ();
+                                       send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
+                                                                                      MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
                        
-                       for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) {
-                               send_queue = MODEST_TNY_SEND_QUEUE (node->data);
-                               
-                               /* Check if msg uid is being processed inside send queue */
-                               found = modest_tny_send_queue_msg_is_being_sent (send_queue, msg_uid);          
+                                       g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues);
+                                       
+                                       for (node = send_queues; node != NULL && !found; node = g_slist_next (node)) {
+                                               send_queue = MODEST_TNY_SEND_QUEUE (node->data);
+                                               
+                                               /* Check if msg uid is being processed inside send queue */
+                                               found = modest_tny_send_queue_msg_is_being_sent (send_queue, msg_uid);          
+                                       }
+                                       state->sent_in_progress = found;
+                               }
                        }
-                       state->sent_in_progress = found;
+                       g_object_unref (folder);
                }
-
                tny_iterator_next (iter);
                g_object_unref (header);
        }
@@ -333,18 +337,14 @@ modest_ui_dimming_rules_on_new_msg (ModestWindow *win, gpointer user_data)
                
        /* Check dimmed rule */ 
        if (MODEST_IS_MSG_VIEW_WINDOW(win)) {
-               if (!dimmed) {
-                       dimmed = _msg_download_in_progress (win);
-                       if (dimmed)
-                               modest_dimming_rule_set_notification (rule, "");
-               }
+               dimmed = _msg_download_in_progress (win);
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, "");                
        } else if (MODEST_IS_MAIN_WINDOW(win)) {
-               if (!dimmed) {
-                       dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
-                                                                 TRUE);        
-                       if (dimmed)
-                               modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
-               }
+               dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
+                                                         TRUE);        
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
        }
 
        return dimmed;
@@ -362,12 +362,10 @@ modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data)
        g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
        rule = MODEST_DIMMING_RULE (user_data);
 
-       if (!dimmed) {
-               dimmed = _transfer_mode_enabled (win);
-               if (dimmed) {
-                       modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
-                       return dimmed;
-               }
+       dimmed = _transfer_mode_enabled (win);
+       if (dimmed) {
+               modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
+               return dimmed;
        }
 
        /* Get selected folder as parent of new folder to create */
@@ -385,18 +383,19 @@ modest_ui_dimming_rules_on_new_folder (ModestWindow *win, gpointer user_data)
                if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
                        dimmed = FALSE;
                } else {
-                       const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (parent_folder));
-                       if (proto_str != NULL) {
-                               /* If it's POP then dim */                      
-                               dimmed = (modest_protocol_info_get_transport_store_protocol (proto_str) == 
-                                         MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
+                       ModestProtocolType protocol_type = modest_tny_account_get_protocol_type (TNY_ACCOUNT (parent_folder));
+                       if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
+                               ModestProtocolRegistry *protocol_registry;
+
+                               protocol_registry = modest_runtime_get_protocol_registry ();
+                               /* If account does not support folders (pop) then dim */
+                               dimmed = (!modest_protocol_registry_protocol_type_has_tag (protocol_registry, protocol_type,
+                                                                                          MODEST_PROTOCOL_REGISTRY_STORE_HAS_FOLDERS));
                                if (dimmed)
                                        modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_create_error"));
                        }
                }
-       } else {
-               /* TODO: the specs say that only one level of subfolder is allowed, is this true ? */
-               
+       } else {        
                TnyFolderType types[3];
                                
                types[0] = TNY_FOLDER_TYPE_DRAFTS; 
@@ -488,11 +487,9 @@ modest_ui_dimming_rules_on_delete_folder (ModestWindow *win, gpointer user_data)
 
                
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _selected_folder_not_deletable (MODEST_MAIN_WINDOW(win));
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
-       }
+       dimmed = _selected_folder_not_deletable (MODEST_MAIN_WINDOW(win));
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
        if (!dimmed) {
                dimmed = _selected_folder_is_any_of_type (win, types, 6);
                if (dimmed)
@@ -504,11 +501,6 @@ modest_ui_dimming_rules_on_delete_folder (ModestWindow *win, gpointer user_data)
                        modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
        }
        if (!dimmed) {
-               dimmed = _selected_folder_is_MMC_or_POP_root (MODEST_MAIN_WINDOW(win));
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mail_in_ui_folder_delete_error"));
-       }
-       if (!dimmed) {
                dimmed = _transfer_mode_enabled (win);
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
@@ -528,15 +520,10 @@ modest_ui_dimming_rules_on_sort (ModestWindow *win, gpointer user_data)
        rule = MODEST_DIMMING_RULE (user_data);
                
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _selected_folder_is_root (MODEST_MAIN_WINDOW(win));
-               modest_dimming_rule_set_notification (rule, _CS("ckdg_ib_nothing_to_sort"));
-       }
+       dimmed = _selected_folder_is_root (MODEST_MAIN_WINDOW(win));
 
-       if (!dimmed) {
+       if (!dimmed)
                dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
-               modest_dimming_rule_set_notification (rule, _CS("ckdg_ib_nothing_to_sort"));
-       }
 
        return dimmed;
        
@@ -559,11 +546,9 @@ modest_ui_dimming_rules_on_rename_folder (ModestWindow *win, gpointer user_data)
        types[3] = TNY_FOLDER_TYPE_ARCHIVE;
        
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _selected_folder_not_renameable (MODEST_MAIN_WINDOW(win));
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, "");
-       }
+       dimmed = _selected_folder_not_renameable (MODEST_MAIN_WINDOW(win));
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, "");
        if (!dimmed) {
                dimmed = _selected_folder_is_root_or_inbox (MODEST_MAIN_WINDOW(win));
                if (dimmed)
@@ -596,9 +581,7 @@ modest_ui_dimming_rules_on_open_msg (ModestWindow *win, gpointer user_data)
        state = modest_window_get_dimming_state (win);          
 
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);
-       }
+       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);      
        if (!dimmed) {
                dimmed = state->any_marked_as_deleted;
                if (dimmed) {
@@ -631,11 +614,9 @@ modest_ui_dimming_rules_on_reply_msg (ModestWindow *win, gpointer user_data)
        types[2] = TNY_FOLDER_TYPE_ROOT;
 
        /* Check dimmed rule */
-       if (!dimmed) {
-               dimmed = _selected_folder_is_any_of_type (win, types, 3);
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply"));
-       }
+       dimmed = _selected_folder_is_any_of_type (win, types, 3);
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_reply"));
 
        /* main window dimming rules */
        if (MODEST_IS_MAIN_WINDOW(win)) {
@@ -679,9 +660,7 @@ modest_ui_dimming_rules_on_contents_msg (ModestWindow *win, gpointer user_data)
        rule = MODEST_DIMMING_RULE (user_data);
                
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
-       }
+       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);     
        if (!dimmed) {
                dimmed = _msg_download_completed (MODEST_MAIN_WINDOW(win));
                if (dimmed)
@@ -694,17 +673,38 @@ modest_ui_dimming_rules_on_contents_msg (ModestWindow *win, gpointer user_data)
 gboolean 
 modest_ui_dimming_rules_always_dimmed (ModestWindow *win, gpointer user_data)
 {
-       gboolean dimmed = FALSE;
-
        g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
-               
-       /* Check dimmed rule */ 
-       if (!dimmed)
-               dimmed = TRUE;
 
-       return dimmed;
+       return TRUE;
+}
+
+static gboolean
+_message_already_sent (ModestMsgViewWindow *view_window)
+{
+       TnyHeader *header;
+       TnyFolder *folder;
+       gboolean already_sent = FALSE;
+
+       header = modest_msg_view_window_get_header (view_window);
+       if (header) {
+               folder = tny_header_get_folder (header);
+               if (folder) {
+                       if (modest_tny_folder_guess_folder_type (folder) ==
+                           TNY_FOLDER_TYPE_OUTBOX) {                           
+                               ModestTnySendQueueStatus status = 
+                                       modest_tny_all_send_queues_get_msg_status (header);
+                               if (status == MODEST_TNY_SEND_QUEUE_UNKNOWN ||
+                                   status == MODEST_TNY_SEND_QUEUE_SENDING)
+                                       already_sent = TRUE;
+                       }
+                       g_object_unref (folder);
+               }
+               g_object_unref (header);
+       }
+       return already_sent;
 }
 
+
 gboolean 
 modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
 {
@@ -718,11 +718,9 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
        
        /* Check dimmed rule */         
        if (MODEST_IS_MAIN_WINDOW (win)) {
-               if (!dimmed) {
-                       dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));                   
-                       if (dimmed)
-                               modest_dimming_rule_set_notification (rule, _CS("ckct_ib_nothing_to_delete"));
-               }
+               dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));                   
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, _CS("ckct_ib_nothing_to_delete"));  
                if (!dimmed) {
                        dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
                }
@@ -753,11 +751,9 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                }
        } 
        else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
-               if (!dimmed) {
-                       dimmed = _transfer_mode_enabled (win);                  
-                       if (dimmed)
-                               modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
-               }
+               dimmed = _transfer_mode_enabled (win);                  
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));             
                if (!dimmed) {
                        dimmed = state->any_marked_as_deleted;
                        if (dimmed) {
@@ -771,6 +767,11 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                        if (dimmed)
                                modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
                }
+
+               /* This could happen if we're viewing a message of the
+                  outbox that has been already sent */
+               if (!dimmed)
+                       dimmed = _message_already_sent (MODEST_MSG_VIEW_WINDOW(win));
                
                /* The delete button should be dimmed when viewing an attachment,
                 * but should be enabled when viewing a message from the list, 
@@ -840,20 +841,18 @@ modest_ui_dimming_rules_on_details (ModestWindow *win, gpointer user_data)
                                                modest_dimming_rule_set_notification (rule, "");
                                }
 
+                       } else {
+                               return TRUE;
                        }
-
                }
 
        /* msg view window dimming rules */
        } else {
-
                /* Check dimmed rule */ 
-               if (!dimmed) {
-                       if (MODEST_IS_MSG_VIEW_WINDOW (win))
-                               dimmed = _msg_download_in_progress (win);
-                       if (dimmed)
-                               modest_dimming_rule_set_notification (rule, "");
-               }
+               if (MODEST_IS_MSG_VIEW_WINDOW (win))
+                       dimmed = _msg_download_in_progress (win);
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, "");                
                if (!dimmed) {
                        if (!modest_msg_view_window_is_search_result (MODEST_MSG_VIEW_WINDOW(win))) {
                                dimmed = !modest_msg_view_window_has_headers_model (MODEST_MSG_VIEW_WINDOW (win));
@@ -883,9 +882,7 @@ modest_ui_dimming_rules_on_mark_as_read_msg (ModestWindow *win, gpointer user_da
        flags = TNY_HEADER_FLAG_SEEN; 
 
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
-       }
+       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);     
        if (!dimmed) {
                dimmed = state->all_marked_as_seen;
                if (dimmed)
@@ -911,8 +908,7 @@ modest_ui_dimming_rules_on_mark_as_unread_msg (ModestWindow *win, gpointer user_
        flags = TNY_HEADER_FLAG_SEEN; 
 
        /* Check dimmed rule */ 
-       if (!dimmed)
-               dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
+       dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
        if (!dimmed) {
                dimmed = !state->any_marked_as_seen;
                if (dimmed)
@@ -969,11 +965,9 @@ modest_ui_dimming_rules_on_main_window_move_to (ModestWindow *win, gpointer user
                types[4] = TNY_FOLDER_TYPE_INBOX; 
                
                /* Apply folder rules */        
-               if (!dimmed) {
-                       dimmed = _selected_folder_not_moveable (MODEST_MAIN_WINDOW(win));
-                       if (dimmed)
-                               modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items"));
-               }
+               dimmed = _selected_folder_not_moveable (MODEST_MAIN_WINDOW(win));
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_items"));           
                if (!dimmed) {
                        dimmed = _selected_folder_is_any_of_type (win, types, 5);
                        if (dimmed)
@@ -1016,10 +1010,16 @@ modest_ui_dimming_rules_on_view_window_move_to (ModestWindow *win, gpointer user
        rule = MODEST_DIMMING_RULE (user_data);
 
        /* Check dimmed rule */ 
+       dimmed = _transfer_mode_enabled (win);                  
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));     
        if (!dimmed) {
-               dimmed = _transfer_mode_enabled (win);                  
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+               dimmed = modest_window_get_dimming_state (win)->any_marked_as_deleted;
+               if (dimmed) {
+                       gchar *msg = modest_ui_actions_get_msg_already_deleted_error_msg (win);
+                       modest_dimming_rule_set_notification (rule, msg);
+                       g_free (msg);
+               }
        }
        
        if (!dimmed) {
@@ -1027,6 +1027,12 @@ modest_ui_dimming_rules_on_view_window_move_to (ModestWindow *win, gpointer user
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_item"));
        }
+
+       /* This could happen if we're viewing a message of the outbox
+          that has been already sent */
+       if (!dimmed)
+               dimmed = _message_already_sent (MODEST_MSG_VIEW_WINDOW(win));
+
        if (!dimmed) {
                if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
                        /* The move_to button should be dimmed when viewing an attachment,
@@ -1056,11 +1062,9 @@ modest_ui_dimming_rules_on_find_msg (ModestWindow *win, gpointer user_data)
        rule = MODEST_DIMMING_RULE (user_data);
 
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _transfer_mode_enabled (win);                  
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
-       }
+       dimmed = _transfer_mode_enabled (win);                  
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));     
 
        return dimmed;
 }
@@ -1081,13 +1085,11 @@ modest_ui_dimming_rules_on_paste (ModestWindow *win, gpointer user_data)
        types[2] = TNY_FOLDER_TYPE_SENT;
        
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _clipboard_is_empty (win);
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, 
-                                                             dgettext("hildon-common-strings", 
-                                                                      "ecoc_ib_edwin_nothing_to_paste"));
-       }
+       dimmed = _clipboard_is_empty (win);
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, 
+                                                     dgettext("hildon-common-strings", 
+                                                              "ecoc_ib_edwin_nothing_to_paste"));
        if (!dimmed) {
                dimmed = _selected_folder_is_any_of_type (win, types, 3);
                if (dimmed)
@@ -1138,7 +1140,7 @@ modest_ui_dimming_rules_on_select_all (ModestWindow *win, gpointer user_data)
        focused = gtk_window_get_focus (GTK_WINDOW (win));
 
        /* Main window dimming rules */ 
-       if (!dimmed && MODEST_IS_MAIN_WINDOW (win))
+       if (MODEST_IS_MAIN_WINDOW (win))
                dimmed = _selected_folder_is_empty (MODEST_MAIN_WINDOW(win));
 
        if (!dimmed && MODEST_IS_MAIN_WINDOW (win))
@@ -1171,8 +1173,7 @@ modest_ui_dimming_rules_on_view_attachments (ModestWindow *win, gpointer user_da
        rule = MODEST_DIMMING_RULE (user_data);
 
        /* Check dimmed rule */ 
-       if (!dimmed) 
-               dimmed = _invalid_attach_selected (win, TRUE, TRUE, FALSE, rule);                       
+       dimmed = _invalid_attach_selected (win, TRUE, TRUE, FALSE, rule);                       
 
        if (!dimmed) {
                dimmed = _purged_attach_selected (win, FALSE, NULL);
@@ -1195,8 +1196,7 @@ modest_ui_dimming_rules_on_save_attachments (ModestWindow *win, gpointer user_da
        rule = MODEST_DIMMING_RULE (user_data);
 
        /* Check dimmed rule */ 
-       if (!dimmed) 
-               dimmed = _invalid_attach_selected (win, FALSE, FALSE, FALSE, rule);
+       dimmed = _invalid_attach_selected (win, FALSE, FALSE, FALSE, rule);
 
        if (!dimmed) {
                dimmed = _purged_attach_selected (win, FALSE, NULL);
@@ -1221,7 +1221,7 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_
        state = modest_window_get_dimming_state (win);          
 
        /* Check in main window if there's only one message selected */
-       if (!dimmed && MODEST_IS_MAIN_WINDOW (win)) {
+       if (MODEST_IS_MAIN_WINDOW (win)) {
                dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW (win), TRUE, rule);
        }
 
@@ -1232,6 +1232,26 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_
                        modest_dimming_rule_set_notification (rule, _("FIXME:no attachment selected"));
        }
 
+       /* Messages as attachments could not be removed */
+       if (!dimmed && MODEST_IS_MSG_VIEW_WINDOW (win)) {
+               TnyList *attachments;
+               TnyIterator *iter;
+               attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW (win));
+               if (attachments) {
+                       iter = tny_list_create_iterator (attachments);
+                       while (!tny_iterator_is_done (iter) && !dimmed) {
+                               TnyMimePart *mime_part = (TnyMimePart *)
+                                       tny_iterator_get_current (iter);
+                               if (modest_tny_mime_part_is_msg (mime_part))
+                                       dimmed = TRUE;
+                               g_object_unref (mime_part);
+                               tny_iterator_next (iter);
+                       }
+                       g_object_unref (iter);
+                       g_object_unref (attachments);
+               }
+       }
+
        if (!dimmed) {
 
                dimmed = _selected_msg_sent_in_progress (win);
@@ -1240,14 +1260,11 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_
                }
        }
 
-       /* cannot purge in pop accounts */
-       if (!dimmed) {
-               dimmed = _invalid_account_for_purge (win, rule);
-       }
-
        /* cannot purge in editable drafts nor pop folders */
        if (!dimmed) {
                dimmed = _invalid_folder_for_purge (win, rule);
+               if (dimmed)
+                       modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments"));
        }
 
        /* Check if the selected message in main window has attachments */
@@ -1269,7 +1286,6 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_
                        modest_dimming_rule_set_notification (rule, _("mail_ib_attach_not_local"));
        }
 
-
        return dimmed;
 }
 
@@ -1283,7 +1299,7 @@ modest_ui_dimming_rules_on_undo (ModestWindow *win, gpointer user_data)
        rule = MODEST_DIMMING_RULE (user_data);
 
        /* Check dimmed rule */ 
-       if (!dimmed && MODEST_IS_MAIN_WINDOW (win)) {
+       if (MODEST_IS_MAIN_WINDOW (win)) {
                dimmed = _clipboard_is_empty (win); 
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, "");
@@ -1306,7 +1322,7 @@ modest_ui_dimming_rules_on_redo (ModestWindow *win, gpointer user_data)
        rule = MODEST_DIMMING_RULE (user_data);
 
        /* Check dimmed rule */ 
-       if (!dimmed && MODEST_IS_MSG_EDIT_WINDOW (win)) {
+       if (MODEST_IS_MSG_EDIT_WINDOW (win)) {
                dimmed = !modest_msg_edit_window_can_redo (MODEST_MSG_EDIT_WINDOW (win));
        }
                                
@@ -1325,9 +1341,7 @@ modest_ui_dimming_rules_on_cut (ModestWindow *win, gpointer user_data)
        state = modest_window_get_dimming_state (win);
 
        /* Check common dimming rules */
-       if (!dimmed) {
-               dimmed = _invalid_clipboard_selected (win, rule);
-       }
+       dimmed = _invalid_clipboard_selected (win, rule);
 
        /* Check window specific dimming rules */
        if (MODEST_IS_MAIN_WINDOW (win)) {
@@ -1392,9 +1406,7 @@ modest_ui_dimming_rules_on_copy (ModestWindow *win, gpointer user_data)
        state = modest_window_get_dimming_state (win);
 
        /* Check common dimming rules */
-       if (!dimmed) {
-               dimmed = _invalid_clipboard_selected (win, rule);
-       }
+       dimmed = _invalid_clipboard_selected (win, rule);       
        
        /* Check window specific dimming rules */
        if (MODEST_IS_MAIN_WINDOW (win)) {
@@ -1455,14 +1467,12 @@ modest_ui_dimming_rules_on_set_style (ModestWindow *win, gpointer user_data)
 
 
        /* Check common dimming rules */
-       if (!dimmed) {
-               ModestMsgEditFormat format;
-               format = modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (win));
+       ModestMsgEditFormat format;
+       format = modest_msg_edit_window_get_format (MODEST_MSG_EDIT_WINDOW (win));
 
-               dimmed = (format != MODEST_MSG_EDIT_FORMAT_HTML);
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mcen_ib_item_unavailable_plaintext"));
-       }
+       dimmed = (format != MODEST_MSG_EDIT_FORMAT_HTML);
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_item_unavailable_plaintext"));
 
        if (!dimmed) {
                GtkWidget *body;
@@ -1490,16 +1500,13 @@ modest_ui_dimming_rules_on_zoom (ModestWindow *win, gpointer user_data)
        rule = MODEST_DIMMING_RULE (user_data);
        state = modest_window_get_dimming_state (win);
 
-       if (!dimmed) {
-               GtkWidget *body;
-               body = modest_msg_edit_window_get_child_widget (MODEST_MSG_EDIT_WINDOW (win),
-                                                               MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY);
-               
-               dimmed = ((body == NULL)||(!gtk_widget_is_focus (body)));
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mcen_ib_move_cursor_to_message"));
-       }
-              
+       GtkWidget *body;
+       body = modest_msg_edit_window_get_child_widget (MODEST_MSG_EDIT_WINDOW (win),
+                                                       MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY);
+       
+       dimmed = ((body == NULL)||(!gtk_widget_is_focus (body)));
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_move_cursor_to_message"));
        
        return dimmed;
 }
@@ -1519,10 +1526,8 @@ modest_ui_dimming_rules_on_editor_paste (ModestWindow *win, gpointer user_data)
 
        focused = gtk_window_get_focus (GTK_WINDOW (win));
 
-       if (!dimmed) {
-               dimmed = MODEST_IS_ATTACHMENTS_VIEW (focused);
-       }
-
+       dimmed = MODEST_IS_ATTACHMENTS_VIEW (focused);
+       
        if (!dimmed) {
                dimmed = GTK_IS_TOGGLE_BUTTON (focused);
        }
@@ -1544,27 +1549,25 @@ modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer
        ModestDimmingRule *rule = NULL;
        const DimmedState *state = NULL;
        gboolean dimmed = FALSE;
+       TnyList *selected_attachments = NULL;
+       gint n_att_selected = 0;
+       GtkWidget *attachments_view;
        
        g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
        rule = MODEST_DIMMING_RULE (user_data);
        state = modest_window_get_dimming_state (win);
 
-       if (!dimmed) {
-               TnyList *selected_attachments = NULL;
-               gint n_att_selected = 0;
-               GtkWidget *attachments_view;
-               attachments_view = modest_msg_edit_window_get_child_widget (
-                       MODEST_MSG_EDIT_WINDOW (win),
-                       MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_ATTACHMENTS);
-               
-               selected_attachments = modest_attachments_view_get_selection (
-                       MODEST_ATTACHMENTS_VIEW (attachments_view));
-               n_att_selected = tny_list_get_length (selected_attachments);
-               g_object_unref (selected_attachments);
-
-               dimmed = (n_att_selected < 1);
-       }
+       attachments_view = modest_msg_edit_window_get_child_widget (
+                                                                   MODEST_MSG_EDIT_WINDOW (win),
+                                                                   MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_ATTACHMENTS);
+       
+       selected_attachments = modest_attachments_view_get_selection (
+                                                                     MODEST_ATTACHMENTS_VIEW (attachments_view));
+       n_att_selected = tny_list_get_length (selected_attachments);
+       g_object_unref (selected_attachments);
+       
+       dimmed = (n_att_selected < 1);  
        
        return dimmed;
 }
@@ -1575,30 +1578,27 @@ modest_ui_dimming_rules_on_send (ModestWindow *win, gpointer user_data)
        ModestDimmingRule *rule = NULL;
        const DimmedState *state = NULL;
        gboolean dimmed = FALSE;
+       GtkWidget *subject_field, *body_field;
+       GtkTextBuffer *body_buffer;
+       const gchar *subject = NULL;
        
        g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
        g_return_val_if_fail (MODEST_IS_MSG_EDIT_WINDOW (win), TRUE);
        rule = MODEST_DIMMING_RULE (user_data);
        state = modest_window_get_dimming_state (win);
 
-       if (!dimmed) {
-               GtkWidget *subject_field, *body_field;
-               GtkTextBuffer *body_buffer;
-               const gchar *subject = NULL;
-               body_field = modest_msg_edit_window_get_child_widget (
-                       MODEST_MSG_EDIT_WINDOW (win),
-                       MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY);
-               subject_field = modest_msg_edit_window_get_child_widget (
-                       MODEST_MSG_EDIT_WINDOW (win),
-                       MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_SUBJECT);
-               body_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (body_field));
-               subject = gtk_entry_get_text (GTK_ENTRY (subject_field));
-
-               dimmed = ((subject == NULL || subject[0] == '\0')
-                         || (gtk_text_buffer_get_char_count(body_buffer) == 0));
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mcen_ib_subject_or_body_not_modified"));
-       }
+       body_field = modest_msg_edit_window_get_child_widget (
+                                                             MODEST_MSG_EDIT_WINDOW (win),
+                                                             MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BODY);
+       subject_field = modest_msg_edit_window_get_child_widget (
+                                                                MODEST_MSG_EDIT_WINDOW (win),
+                                                                MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_SUBJECT);
+       body_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (body_field));
+       subject = gtk_entry_get_text (GTK_ENTRY (subject_field));
+
+       dimmed = (subject == NULL || subject[0] == '\0');
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mcen_ib_subject_not_modified"));
               
        if (!dimmed) {
                GtkWidget *to_field, *cc_field, *bcc_field;
@@ -1638,12 +1638,10 @@ modest_ui_dimming_rules_on_view_previous (ModestWindow *win, gpointer user_data)
        g_return_val_if_fail (MODEST_IS_MSG_VIEW_WINDOW(win), FALSE);
 
        /* Check dimmed rule */
-       if (!dimmed) {
-               dimmed = _transfer_mode_enabled (win);
-               if (dimmed)
-                       modest_dimming_rule_set_notification (
-                                       rule, _("mail_ib_notavailable_downloading"));
-       }
+       dimmed = _transfer_mode_enabled (win);
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+       
        if (!dimmed) {
                dimmed = modest_msg_view_window_first_message_selected (
                                MODEST_MSG_VIEW_WINDOW(win));
@@ -1664,11 +1662,10 @@ modest_ui_dimming_rules_on_view_next (ModestWindow *win, gpointer user_data)
        rule = MODEST_DIMMING_RULE (user_data);
 
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = _transfer_mode_enabled (win);                  
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
-       }
+       dimmed = _transfer_mode_enabled (win);                  
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+       
        if (!dimmed) {
                dimmed = modest_msg_view_window_last_message_selected (MODEST_MSG_VIEW_WINDOW (win));
                modest_dimming_rule_set_notification (rule, NULL);
@@ -1681,11 +1678,8 @@ modest_ui_dimming_rules_on_view_next (ModestWindow *win, gpointer user_data)
 gboolean 
 modest_ui_dimming_rules_on_tools_smtp_servers (ModestWindow *win, gpointer user_data)
 {
-       const gboolean dimmed = 
-               !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
-                       TRUE);  
-               
-       return dimmed;
+       return !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
+                                               TRUE);  
 }
 
 gboolean 
@@ -1704,43 +1698,11 @@ modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data
        types[0] = TNY_FOLDER_TYPE_OUTBOX; 
 
        /* Check dimmed rules */        
+       dimmed = !_selected_folder_is_any_of_type (win, types, 1);
+       if (dimmed) 
+               modest_dimming_rule_set_notification (rule, "");        
        if (!dimmed) {
-               dimmed = !_selected_folder_is_any_of_type (win, types, 1);
-               if (dimmed) 
-                       modest_dimming_rule_set_notification (rule, "");
-       }
-       if (!dimmed) {
-               dimmed = !_sending_in_progress (win);
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, "");
-       }
-
-       return dimmed;
-}
-
-gboolean 
-modest_ui_dimming_rules_on_csm_cancel_sending (ModestWindow *win, gpointer user_data)
-{
-       ModestDimmingRule *rule = NULL;
-       TnyFolderType types[1];
-       const DimmedState *state = NULL;
-       gboolean dimmed = FALSE;
-
-       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
-       g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
-       rule = MODEST_DIMMING_RULE (user_data);
-       state = modest_window_get_dimming_state (win);
-
-       types[0] = TNY_FOLDER_TYPE_OUTBOX; 
-
-       /* Check dimmed rules */        
-       if (!dimmed) {
-               dimmed = !_selected_folder_is_any_of_type (win, types, 1);
-               if (dimmed) 
-                       modest_dimming_rule_set_notification (rule, "");
-       }
-       if (!dimmed) {
-               dimmed = !_sending_in_progress (win);
+               dimmed = !state->sent_in_progress;
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, "");
        }
@@ -1758,12 +1720,10 @@ modest_ui_dimming_rules_on_send_receive (ModestWindow *win, gpointer user_data)
        rule = MODEST_DIMMING_RULE (user_data);
  
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
-                                                         TRUE);        
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
-       }
+       dimmed = !modest_account_mgr_has_accounts(modest_runtime_get_account_mgr(), 
+                                                 TRUE);        
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
 
        return dimmed;
 }
@@ -1778,15 +1738,13 @@ modest_ui_dimming_rules_on_send_receive_all (ModestWindow *win, gpointer user_da
        rule = MODEST_DIMMING_RULE (user_data);
  
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr (), TRUE);
-               if (g_slist_length (account_names) <= 1)
-                       dimmed = TRUE;
-               if (dimmed)
-                       modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
-               
-               modest_account_mgr_free_account_names (account_names);
-       }
+       GSList *account_names = modest_account_mgr_account_names (modest_runtime_get_account_mgr (), TRUE);
+       if (g_slist_length (account_names) <= 1)
+               dimmed = TRUE;
+       if (dimmed)
+               modest_dimming_rule_set_notification (rule, _("mcen_nc_no_email_acnts_defined"));
+       
+       modest_account_mgr_free_account_names (account_names);
 
        return dimmed;
 }
@@ -1823,6 +1781,8 @@ modest_ui_dimming_rules_on_add_to_contacts (ModestWindow *win, gpointer user_dat
                                int len = -1;
                                sel = gtk_html_get_selection_html (GTK_HTML (focused), &len);
                                do_check = !((sel == NULL) || (sel[0] == '\0'));
+                       } else if (MODEST_IS_ATTACHMENTS_VIEW (focused)) {
+                               do_check = FALSE;
                        }
                        if (do_check) {
                                clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);
@@ -2016,7 +1976,7 @@ _selected_folder_is_root_or_inbox (ModestMainWindow *win)
 
        /* Check pop and MMC accounts */
        if (!result) {
-               result = _selected_folder_is_MMC_or_POP_root (win);
+               result = _selected_folder_is_root (win);
        }
                
        return result;
@@ -2040,6 +2000,7 @@ _selected_folder_is_root (ModestMainWindow *win)
                        modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
                if (folder_store) {
                        is_account = TNY_IS_ACCOUNT (folder_store);
+
                        g_object_unref (folder_store);
                        folder_store = NULL;
                }
@@ -2054,49 +2015,6 @@ _selected_folder_is_root (ModestMainWindow *win)
        /* Check folder type */
        result = _selected_folder_is_any_of_type (MODEST_WINDOW(win), types, 1);
                
-       /* Check pop and MMC accounts */
-       if (!result) {
-               result = _selected_folder_is_MMC_or_POP_root (win);
-       }
-
-       return result;
-}
-
-static gboolean
-_selected_folder_is_MMC_or_POP_root (ModestMainWindow *win)
-{
-       GtkWidget *folder_view = NULL;
-       TnyFolderStore *parent_folder = NULL;
-       gboolean result = FALSE;
-
-       folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
-                                                          MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
-       if (!folder_view)
-               return FALSE;
-
-       /* Get selected folder as parent of new folder to create */
-       parent_folder = modest_folder_view_get_selected (MODEST_FOLDER_VIEW(folder_view));
-       if (!parent_folder)
-               return TRUE;
-       
-       if (TNY_IS_ACCOUNT (parent_folder)) {
-               /* If it's the local account then do not dim */
-               if (modest_tny_account_is_virtual_local_folders (TNY_ACCOUNT (parent_folder))) {
-                       result = FALSE;
-               } else {
-                               /* If it's the MMC root folder then dim it */
-                       if (!strcmp (tny_account_get_id (TNY_ACCOUNT (parent_folder)), MODEST_MMC_ACCOUNT_ID)) {
-                                       result = TRUE;
-                       } else {
-                               const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (parent_folder));
-                               /* If it's POP then dim */
-                               result = (modest_protocol_info_get_transport_store_protocol (proto_str) == 
-                                                 MODEST_PROTOCOL_STORE_POP) ? TRUE : FALSE;
-                       }
-               }
-       }
-       g_object_unref (parent_folder);
-
        return result;
 }
 
@@ -2115,7 +2033,7 @@ _header_view_is_all_selected (ModestMainWindow *win)
 static gboolean
 _selected_folder_is_empty (ModestMainWindow *win)
 {
-       GtkWidget *folder_view = NULL;
+       GtkWidget *folder_view = NULL, *header_view = NULL;
        TnyFolderStore *folder = NULL;
        gboolean result = FALSE;
 
@@ -2124,8 +2042,12 @@ _selected_folder_is_empty (ModestMainWindow *win)
        /* Get folder view */
        folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
                                                           MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
+
+       header_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
+                                                          MODEST_MAIN_WINDOW_WIDGET_TYPE_HEADER_VIEW);
+
        /* If no folder view, always dimmed */
-       if (!folder_view)
+       if (!folder_view || !header_view)
                return TRUE;
        
        /* Get selected folder as parent of new folder to create */
@@ -2137,7 +2059,9 @@ _selected_folder_is_empty (ModestMainWindow *win)
        }
        
        /* Check folder type */
-       result = tny_folder_get_all_count (TNY_FOLDER (folder)) == 0;
+       if (modest_header_view_is_empty (MODEST_HEADER_VIEW (header_view)) ||
+           tny_folder_get_all_count (TNY_FOLDER (folder)) == 0)
+               result = TRUE;
 
        /* free */
        g_object_unref (folder);
@@ -2406,9 +2330,15 @@ _invalid_attach_selected (ModestWindow *win,
                        while (!tny_iterator_is_done (iter) && !result) {
                                TnyMimePart *mime_part = TNY_MIME_PART (tny_iterator_get_current (iter));
                                TnyList *nested_list = tny_simple_list_new ();
-                               if (!for_remove && TNY_IS_MSG (mime_part)) {
-                                       selected_messages = TRUE;
-                                       result = TRUE;
+
+                               if (!for_remove && modest_tny_mime_part_is_msg (mime_part)) {
+                                       TnyMsg *window_msg;
+                                       window_msg = modest_msg_view_window_get_message (MODEST_MSG_VIEW_WINDOW (win));
+                                       if ((TnyMimePart *) window_msg != mime_part) {
+                                               selected_messages = TRUE;
+                                               result = TRUE;
+                                       }
+                                       g_object_unref (window_msg);
                                }
                                tny_mime_part_get_parts (mime_part, nested_list);
                                if (!for_remove && tny_list_get_length (nested_list) > 0) {
@@ -2466,7 +2396,7 @@ _purged_attach_selected (ModestWindow *win, gboolean all, ModestDimmingRule *rul
        if (attachments == NULL)
                return FALSE;
 
-       if (tny_list_get_length (attachments)) {
+       if (tny_list_get_length (attachments) == 0) {
                g_object_unref (attachments);
                return FALSE;
        }
@@ -2573,77 +2503,6 @@ _selected_msg_sent_in_progress (ModestWindow *win)
 
 
 static gboolean
-_sending_in_progress (ModestWindow *win)
-{
-       GHashTable *send_queue_cache = NULL;
-       ModestCacheMgr *cache_mgr = NULL;
-       ModestTnySendQueue *send_queue = NULL;
-       GSList *send_queues = NULL, *node = NULL;
-       gboolean result = FALSE;
-       
-       g_return_val_if_fail (MODEST_IS_MAIN_WINDOW (win), FALSE);
-       
-       /* Get send queue */
-       cache_mgr = modest_runtime_get_cache_mgr ();
-       send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
-                                                      MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE);
-       
-       g_hash_table_foreach (send_queue_cache, (GHFunc) fill_list_of_caches, &send_queues);
-       
-       for (node = send_queues; node != NULL && !result; node = g_slist_next (node)) {
-               send_queue = MODEST_TNY_SEND_QUEUE (node->data);
-               
-               /* Check if send operation is in progress */
-               result = modest_tny_send_queue_sending_in_progress (send_queue);
-       }
-       
-       return result;
-}
-
-static gboolean
-_invalid_account_for_purge (ModestWindow *win,
-                           ModestDimmingRule *rule)
-{
-       const gchar *account_name;
-       ModestTnyAccountStore *account_store;
-       TnyAccount *store_account = NULL;
-       gboolean result = FALSE;
-       const gchar *protocol_name;
-
-       account_name = modest_window_get_active_account (win);
-       if (account_name == NULL)
-               goto frees;
-
-       account_store = modest_runtime_get_account_store ();
-       store_account = modest_tny_account_store_get_server_account (account_store, account_name, TNY_ACCOUNT_TYPE_STORE);
-       if (store_account == NULL)
-               goto frees;
-
-       protocol_name = tny_account_get_proto (store_account);
-       if (modest_protocol_info_get_transport_store_protocol (protocol_name) == MODEST_PROTOCOL_STORE_POP) {
-               gint n_selected = 0;
-               result = TRUE;
-
-               if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
-                       TnyList *attachments;
-                       attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win));
-                       n_selected = tny_list_get_length (attachments);
-                       g_object_unref (attachments);
-               }
-                       
-               modest_dimming_rule_set_notification (rule, 
-                                                     ngettext ("mail_ib_unable_to_pure_attach_pop_mail_singular",
-                                                               "mail_ib_unable_to_pure_attach_pop_mail_plural", 
-                                                               n_selected));
-               
-       }
-frees:
-       if (store_account)
-               g_object_unref (store_account);
-       return result;
-}
-
-static gboolean
 _invalid_folder_for_purge (ModestWindow *win, 
                           ModestDimmingRule *rule)
 {
@@ -2659,7 +2518,7 @@ _invalid_folder_for_purge (ModestWindow *win,
                folder = tny_msg_get_folder (msg);      
                g_object_unref (msg);
                if (folder == NULL) {
-                       modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments"));
+                       result = TRUE;
                        goto frees;
                }
        } else if (MODEST_IS_MAIN_WINDOW (win)) {
@@ -2667,7 +2526,8 @@ _invalid_folder_for_purge (ModestWindow *win,
                                                                              MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
                if (!folder_view)
                        return FALSE;
-               folder = TNY_FOLDER (modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view)));
+               folder = (TnyFolder *) modest_folder_view_get_selected (MODEST_FOLDER_VIEW (folder_view));
+               /* Could be a folder store */
                if (folder == NULL || ! TNY_IS_FOLDER (folder))
                        goto frees;             
        } else {
@@ -2684,31 +2544,14 @@ _invalid_folder_for_purge (ModestWindow *win,
                
                if (_selected_folder_is_any_of_type (win, types, 2)) {
                        result = TRUE;
-                       modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_editable_msg"));
-               } else {
-                       result = FALSE;
                }
        } else {
-               const gchar *proto_str = tny_account_get_proto (TNY_ACCOUNT (account));
-               /* If it's POP then dim */
-               if (modest_protocol_info_get_transport_store_protocol (proto_str) == 
-                   MODEST_PROTOCOL_STORE_POP) {
-                       TnyList *attachments = NULL;
-                       gint n_selected = 0;
+               ModestProtocolType protocol_type = modest_tny_account_get_protocol_type (TNY_ACCOUNT (account));
+               /* If it's a remote folder then dim */
+               if (modest_protocol_registry_protocol_type_has_tag (modest_runtime_get_protocol_registry (),
+                                                                   protocol_type,
+                                                                   MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS)) {
                        result = TRUE;
-                       
-                       /* TODO: This check is here to prevent a gwarning, but this looks like a logic error.
-                        * murrayc */
-                       if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
-                               attachments = modest_msg_view_window_get_attachments (MODEST_MSG_VIEW_WINDOW(win));
-                               n_selected = tny_list_get_length (attachments);
-                               g_object_unref (attachments);
-                       }
-                       
-                       modest_dimming_rule_set_notification (rule, 
-                                                             ngettext ("mail_ib_unable_to_pure_attach_pop_mail_singular",
-                                                                       "mail_ib_unable_to_pure_attach_pop_mail_plural", 
-                                                                       n_selected));
                }
        }
        
@@ -2782,18 +2625,13 @@ modest_ui_dimming_rules_on_save_to_drafts (ModestWindow *win,
                                           gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
-       gboolean dimmed = FALSE;
 
        g_return_val_if_fail (MODEST_MSG_EDIT_WINDOW (win), FALSE);
        g_return_val_if_fail (MODEST_IS_DIMMING_RULE (user_data), FALSE);
        rule = MODEST_DIMMING_RULE (user_data);
 
        /* Check dimmed rule */ 
-       if (!dimmed) {
-               dimmed = !modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (win));
-       }
-
-       return dimmed;  
+       return !modest_msg_edit_window_is_modified (MODEST_MSG_EDIT_WINDOW (win));
 }
 
 gboolean