Increase the limit of characters to "secure" headers to 2048
[modest] / src / modest-ui-dimming-rules.c
index 355be4f..011b495 100644 (file)
@@ -47,6 +47,7 @@
 #include <widgets/modest-attachments-view.h>
 #include <modest-runtime.h>
 #include <tny-simple-list.h>
+#include <tny-merge-folder.h>
 #include <widgets/modest-recpt-editor.h>
 #include <gtkhtml/gtkhtml.h>
 #include <modest-runtime.h>
@@ -85,6 +86,7 @@ static void fill_list_of_caches (gpointer key, gpointer value, gpointer userdata
 static gboolean _send_receive_in_progress (ModestWindow *win);
 static gboolean _msgs_send_in_progress (void);
 static gboolean _all_msgs_in_sending_status (ModestHeaderView *header_view) G_GNUC_UNUSED;
+static gboolean _forbid_outgoing_xfers (ModestWindow *window);
 
 static DimmedState *
 _define_main_window_dimming_state (ModestMainWindow *window)
@@ -639,7 +641,8 @@ modest_ui_dimming_rules_on_open_msg (ModestWindow *win, gpointer user_data)
        /* Check dimmed rule */ 
        dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), TRUE, user_data);      
        if (!dimmed) {
-               dimmed = state->any_marked_as_deleted;
+               if (state)
+                       dimmed = state->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);
@@ -796,12 +799,14 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                        dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
                }
                if (!dimmed) {
-                       dimmed = state->sent_in_progress;
+                       if (state)
+                               dimmed = state->sent_in_progress;
                        if (dimmed)
                                modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
                }
                if (!dimmed) {
-                       dimmed = state->any_marked_as_deleted;
+                       if (state)
+                               dimmed = state->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);
@@ -809,18 +814,19 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                        }
                }
                if (!dimmed) {
-                       dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
-                       if (dimmed) {
-                               gchar *message = NULL;
+                       if (state) {
+                               dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
+                               if (dimmed) {
+                                       gchar *message = NULL;
 
-                               message = g_strdup_printf(_("mcen_nc_unable_to_delete_n_messages"),
-                                                         state->already_opened_msg);
-                               modest_dimming_rule_set_notification (rule, message);
-                               g_free(message);
+                                       message = g_strdup_printf(_("mcen_nc_unable_to_delete_n_messages"),
+                                                                 state->already_opened_msg);
+                                       modest_dimming_rule_set_notification (rule, message);
+                                       g_free(message);
+                               }
                        }
-
                }
-       } 
+       }
        else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
                /* This could happen if we load the msg view window with a
                   preview before loading the full message */
@@ -832,7 +838,8 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                }
 
                if (!dimmed) {
-                       dimmed = state->any_marked_as_deleted;
+                       if (state)
+                               dimmed = state->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);
@@ -840,7 +847,8 @@ modest_ui_dimming_rules_on_delete_msg (ModestWindow *win, gpointer user_data)
                        }
                }
                if (!dimmed) {
-                       dimmed = state->sent_in_progress;
+                       if (state)
+                               dimmed = state->sent_in_progress;
                        if (dimmed)
                                modest_dimming_rule_set_notification (rule, _CS("ckct_ib_unable_to_delete"));
                }
@@ -1033,7 +1041,8 @@ modest_ui_dimming_rules_on_mark_as_read_msg (ModestWindow *win, gpointer user_da
        /* Check dimmed rule */ 
        dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);     
        if (!dimmed) {
-               dimmed = state->all_marked_as_seen;
+               if (state)
+                       dimmed = state->all_marked_as_seen;
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, "");
        }       
@@ -1059,7 +1068,8 @@ modest_ui_dimming_rules_on_mark_as_unread_msg (ModestWindow *win, gpointer user_
        /* Check dimmed rule */ 
        dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
        if (!dimmed) {
-               dimmed = !state->any_marked_as_seen;
+               if (state)
+                       dimmed = !state->any_marked_as_seen;
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, "");
        }
