From 429ac6ac1df8c8e91a615c9c0fb3f709230e52bc Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Thu, 4 Dec 2003 14:14:36 +0000 Subject: monitor gconf key /apps/evolution/mail/junk/check_incoming and keep 2003-12-04 Radek Doulik * mail-session.c: monitor gconf key /apps/evolution/mail/junk/check_incoming and keep session junk flag uptodate * em-mailer-prefs.c (em_mailer_prefs_construct): added junk preferences svn path=/trunk/; revision=23630 --- mail/ChangeLog | 9 +++ mail/em-junk-plugin.h | 11 ++- mail/em-mailer-prefs.c | 10 +++ mail/em-mailer-prefs.h | 3 + mail/evolution-mail.schemas.in.in | 16 ++++ mail/mail-config.glade | 155 ++++++++++++++++++++++++++++++++++++++ mail/mail-session.c | 68 ++++++++++++----- 7 files changed, 246 insertions(+), 26 deletions(-) (limited to 'mail') diff --git a/mail/ChangeLog b/mail/ChangeLog index f8233a7bd3..10c13bb6d5 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,12 @@ +2003-12-04 Radek Doulik + + * mail-session.c: monitor gconf key + /apps/evolution/mail/junk/check_incoming and keep session junk + flag uptodate + + * em-mailer-prefs.c (em_mailer_prefs_construct): added junk + preferences + 2003-12-03 Jeffrey Stedfast * mail-config.c (uri_to_evname): Updated to add use mail subdirs. diff --git a/mail/em-junk-plugin.h b/mail/em-junk-plugin.h index 0c7eacd165..bd4af4cf9a 100644 --- a/mail/em-junk-plugin.h +++ b/mail/em-junk-plugin.h @@ -34,14 +34,13 @@ struct _EMJunkPlugin { CamelJunkPlugin csp; - /* when called, it should insert own GUI configuration into supplied. - container. returns data pointer which is later passed to apply, + /* when called, it should return widget containing UI configuration. plugin has to call (*changed_cb) (); whenever configuration - is changed to notify settings dialog about a change. - if setup_config_ui is NULL, it means there are no options */ + is changed to notify settings dialog about that change. + if setup_widget is NULL, it means there is no UI configuration */ - gpointer (*setup_config_ui) (GtkWidget *container, void (*changed_cb) ()); - void (*apply) (gpointer data); + GtkWidget (*setup_widget) (void (*changed_cb) ()); + void (*apply) (); }; #endif diff --git a/mail/em-mailer-prefs.c b/mail/em-mailer-prefs.c index b391af1655..a4c5f2e25a 100644 --- a/mail/em-mailer-prefs.c +++ b/mail/em-mailer-prefs.c @@ -360,6 +360,12 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs) prefs->restore_labels = GTK_BUTTON (glade_xml_get_widget (gui, "cmdRestoreLabels")); g_signal_connect (prefs->restore_labels, "clicked", G_CALLBACK (restore_labels_clicked), prefs); + + /* Junk prefs */ + prefs->check_incoming = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkCheckIncomingMail")); + bool = gconf_client_get_bool (prefs->gconf, "/apps/evolution/mail/junk/check_incoming", NULL); + gtk_toggle_button_set_active (prefs->check_incoming, bool); + g_signal_connect (prefs->check_incoming, "toggled", G_CALLBACK (settings_changed), prefs); } @@ -470,5 +476,9 @@ em_mailer_prefs_apply (EMMailerPrefs *prefs) l = n; } + /* junk prefs */ + gconf_client_set_bool (prefs->gconf, "/apps/evolution/mail/junk/check_incoming", + gtk_toggle_button_get_active (prefs->check_incoming), NULL); + gconf_client_suggest_sync (prefs->gconf, NULL); } diff --git a/mail/em-mailer-prefs.h b/mail/em-mailer-prefs.h index 0555d03b06..27de7b3ca9 100644 --- a/mail/em-mailer-prefs.h +++ b/mail/em-mailer-prefs.h @@ -98,6 +98,9 @@ struct _EMMailerPrefs { GnomeColorPicker *color; } labels[5]; GtkButton *restore_labels; + + /* Junk prefs */ + GtkToggleButton *check_incoming; }; struct _EMMailerPrefsClass { diff --git a/mail/evolution-mail.schemas.in.in b/mail/evolution-mail.schemas.in.in index 013af3f96a..297d158d6b 100644 --- a/mail/evolution-mail.schemas.in.in +++ b/mail/evolution-mail.schemas.in.in @@ -603,6 +603,22 @@ + + + + /schemas/apps/evolution/mail/junk/check_incoming + /apps/evolution/mail/junk/check_incoming + evolution-mail + bool + true + + Check incoming mail being junk + + Run junk test on incoming mail + + + + diff --git a/mail/mail-config.glade b/mail/mail-config.glade index 68fc074247..7b451f0a56 100644 --- a/mail/mail-config.glade +++ b/mail/mail-config.glade @@ -4475,6 +4475,107 @@ For example: "Work" or "Personal" tab + + + + 6 + True + False + 6 + + + + True + False + 3 + + + + True + Checks incoming mail messages to be Junk + True + Check _Incoming Mail + True + GTK_RELIEF_NORMAL + False + False + True + + + 0 + False + False + + + + + 0 + False + True + + + + + + True + 0 + 0.5 + GTK_SHADOW_ETCHED_IN + + + + + + + + True + Filter Options + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + label_item + + + + + 0 + False + True + + + + + False + True + + + + + + True + _Junk + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + @@ -5862,4 +5963,58 @@ for display purposes only. + + window1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + + + + 6 + True + False + 3 + + + + True + True + _Local Tests Only + True + GTK_RELIEF_NORMAL + False + False + True + + + 0 + False + False + + + + + + True + True + Use _Daemon + True + GTK_RELIEF_NORMAL + False + False + True + + + 0 + False + False + + + + + + diff --git a/mail/mail-session.c b/mail/mail-session.c index b484fd03ef..75f95f906b 100644 --- a/mail/mail-session.c +++ b/mail/mail-session.c @@ -53,7 +53,7 @@ #define d(x) CamelSession *session; - +static int session_check_junk_notify_id = -1; #define MAIL_SESSION_TYPE (mail_session_get_type ()) #define MAIL_SESSION(obj) (CAMEL_CHECK_CAST((obj), MAIL_SESSION_TYPE, MailSession)) @@ -100,6 +100,9 @@ init (MailSession *session) static void finalise (MailSession *session) { + if (session_check_junk_notify_id != -1) + gconf_client_notify_remove (mail_config_get_gconf_client (), session_check_junk_notify_id); + mail_async_event_destroy(session->async); e_mutex_destroy(session->lock); } @@ -586,7 +589,6 @@ static CamelFilterDriver * main_get_filter_driver (CamelSession *session, const char *type, CamelException *ex) { CamelFilterDriver *driver; - GString *fsearch, *faction; FilterRule *rule = NULL; char *user, *system; GConfClient *gconf; @@ -623,26 +625,33 @@ main_get_filter_driver (CamelSession *session, const char *type, CamelException camel_filter_driver_set_shell_func (driver, mail_execute_shell_command, NULL); camel_filter_driver_set_play_sound_func (driver, session_play_sound, NULL); camel_filter_driver_set_system_beep_func (driver, session_system_beep, NULL); - - fsearch = g_string_new (""); - faction = g_string_new (""); - /* implicit junk check as 1st rule */ - camel_filter_driver_add_rule (driver, "Junk check", "(junk-test)", "(begin (set-system-flag \"junk\"))"); - - /* add the user-defined rules next */ - while ((rule = rule_context_next_rule (fc, rule, type))) { - g_string_truncate (fsearch, 0); - g_string_truncate (faction, 0); + if ((!strcmp (type, FILTER_SOURCE_INCOMING) || !strcmp (type, FILTER_SOURCE_JUNKTEST)) + && camel_session_check_junk (session)) { + /* implicit junk check as 1st rule */ + camel_filter_driver_add_rule (driver, "Junk check", "(junk-test)", "(begin (set-system-flag \"junk\"))"); + } + + if (strcmp (type, FILTER_SOURCE_JUNKTEST)) { + GString *fsearch, *faction; + + fsearch = g_string_new (""); + faction = g_string_new (""); + + /* add the user-defined rules next */ + while ((rule = rule_context_next_rule (fc, rule, type))) { + g_string_truncate (fsearch, 0); + g_string_truncate (faction, 0); - filter_rule_build_code (rule, fsearch); - filter_filter_build_action ((FilterFilter *) rule, faction); - camel_filter_driver_add_rule (driver, rule->name, fsearch->str, faction->str); + filter_rule_build_code (rule, fsearch); + filter_filter_build_action ((FilterFilter *) rule, faction); + camel_filter_driver_add_rule (driver, rule->name, fsearch->str, faction->str); + } + + g_string_free (fsearch, TRUE); + g_string_free (faction, TRUE); } - g_string_free (fsearch, TRUE); - g_string_free (faction, TRUE); - g_object_unref (fc); return driver; @@ -745,11 +754,25 @@ mail_session_forget_password (const char *key) e_passwords_forget_password ("Mail", key); } +static void +mail_session_check_junk_notify (GConfClient *gconf, guint id, GConfEntry *entry, CamelSession *session) +{ + gchar *key; + + g_return_if_fail (gconf_entry_get_key (entry) != NULL); + g_return_if_fail (gconf_entry_get_value (entry) != NULL); + + key = strrchr (gconf_entry_get_key (entry), '/'); + if (!strcmp (key, "check_incoming")) + camel_session_set_check_junk (session, gconf_value_get_bool (gconf_entry_get_value (entry))); +} + void mail_session_init (const char *base_directory) { char *camel_dir; - + GConfClient *gconf; + if (camel_init (base_directory, TRUE) != 0) exit (0); @@ -758,8 +781,13 @@ mail_session_init (const char *base_directory) camel_dir = g_strdup_printf ("%s/mail", base_directory); camel_session_construct (session, camel_dir); + gconf = mail_config_get_gconf_client (); + camel_session_set_check_junk (session, gconf_client_get_bool (gconf, "/apps/evolution/mail/junk/check_incoming", NULL)); + session_check_junk_notify_id = gconf_client_notify_add (gconf, "/apps/evolution/mail/junk", + (GConfClientNotifyFunc) mail_session_check_junk_notify, + session, NULL, NULL); session->junk_plugin = CAMEL_JUNK_PLUGIN (em_junk_filter_get_plugin ()); - + /* The shell will tell us to go online. */ camel_session_set_online ((CamelSession *) session, FALSE); -- cgit v1.2.3