From abafd9de4f2e7f63ec522aae1009a671cb19425c Mon Sep 17 00:00:00 2001 From: Not Zed Date: Tue, 6 Aug 2002 02:45:07 +0000 Subject: Unref the driver before returning to main thread, so any closing 2002-08-06 Not Zed * mail-ops.c (filter_folder_filter): Unref the driver before returning to main thread, so any closing operations are handled async (as in fetch_mail_fetch()), for #28072. ** fixes for #24605. * mail-vfolder.c (vfolder_gui_add_from_mlist): Removed. * folder-browser.c (filter_type_uid,vfolder_type_uid): Changed to accept args directly. Fixed callers. (filter_mlist_uid,vfolder_mlist_uid): Use filter_type_uid instead of mlist variant. (vfolder_type_current): new function to handle setup of vfolders from the main menu. It now uses the vfolder_type_uid function the same as the popup. (vfolder_subject, vfolder_sender, vfolder_recipient, vfolder_mlist): Changed to use vfolder_type_current. (filter_type_current): Similar for filters. (filter_subject, filter_sender, filter_recipient, filter_mlist): Changed to use filter_type_current. * mail-autofilter.c (rule_from_message): Handle AUTO_MLIST type. (rule_from_mlist): (vfolder_rule_from_mlist): (filter_rule_from_mlist): Removed. (filter_gui_add_from_mlist): Removed. * mail-autofilter.h: Added AUTO_MLIST type. svn path=/trunk/; revision=17704 --- mail/ChangeLog | 31 +++++++++++ mail/folder-browser.c | 143 +++++++++++++++++++------------------------------ mail/mail-autofilter.c | 99 +++++++++++----------------------- mail/mail-autofilter.h | 7 +-- mail/mail-ops.c | 5 ++ mail/mail-vfolder.c | 12 ----- mail/mail-vfolder.h | 1 - 7 files changed, 125 insertions(+), 173 deletions(-) diff --git a/mail/ChangeLog b/mail/ChangeLog index 0246b8b847..389f828f88 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,34 @@ +2002-08-06 Not Zed + + * mail-ops.c (filter_folder_filter): Unref the driver before + returning to main thread, so any closing operations are handled + async (as in fetch_mail_fetch()), for #28072. + + ** fixes for #24605. + + * mail-vfolder.c (vfolder_gui_add_from_mlist): Removed. + + * folder-browser.c (filter_type_uid,vfolder_type_uid): Changed to + accept args directly. Fixed callers. + (filter_mlist_uid,vfolder_mlist_uid): Use filter_type_uid instead + of mlist variant. + (vfolder_type_current): new function to handle setup of vfolders + from the main menu. It now uses the vfolder_type_uid function the + same as the popup. + (vfolder_subject, vfolder_sender, vfolder_recipient, + vfolder_mlist): Changed to use vfolder_type_current. + (filter_type_current): Similar for filters. + (filter_subject, filter_sender, filter_recipient, + filter_mlist): Changed to use filter_type_current. + + * mail-autofilter.c (rule_from_message): Handle AUTO_MLIST type. + (rule_from_mlist): + (vfolder_rule_from_mlist): + (filter_rule_from_mlist): Removed. + (filter_gui_add_from_mlist): Removed. + + * mail-autofilter.h: Added AUTO_MLIST type. + 2002-08-05 Jeffrey Stedfast * mail-mt.c (mail_msg_check_error): If we are not in interactive diff --git a/mail/folder-browser.c b/mail/folder-browser.c index bff73f9922..b367d124d3 100644 --- a/mail/folder-browser.c +++ b/mail/folder-browser.c @@ -1297,91 +1297,63 @@ folder_browser_charset_changed (BonoboUIComponent *component, } } -/* external api to vfolder/filter on X, based on current message */ -void -vfolder_subject (GtkWidget *w, FolderBrowser *fb) -{ - vfolder_gui_add_from_message (fb->mail_display->current_message, AUTO_SUBJECT, fb->uri); -} - -void -vfolder_sender (GtkWidget *w, FolderBrowser *fb) -{ - vfolder_gui_add_from_message (fb->mail_display->current_message, AUTO_FROM, fb->uri); -} +static void vfolder_type_uid(CamelFolder *folder, const char *uid, const char *uri, int type); -void -vfolder_recipient (GtkWidget *w, FolderBrowser *fb) +static void +vfolder_type_current(FolderBrowser *fb, int type) { - vfolder_gui_add_from_message (fb->mail_display->current_message, AUTO_TO, fb->uri); -} + GPtrArray *uids; + int i; -void -vfolder_mlist (GtkWidget *w, FolderBrowser *fb) -{ - char *name; + /* get uid */ + uids = g_ptr_array_new(); + message_list_foreach(fb->message_list, enumerate_msg, uids); - g_return_if_fail (fb->mail_display->current_message != NULL); + if (uids->len == 1) + vfolder_type_uid(fb->folder, (char *)uids->pdata[0], fb->uri, type); - name = header_raw_check_mailing_list(&((CamelMimePart *)fb->mail_display->current_message)->headers); - if (name) { - g_strstrip (name); - vfolder_gui_add_from_mlist(name, fb->uri); - g_free(name); - } + for (i=0; ilen; i++) + g_free(uids->pdata[i]); + g_ptr_array_free(uids, TRUE); } -void -filter_subject (GtkWidget *w, FolderBrowser *fb) -{ - const char *source = FILTER_SOURCE_INCOMING; - - if (folder_browser_is_sent (fb) || folder_browser_is_outbox (fb)) - source = FILTER_SOURCE_OUTGOING; - - filter_gui_add_from_message (fb->mail_display->current_message, source, AUTO_SUBJECT); -} +/* external api to vfolder/filter on X, based on current message */ +void vfolder_subject(GtkWidget *w, FolderBrowser *fb) { vfolder_type_current(fb, AUTO_SUBJECT); } +void vfolder_sender(GtkWidget *w, FolderBrowser *fb) { vfolder_type_current(fb, AUTO_FROM); } +void vfolder_recipient(GtkWidget *w, FolderBrowser *fb) { vfolder_type_current(fb, AUTO_TO); } +void vfolder_mlist(GtkWidget *w, FolderBrowser *fb) { vfolder_type_current(fb, AUTO_MLIST); } -void -filter_sender (GtkWidget *w, FolderBrowser *fb) -{ - const char *source = FILTER_SOURCE_INCOMING; - - if (folder_browser_is_sent (fb) || folder_browser_is_outbox (fb)) - source = FILTER_SOURCE_OUTGOING; - - filter_gui_add_from_message (fb->mail_display->current_message, source, AUTO_FROM); -} +static void filter_type_uid(CamelFolder *folder, const char *uid, const char *source, int type); -void -filter_recipient (GtkWidget *w, FolderBrowser *fb) +static void +filter_type_current(FolderBrowser *fb, int type) { - const char *source = FILTER_SOURCE_INCOMING; - - if (folder_browser_is_sent (fb) || folder_browser_is_outbox (fb)) - source = FILTER_SOURCE_OUTGOING; - - filter_gui_add_from_message (fb->mail_display->current_message, source, AUTO_TO); -} + GPtrArray *uids; + int i; + const char *source; -void -filter_mlist (GtkWidget *w, FolderBrowser *fb) -{ - const char *source = FILTER_SOURCE_INCOMING; - char *name; - - g_return_if_fail (fb->mail_display->current_message != NULL); - if (folder_browser_is_sent (fb) || folder_browser_is_outbox (fb)) source = FILTER_SOURCE_OUTGOING; - - name = header_raw_check_mailing_list(&((CamelMimePart *)fb->mail_display->current_message)->headers); - if (name) { - filter_gui_add_from_mlist(source, name); - g_free(name); - } + else + source = FILTER_SOURCE_INCOMING; + + /* get uid */ + uids = g_ptr_array_new(); + message_list_foreach(fb->message_list, enumerate_msg, uids); + + if (uids->len == 1) + filter_type_uid(fb->folder, (char *)uids->pdata[0], source, type); + + for (i=0; ilen; i++) + g_free(uids->pdata[i]); + g_ptr_array_free(uids, TRUE); } +void filter_subject(GtkWidget *w, FolderBrowser *fb) { filter_type_current(fb, AUTO_SUBJECT); } +void filter_sender(GtkWidget *w, FolderBrowser *fb) { filter_type_current(fb, AUTO_FROM); } +void filter_recipient(GtkWidget *w, FolderBrowser *fb) { filter_type_current(fb, AUTO_TO); } +void filter_mlist(GtkWidget *w, FolderBrowser *fb) { filter_type_current(fb, AUTO_MLIST); } + /* ************************************************************ */ /* popup api to vfolder/filter on X, based on current selection */ @@ -1417,22 +1389,20 @@ vfolder_type_got_message(CamelFolder *folder, const char *uid, CamelMimeMessage } static void -vfolder_type_uid(struct _filter_data *fdata, int type) +vfolder_type_uid(CamelFolder *folder, const char *uid, const char *uri, int type) { struct _filter_data *data; - /* sigh, we need to copy this because the menu will free the one we got passed in */ data = g_malloc0(sizeof(*data)); data->type = type; - data->uri = fdata->uri; - fdata->uri = NULL; - mail_get_message(fdata->folder, fdata->uid, vfolder_type_got_message, data, mail_thread_new); + data->uri = g_strdup(uri); + mail_get_message(folder, uid, vfolder_type_got_message, data, mail_thread_new); } -static void vfolder_subject_uid (GtkWidget *w, struct _filter_data *fdata) { vfolder_type_uid(fdata, AUTO_SUBJECT); } -static void vfolder_sender_uid(GtkWidget *w, struct _filter_data *fdata) { vfolder_type_uid(fdata, AUTO_FROM); } -static void vfolder_recipient_uid(GtkWidget *w, struct _filter_data *fdata) { vfolder_type_uid(fdata, AUTO_TO); } -static void vfolder_mlist_uid(GtkWidget *w, struct _filter_data *fdata) { vfolder_gui_add_from_mlist(fdata->mlist, fdata->uri); } +static void vfolder_subject_uid (GtkWidget *w, struct _filter_data *fdata) { vfolder_type_uid(fdata->folder, fdata->uid, fdata->uri, AUTO_SUBJECT); } +static void vfolder_sender_uid(GtkWidget *w, struct _filter_data *fdata) { vfolder_type_uid(fdata->folder, fdata->uid, fdata->uri, AUTO_FROM); } +static void vfolder_recipient_uid(GtkWidget *w, struct _filter_data *fdata) { vfolder_type_uid(fdata->folder, fdata->uid, fdata->uri, AUTO_TO); } +static void vfolder_mlist_uid(GtkWidget *w, struct _filter_data *fdata) { vfolder_type_uid(fdata->folder, fdata->uid, fdata->uri, AUTO_MLIST); } static void filter_type_got_message(CamelFolder *folder, const char *uid, CamelMimeMessage *msg, void *d) @@ -1446,21 +1416,20 @@ filter_type_got_message(CamelFolder *folder, const char *uid, CamelMimeMessage * } static void -filter_type_uid(struct _filter_data *fdata, int type) +filter_type_uid(CamelFolder *folder, const char *uid, const char *source, int type) { struct _filter_data *data; - /* sigh, we need to copy this because the menu will free the one we got passed in */ data = g_malloc0(sizeof(*data)); data->type = type; - data->source = fdata->source; - mail_get_message(fdata->folder, fdata->uid, filter_type_got_message, data, mail_thread_new); + data->source = source; + mail_get_message(folder, uid, filter_type_got_message, data, mail_thread_new); } -static void filter_subject_uid (GtkWidget *w, struct _filter_data *fdata) { filter_type_uid(fdata, AUTO_SUBJECT); } -static void filter_sender_uid(GtkWidget *w, struct _filter_data *fdata) { filter_type_uid(fdata, AUTO_FROM); } -static void filter_recipient_uid(GtkWidget *w, struct _filter_data *fdata) { filter_type_uid(fdata, AUTO_TO); } -static void filter_mlist_uid(GtkWidget *w, struct _filter_data *fdata) { filter_gui_add_from_mlist(fdata->source, fdata->mlist); } +static void filter_subject_uid (GtkWidget *w, struct _filter_data *fdata) { filter_type_uid(fdata->folder, fdata->uid, fdata->source, AUTO_SUBJECT); } +static void filter_sender_uid(GtkWidget *w, struct _filter_data *fdata) { filter_type_uid(fdata->folder, fdata->uid, fdata->source, AUTO_FROM); } +static void filter_recipient_uid(GtkWidget *w, struct _filter_data *fdata) { filter_type_uid(fdata->folder, fdata->uid, fdata->source, AUTO_TO); } +static void filter_mlist_uid(GtkWidget *w, struct _filter_data *fdata) { filter_type_uid(fdata->folder, fdata->uid, fdata->source, AUTO_MLIST); } void hide_none(GtkWidget *w, FolderBrowser *fb) diff --git a/mail/mail-autofilter.c b/mail/mail-autofilter.c index a4807b1f32..cb69a420fb 100644 --- a/mail/mail-autofilter.c +++ b/mail/mail-autofilter.c @@ -207,6 +207,25 @@ rule_match_subject (RuleContext *context, FilterRule *rule, const char *subject) rule_add_subject (context, rule, tmp); } +static void +rule_match_mlist(RuleContext *context, FilterRule *rule, const char *mlist) +{ + FilterPart *part; + FilterElement *element; + + if (mlist[0] == 0) + return; + + part = rule_context_create_part(context, "mlist"); + filter_rule_add_part(rule, part); + + element = filter_part_find_element(part, "mlist-type"); + filter_option_set_current((FilterOption *)element, "is"); + + element = filter_part_find_element (part, "mlist"); + filter_input_set_value((FilterInput *)element, mlist); +} + static void rule_from_message (FilterRule *rule, RuleContext *context, CamelMimeMessage *msg, int flags) { @@ -247,6 +266,18 @@ rule_from_message (FilterRule *rule, RuleContext *context, CamelMimeMessage *msg addr = (CamelInternetAddress *)camel_mime_message_get_recipients (msg, CAMEL_RECIPIENT_TYPE_CC); rule_match_recipients (context, rule, addr); } + if (flags & AUTO_MLIST) { + char *name, *mlist; + + mlist = header_raw_check_mailing_list(&((CamelMimePart *)msg)->headers); + if (mlist) { + rule_match_mlist(context, rule, mlist); + name = g_strdup_printf(U_("%s mailing list"), mlist); + filter_rule_set_name(rule, name); + g_free(name); + } + g_free(mlist); + } } FilterRule * @@ -276,54 +307,6 @@ filter_rule_from_message (FilterContext *context, CamelMimeMessage *msg, int fla return (FilterRule *)rule; } -static void -rule_from_mlist(FilterRule *rule, RuleContext *context, const char *mlist) -{ - FilterPart *part; - FilterElement *element; - char *rule_name; - - part = rule_context_create_part(context, "mlist"); - filter_rule_add_part(rule, part); - - element = filter_part_find_element(part, "mlist-type"); - filter_option_set_current((FilterOption *)element, "is"); - - element = filter_part_find_element (part, "mlist"); - filter_input_set_value((FilterInput *)element, mlist); - - rule_name = g_strdup_printf(U_("%s mailing list"), mlist); - filter_rule_set_name((FilterRule *) rule, rule_name); - g_free (rule_name); -} - -FilterRule * -vfolder_rule_from_mlist(VfolderContext *context, const char *mlist, const char *source) -{ - VfolderRule *rule; - - rule = vfolder_rule_new (); - vfolder_rule_add_source (rule, source); - rule_from_mlist((FilterRule *)rule, (RuleContext *)context, mlist); - - return (FilterRule *)rule; -} - -FilterRule * -filter_rule_from_mlist (FilterContext *context, const char *mlist) -{ - FilterFilter *rule; - FilterPart *part; - - rule = filter_filter_new (); - rule_from_mlist((FilterRule *)rule, (RuleContext *)context, mlist); - - part = filter_context_next_action (context, NULL); - filter_filter_add_action (rule, filter_part_clone (part)); - - return (FilterRule *)rule; -} - void filter_gui_add_from_message (CamelMimeMessage *msg, const char *source, int flags) { @@ -346,26 +329,6 @@ filter_gui_add_from_message (CamelMimeMessage *msg, const char *source, int flag gtk_object_unref (GTK_OBJECT (fc)); } -void -filter_gui_add_from_mlist (const char *source, const char *mlist) -{ - FilterContext *fc; - char *user, *system; - FilterRule *rule; - - fc = filter_context_new (); - user = g_strdup_printf ("%s/filters.xml", evolution_dir); - system = EVOLUTION_DATADIR "/evolution/filtertypes.xml"; - rule_context_load ((RuleContext *)fc, system, user); - rule = filter_rule_from_mlist(fc, mlist); - - filter_rule_set_source (rule, source); - - rule_context_add_rule_gui ((RuleContext *)fc, rule, _("Add Filter Rule"), user); - g_free (user); - gtk_object_unref (GTK_OBJECT (fc)); -} - void mail_filter_rename_uri(CamelStore *store, const char *olduri, const char *newuri) { diff --git a/mail/mail-autofilter.h b/mail/mail-autofilter.h index ca7935411d..45f9d15863 100644 --- a/mail/mail-autofilter.h +++ b/mail/mail-autofilter.h @@ -33,18 +33,15 @@ enum { AUTO_SUBJECT = 1, AUTO_FROM = 2, - AUTO_TO = 4 + AUTO_TO = 4, + AUTO_MLIST = 8, }; FilterRule *vfolder_rule_from_message(VfolderContext *context, CamelMimeMessage *msg, int flags, const char *source); FilterRule *filter_rule_from_message(FilterContext *context, CamelMimeMessage *msg, int flags); -FilterRule *vfolder_rule_from_mlist(VfolderContext *context, const char *mlist, const char *source); -FilterRule *filter_rule_from_mlist(FilterContext *context, const char *mlist); /* easiest place to put this */ - void filter_gui_add_from_message (CamelMimeMessage *msg, const char *source, int flags); -void filter_gui_add_from_mlist (const char *source, const char *mlist); /* Also easiest place for these, we should really share a global rule context for this stuff ... */ void mail_filter_rename_uri(CamelStore *store, const char *olduri, const char *newuri); diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 4f9fc77968..38225769b7 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -134,6 +134,11 @@ filter_folder_filter (struct _mail_msg *mm) if (m->destination) camel_folder_thaw (m->destination); + + /* this may thaw/unref source folders, do it here so we dont do it in the main thread + see also fetch_mail_fetch() below */ + camel_object_unref(CAMEL_OBJECT(m->driver)); + m->driver = NULL; if (m->cancel) camel_operation_unregister (m->cancel); diff --git a/mail/mail-vfolder.c b/mail/mail-vfolder.c index 2b2e05ae89..7a8ac3011d 100644 --- a/mail/mail-vfolder.c +++ b/mail/mail-vfolder.c @@ -954,18 +954,6 @@ vfolder_gui_add_from_message(CamelMimeMessage *msg, int flags, const char *sourc vfolder_gui_add_rule(rule); } -void -vfolder_gui_add_from_mlist(const char *mlist, const char *source) -{ - VfolderRule *rule; - - g_return_if_fail (mlist != NULL); - g_return_if_fail (source != NULL); - - rule = (VfolderRule*)vfolder_rule_from_mlist(context, mlist, source); - vfolder_gui_add_rule(rule); -} - static void vfolder_foreach_cb (gpointer key, gpointer data, gpointer user_data) { diff --git a/mail/mail-vfolder.h b/mail/mail-vfolder.h index 6de0ff52b6..955b358c30 100644 --- a/mail/mail-vfolder.h +++ b/mail/mail-vfolder.h @@ -19,7 +19,6 @@ FilterPart *vfolder_create_part (const char *name); FilterRule *vfolder_clone_rule (FilterRule *in); void vfolder_gui_add_rule (VfolderRule *rule); void vfolder_gui_add_from_message (CamelMimeMessage *msg, int flags, const char *source); -void vfolder_gui_add_from_mlist (const char *mlist, const char *source); /* add a uri that is now (un)available to vfolders in a transient manner */ void mail_vfolder_add_uri(CamelStore *store, const char *uri, int remove); -- cgit