@@ -1108,11 +1118,35 @@ modest_ui_dimming_rules_on_main_window_move_to (ModestWindow *win, gpointer user
        folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW(win),
                                                           MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
 
-       
+       if (folder_view) {
+               TnyFolderStore *selected = modest_folder_view_get_selected ((ModestFolderView *)folder_view);
+               if (selected) {
+                       TnyAccount *account = NULL;
+
+                       if (TNY_IS_ACCOUNT (selected)) {
+                               account = g_object_ref (selected);
+                       } else if (!TNY_IS_MERGE_FOLDER (selected)){
+                               account = tny_folder_get_account (TNY_FOLDER (selected));
+                       }
+                       if (account) {
+                               ModestProtocolType protocol_type;
+
+                               protocol_type = modest_tny_account_get_protocol_type (account);
+                               dimmed  = modest_protocol_registry_protocol_type_has_tag
+                                       (modest_runtime_get_protocol_registry (),
+                                        protocol_type,
+                                        MODEST_PROTOCOL_REGISTRY_STORE_FORBID_OUTGOING_XFERS);
+
+                               g_object_unref (account);
+                       }
+                       g_object_unref (selected);
+               }
+       }
+
        /* Check diming rules for folders transfer  */
-       if (folder_view && gtk_widget_is_focus (folder_view)) {
+       if (!dimmed && folder_view && gtk_widget_is_focus (folder_view)) {
                TnyFolderType types[5];
-               
+
                types[0] = TNY_FOLDER_TYPE_DRAFTS; 
                types[1] = TNY_FOLDER_TYPE_OUTBOX;
                types[2] = TNY_FOLDER_TYPE_SENT;
@@ -1132,25 +1166,53 @@ modest_ui_dimming_rules_on_main_window_move_to (ModestWindow *win, gpointer user
        
        /* Check diming rules for messages transfer  */
        if (!dimmed) {
-               dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
-               if (dimmed) {
-                       gchar *message = g_strdup_printf(_("emev_nc_unabletomove_items"),
-                                                        state->already_opened_msg);
-                       modest_dimming_rule_set_notification (rule, message);
-                       g_free(message);
+               if (state) {
+                       dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
+                       if (dimmed) {
+                               gchar *message = g_strdup_printf(_("emev_nc_unabletomove_items"),
+                                                                state->already_opened_msg);
+                               modest_dimming_rule_set_notification (rule, message);
+                               g_free(message);
+                       }
                }
        }
        if (!dimmed) {
                if (!(folder_view && gtk_widget_is_focus (folder_view)))
                        dimmed = _invalid_msg_selected (MODEST_MAIN_WINDOW(win), FALSE, user_data);
-               
+
        }
        if (!dimmed) {
                dimmed = _selected_msg_sent_in_progress (win);
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, _("sfil_ib_unable_to_move_selected_items"));
        }
-       
+
+       return dimmed;
+}
+
+static gboolean
+_forbid_outgoing_xfers (ModestWindow *window)
+{
+       const gchar *account_name;
+       TnyAccount *account;
+       gboolean dimmed = FALSE;
+
+       account_name = modest_window_get_active_account (window);
+       account = modest_tny_account_store_get_server_account (modest_runtime_get_account_store (),
+                                                              account_name,
+                                                              TNY_ACCOUNT_TYPE_STORE);
+
+       if (account) {
+               ModestProtocolType protocol_type;
+
+               protocol_type = modest_tny_account_get_protocol_type (account);
+               dimmed  = modest_protocol_registry_protocol_type_has_tag
+                       (modest_runtime_get_protocol_registry (),
+                        protocol_type,
+                        MODEST_PROTOCOL_REGISTRY_STORE_FORBID_OUTGOING_XFERS);
+
+               g_object_unref (account);
+       }
        return dimmed;
 }
 
@@ -1174,19 +1236,25 @@ modest_ui_dimming_rules_on_view_window_move_to (ModestWindow *win, gpointer user
        }
 
        /* Check dimmed rule */
-
        dimmed = _transfer_mode_enabled (win);
        if (dimmed)
-               modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));     
+               modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
+
+       if (!dimmed)
+               dimmed = _forbid_outgoing_xfers (win);
+
        if (!dimmed) {
-               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);
+               const DimmedState *state = modest_window_get_dimming_state (win);
+               if (state) {
+                       dimmed = state->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) {
                dimmed = _selected_msg_sent_in_progress (win);
                if (dimmed)
@@ -1208,7 +1276,6 @@ modest_ui_dimming_rules_on_view_window_move_to (ModestWindow *win, gpointer user
                                dimmed = !modest_msg_view_window_has_headers_model (MODEST_MSG_VIEW_WINDOW (win));
                        }
                }
-               
                if (dimmed) 
                        modest_dimming_rule_set_notification (rule, _("emev_nc_unabletomove_item"));
        }
