From 5b1742b202ca9505ccd818918b4afe82fc61b63b Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Fri, 14 Jun 2013 22:55:03 -0400 Subject: Add e_mail_reader_ref_folder(). Replaces e_mail_reader_get_folder(). --- mail/e-mail-browser.c | 37 ++-- mail/e-mail-folder-pane.c | 28 ++- mail/e-mail-paned-view.c | 67 +++--- mail/e-mail-reader-utils.c | 100 +++++---- mail/e-mail-reader.c | 237 +++++++++++++-------- mail/e-mail-reader.h | 4 +- modules/mail/e-mail-shell-view-actions.c | 29 ++- modules/mail/e-mail-shell-view-private.c | 31 +-- modules/mail/e-mail-shell-view.c | 23 +- modules/mdn/evolution-mdn.c | 35 ++- plugins/mail-to-task/mail-to-task.c | 4 +- .../mailing-list-actions/mailing-list-actions.c | 7 +- plugins/templates/templates.c | 15 +- 13 files changed, 377 insertions(+), 240 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, diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c index c123696de4..4056a7b08f 100644 --- a/modules/mail/e-mail-shell-view-actions.c +++ b/modules/mail/e-mail-shell-view-actions.c @@ -210,9 +210,6 @@ action_mail_create_search_folder_cb (GtkAction *action, if (search_text == NULL || *search_text == '\0') search_text = "''"; - reader = E_MAIL_READER (mail_view); - folder = e_mail_reader_get_folder (reader); - backend = E_MAIL_BACKEND (shell_backend); session = e_mail_backend_get_session (backend); @@ -224,12 +221,15 @@ action_mail_create_search_folder_cb (GtkAction *action, e_filter_rule_set_name (search_rule, rule_name); g_free (rule_name); + reader = E_MAIL_READER (mail_view); + folder = e_mail_reader_ref_folder (reader); folder_uri = e_mail_folder_uri_from_folder (folder); vfolder_rule = EM_VFOLDER_RULE (search_rule); em_vfolder_rule_add_source (vfolder_rule, folder_uri); vfolder_gui_add_rule (vfolder_rule); + g_clear_object (&folder); g_free (folder_uri); } @@ -702,18 +702,22 @@ action_mail_folder_mark_all_as_read_cb (GtkAction *action, reader = E_MAIL_READER (mail_view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); g_return_if_fail (folder != NULL); - if (folder->summary && - camel_folder_summary_get_unread_count (folder->summary) == 0) + if (folder->summary != NULL && + camel_folder_summary_get_unread_count (folder->summary) == 0) { + g_object_unref (folder); return; + } e_mail_shell_view_actions_mark_all_read ( mail_shell_view, camel_folder_get_parent_store (folder), camel_folder_get_full_name (folder), FALSE); + + g_object_unref (folder); } static void @@ -985,7 +989,7 @@ action_mail_label_cb (GtkToggleAction *action, mail_view = e_mail_shell_content_get_mail_view (mail_shell_content); reader = E_MAIL_READER (mail_view); - 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); @@ -1002,6 +1006,7 @@ action_mail_label_cb (GtkToggleAction *action, } camel_folder_thaw (folder); + g_clear_object (&folder); em_utils_uids_free (uids); } @@ -1067,13 +1072,14 @@ action_mail_label_new_cb (GtkAction *action, mail_view = e_mail_shell_content_get_mail_view (mail_shell_content); reader = E_MAIL_READER (mail_view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); uids = e_mail_reader_get_selected_uids (reader); for (ii = 0; ii < uids->len; ii++) camel_folder_set_message_user_flag ( folder, uids->pdata[ii], label_tag, TRUE); + g_clear_object (&folder); em_utils_uids_free (uids); g_free (label_tag); @@ -1112,7 +1118,7 @@ action_mail_label_none_cb (GtkAction *action, mail_view = e_mail_shell_content_get_mail_view (mail_shell_content); reader = E_MAIL_READER (mail_view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); uids = e_mail_reader_get_selected_uids (reader); valid = gtk_tree_model_get_iter_first ( @@ -1136,6 +1142,7 @@ action_mail_label_none_cb (GtkAction *action, GTK_TREE_MODEL (label_store), &iter); } + g_clear_object (&folder); em_utils_uids_free (uids); } @@ -2237,7 +2244,7 @@ mail_shell_view_update_label_action (GtkToggleAction *action, gboolean sensitive; guint ii; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); /* Figure out the proper label action state for the selected * messages. If all the selected messages have the given label, @@ -2277,6 +2284,8 @@ mail_shell_view_update_label_action (GtkToggleAction *action, sensitive = !(exists && not_exists); gtk_toggle_action_set_active (action, exists); gtk_action_set_sensitive (GTK_ACTION (action), sensitive); + + g_clear_object (&folder); } void diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c index aa9addf4a5..16971771de 100644 --- a/modules/mail/e-mail-shell-view-private.c +++ b/modules/mail/e-mail-shell-view-private.c @@ -212,7 +212,7 @@ mail_shell_view_folder_tree_selection_done_cb (EMailShellView *mail_shell_view, reader = E_MAIL_READER (mail_view); message_list = e_mail_reader_get_message_list (reader); - /* Don't use e_mail_reader_get_folder() here. The fact that the + /* Don't use e_mail_reader_ref_folder() here. The fact that the * method gets the folder from the message list is supposed to be * a hidden implementation detail, and we want to explicitly get * the folder URI from the message list here. */ @@ -523,18 +523,18 @@ mail_shell_view_prepare_for_quit_cb (EMailShellView *mail_shell_view, mail_view = e_mail_shell_content_get_mail_view (mail_shell_content); reader = E_MAIL_READER (mail_view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); message_list = e_mail_reader_get_message_list (reader); message_list_save_state (MESSAGE_LIST (message_list)); - if (folder == NULL) - return; - - mail_sync_folder ( - folder, TRUE, - mail_shell_view_prepare_for_quit_done_cb, - g_object_ref (activity)); + if (folder != NULL) { + mail_sync_folder ( + folder, TRUE, + mail_shell_view_prepare_for_quit_done_cb, + g_object_ref (activity)); + g_object_unref (folder); + } } static void @@ -914,7 +914,7 @@ e_mail_shell_view_restore_state (EMailShellView *mail_shell_view) searchbar = e_mail_shell_content_get_searchbar (mail_shell_content); reader = E_MAIL_READER (mail_view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); if (folder == NULL) { if (e_shell_searchbar_get_state_group (searchbar)) { @@ -930,11 +930,11 @@ e_mail_shell_view_restore_state (EMailShellView *mail_shell_view) vee_folder = mail_shell_view->priv->search_account_all; if (vee_folder != NULL && folder == CAMEL_FOLDER (vee_folder)) - return; + goto exit; vee_folder = mail_shell_view->priv->search_account_current; if (vee_folder != NULL && folder == CAMEL_FOLDER (vee_folder)) - return; + goto exit; folder_uri = e_mail_folder_uri_from_folder (folder); new_state_group = g_strdup_printf ("Folder %s", folder_uri); @@ -948,6 +948,9 @@ e_mail_shell_view_restore_state (EMailShellView *mail_shell_view) } g_free (new_state_group); + +exit: + g_clear_object (&folder); } void @@ -989,7 +992,7 @@ e_mail_shell_view_update_sidebar (EMailShellView *mail_shell_view) registry = e_shell_get_registry (shell); reader = E_MAIL_READER (mail_view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); /* If no folder is selected, reset the sidebar banners * to their default values and stop. */ @@ -1113,6 +1116,8 @@ e_mail_shell_view_update_sidebar (EMailShellView *mail_shell_view) g_free (title); g_string_free (buffer, TRUE); + + g_clear_object (&folder); } typedef struct { diff --git a/modules/mail/e-mail-shell-view.c b/modules/mail/e-mail-shell-view.c index ca4d01e266..a5e5d62eaa 100644 --- a/modules/mail/e-mail-shell-view.c +++ b/modules/mail/e-mail-shell-view.c @@ -327,7 +327,7 @@ mail_shell_view_execute_search (EShellView *shell_view) folder_tree = e_mail_shell_sidebar_get_folder_tree (mail_shell_sidebar); reader = E_MAIL_READER (mail_view); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); message_list = e_mail_reader_get_message_list (reader); registry = e_mail_session_get_registry (session); @@ -613,14 +613,17 @@ all_accounts: camel_service_connect_sync (service, NULL, NULL); search_folder = (CamelVeeFolder *) camel_vee_folder_new ( - CAMEL_STORE (service), _("All Account Search"), CAMEL_STORE_FOLDER_PRIVATE); + CAMEL_STORE (service), + _("All Account Search"), + CAMEL_STORE_FOLDER_PRIVATE); priv->search_account_all = search_folder; g_object_unref (service); camel_vee_folder_set_expression (search_folder, query); - all_accounts_setup: +all_accounts_setup: + list = em_folder_tree_model_list_stores (EM_FOLDER_TREE_MODEL ( gtk_tree_view_get_model (GTK_TREE_VIEW (folder_tree)))); g_list_foreach (list, (GFunc) g_object_ref, NULL); @@ -714,14 +717,16 @@ current_account: camel_service_connect_sync (service, NULL, NULL); search_folder = (CamelVeeFolder *) camel_vee_folder_new ( - CAMEL_STORE (service), _("Account Search"), CAMEL_STORE_FOLDER_PRIVATE); + CAMEL_STORE (service), + _("Account Search"), + CAMEL_STORE_FOLDER_PRIVATE); priv->search_account_current = search_folder; g_object_unref (service); camel_vee_folder_set_expression (search_folder, query); - current_accout_setup: +current_accout_setup: if (folder != NULL && folder != CAMEL_FOLDER (search_folder)) { store = camel_folder_get_parent_store (folder); @@ -760,6 +765,8 @@ execute: g_slist_free (search_strings); g_free (query); + + g_clear_object (&folder); } static void @@ -897,7 +904,7 @@ mail_shell_view_update_actions (EShellView *shell_view) GtkTreeRowReference *reference; CamelFolder *folder; - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); /* XXX If the user right-clicks on a folder other than what * the message list is showing, disable folder rename. @@ -906,13 +913,15 @@ mail_shell_view_update_actions (EShellView *shell_view) * back to where it was to avoid cancelling the inline * folder tree editing, it's just too hairy to try to * get right. So we're punting. */ - if (CAMEL_IS_FOLDER (folder)) { + if (folder != NULL) { gchar *folder_uri; folder_uri = e_mail_folder_uri_from_folder (folder); folder_tree_and_message_list_agree = (g_strcmp0 (uri, folder_uri) == 0); g_free (folder_uri); + + g_object_unref (folder); } reference = em_folder_tree_model_lookup_uri (model, uri); diff --git a/modules/mdn/evolution-mdn.c b/modules/mdn/evolution-mdn.c index 441b063dc1..b037fc36c3 100644 --- a/modules/mdn/evolution-mdn.c +++ b/modules/mdn/evolution-mdn.c @@ -481,13 +481,13 @@ mdn_message_loaded_cb (EMailReader *reader, session = e_mail_backend_get_session (backend); registry = e_mail_session_get_registry (session); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); mdn_remove_alert (mdn); info = camel_folder_get_message_info (folder, message_uid); if (info == NULL) - return; + goto exit; if (camel_message_info_user_flag (info, MDN_USER_FLAG)) { alert = e_alert_new ("mdn:sender-notified", NULL); @@ -500,11 +500,18 @@ mdn_message_loaded_cb (EMailReader *reader, if (notify_to == NULL) goto exit; - /* do not show the notice in special folders */ - if (em_utils_folder_is_drafts (registry, folder) || - em_utils_folder_is_templates (registry, folder) || - em_utils_folder_is_sent (registry, folder) || - em_utils_folder_is_outbox (registry, folder)) + /* Do not show the notice in special folders. */ + + if (em_utils_folder_is_drafts (registry, folder)) + goto exit; + + if (em_utils_folder_is_templates (registry, folder)) + goto exit; + + if (em_utils_folder_is_sent (registry, folder)) + goto exit; + + if (em_utils_folder_is_outbox (registry, folder)) goto exit; /* This returns a new ESource reference. */ @@ -560,7 +567,10 @@ mdn_message_loaded_cb (EMailReader *reader, g_object_unref (source); exit: - camel_folder_free_message_info (folder, info); + g_clear_object (&folder); + + if (info != NULL) + camel_folder_free_message_info (folder, info); g_free (notify_to); } @@ -584,11 +594,11 @@ mdn_message_seen_cb (EMailReader *reader, session = e_mail_backend_get_session (backend); registry = e_mail_session_get_registry (session); - folder = e_mail_reader_get_folder (reader); + folder = e_mail_reader_ref_folder (reader); info = camel_folder_get_message_info (folder, message_uid); if (info == NULL) - return; + goto exit; if (camel_message_info_user_flag (info, MDN_USER_FLAG)) goto exit; @@ -617,7 +627,10 @@ mdn_message_seen_cb (EMailReader *reader, g_object_unref (source); exit: - camel_folder_free_message_info (folder, info); + g_clear_object (&folder); + + if (info != NULL) + camel_folder_free_message_info (folder, info); g_free (notify_to); } diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c index 0293701a0e..12ff5b0c95 100644 --- a/plugins/mail-to-task/mail-to-task.c +++ b/plugins/mail-to-task/mail-to-task.c @@ -1105,7 +1105,6 @@ mail_to_event (ECalClientSourceType source_type, EShell *shell; EMailBackend *backend; ESourceRegistry *registry; - CamelFolder *folder; GPtrArray *uids; ESource *source = NULL; ESource *default_source; @@ -1114,7 +1113,6 @@ mail_to_event (ECalClientSourceType source_type, const gchar *extension_name; GError *error = NULL; - folder = e_mail_reader_get_folder (reader); parent = e_mail_reader_get_window (reader); uids = e_mail_reader_get_selected_uids (reader); @@ -1213,7 +1211,7 @@ mail_to_event (ECalClientSourceType source_type, data = g_new0 (AsyncData, 1); data->source = g_object_ref (source); data->source_type = source_type; - data->folder = g_object_ref (folder); + data->folder = e_mail_reader_ref_folder (reader); data->uids = uids; data->with_attendees = with_attendees; diff --git a/plugins/mailing-list-actions/mailing-list-actions.c b/plugins/mailing-list-actions/mailing-list-actions.c index c6a3cab235..efbe222307 100644 --- a/plugins/mailing-list-actions/mailing-list-actions.c +++ b/plugins/mailing-list-actions/mailing-list-actions.c @@ -295,9 +295,6 @@ emla_list_action (EMailReader *reader, GPtrArray *uids; const gchar *message_uid; - 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); @@ -310,11 +307,15 @@ emla_list_action (EMailReader *reader, context->reader = g_object_ref (reader); context->action = action; + folder = e_mail_reader_ref_folder (reader); + camel_folder_get_message ( folder, message_uid, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) emla_list_action_cb, context); + g_clear_object (&folder); + em_utils_uids_free (uids); } diff --git a/plugins/templates/templates.c b/plugins/templates/templates.c index 7a176b4b70..d83e1fbe17 100644 --- a/plugins/templates/templates.c +++ b/plugins/templates/templates.c @@ -994,7 +994,8 @@ action_reply_with_template_cb (GtkAction *action, EActivity *activity; AsyncContext *context; GCancellable *cancellable; - CamelFolder *folder, *template_folder; + CamelFolder *folder; + CamelFolder *template_folder; EShellContent *shell_content; EMailReader *reader; GPtrArray *uids; @@ -1004,9 +1005,6 @@ action_reply_with_template_cb (GtkAction *action, shell_content = e_shell_view_get_shell_content (shell_view); reader = E_MAIL_READER (shell_content); - 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); @@ -1025,11 +1023,14 @@ action_reply_with_template_cb (GtkAction *action, context->template_folder = g_object_ref (template_folder); context->template_message_uid = g_strdup (template_message_uid); + folder = e_mail_reader_ref_folder (reader); + em_utils_get_real_folder_uri_and_message_uid ( folder, message_uid, - &context->source_folder_uri, &context->message_uid); + &context->source_folder_uri, + &context->message_uid); - if (!context->message_uid) + if (context->message_uid == NULL) context->message_uid = g_strdup (message_uid); camel_folder_get_message ( @@ -1037,6 +1038,8 @@ action_reply_with_template_cb (GtkAction *action, cancellable, (GAsyncReadyCallback) template_got_source_message, context); + g_clear_object (&folder); + em_utils_uids_free (uids); } -- cgit v1.2.3