From 1c4599a82920d2ca4144517a32af9dfd453435be Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Mon, 12 Jan 2004 17:11:18 +0000 Subject: added SA prefs (mail_session_get_sa_local_only): new helper method 2004-01-12 Radek Doulik * mail-session.c: added SA prefs (mail_session_get_sa_local_only): new helper method (mail_session_set_sa_local_only): ditto (mail_session_get_sa_use_daemon): ditto (mail_session_set_sa_use_daemon): ditto (mail_session_check_junk_notify): fix the key comparison (mail_session_init): add gconf dir so that we get notified * mail-config.glade: added SA preferences * em-mailer-prefs.c (em_mailer_prefs_construct): added more junk prefs (em_mailer_prefs_apply): ditto * em-junk-filter.c: use preferences svn path=/trunk/; revision=24174 --- mail/ChangeLog | 18 ++++++++ mail/em-junk-filter.c | 61 +++++++++++++++--------- mail/em-mailer-prefs.c | 14 ++++++ mail/em-mailer-prefs.h | 2 + mail/evolution-mail.schemas.in.in | 22 +++++++++ mail/mail-config.glade | 97 +++++++++++++++++---------------------- mail/mail-session.c | 42 ++++++++++++++++- mail/mail-session.h | 5 ++ 8 files changed, 182 insertions(+), 79 deletions(-) diff --git a/mail/ChangeLog b/mail/ChangeLog index ddb65d5891..9644d88135 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,21 @@ +2004-01-12 Radek Doulik + + * mail-session.c: added SA prefs + (mail_session_get_sa_local_only): new helper method + (mail_session_set_sa_local_only): ditto + (mail_session_get_sa_use_daemon): ditto + (mail_session_set_sa_use_daemon): ditto + (mail_session_check_junk_notify): fix the key comparison + (mail_session_init): add gconf dir so that we get notified + + * mail-config.glade: added SA preferences + + * em-mailer-prefs.c (em_mailer_prefs_construct): added more junk + prefs + (em_mailer_prefs_apply): ditto + + * em-junk-filter.c: use preferences + 2004-01-12 Larry Ewing * GNOME_Evolution_Mail.server.in.in: fix up the controls factory diff --git a/mail/em-junk-filter.c b/mail/em-junk-filter.c index 8c5888e7c5..d81b04feda 100644 --- a/mail/em-junk-filter.c +++ b/mail/em-junk-filter.c @@ -32,6 +32,7 @@ #include #include +#include "mail-session.h" #include "em-junk-filter.h" #define LOCK(x) pthread_mutex_lock(&x) @@ -228,7 +229,7 @@ em_junk_sa_test_spamd () for (i = 0; i < NPORTS; i ++) { d(fprintf (stderr, "trying to run spamd at port %d\n", port)); - sad_args [2] = g_strdup_printf ("spamd --port %d --local --daemonize", port); + sad_args [2] = g_strdup_printf ("spamd --port %d %s--daemonize", port, mail_session_get_sa_local_only () ? "--local " : ""); if (!pipe_to_sa (NULL, NULL, 3, sad_args)) { g_free (sad_args [2]); em_junk_sa_use_spamc = TRUE; @@ -282,10 +283,11 @@ em_junk_sa_check_junk (CamelMimeMessage *msg) " -c" /* Exit with a non-zero exit code if the tested message was junk */ " -p %d", em_junk_sa_spamd_port)) - : g_strdup ("spamassassin" - " --exit-code" /* Exit with a non-zero exit code if the - tested message was junk */ - " --local"); /* Local tests only (no online tests) */ + : g_strdup_printf ("spamassassin" + " --exit-code%s", /* Exit with a non-zero exit code if the + tested message was junk */ + mail_session_get_sa_local_only () + ? " --local" : ""); /* Local tests only (no online tests) */ retval = pipe_to_sa (msg, NULL, 3, args); @@ -300,18 +302,23 @@ em_junk_sa_report_junk (CamelMimeMessage *msg) static gchar *args [4] = { "/bin/sh", "-c", - "sa-learn" - " --no-rebuild" /* do not rebuild db */ - " --spam" /* report junk */ - " --single" /* single message */ - " --local", /* local only */ + NULL, NULL }; d(fprintf (stderr, "em_junk_sa_report_junk\n")); - if (em_junk_sa_is_available ()) + if (em_junk_sa_is_available ()) { + args [2] = g_strdup_printf + ("sa-learn" + " --no-rebuild" /* do not rebuild db */ + " --spam" /* report junk */ + " --single%s", /* single message */ + mail_session_get_sa_local_only () + ? " --local" : ""); /* local only */ pipe_to_sa (msg, NULL, 3, args); + g_free (args [2]); + } } static void @@ -320,18 +327,23 @@ em_junk_sa_report_notjunk (CamelMimeMessage *msg) static gchar *args [4] = { "/bin/sh", "-c", - "sa-learn" - " --no-rebuild" /* do not rebuild db */ - " --ham" /* report notjunk */ - " --single" /* single message */ - " --local", /* local only */ + NULL, NULL }; d(fprintf (stderr, "em_junk_sa_report_notjunk\n")); - if (em_junk_sa_is_available ()) + if (em_junk_sa_is_available ()) { + args [2] = g_strdup_printf + ("sa-learn" + " --no-rebuild" /* do not rebuild db */ + " --ham" /* report notjunk */ + " --single%s", /* single message */ + mail_session_get_sa_local_only () + ? " --local" : ""); /* local only */ pipe_to_sa (msg, NULL, 3, args); + g_free (args [2]); + } } static void @@ -340,16 +352,21 @@ em_junk_sa_commit_reports (void) static gchar *args [4] = { "/bin/sh", "-c", - "sa-learn" - " --rebuild" /* do not rebuild db */ - " --local", /* local only */ + NULL, NULL }; - d(fprintf (stderr, "em_junk_sa_commit_reports\n");) + d(fprintf (stderr, "em_junk_sa_commit_reports\n")); - if (em_junk_sa_is_available ()) + if (em_junk_sa_is_available ()) { + args [2] = g_strdup_printf + ("sa-learn" + " --rebuild%s", /* do not rebuild db */ + mail_session_get_sa_local_only () + ? " --local" : ""); /* local only */ pipe_to_sa (NULL, NULL, 3, args); + g_free (args [2]); + } } const EMJunkPlugin * diff --git a/mail/em-mailer-prefs.c b/mail/em-mailer-prefs.c index 8c6cbabec1..d5a80beef3 100644 --- a/mail/em-mailer-prefs.c +++ b/mail/em-mailer-prefs.c @@ -652,6 +652,16 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs) 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); + + prefs->sa_local_tests_only = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkSALocalTestsOnly")); + bool = gconf_client_get_bool (prefs->gconf, "/apps/evolution/mail/junk/sa/local_only", NULL); + gtk_toggle_button_set_active (prefs->sa_local_tests_only, bool); + g_signal_connect (prefs->sa_local_tests_only, "toggled", G_CALLBACK (settings_changed), prefs); + + prefs->sa_use_daemon = GTK_TOGGLE_BUTTON (glade_xml_get_widget (gui, "chkSAUseDaemon")); + bool = gconf_client_get_bool (prefs->gconf, "/apps/evolution/mail/junk/sa/use_daemon", NULL); + gtk_toggle_button_set_active (prefs->sa_use_daemon, bool); + g_signal_connect (prefs->sa_use_daemon, "toggled", G_CALLBACK (settings_changed), prefs); } @@ -792,6 +802,10 @@ em_mailer_prefs_apply (EMMailerPrefs *prefs) /* 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_set_bool (prefs->gconf, "/apps/evolution/mail/junk/sa/local_only", + gtk_toggle_button_get_active (prefs->sa_local_tests_only), NULL); + gconf_client_set_bool (prefs->gconf, "/apps/evolution/mail/junk/sa/use_daemon", + gtk_toggle_button_get_active (prefs->sa_use_daemon), NULL); gconf_client_suggest_sync (prefs->gconf, NULL); } diff --git a/mail/em-mailer-prefs.h b/mail/em-mailer-prefs.h index 60c362607c..3a182476ff 100644 --- a/mail/em-mailer-prefs.h +++ b/mail/em-mailer-prefs.h @@ -116,6 +116,8 @@ struct _EMMailerPrefs { /* Junk prefs */ GtkToggleButton *check_incoming; + GtkToggleButton *sa_local_tests_only; + GtkToggleButton *sa_use_daemon; }; struct _EMMailerPrefsClass { diff --git a/mail/evolution-mail.schemas.in.in b/mail/evolution-mail.schemas.in.in index 7f8d6a25c3..8e2bf3bec8 100644 --- a/mail/evolution-mail.schemas.in.in +++ b/mail/evolution-mail.schemas.in.in @@ -637,6 +637,28 @@ + + /schemas/apps/evolution/mail/junk/sa/local_only + /apps/evolution/mail/junk/sa/local_only + evolution-mail + bool + true + + + + /schemas/apps/evolution/mail/junk/sa/use_daemon + /apps/evolution/mail/junk/sa/use_daemon + evolution-mail + bool + true + + Use Spamasssassin daemon and client + + Use Spamasssassin daemon and client (spamc/spamd) + + + + diff --git a/mail/mail-config.glade b/mail/mail-config.glade index 62fce2509a..70283e9153 100644 --- a/mail/mail-config.glade +++ b/mail/mail-config.glade @@ -4694,7 +4694,48 @@ For example: "Work" or "Personal" GTK_SHADOW_ETCHED_IN - + + 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 + + + @@ -6134,58 +6175,4 @@ 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 75f95f906b..02294201ea 100644 --- a/mail/mail-session.c +++ b/mail/mail-session.c @@ -72,6 +72,10 @@ typedef struct _MailSession { EMutex *lock; MailAsyncEvent *async; + + /* spamassassin filter options */ + gboolean sa_local_only; + gboolean sa_use_daemon; } MailSession; typedef struct _MailSessionClass { @@ -95,6 +99,8 @@ init (MailSession *session) { session->lock = e_mutex_new(E_MUTEX_REC); session->async = mail_async_event_new(); + session->sa_local_only = gconf_client_get_bool (mail_config_get_gconf_client (), "/apps/evolution/mail/junk/sa/local_only", NULL); + session->sa_use_daemon = gconf_client_get_bool (mail_config_get_gconf_client (), "/apps/evolution/mail/junk/sa/use_daemon", NULL); } static void @@ -754,6 +760,30 @@ mail_session_forget_password (const char *key) e_passwords_forget_password ("Mail", key); } +gboolean +mail_session_get_sa_local_only () +{ + return MAIL_SESSION (session)->sa_local_only; +} + +void +mail_session_set_sa_local_only (gboolean value) +{ + MAIL_SESSION (session)->sa_local_only = value; +} + +gboolean +mail_session_get_sa_use_daemon () +{ + return MAIL_SESSION (session)->sa_use_daemon; +} + +void +mail_session_set_sa_use_daemon (gboolean value) +{ + MAIL_SESSION (session)->sa_use_daemon = value; +} + static void mail_session_check_junk_notify (GConfClient *gconf, guint id, GConfEntry *entry, CamelSession *session) { @@ -763,8 +793,15 @@ mail_session_check_junk_notify (GConfClient *gconf, guint id, GConfEntry *entry, 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))); + if (key) { + key ++; + if (!strcmp (key, "check_incoming")) + camel_session_set_check_junk (session, gconf_value_get_bool (gconf_entry_get_value (entry))); + else if (!strcmp (key, "local_only")) + mail_session_set_sa_local_only (gconf_value_get_bool (gconf_entry_get_value (entry))); + else if (!strcmp (key, "use_daemon")) + mail_session_set_sa_use_daemon (gconf_value_get_bool (gconf_entry_get_value (entry))); + } } void @@ -782,6 +819,7 @@ mail_session_init (const char *base_directory) camel_session_construct (session, camel_dir); gconf = mail_config_get_gconf_client (); + gconf_client_add_dir (gconf, "/apps/evolution/mail/junk", GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); 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, diff --git a/mail/mail-session.h b/mail/mail-session.h index 2a7559964c..7fe591540c 100644 --- a/mail/mail-session.h +++ b/mail/mail-session.h @@ -49,6 +49,11 @@ void mail_session_forget_password (const char *key); void mail_session_flush_filter_log (void); +gboolean mail_session_get_sa_local_only (void); +void mail_session_set_sa_local_only (gboolean value); +gboolean mail_session_get_sa_use_daemon (void); +void mail_session_set_sa_use_daemon (gboolean value); + extern CamelSession *session; #ifdef __cplusplus -- cgit v1.2.3