@@ -1216,11 +1283,8 @@ modest_ui_dimming_rules_on_view_window_move_to (ModestWindow *win, gpointer user
        return dimmed;
 }
 
-#ifdef MODEST_TOOLKIT_HILDON2
-#endif
-
 gboolean 
-modest_ui_dimming_rules_on_find_msg (ModestWindow *win, gpointer user_data)
+modest_ui_dimming_rules_on_find_in_msg (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
        gboolean dimmed = FALSE;
@@ -1490,7 +1554,8 @@ modest_ui_dimming_rules_on_remove_attachments (ModestWindow *win, gpointer user_
 
        /* Check if the selected message in main window has attachments */
        if (!dimmed && MODEST_IS_MAIN_WINDOW (win)) {
-               dimmed = !(state->any_has_attachments);
+               if (state)
+                       dimmed = !(state->any_has_attachments);
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, _("mail_ib_unable_to_purge_attachments"));
        }
@@ -1581,7 +1646,8 @@ modest_ui_dimming_rules_on_cut (ModestWindow *win, gpointer user_data)
                                        modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_cut_mess"));
                        }
                        if (!dimmed) {
-                               dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
+                               if (state)
+                                       dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
                                if(dimmed)
                                        modest_dimming_rule_set_notification (rule, _("mcen_ib_unable_to_cut_mess"));
                        }
@@ -1646,7 +1712,8 @@ modest_ui_dimming_rules_on_copy (ModestWindow *win, gpointer user_data)
                                        modest_dimming_rule_set_notification (rule, _(""));
                        }
                        if (!dimmed) {
-                               dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
+                               if (state)
+                                       dimmed = (state->already_opened_msg > 0) ? TRUE : FALSE;
                                if(dimmed)
                                        modest_dimming_rule_set_notification (rule, _(""));
                        }
@@ -1678,14 +1745,11 @@ gboolean
 modest_ui_dimming_rules_on_set_style (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
-       const DimmedState *state = NULL;
        gboolean dimmed = FALSE;
        
        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);
-
 
        /* Check common dimming rules */
        ModestMsgEditFormat format;
