aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/bogo-junk-plugin
diff options
context:
space:
mode:
authorsrinivasa ragavan <sragavan@novell.com>2008-12-15 14:41:26 +0800
committerSrinivasa Ragavan <sragavan@src.gnome.org>2008-12-15 14:41:26 +0800
commit19db3033bfa7429b00a5c3b5074ddd13567516bf (patch)
tree218c958dbb30fc9d1f0f7a54b3ac0c09a1d01c29 /plugins/bogo-junk-plugin
parentb6c295f4e4fe22e292db9773151d17a83703982b (diff)
downloadgsoc2013-evolution-19db3033bfa7429b00a5c3b5074ddd13567516bf.tar
gsoc2013-evolution-19db3033bfa7429b00a5c3b5074ddd13567516bf.tar.gz
gsoc2013-evolution-19db3033bfa7429b00a5c3b5074ddd13567516bf.tar.bz2
gsoc2013-evolution-19db3033bfa7429b00a5c3b5074ddd13567516bf.tar.lz
gsoc2013-evolution-19db3033bfa7429b00a5c3b5074ddd13567516bf.tar.xz
gsoc2013-evolution-19db3033bfa7429b00a5c3b5074ddd13567516bf.tar.zst
gsoc2013-evolution-19db3033bfa7429b00a5c3b5074ddd13567516bf.zip
init the bogofilter if it wasn't. say that evolution's welcome message is
2008-12-15 srinivasa ragavan <sragavan@novell.com> * makefile.am: * bf-junk-filter.c: (init_db), (pipe_to_bogofilter): init the bogofilter if it wasn't. say that evolution's welcome message is not junk. svn path=/trunk/; revision=36883
Diffstat (limited to 'plugins/bogo-junk-plugin')
-rw-r--r--plugins/bogo-junk-plugin/ChangeLog7
-rw-r--r--plugins/bogo-junk-plugin/Makefile.am1
-rw-r--r--plugins/bogo-junk-plugin/bf-junk-filter.c47
3 files changed, 54 insertions, 1 deletions
diff --git a/plugins/bogo-junk-plugin/ChangeLog b/plugins/bogo-junk-plugin/ChangeLog
index b14a280332..e4007d4525 100644
--- a/plugins/bogo-junk-plugin/ChangeLog
+++ b/plugins/bogo-junk-plugin/ChangeLog
@@ -1,3 +1,10 @@
+2008-12-15 srinivasa ragavan <sragavan@novell.com>
+
+ * makefile.am:
+ * bf-junk-filter.c: (init_db), (pipe_to_bogofilter): init the
+ bogofilter if it wasn't. say that evolution's welcome message is not
+ junk.
+
2008-10-14 Sankar P <psankar@novell.com>
License Changes
diff --git a/plugins/bogo-junk-plugin/Makefile.am b/plugins/bogo-junk-plugin/Makefile.am
index cc89c0072e..886d60392d 100644
--- a/plugins/bogo-junk-plugin/Makefile.am
+++ b/plugins/bogo-junk-plugin/Makefile.am
@@ -1,5 +1,6 @@
INCLUDES = \
-I$(top_srcdir) \
+ -DWELCOME_MESSAGE=\""$(privdatadir)/default/C/mail/local/Inbox"\" \
$(EVOLUTION_MAIL_CFLAGS)
@EVO_PLUGIN_RULE@
diff --git a/plugins/bogo-junk-plugin/bf-junk-filter.c b/plugins/bogo-junk-plugin/bf-junk-filter.c
index 1e5fbbc656..aca10643e8 100644
--- a/plugins/bogo-junk-plugin/bf-junk-filter.c
+++ b/plugins/bogo-junk-plugin/bf-junk-filter.c
@@ -40,6 +40,8 @@
#include "mail/em-config.h"
#include <mail/em-junk-hook.h>
#include <camel/camel-data-wrapper.h>
+#include <camel/camel-mime-message.h>
+#include <camel/camel-mime-parser.h>
#include <camel/camel-stream-fs.h>
#include <camel/camel-debug.h>
#include <gconf/gconf-client.h>
@@ -69,6 +71,7 @@ void *em_junk_bf_validate_binary (EPlugin *ep, EMJunkHookTarget *target);
void em_junk_bf_report_junk (EPlugin *ep, EMJunkHookTarget *target);
void em_junk_bf_report_non_junk (EPlugin *ep, EMJunkHookTarget *target);
void em_junk_bf_commit_reports (EPlugin *ep, EMJunkHookTarget *target);
+static gint pipe_to_bogofilter (CamelMimeMessage *msg, gchar **argv, GError **error);
/* eplugin stuff */
int e_plugin_lib_enable (EPluginLib *ep, int enable);
@@ -78,6 +81,37 @@ int e_plugin_lib_enable (EPluginLib *ep, int enable);
static gboolean em_junk_bf_unicode = TRUE;
+static void
+init_db ()
+{
+ CamelStream *stream = camel_stream_fs_new_with_name (WELCOME_MESSAGE, O_RDONLY, 0);
+ CamelMimeParser *parser = camel_mime_parser_new ();
+ CamelMimeMessage *msg = camel_mime_message_new ();
+ gchar *argv[] = {
+ em_junk_bf_binary,
+ "-n",
+ NULL,
+ NULL
+ };
+
+ camel_mime_parser_init_with_stream (parser, stream);
+ camel_mime_parser_scan_from (parser, FALSE);
+ camel_object_unref (stream);
+
+ camel_mime_part_construct_from_parser ((CamelMimePart *) msg, parser);
+ camel_object_unref (parser);
+
+ d(fprintf (stderr, "Initing the bogofilter DB with Welcome message\n"));
+
+ if (em_junk_bf_unicode) {
+ argv[2] = "--unicode=yes";
+ }
+
+ pipe_to_bogofilter (msg, argv, NULL);
+ camel_object_unref (msg);
+
+}
+
static gint
pipe_to_bogofilter (CamelMimeMessage *msg, gchar **argv, GError **error)
{
@@ -88,7 +122,9 @@ pipe_to_bogofilter (CamelMimeMessage *msg, gchar **argv, GError **error)
gint status;
gint waitres;
gint res;
+ static gboolean only_once = FALSE;
+retry:
if (camel_debug_start ("junk")) {
int i;
@@ -153,8 +189,17 @@ pipe_to_bogofilter (CamelMimeMessage *msg, gchar **argv, GError **error)
res = BOGOFILTER_ERROR;
}
- if (res < 0 || res > 2)
+ if (res < 0 || res > 2) {
+ if (!only_once) {
+ /* Create wordlist.db */
+ only_once = TRUE;
+ init_db();
+
+ goto retry;
+ }
g_set_error (error, EM_JUNK_ERROR, res, _("Pipe to Bogofilter failed, error code: %d."), res);
+
+ }
return res;
}