diff options
Diffstat (limited to 'mail')
-rw-r--r-- | mail/e-mail-browser.c | 37 | ||||
-rw-r--r-- | mail/e-mail-folder-pane.c | 28 | ||||
-rw-r--r-- | mail/e-mail-paned-view.c | 67 | ||||
-rw-r--r-- | mail/e-mail-reader-utils.c | 100 | ||||
-rw-r--r-- | mail/e-mail-reader.c | 237 | ||||
-rw-r--r-- | mail/e-mail-reader.h | 4 |
6 files changed, 286 insertions, 187 deletions
diff --git a/mail/e-mail-browser.c b/mail/e-mail-browser.c index 8c5e4bb1fd..2df99d618e 100644 --- a/mail/e-mail-browser.c +++ b/mail/e-mail-browser.c @@ -262,8 +262,6 @@ mail_browser_message_selected_cb (EMailBrowser *browser, CamelMessageInfo *info; CamelFolder *folder; EMailReader *reader; - EMailDisplay *display; - const gchar *title; guint32 state; reader = E_MAIL_READER (browser); @@ -273,24 +271,30 @@ mail_browser_message_selected_cb (EMailBrowser *browser, if (uid == NULL) return; - folder = e_mail_reader_get_folder (reader); - display = e_mail_reader_get_mail_display (reader); + folder = e_mail_reader_ref_folder (reader); info = camel_folder_get_message_info (folder, uid); - if (info == NULL) - return; + if (info != NULL) { + EMailDisplay *display; + const gchar *title; + + display = e_mail_reader_get_mail_display (reader); - title = camel_message_info_subject (info); - if (title == NULL || *title == '\0') - title = _("(No Subject)"); + title = camel_message_info_subject (info); + if (title == NULL || *title == '\0') + title = _("(No Subject)"); - gtk_window_set_title (GTK_WINDOW (browser), title); - gtk_widget_grab_focus (GTK_WIDGET (display)); + gtk_window_set_title (GTK_WINDOW (browser), title); + gtk_widget_grab_focus (GTK_WIDGET (display)); - camel_message_info_set_flags ( - info, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN); - camel_folder_free_message_info (folder, info); + camel_message_info_set_flags ( + info, CAMEL_MESSAGE_SEEN, CAMEL_MESSAGE_SEEN); + + camel_folder_free_message_info (folder, info); + } + + g_clear_object (&folder); } static gboolean @@ -851,7 +855,8 @@ mail_browser_set_message (EMailReader *reader, return; } - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); + info = camel_folder_get_message_info (folder, uid); if (info != NULL) { @@ -860,6 +865,8 @@ mail_browser_set_message (EMailReader *reader, camel_message_info_subject (info)); camel_folder_free_message_info (folder, info); } + + g_clear_object (&folder); } static void diff --git a/mail/e-mail-folder-pane.c b/mail/e-mail-folder-pane.c index 300835384e..5da74e4e7b 100644 --- a/mail/e-mail-folder-pane.c +++ b/mail/e-mail-folder-pane.c @@ -76,10 +76,10 @@ mail_paned_view_open_selected_mail (EMailPanedView *view) GtkWindow *window; CamelFolder *folder; GPtrArray *views; - guint n_views, ii; + guint ii, n_views = 0; reader = E_MAIL_READER (view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); window = e_mail_reader_get_window (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_val_if_fail (uids != NULL, 0); @@ -92,17 +92,22 @@ mail_paned_view_open_selected_mail (EMailPanedView *view) * or MessageList should do this itself. */ g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (!em_utils_ask_open_many (window, uids->len)) { - g_ptr_array_unref (uids); - return 0; + if (!em_utils_ask_open_many (window, uids->len)) + goto exit; + + if (em_utils_folder_is_drafts (registry, folder)) { + e_mail_reader_edit_messages (reader, folder, uids, TRUE, TRUE); + goto exit; + } + + if (em_utils_folder_is_outbox (registry, folder)) { + e_mail_reader_edit_messages (reader, folder, uids, TRUE, TRUE); + goto exit; } - if (em_utils_folder_is_drafts (registry, folder) || - em_utils_folder_is_outbox (registry, folder) || - em_utils_folder_is_templates (registry, folder)) { + if (em_utils_folder_is_templates (registry, folder)) { e_mail_reader_edit_messages (reader, folder, uids, TRUE, TRUE); - g_ptr_array_unref (uids); - return 0; + goto exit; } views = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free); @@ -151,6 +156,9 @@ mail_paned_view_open_selected_mail (EMailPanedView *view) g_signal_emit_by_name (view, "open-mail", views->pdata[i]); g_ptr_array_unref (views); + +exit: + g_clear_object (&folder); g_ptr_array_unref (uids); return n_views; diff --git a/mail/e-mail-paned-view.c b/mail/e-mail-paned-view.c index 440c83b624..67cf5b90b1 100644 --- a/mail/e-mail-paned-view.c +++ b/mail/e-mail-paned-view.c @@ -92,31 +92,34 @@ mail_paned_view_save_boolean (EMailView *view, const gchar *key, gboolean value) { - EShellView *shell_view; EMailReader *reader; CamelFolder *folder; - GKeyFile *key_file; - gchar *folder_uri; - gchar *group_name; - - shell_view = e_mail_view_get_shell_view (view); - key_file = e_shell_view_get_state_key_file (shell_view); reader = E_MAIL_READER (view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); - if (folder == NULL) - return; + if (folder != NULL) { + EShellView *shell_view; + GKeyFile *key_file; + gchar *folder_uri; + gchar *group_name; - folder_uri = e_mail_folder_uri_from_folder (folder); - group_name = g_strdup_printf ("Folder %s", folder_uri); - g_key_file_set_boolean (key_file, group_name, key, value); - g_free (group_name); - g_free (folder_uri); + shell_view = e_mail_view_get_shell_view (view); + key_file = e_shell_view_get_state_key_file (shell_view); - g_key_file_set_boolean (key_file, STATE_GROUP_GLOBAL_FOLDER, key, value); + folder_uri = e_mail_folder_uri_from_folder (folder); + group_name = g_strdup_printf ("Folder %s", folder_uri); + g_key_file_set_boolean (key_file, group_name, key, value); + g_free (group_name); + g_free (folder_uri); - e_shell_view_set_state_dirty (shell_view); + g_key_file_set_boolean ( + key_file, STATE_GROUP_GLOBAL_FOLDER, key, value); + + e_shell_view_set_state_dirty (shell_view); + + g_object_unref (folder); + } } static void @@ -828,7 +831,7 @@ mail_paned_view_update_view_instance (EMailView *view) registry = e_shell_get_registry (shell); reader = E_MAIL_READER (view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); /* If no folder is selected, return silently. */ if (folder == NULL) @@ -852,12 +855,18 @@ mail_paned_view_update_view_instance (EMailView *view) settings, "global-view-setting"); g_object_unref (settings); - if (global_view_setting) + if (global_view_setting) { + if (outgoing_folder) { + view_instance = e_shell_view_new_view_instance ( + shell_view, "global_view_sent_setting"); + } else { + view_instance = e_shell_view_new_view_instance ( + shell_view, "global_view_setting"); + } + } else { view_instance = e_shell_view_new_view_instance ( - shell_view, outgoing_folder ? - "global_view_sent_setting" : "global_view_setting"); - else - view_instance = e_shell_view_new_view_instance (shell_view, view_id); + shell_view, view_id); + } priv->view_instance = view_instance; @@ -869,29 +878,23 @@ mail_paned_view_update_view_instance (EMailView *view) if (show_vertical_view) { gchar *filename; - gchar *safe_view_id; /* Force the view instance into vertical view. */ g_free (view_instance->custom_filename); g_free (view_instance->current_view_filename); - safe_view_id = g_strdup (view_id); - e_filename_make_safe (safe_view_id); - filename = g_strdup_printf ( - "custom_wide_view-%s.xml", safe_view_id); + "custom_wide_view-%s.xml", view_id); view_instance->custom_filename = g_build_filename ( view_collection->local_dir, filename, NULL); g_free (filename); filename = g_strdup_printf ( - "current_wide_view-%s.xml", safe_view_id); + "current_wide_view-%s.xml", view_id); view_instance->current_view_filename = g_build_filename ( view_collection->local_dir, filename, NULL); g_free (filename); - - g_free (safe_view_id); } g_free (view_id); @@ -955,6 +958,8 @@ mail_paned_view_update_view_instance (EMailView *view) mail_paned_display_view_cb ( view, gal_view_instance_get_current_view (view_instance)); + + g_clear_object (&folder); } static void diff --git a/mail/e-mail-reader-utils.c b/mail/e-mail-reader-utils.c index 8a711a52a1..2cd9f96351 100644 --- a/mail/e-mail-reader-utils.c +++ b/mail/e-mail-reader-utils.c @@ -126,7 +126,7 @@ e_mail_reader_confirm_delete (EMailReader *reader) g_return_val_if_fail (E_IS_MAIL_READER (reader), FALSE); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); window = e_mail_reader_get_window (reader); settings = g_settings_new ("org.gnome.evolution.mail"); @@ -165,6 +165,8 @@ e_mail_reader_confirm_delete (EMailReader *reader) gtk_widget_destroy (dialog); exit: + g_clear_object (&folder); + return (response == GTK_RESPONSE_OK); } @@ -745,29 +747,33 @@ e_mail_reader_mark_selected (EMailReader *reader, guint32 set) { CamelFolder *folder; - GPtrArray *uids; - guint ii; + guint ii = 0; g_return_val_if_fail (E_IS_MAIL_READER (reader), 0); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); - if (folder == NULL) - return 0; + if (folder != NULL) { + GPtrArray *uids; - camel_folder_freeze (folder); - uids = e_mail_reader_get_selected_uids (reader); + camel_folder_freeze (folder); - for (ii = 0; ii < uids->len; ii++) - camel_folder_set_message_flags ( - folder, uids->pdata[ii], mask, set); + uids = e_mail_reader_get_selected_uids (reader); - em_utils_uids_free (uids); + for (ii = 0; ii < uids->len; ii++) + camel_folder_set_message_flags ( + folder, uids->pdata[ii], mask, set); + + em_utils_uids_free (uids); + + camel_folder_thaw (folder); - camel_folder_thaw (folder); + g_object_unref (folder); + } return ii; } + static void copy_tree_state (EMailReader *src_reader, EMailReader *des_reader) @@ -804,7 +810,7 @@ e_mail_reader_open_selected (EMailReader *reader) GtkWindow *window; GPtrArray *views; GPtrArray *uids; - guint ii; + guint ii = 0; g_return_val_if_fail (E_IS_MAIL_READER (reader), 0); @@ -812,19 +818,22 @@ e_mail_reader_open_selected (EMailReader *reader) shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); registry = e_shell_get_registry (shell); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); uids = e_mail_reader_get_selected_uids (reader); window = e_mail_reader_get_window (reader); - if (!em_utils_ask_open_many (window, uids->len)) { - em_utils_uids_free (uids); - return 0; - } + if (!em_utils_ask_open_many (window, uids->len)) + goto exit; if (em_utils_folder_is_drafts (registry, folder) || em_utils_folder_is_outbox (registry, folder) || em_utils_folder_is_templates (registry, folder)) { + + /* FIXME This is leaking the UID array. Give + * the array a "free func" and unref it. */ e_mail_reader_edit_messages (reader, folder, uids, TRUE, TRUE); + g_clear_object (&folder); + return uids->len; } @@ -858,6 +867,7 @@ e_mail_reader_open_selected (EMailReader *reader) g_ptr_array_add (edits, real_uid); e_mail_reader_edit_messages ( reader, real_folder, edits, TRUE, TRUE); + g_ptr_array_unref (edits); } else { g_free (real_uid); g_ptr_array_add (views, g_strdup (uid)); @@ -894,6 +904,8 @@ e_mail_reader_open_selected (EMailReader *reader) g_ptr_array_foreach (views, (GFunc) g_free, NULL); g_ptr_array_free (views, TRUE); +exit: + g_clear_object (&folder); em_utils_uids_free (uids); return ii; @@ -1035,14 +1047,12 @@ e_mail_reader_print (EMailReader *reader, GtkPrintOperationAction action) { EActivity *activity; - CamelFolder *folder; GCancellable *cancellable; MessageList *message_list; AsyncContext *async_context; g_return_if_fail (E_IS_MAIL_READER (reader)); - folder = e_mail_reader_get_folder (reader); message_list = MESSAGE_LIST (e_mail_reader_get_message_list (reader)); activity = e_mail_reader_new_activity (reader); @@ -1050,7 +1060,7 @@ e_mail_reader_print (EMailReader *reader, async_context = g_slice_new0 (AsyncContext); async_context->activity = g_object_ref (activity); - async_context->folder = g_object_ref (folder); + async_context->folder = e_mail_reader_ref_folder (reader); async_context->reader = g_object_ref (reader); async_context->message_uid = g_strdup (message_list->cursor_uid); async_context->print_action = action; @@ -1108,7 +1118,6 @@ e_mail_reader_remove_attachments (EMailReader *reader) g_return_if_fail (E_IS_MAIL_READER (reader)); - folder = e_mail_reader_get_folder (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); @@ -1125,6 +1134,8 @@ e_mail_reader_remove_attachments (EMailReader *reader) async_context->activity = g_object_ref (activity); async_context->reader = g_object_ref (reader); + folder = e_mail_reader_ref_folder (reader); + e_mail_folder_remove_attachments ( folder, uids, G_PRIORITY_DEFAULT, @@ -1132,6 +1143,8 @@ e_mail_reader_remove_attachments (EMailReader *reader) mail_reader_remove_attachments_cb, async_context); + g_object_unref (folder); + g_object_unref (activity); g_ptr_array_unref (uids); @@ -1248,7 +1261,6 @@ e_mail_reader_remove_duplicates (EMailReader *reader) g_return_if_fail (E_IS_MAIL_READER (reader)); - folder = e_mail_reader_get_folder (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); @@ -1265,6 +1277,8 @@ e_mail_reader_remove_duplicates (EMailReader *reader) async_context->activity = g_object_ref (activity); async_context->reader = g_object_ref (reader); + folder = e_mail_reader_ref_folder (reader); + e_mail_folder_find_duplicate_messages ( folder, uids, G_PRIORITY_DEFAULT, @@ -1272,6 +1286,8 @@ e_mail_reader_remove_duplicates (EMailReader *reader) mail_reader_remove_duplicates_cb, async_context); + g_object_unref (folder); + g_object_unref (activity); g_ptr_array_unref (uids); @@ -1756,7 +1772,6 @@ e_mail_reader_reply_to_message (EMailReader *reader, g_return_if_fail (E_IS_MAIL_READER (reader)); backend = e_mail_reader_get_backend (reader); - folder = e_mail_reader_get_folder (reader); display = e_mail_reader_get_mail_display (reader); message_list = e_mail_reader_get_message_list (reader); reply_style = e_mail_reader_get_reply_style (reader); @@ -1794,6 +1809,8 @@ e_mail_reader_reply_to_message (EMailReader *reader, uid = MESSAGE_LIST (message_list)->cursor_uid; g_return_if_fail (uid != NULL); + folder = e_mail_reader_ref_folder (reader); + if (!gtk_widget_get_visible (GTK_WIDGET (web_view))) goto whole_message; @@ -1912,14 +1929,11 @@ e_mail_reader_reply_to_message (EMailReader *reader, e_mail_reader_composer_created (reader, composer, new_message); - if (address) - g_object_unref (address); - g_object_unref (new_message); g_free (selection); - return; + goto exit; whole_message: if (src_message == NULL) { @@ -1959,7 +1973,9 @@ whole_message: e_mail_reader_composer_created (reader, composer, src_message); } +exit: g_clear_object (&address); + g_clear_object (&folder); } static void @@ -2011,7 +2027,7 @@ e_mail_reader_save_messages (EMailReader *reader) const gchar *title; gchar *suggestion = NULL; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); backend = e_mail_reader_get_backend (reader); uids = e_mail_reader_get_selected_uids (reader); @@ -2062,10 +2078,8 @@ e_mail_reader_save_messages (EMailReader *reader) shell, title, suggestion, "*.mbox:application/mbox,message/rfc822", NULL, NULL); - if (destination == NULL) { - g_ptr_array_unref (uids); - return; - } + if (destination == NULL) + goto exit; /* Save messages asynchronously. */ @@ -2087,6 +2101,9 @@ e_mail_reader_save_messages (EMailReader *reader) g_object_unref (activity); g_object_unref (destination); + +exit: + g_clear_object (&folder); g_ptr_array_unref (uids); } @@ -2198,8 +2215,8 @@ e_mail_reader_create_filter_from_selected (EMailReader *reader, shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); registry = e_shell_get_registry (shell); - folder = e_mail_reader_get_folder (reader); - g_return_if_fail (CAMEL_IS_FOLDER (folder)); + folder = e_mail_reader_ref_folder (reader); + g_return_if_fail (folder != NULL); if (em_utils_folder_is_sent (registry, folder) || em_utils_folder_is_outbox (registry, folder)) @@ -2230,6 +2247,8 @@ e_mail_reader_create_filter_from_selected (EMailReader *reader, g_object_unref (activity); em_utils_uids_free (uids); + + g_object_unref (folder); } /* Helper for e_mail_reader_create_vfolder_from_selected() */ @@ -2315,15 +2334,11 @@ e_mail_reader_create_vfolder_from_selected (EMailReader *reader, EActivity *activity; GCancellable *cancellable; AsyncContext *async_context; - CamelFolder *folder; GPtrArray *uids; const gchar *message_uid; g_return_if_fail (E_IS_MAIL_READER (reader)); - folder = e_mail_reader_get_folder (reader); - g_return_if_fail (CAMEL_IS_FOLDER (folder)); - uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL && uids->len == 1); message_uid = g_ptr_array_index (uids, 0); @@ -2333,13 +2348,14 @@ e_mail_reader_create_vfolder_from_selected (EMailReader *reader, async_context = g_slice_new0 (AsyncContext); async_context->activity = g_object_ref (activity); - async_context->folder = g_object_ref (folder); + async_context->folder = e_mail_reader_ref_folder (reader); async_context->reader = g_object_ref (reader); async_context->message_uid = g_strdup (message_uid); async_context->filter_type = vfolder_type; camel_folder_get_message ( - folder, message_uid, + async_context->folder, + async_context->message_uid, G_PRIORITY_DEFAULT, cancellable, mail_reader_create_vfolder_cb, diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c index 057e9d9025..598be3a5f2 100644 --- a/mail/e-mail-reader.c +++ b/mail/e-mail-reader.c @@ -165,7 +165,7 @@ action_mail_add_sender_cb (GtkAction *action, const gchar *address; const gchar *message_uid; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); backend = e_mail_reader_get_backend (reader); session = e_mail_backend_get_session (backend); @@ -204,6 +204,8 @@ exit: if (info != NULL) camel_folder_free_message_info (folder, info); em_utils_uids_free (uids); + + g_clear_object (&folder); } static void @@ -422,7 +424,7 @@ action_mail_check_for_junk_cb (GtkAction *action, CamelFolder *folder; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); backend = e_mail_reader_get_backend (reader); uids = e_mail_reader_get_selected_uids (reader); @@ -431,6 +433,8 @@ action_mail_check_for_junk_cb (GtkAction *action, mail_filter_folder ( session, folder, uids, E_FILTER_SOURCE_JUNKTEST, FALSE); + + g_clear_object (&folder); } static void @@ -451,7 +455,7 @@ action_mail_copy_cb (GtkAction *action, backend = e_mail_reader_get_backend (reader); session = e_mail_backend_get_session (backend); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); window = e_mail_reader_get_window (reader); uids = e_mail_reader_get_selected_uids (reader); @@ -495,6 +499,8 @@ exit: em_utils_uids_free (uids); gtk_widget_destroy (dialog); + + g_clear_object (&folder); } static void @@ -551,7 +557,7 @@ action_mail_filters_apply_cb (GtkAction *action, CamelFolder *folder; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); backend = e_mail_reader_get_backend (reader); uids = e_mail_reader_get_selected_uids (reader); @@ -560,6 +566,8 @@ action_mail_filters_apply_cb (GtkAction *action, mail_filter_folder ( session, folder, uids, E_FILTER_SOURCE_DEMAND, FALSE); + + g_clear_object (&folder); } static void @@ -592,7 +600,7 @@ action_mail_flag_clear_cb (GtkAction *action, GtkWindow *window; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); display = e_mail_reader_get_mail_display (reader); uids = e_mail_reader_get_selected_uids (reader); window = e_mail_reader_get_window (reader); @@ -600,6 +608,8 @@ action_mail_flag_clear_cb (GtkAction *action, em_utils_flag_for_followup_clear (window, folder, uids); e_mail_display_reload (display); + + g_clear_object (&folder); } static void @@ -611,7 +621,7 @@ action_mail_flag_completed_cb (GtkAction *action, GtkWindow *window; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); display = e_mail_reader_get_mail_display (reader); uids = e_mail_reader_get_selected_uids (reader); window = e_mail_reader_get_window (reader); @@ -619,6 +629,8 @@ action_mail_flag_completed_cb (GtkAction *action, em_utils_flag_for_followup_completed (window, folder, uids); e_mail_display_reload (display); + + g_clear_object (&folder); } static void @@ -628,21 +640,21 @@ action_mail_flag_for_followup_cb (GtkAction *action, CamelFolder *folder; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); uids = e_mail_reader_get_selected_uids (reader); em_utils_flag_for_followup (reader, folder, uids); + + g_clear_object (&folder); } static void action_mail_forward_cb (GtkAction *action, EMailReader *reader) { - CamelFolder *folder; GtkWindow *window; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); window = e_mail_reader_get_window (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); @@ -651,11 +663,18 @@ action_mail_forward_cb (GtkAction *action, * or MessageList should do this itself. */ g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (em_utils_ask_open_many (window, uids->len)) + if (em_utils_ask_open_many (window, uids->len)) { + CamelFolder *folder; + + folder = e_mail_reader_ref_folder (reader); + e_mail_reader_forward_messages ( reader, folder, uids, e_mail_reader_get_forward_style (reader)); + g_clear_object (&folder); + } + g_ptr_array_unref (uids); } @@ -663,11 +682,9 @@ static void action_mail_forward_attached_cb (GtkAction *action, EMailReader *reader) { - CamelFolder *folder; GtkWindow *window; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); window = e_mail_reader_get_window (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); @@ -676,11 +693,18 @@ action_mail_forward_attached_cb (GtkAction *action, * or MessageList should do this itself. */ g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (em_utils_ask_open_many (window, uids->len)) + if (em_utils_ask_open_many (window, uids->len)) { + CamelFolder *folder; + + folder = e_mail_reader_ref_folder (reader); + e_mail_reader_forward_messages ( reader, folder, uids, E_MAIL_FORWARD_STYLE_ATTACHED); + g_clear_object (&folder); + } + g_ptr_array_unref (uids); } @@ -688,11 +712,9 @@ static void action_mail_forward_inline_cb (GtkAction *action, EMailReader *reader) { - CamelFolder *folder; GtkWindow *window; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); window = e_mail_reader_get_window (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); @@ -701,11 +723,18 @@ action_mail_forward_inline_cb (GtkAction *action, * or MessageList should do this itself. */ g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (em_utils_ask_open_many (window, uids->len)) + if (em_utils_ask_open_many (window, uids->len)) { + CamelFolder *folder; + + folder = e_mail_reader_ref_folder (reader); + e_mail_reader_forward_messages ( reader, folder, uids, E_MAIL_FORWARD_STYLE_INLINE); + g_clear_object (&folder); + } + g_ptr_array_unref (uids); } @@ -713,11 +742,9 @@ static void action_mail_forward_quoted_cb (GtkAction *action, EMailReader *reader) { - CamelFolder *folder; GtkWindow *window; GPtrArray *uids; - folder = e_mail_reader_get_folder (reader); window = e_mail_reader_get_window (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); @@ -726,11 +753,18 @@ action_mail_forward_quoted_cb (GtkAction *action, * or MessageList should do this itself. */ g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); - if (em_utils_ask_open_many (window, uids->len)) + if (em_utils_ask_open_many (window, uids->len)) { + CamelFolder *folder; + + folder = e_mail_reader_ref_folder (reader); + e_mail_reader_forward_messages ( reader, folder, uids, E_MAIL_FORWARD_STYLE_QUOTED); + g_clear_object (&folder); + } + g_ptr_array_unref (uids); } @@ -755,19 +789,6 @@ action_mail_mark_important_cb (GtkAction *action, e_mail_reader_mark_selected (reader, mask, set); } -static gboolean -is_junk_folder_selected (EMailReader *reader) -{ - CamelFolder *folder; - - folder = e_mail_reader_get_folder (reader); - - if (folder == NULL) - return FALSE; - - return (folder->folder_flags & CAMEL_FOLDER_IS_JUNK) != 0; -} - static void action_mail_mark_junk_cb (GtkAction *action, EMailReader *reader) @@ -782,9 +803,21 @@ action_mail_mark_junk_cb (GtkAction *action, CAMEL_MESSAGE_JUNK | CAMEL_MESSAGE_JUNK_LEARN; - if (e_mail_reader_mark_selected (reader, mask, set) == 1 && - !is_junk_folder_selected (reader)) - e_mail_reader_select_next_message (reader, TRUE); + if (e_mail_reader_mark_selected (reader, mask, set) == 1) { + CamelFolder *folder; + gboolean select_next_message; + + folder = e_mail_reader_ref_folder (reader); + + select_next_message = + (folder != NULL) && + (folder->folder_flags & CAMEL_FOLDER_IS_JUNK); + + if (select_next_message) + e_mail_reader_select_next_message (reader, TRUE); + + g_clear_object (&folder); + } } static void @@ -799,9 +832,19 @@ action_mail_mark_notjunk_cb (GtkAction *action, CAMEL_MESSAGE_NOTJUNK | CAMEL_MESSAGE_JUNK_LEARN; - if (e_mail_reader_mark_selected (reader, mask, set) == 1 && - is_junk_folder_selected (reader)) - e_mail_reader_select_next_message (reader, TRUE); + if (e_mail_reader_mark_selected (reader, mask, set) == 1) { + CamelFolder *folder; + gboolean select_next_message; + + folder = e_mail_reader_ref_folder (reader); + + select_next_message = + (folder != NULL) && + (folder->folder_flags & CAMEL_FOLDER_IS_JUNK); + + if (select_next_message) + e_mail_reader_select_next_message (reader, TRUE); + } } static void @@ -844,11 +887,14 @@ action_mail_mark_unread_cb (GtkAction *action, MESSAGE_LIST (message_list)->seen_id = 0; } + folder = e_mail_reader_ref_folder (reader); + /* Notify the tree model that the user has marked messages as * unread so it doesn't mistake the event as new mail arriving. */ model = em_folder_tree_model_get_default (); - folder = e_mail_reader_get_folder (reader); em_folder_tree_model_user_marked_unread (model, folder, n_marked); + + g_clear_object (&folder); } static void @@ -862,7 +908,6 @@ action_mail_message_edit_cb (GtkAction *action, GPtrArray *uids; gboolean replace; - folder = e_mail_reader_get_folder (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL); @@ -874,8 +919,10 @@ action_mail_message_edit_cb (GtkAction *action, * or MessageList should do this itself. */ g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free); + folder = e_mail_reader_ref_folder (reader); replace = em_utils_folder_is_drafts (registry, folder); e_mail_reader_edit_messages (reader, folder, uids, replace, replace); + g_clear_object (&folder); g_ptr_array_unref (uids); } @@ -890,7 +937,7 @@ action_mail_message_new_cb (GtkAction *action, CamelFolder *folder; EMsgComposer *composer; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); backend = e_mail_reader_get_backend (reader); shell_backend = E_SHELL_BACKEND (backend); @@ -899,6 +946,8 @@ action_mail_message_new_cb (GtkAction *action, composer = em_utils_compose_new_message (shell, folder); e_mail_reader_composer_created (reader, composer, NULL); + + g_clear_object (&folder); } static void @@ -926,7 +975,7 @@ action_mail_move_cb (GtkAction *action, backend = e_mail_reader_get_backend (reader); session = e_mail_backend_get_session (backend); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); uids = e_mail_reader_get_selected_uids (reader); window = e_mail_reader_get_window (reader); @@ -970,6 +1019,8 @@ exit: em_utils_uids_free (uids); gtk_widget_destroy (dialog); + + g_clear_object (&folder); } static void @@ -1179,9 +1230,7 @@ action_mail_redirect_cb (GtkAction *action, CamelFolder *folder; const gchar *message_uid; - folder = e_mail_reader_get_folder (reader); message_list = e_mail_reader_get_message_list (reader); - message_uid = MESSAGE_LIST (message_list)->cursor_uid; g_return_if_fail (message_uid != NULL); @@ -1194,10 +1243,14 @@ action_mail_redirect_cb (GtkAction *action, closure->activity = activity; closure->reader = g_object_ref (reader); + folder = e_mail_reader_ref_folder (reader); + camel_folder_get_message ( folder, message_uid, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) mail_reader_redirect_cb, closure); + + g_clear_object (&folder); } static void @@ -1324,9 +1377,6 @@ action_mail_reply_all_cb (GtkAction *action, GtkWidget *message_list; const gchar *message_uid; - folder = e_mail_reader_get_folder (reader); - g_return_if_fail (CAMEL_IS_FOLDER (folder)); - message_list = e_mail_reader_get_message_list (reader); message_uid = MESSAGE_LIST (message_list)->cursor_uid; g_return_if_fail (message_uid != NULL); @@ -1338,11 +1388,15 @@ action_mail_reply_all_cb (GtkAction *action, closure->activity = activity; closure->reader = g_object_ref (reader); + folder = e_mail_reader_ref_folder (reader); + camel_folder_get_message ( folder, message_uid, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) action_mail_reply_all_check, closure); + g_clear_object (&folder); + return; } @@ -1591,9 +1645,6 @@ action_mail_reply_sender_cb (GtkAction *action, GtkWidget *message_list; const gchar *message_uid; - folder = e_mail_reader_get_folder (reader); - g_return_if_fail (CAMEL_IS_FOLDER (folder)); - message_list = e_mail_reader_get_message_list (reader); message_uid = MESSAGE_LIST (message_list)->cursor_uid; g_return_if_fail (message_uid != NULL); @@ -1605,11 +1656,15 @@ action_mail_reply_sender_cb (GtkAction *action, closure->activity = activity; closure->reader = g_object_ref (reader); + folder = e_mail_reader_ref_folder (reader); + camel_folder_get_message ( folder, message_uid, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) action_mail_reply_sender_check, closure); + g_clear_object (&folder); + return; } @@ -1742,7 +1797,7 @@ action_mail_show_source_cb (GtkAction *action, EMailReaderClosure *closure; backend = e_mail_reader_get_backend (reader); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); uids = e_mail_reader_get_selected_uids (reader); g_return_if_fail (uids != NULL && uids->len == 1); message_uid = g_ptr_array_index (uids, 0); @@ -1775,6 +1830,8 @@ action_mail_show_source_cb (GtkAction *action, g_object_unref (activity); em_utils_uids_free (uids); + + g_clear_object (&folder); } static void @@ -1785,7 +1842,7 @@ action_mail_toggle_important_cb (GtkAction *action, GPtrArray *uids; guint ii; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); uids = e_mail_reader_get_selected_uids (reader); camel_folder_freeze (folder); @@ -1806,6 +1863,7 @@ action_mail_toggle_important_cb (GtkAction *action, camel_folder_thaw (folder); + g_clear_object (&folder); em_utils_uids_free (uids); } @@ -1859,13 +1917,11 @@ action_search_folder_recipient_cb (GtkAction *action, EMailBackend *backend; EMailSession *session; EWebView *web_view; - CamelFolder *folder; CamelURL *curl; const gchar *uri; /* This action is defined in EMailDisplay. */ - folder = e_mail_reader_get_folder (reader); web_view = E_WEB_VIEW (e_mail_reader_get_mail_display (reader)); uri = e_web_view_get_selected_uri (web_view); @@ -1878,13 +1934,18 @@ action_search_folder_recipient_cb (GtkAction *action, session = e_mail_backend_get_session (backend); if (curl->path != NULL && *curl->path != '\0') { + CamelFolder *folder; CamelInternetAddress *inet_addr; + folder = e_mail_reader_ref_folder (reader); + inet_addr = camel_internet_address_new (); camel_address_decode (CAMEL_ADDRESS (inet_addr), curl->path); vfolder_gui_add_from_address ( session, inet_addr, AUTO_TO, folder); g_object_unref (inet_addr); + + g_clear_object (&folder); } camel_url_free (curl); @@ -1897,13 +1958,11 @@ action_search_folder_sender_cb (GtkAction *action, EMailBackend *backend; EMailSession *session; EWebView *web_view; - CamelFolder *folder; CamelURL *curl; const gchar *uri; /* This action is defined in EMailDisplay. */ - folder = e_mail_reader_get_folder (reader); web_view = E_WEB_VIEW (e_mail_reader_get_mail_display (reader)); uri = e_web_view_get_selected_uri (web_view); @@ -1916,13 +1975,18 @@ action_search_folder_sender_cb (GtkAction *action, session = e_mail_backend_get_session (backend); if (curl->path != NULL && *curl->path != '\0') { + CamelFolder *folder; CamelInternetAddress *inet_addr; + folder = e_mail_reader_ref_folder (reader); + inet_addr = camel_internet_address_new (); camel_address_decode (CAMEL_ADDRESS (inet_addr), curl->path); vfolder_gui_add_from_address ( session, inet_addr, AUTO_FROM, folder); g_object_unref (inet_addr); + + g_clear_object (&folder); } camel_url_free (curl); @@ -2811,15 +2875,12 @@ mail_reader_message_selected_timeout_cb (EMailReader *reader) EMailReaderPrivate *priv; EMailDisplay *display; GtkWidget *message_list; - CamelFolder *folder; const gchar *cursor_uid; const gchar *format_uid; EMailPartList *parts; priv = E_MAIL_READER_GET_PRIVATE (reader); - folder = e_mail_reader_get_folder (reader); - message_list = e_mail_reader_get_message_list (reader); display = e_mail_reader_get_mail_display (reader); parts = e_mail_display_get_parts_list (display); @@ -2844,6 +2905,7 @@ mail_reader_message_selected_timeout_cb (EMailReader *reader) if (display_visible && selected_uid_changed) { EMailReaderClosure *closure; GCancellable *cancellable; + CamelFolder *folder; EActivity *activity; gchar *string; @@ -2862,11 +2924,15 @@ mail_reader_message_selected_timeout_cb (EMailReader *reader) closure->reader = g_object_ref (reader); closure->message_uid = g_strdup (cursor_uid); + folder = e_mail_reader_ref_folder (reader); + camel_folder_get_message ( folder, cursor_uid, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) mail_reader_message_loaded_cb, closure); + g_clear_object (&folder); + if (priv->retrieving_message != NULL) g_object_unref (priv->retrieving_message); priv->retrieving_message = g_object_ref (cancellable); @@ -2990,21 +3056,13 @@ mail_reader_get_selected_uids (EMailReader *reader) } static CamelFolder * -mail_reader_get_folder (EMailReader *reader) +mail_reader_ref_folder (EMailReader *reader) { GtkWidget *message_list; - CamelFolder *folder; message_list = e_mail_reader_get_message_list (reader); - /* FIXME This is dangerous. EMailReader should return a - * new CamelFolder reference and rename this method - * to "ref_folder()" instead of "get_folder()". */ - folder = message_list_ref_folder (MESSAGE_LIST (message_list)); - if (folder != NULL) - g_object_unref (folder); - - return folder; + return message_list_ref_folder (MESSAGE_LIST (message_list)); } static void @@ -3025,7 +3083,7 @@ mail_reader_set_folder (EMailReader *reader, display = e_mail_reader_get_mail_display (reader); message_list = e_mail_reader_get_message_list (reader); - previous_folder = e_mail_reader_get_folder (reader); + previous_folder = e_mail_reader_ref_folder (reader); backend = e_mail_reader_get_backend (reader); shell = e_shell_backend_get_shell (E_SHELL_BACKEND (backend)); @@ -3039,21 +3097,22 @@ mail_reader_set_folder (EMailReader *reader, mail_sync_folder (previous_folder, TRUE, NULL, NULL); /* Skip the rest if we're already viewing the folder. */ - if (folder == previous_folder) - return; + if (folder != previous_folder) { + e_web_view_clear (E_WEB_VIEW (display)); - e_web_view_clear (E_WEB_VIEW (display)); + priv->folder_was_just_selected = (folder != NULL); - priv->folder_was_just_selected = (folder != NULL); + /* This is to make sure any post-poned changes in Search + * Folders will be propagated on folder selection. */ + if (CAMEL_IS_VEE_FOLDER (folder)) + mail_sync_folder (folder, FALSE, NULL, NULL); - /* This is to make sure any post-poned changes in Search - * Folders will be propagated on folder selection. */ - if (CAMEL_IS_VEE_FOLDER (folder)) - mail_sync_folder (folder, FALSE, NULL, NULL); + message_list_set_folder (MESSAGE_LIST (message_list), folder); - message_list_set_folder (MESSAGE_LIST (message_list), folder); + mail_reader_emit_folder_loaded (reader); + } - mail_reader_emit_folder_loaded (reader); + g_clear_object (&previous_folder); } static void @@ -3147,7 +3206,7 @@ mail_reader_message_loaded (EMailReader *reader, priv = E_MAIL_READER_GET_PRIVATE (reader); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); backend = e_mail_reader_get_backend (reader); display = e_mail_reader_get_mail_display (reader); message_list = e_mail_reader_get_message_list (reader); @@ -3194,6 +3253,8 @@ mail_reader_message_loaded (EMailReader *reader, } priv->avoid_next_mark_as_seen = FALSE; + + g_clear_object (&folder); } static void @@ -3207,8 +3268,9 @@ mail_reader_message_seen (EMailReader *reader, mask = CAMEL_MESSAGE_SEEN; set = CAMEL_MESSAGE_SEEN; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); camel_folder_set_message_flags (folder, message_uid, mask, set); + g_clear_object (&folder); } static void @@ -3627,7 +3689,7 @@ e_mail_reader_default_init (EMailReaderInterface *interface) interface->get_alert_sink = mail_reader_get_alert_sink; interface->get_selected_uids = mail_reader_get_selected_uids; - interface->get_folder = mail_reader_get_folder; + interface->ref_folder = mail_reader_ref_folder; interface->set_folder = mail_reader_set_folder; interface->set_message = mail_reader_set_message; interface->open_selected_mail = e_mail_reader_open_selected; @@ -4064,7 +4126,7 @@ e_mail_reader_check_state (EMailReader *reader) account_store = e_mail_ui_session_get_account_store ( E_MAIL_UI_SESSION (mail_session)); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); uids = e_mail_reader_get_selected_uids (reader); if (folder != NULL) { @@ -4200,6 +4262,7 @@ e_mail_reader_check_state (EMailReader *reader) if (is_junk_folder) state |= E_MAIL_READER_FOLDER_IS_JUNK; + g_clear_object (&folder); em_utils_uids_free (uids); return state; @@ -4398,16 +4461,16 @@ e_mail_reader_get_window (EMailReader *reader) } CamelFolder * -e_mail_reader_get_folder (EMailReader *reader) +e_mail_reader_ref_folder (EMailReader *reader) { EMailReaderInterface *interface; g_return_val_if_fail (E_IS_MAIL_READER (reader), NULL); interface = E_MAIL_READER_GET_INTERFACE (reader); - g_return_val_if_fail (interface->get_folder != NULL, NULL); + g_return_val_if_fail (interface->ref_folder != NULL, NULL); - return interface->get_folder (reader); + return interface->ref_folder (reader); } void diff --git a/mail/e-mail-reader.h b/mail/e-mail-reader.h index 392a1717e7..fbaa67c072 100644 --- a/mail/e-mail-reader.h +++ b/mail/e-mail-reader.h @@ -105,7 +105,7 @@ struct _EMailReaderInterface { GPtrArray * (*get_selected_uids) (EMailReader *reader); GtkWindow * (*get_window) (EMailReader *reader); - CamelFolder * (*get_folder) (EMailReader *reader); + CamelFolder * (*ref_folder) (EMailReader *reader); void (*set_folder) (EMailReader *reader, CamelFolder *folder); void (*set_message) (EMailReader *reader, @@ -153,7 +153,7 @@ GtkMenu * e_mail_reader_get_popup_menu (EMailReader *reader); EPreviewPane * e_mail_reader_get_preview_pane (EMailReader *reader); GPtrArray * e_mail_reader_get_selected_uids (EMailReader *reader); GtkWindow * e_mail_reader_get_window (EMailReader *reader); -CamelFolder * e_mail_reader_get_folder (EMailReader *reader); +CamelFolder * e_mail_reader_ref_folder (EMailReader *reader); void e_mail_reader_set_folder (EMailReader *reader, CamelFolder *folder); void e_mail_reader_set_message (EMailReader *reader, |