@@ -1713,13 +1777,11 @@ gboolean
 modest_ui_dimming_rules_on_zoom (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
-       const DimmedState *state = NULL;
        gboolean dimmed = FALSE;
        
        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);
 
        GtkWidget *body;
        body = modest_msg_edit_window_get_child_widget (MODEST_MSG_EDIT_WINDOW (win),
@@ -1736,14 +1798,12 @@ gboolean
 modest_ui_dimming_rules_on_editor_paste (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
-       const DimmedState *state = NULL;
        gboolean dimmed = FALSE;
        GtkWidget *focused = 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);
 
        focused = gtk_window_get_focus (GTK_WINDOW (win));
 
@@ -1768,7 +1828,6 @@ gboolean
 modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer user_data)
 {
        ModestDimmingRule *rule = NULL;
-       const DimmedState *state = NULL;
        gboolean dimmed = FALSE;
        TnyList *selected_attachments = NULL;
        gint n_att_selected = 0;
@@ -1777,7 +1836,6 @@ modest_ui_dimming_rules_on_editor_remove_attachment (ModestWindow *win, gpointer
        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);
 
        attachments_view = modest_msg_edit_window_get_child_widget (
                                                                    MODEST_MSG_EDIT_WINDOW (win),
@@ -1802,40 +1860,25 @@ gboolean
 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;
-       const gchar *subject = NULL;
+       GtkWidget *body_field;
 
        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);
 
-       body_field = modest_msg_edit_window_get_child_widget (
-                                                             MODEST_MSG_EDIT_WINDOW (win),
+       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);
-       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;
                GtkTextBuffer * to_buffer, *cc_buffer, *bcc_buffer;
-               cc_field = modest_msg_edit_window_get_child_widget (
-                       MODEST_MSG_EDIT_WINDOW (win),
-                       MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_CC);
-               to_field = modest_msg_edit_window_get_child_widget (
-                       MODEST_MSG_EDIT_WINDOW (win),
-                       MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_TO);
-               bcc_field = modest_msg_edit_window_get_child_widget (
-                       MODEST_MSG_EDIT_WINDOW (win),
-                       MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BCC);
+               cc_field = modest_msg_edit_window_get_child_widget (MODEST_MSG_EDIT_WINDOW (win),
+                                                                   MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_CC);
+               to_field = modest_msg_edit_window_get_child_widget (MODEST_MSG_EDIT_WINDOW (win),
+                                                                   MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_TO);
+               bcc_field = modest_msg_edit_window_get_child_widget (MODEST_MSG_EDIT_WINDOW (win),
+                                                                    MODEST_MSG_EDIT_WINDOW_WIDGET_TYPE_BCC);
                to_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (to_field));
                cc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (cc_field));
                bcc_buffer = modest_recpt_editor_get_buffer (MODEST_RECPT_EDITOR (bcc_field));
@@ -1958,7 +2001,8 @@ modest_ui_dimming_rules_on_cancel_sending (ModestWindow *win, gpointer user_data
        if (dimmed) 
                modest_dimming_rule_set_notification (rule, "");        
        if (!dimmed) {
-               dimmed = !state->sent_in_progress;
+               if (state)
+                       dimmed = !state->sent_in_progress;
                if (dimmed)
                        modest_dimming_rule_set_notification (rule, "");
        }
@@ -2350,7 +2394,7 @@ _header_view_is_all_selected (ModestMainWindow *win)
 
        state = modest_window_get_dimming_state (MODEST_WINDOW(win));
 
-       return state->all_selected;
+       return (state) ? state->all_selected : TRUE;
 }
 
 static gboolean
