diff options
author | David Ronis <david.ronis@mcgill.ca> | 2009-04-30 01:24:24 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2009-05-01 03:15:42 +0800 |
commit | 5a7a9e12bd4dda605e633c07c00bebfa8e01dfc3 (patch) | |
tree | b9403c6fc0d1d8d68115308b0d84ff781449e308 /plugins | |
parent | 8a361073d46b32e3ed7005e08e3f1cd53c025dbf (diff) | |
download | gsoc2013-evolution-5a7a9e12bd4dda605e633c07c00bebfa8e01dfc3.tar gsoc2013-evolution-5a7a9e12bd4dda605e633c07c00bebfa8e01dfc3.tar.gz gsoc2013-evolution-5a7a9e12bd4dda605e633c07c00bebfa8e01dfc3.tar.bz2 gsoc2013-evolution-5a7a9e12bd4dda605e633c07c00bebfa8e01dfc3.tar.lz gsoc2013-evolution-5a7a9e12bd4dda605e633c07c00bebfa8e01dfc3.tar.xz gsoc2013-evolution-5a7a9e12bd4dda605e633c07c00bebfa8e01dfc3.tar.zst gsoc2013-evolution-5a7a9e12bd4dda605e633c07c00bebfa8e01dfc3.zip |
BUGFIX: bug #579774 Use spamc to learn junk if available
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/sa-junk-plugin/em-junk-filter.c | 65 |
1 files changed, 57 insertions, 8 deletions
diff --git a/plugins/sa-junk-plugin/em-junk-filter.c b/plugins/sa-junk-plugin/em-junk-filter.c index 4cb554eb17..fb30833080 100644 --- a/plugins/sa-junk-plugin/em-junk-filter.c +++ b/plugins/sa-junk-plugin/em-junk-filter.c @@ -90,13 +90,17 @@ static volatile gboolean em_junk_sa_local_only; static volatile gboolean em_junk_sa_use_daemon; static char * em_junk_sa_preferred_socket_path; -static char *em_junk_sa_spamc_binaries [3] = {"spamc", "/usr/sbin/spamc", NULL}; -static char *em_junk_sa_spamd_binaries [3] = {"spamd", "/usr/sbin/spamd", NULL}; +static char *em_junk_sa_spamc_binaries [4] = {"spamc", "/usr/bin/spamc", "/usr/sbin/spamc", NULL}; +static char *em_junk_sa_spamd_binaries [4] = {"spamd", "/usr/bin/spamd", "/usr/sbin/spamd", NULL}; #define SPAMD_RESTARTS_SIZE 8 static time_t em_junk_sa_spamd_restarts [SPAMD_RESTARTS_SIZE] = {0, 0, 0, 0, 0, 0, 0, 0}; static int em_junk_sa_spamd_restarts_count = 0; +/* Variables to indicate whether spamd is running with --allow-tell */ +static int no_allow_tell; +static gboolean em_junk_sa_allow_tell_tested = FALSE; + char *em_junk_sa_spamc_gconf_binary = NULL; char *em_junk_sa_spamd_gconf_binary = NULL; @@ -303,6 +307,26 @@ em_junk_sa_test_spamd_running (char *binary, gboolean system) return rv; } + +/* + One time test to see if spamd is running with --allow-tell. The call + to spamc should return 0 if it is. (Thanks to Karsten Bräckelmann + for the idea). +*/ +static void +em_junk_sa_test_allow_tell (void) +{ + char *argv [4] = { + "spamc", + "-L", + "forget", + NULL + }; + + no_allow_tell = pipe_to_sa (NULL, "\n" , argv, NULL); + em_junk_sa_allow_tell_tested = TRUE; +} + static void em_junk_sa_test_spamassassin (void) { @@ -496,6 +520,10 @@ em_junk_sa_is_available (GError **error) if (!em_junk_sa_available) g_set_error (error, EM_JUNK_ERROR, 1, _("SpamAssassin is not available.")); + /* While we're at it, see if spamd is running with --allow-tell */ + if (!em_junk_sa_allow_tell_tested) + em_junk_sa_test_allow_tell () ; + pthread_mutex_unlock (&em_junk_sa_init_lock); return em_junk_sa_available; @@ -670,6 +698,13 @@ em_junk_sa_report_junk (EPlugin *ep, EMJunkHookTarget *target) NULL, NULL }; + /* Call setup for spamc */ + char *argv2[4] = { + "spamc", + "-L", + "spam", + NULL + }; gchar *sub = NULL; CamelMimeMessage *msg = target->m; @@ -677,13 +712,14 @@ em_junk_sa_report_junk (EPlugin *ep, EMJunkHookTarget *target) g_print ("\nreport junk?? %s\n", sub); d(fprintf (stderr, "em_junk_sa_report_junk\n")); - if (em_junk_sa_is_available (&target->error)) { - if (em_junk_sa_local_only) + if (no_allow_tell && em_junk_sa_local_only) argv[4] = "--local"; pthread_mutex_lock (&em_junk_sa_report_lock); - pipe_to_sa (msg, NULL, argv, &target->error); + pipe_to_sa (msg, NULL, + (no_allow_tell ? argv : argv2), + &target->error); pthread_mutex_unlock (&em_junk_sa_report_lock); } } @@ -700,16 +736,25 @@ em_junk_sa_report_non_junk (EPlugin *ep, EMJunkHookTarget *target) NULL, NULL }; + /* Setup for spamc */ + char *argv2[4] = { + "spamc", + "-L", + "ham", + NULL + }; CamelMimeMessage *msg = target->m; d(fprintf (stderr, "em_junk_sa_report_notjunk\n")); if (em_junk_sa_is_available (&target->error)) { - if (em_junk_sa_local_only) - argv[4] = "--local"; + if (no_allow_tell && em_junk_sa_local_only) + argv[4] = "--local"; pthread_mutex_lock (&em_junk_sa_report_lock); - pipe_to_sa (msg, NULL, argv, &target->error); + pipe_to_sa (msg, NULL, + (no_allow_tell ? argv : argv2), + &target->error); pthread_mutex_unlock (&em_junk_sa_report_lock); } } @@ -717,6 +762,10 @@ em_junk_sa_report_non_junk (EPlugin *ep, EMJunkHookTarget *target) void em_junk_sa_commit_reports (EPlugin *ep) { + /* Only meaningful if we're using sa-learn */ + if (!no_allow_tell) + return; + char *sync_op = ((get_spamassassin_version () >= 3) ? "--sync": "--rebuild"); char *argv[4] = { "sa-learn", |