@@ -2542,12 +2586,11 @@ static gboolean
 _invalid_clipboard_selected (ModestWindow *win,
                             ModestDimmingRule *rule) 
 {
-       const DimmedState *state = NULL;
        gboolean result = FALSE;
        GtkWidget *focused = NULL;
 
        g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
-       state = modest_window_get_dimming_state (win);
+
        /* Get focuesed widget */
        focused = gtk_window_get_focus (GTK_WINDOW (win));
 
@@ -2563,7 +2606,7 @@ _invalid_clipboard_selected (ModestWindow *win,
                result = !has_selection;
        } else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
                if (focused) {
-                       MODEST_DEBUG_BLOCK (g_message ("FOCUSED %s", g_type_name (G_TYPE_FROM_INSTANCE (focused))););
+                       MODEST_DEBUG_BLOCK (g_debug ("FOCUSED %s", g_type_name (G_TYPE_FROM_INSTANCE (focused))););
                        if (GTK_IS_LABEL (focused) && 
                            !gtk_label_get_selection_bounds (GTK_LABEL (focused), NULL, NULL)) {
                                result = TRUE;
@@ -2598,8 +2641,12 @@ _invalid_clipboard_selected (ModestWindow *win,
                
        }               
        else if (MODEST_IS_MAIN_WINDOW (win)) {
+               const DimmedState *state = NULL;
+
                /* Check dimming */
-               result = state->n_selected == 0;
+               state = modest_window_get_dimming_state (win);
+               if (state)
+                       result = state->n_selected == 0;
                if (result)
                        modest_dimming_rule_set_notification (rule, _("mcen_ib_no_message_selected"));                  
        }
@@ -2620,16 +2667,17 @@ _invalid_attach_selected (ModestWindow *win,
        TnyHeaderFlags flags;
        gboolean nested_attachments = FALSE;
        gboolean selected_messages = FALSE;
-       const DimmedState *state = NULL;
        gboolean result = FALSE;
 
        g_return_val_if_fail (MODEST_IS_WINDOW(win), FALSE);
-       state = modest_window_get_dimming_state (win);
 
        if (MODEST_IS_MAIN_WINDOW (win)) {
                flags = TNY_HEADER_FLAG_ATTACHMENTS;
-               if (!result)
+               if (!result) {
+                       const DimmedState *state = NULL;
+                       state = modest_window_get_dimming_state (win);
                        result = !state->any_has_attachments;
+               }
        }
        else if (MODEST_IS_MSG_VIEW_WINDOW (win)) {
                
@@ -2779,24 +2827,28 @@ _invalid_msg_selected (ModestMainWindow *win,
        GtkWidget *folder_view = NULL;
        const DimmedState *state = NULL;
        gboolean result = FALSE;
+       gint n_selected = 0;
 
        g_return_val_if_fail (MODEST_IS_MAIN_WINDOW(win), FALSE);
        g_return_val_if_fail (MODEST_IS_DIMMING_RULE (rule), FALSE);
+
        state = modest_window_get_dimming_state (MODEST_WINDOW(win));
-               
+       if (state)
+               n_selected = state->n_selected;
+
        /* Get folder view to check focus */
        folder_view = modest_main_window_get_child_widget (MODEST_MAIN_WINDOW (win),
                                                           MODEST_MAIN_WINDOW_WIDGET_TYPE_FOLDER_VIEW);
 
        /* Check dimmed rule (TODO: check focus on widgets */   
        if (!result) {
-               result = ((state->n_selected == 0 ) ||
+               result = ((n_selected == 0 ) ||
                          (gtk_widget_is_focus (folder_view)));
                if (result)
                        modest_dimming_rule_set_notification (rule, _("mcen_ib_no_message_selected"));
        }
        if (!result && unique) {
-               result = state->n_selected > 1;
+               result = n_selected > 1;
                if (result)
                        modest_dimming_rule_set_notification (rule, _("mcen_ib_select_one_message"));
        }
@@ -2826,7 +2878,7 @@ static gboolean
 _msg_download_completed (ModestMainWindow *win)
 {
        const DimmedState *state = modest_window_get_dimming_state (MODEST_WINDOW(win));
-       return state->any_marked_as_cached;
+       return (state) ? state->any_marked_as_cached : TRUE;
 }
 
 static void 
@@ -2840,7 +2892,7 @@ static gboolean
 _selected_msg_sent_in_progress (ModestWindow *win)
 {
        const DimmedState *state = modest_window_get_dimming_state (win);
-       return state->sent_in_progress;
+       return (state) ? state->sent_in_progress : TRUE;
 }
 
 
@@ -3102,6 +3154,9 @@ modest_ui_dimming_rules_on_header_window_move_to (ModestWindow *win, gpointer us
        if (dimmed)
                modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
 
+       if (!dimmed)
+               dimmed = _forbid_outgoing_xfers (win);
+
        if (!dimmed) {
                GtkWidget *header_view;
                TnyFolder *folder;
@@ -3138,7 +3193,10 @@ modest_ui_dimming_rules_on_folder_window_move_to (ModestWindow *win, gpointer us
        if (dimmed)
                modest_dimming_rule_set_notification (rule, _("mail_ib_notavailable_downloading"));
 
-       if (MODEST_IS_FOLDER_WINDOW (win)) {
+       if (!dimmed)
+               dimmed = _forbid_outgoing_xfers (win);
+
+       if (!dimmed && MODEST_IS_FOLDER_WINDOW (win)) {
                ModestFolderView *folder_view;
                folder_view = modest_folder_window_get_folder_view (MODEST_FOLDER_WINDOW (win));
                dimmed = !modest_folder_view_any_folder_fulfils_rules (folder_view,