Commit 8dfd4278 authored by Matthew Barnes's avatar Matthew Barnes
Browse files

Convert junk filtering EPlugins to EExtensions.

We now have a proper junk mail filtering API.  All junk filtering
extensions must subclass EMailJunkFilter for user preferences and
availability testing, and implement the CamelJunkFilter interface
for the actual junk filtering and learning operations.

The bogofilter module should be feature-equivalent to its former
EPlugin.  The spamassassin module is far more complex.  It's nearly
feature-equivalent to its former EPlugin, but I ditched the spamd
respawning code since it seemed unnecessary for a mail client to
have to deal with.  If there's a huge outcry from users about it
I'll reluctantly put it back, but I don't expect one.

This gets us a step closer to killing off EConfig, and eventually
the EPlugin framework itself.
parent 2b342a4d
......@@ -198,8 +198,6 @@ case "$host" in
os_win32=yes
NO_UNDEFINED='-no-undefined'
SOEXT='.dll'
SA_JUNK_PLUGIN=''
BF_JUNK_PLUGIN=''
DL_LIB=''
SOFTOKN3_LIB=''
CHAMPLAIN_REQUIREMENT=''
......@@ -218,8 +216,6 @@ case "$host" in
os_win32=no
NO_UNDEFINED='-no-undefined'
SOEXT='.so'
SA_JUNK_PLUGIN=sa-junk-plugin
BF_JUNK_PLUGIN=bogo-junk-plugin
DL_LIB='-ldl'
SOFTOKN3_LIB='-lsoftokn3'
;;
......@@ -1437,8 +1433,8 @@ AC_ARG_ENABLE([plugins],
dnl Add any new plugins here
plugins_base_always="calendar-file calendar-http itip-formatter default-source addressbook-file mark-all-read publish-calendar caldav imap-features google-account-setup webdav-account-setup"
plugins_base="$plugins_base_always $SA_JUNK_PLUGIN $BF_JUNK_PLUGIN"
dist_plugins_base="$plugins_base_always calendar-weather sa-junk-plugin bogo-junk-plugin"
plugins_base="$plugins_base_always"
dist_plugins_base="$plugins_base_always calendar-weather"
plugins_standard_always="bbdb save-calendar mail-to-task mailing-list-actions prefer-plain mail-notification attachment-reminder backup-restore email-custom-header face templates vcard-inline dbx-import"
......@@ -1754,6 +1750,7 @@ mail/importers/Makefile
maint/Makefile
modules/Makefile
modules/addressbook/Makefile
modules/bogofilter/Makefile
modules/calendar/Makefile
modules/mail/Makefile
modules/composer-autosave/Makefile
......@@ -1766,6 +1763,7 @@ modules/plugin-lib/Makefile
modules/plugin-manager/Makefile
modules/plugin-mono/Makefile
modules/plugin-python/Makefile
modules/spamassassin/Makefile
modules/startup-wizard/Makefile
modules/windows-sens/Makefile
plugins/Makefile
......@@ -1774,7 +1772,6 @@ plugins/attachment-reminder/Makefile
plugins/audio-inline/Makefile
plugins/backup-restore/Makefile
plugins/bbdb/Makefile
plugins/bogo-junk-plugin/Makefile
plugins/caldav/Makefile
plugins/calendar-file/Makefile
plugins/calendar-http/Makefile
......@@ -1795,7 +1792,6 @@ plugins/mark-all-read/Makefile
plugins/prefer-plain/Makefile
plugins/pst-import/Makefile
plugins/publish-calendar/Makefile
plugins/sa-junk-plugin/Makefile
plugins/save-calendar/Makefile
plugins/templates/Makefile
plugins/tnef-attachments/Makefile
......
......@@ -56,6 +56,8 @@ mailinclude_HEADERS = \
e-mail-enums.h \
e-mail-enumtypes.h \
e-mail-folder-utils.h \
e-mail-junk-filter.h \
e-mail-junk-options.h \
e-mail-label-action.h \
e-mail-label-dialog.h \
e-mail-label-list-store.h \
......@@ -91,7 +93,6 @@ mailinclude_HEADERS = \
em-format-html-display.h \
em-format-html-print.h \
em-html-stream.h \
em-junk.h \
em-search-context.h \
em-subscription-editor.h \
em-sync-stream.h \
......@@ -128,6 +129,8 @@ libevolution_mail_la_SOURCES = \
e-mail-display.c \
e-mail-enumtypes.c \
e-mail-folder-utils.c \
e-mail-junk-filter.c \
e-mail-junk-options.c \
e-mail-label-action.c \
e-mail-label-dialog.c \
e-mail-label-list-store.c \
......@@ -163,7 +166,6 @@ libevolution_mail_la_SOURCES = \
em-format-html-display.c \
em-format-html-print.c \
em-html-stream.c \
em-junk.c \
em-search-context.c \
em-subscription-editor.c \
em-sync-stream.c \
......
/*
* em-junk.h
* e-mail-junk-filter.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
......@@ -14,52 +14,69 @@
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*
* Authors:
* Vivek Jain <jvivek@novell.com>
*
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
*
*/
#ifndef EM_JUNK_H
#define EM_JUNK_H
#include "e-mail-junk-filter.h"
#include <mail/e-mail-session.h>
G_DEFINE_ABSTRACT_TYPE (
EMailJunkFilter,
e_mail_junk_filter,
E_TYPE_EXTENSION)
static void
e_mail_junk_filter_class_init (EMailJunkFilterClass *class)
{
EExtensionClass *extension_class;
extension_class = E_EXTENSION_CLASS (class);
extension_class->extensible_type = E_TYPE_MAIL_SESSION;
}
#include <camel/camel.h>
#include <e-util/e-plugin.h>
static void
e_mail_junk_filter_init (EMailJunkFilter *junk_filter)
{
}
#define EM_JUNK_ERROR (em_junk_error_quark ())
gboolean
e_mail_junk_filter_available (EMailJunkFilter *junk_filter)
{
EMailJunkFilterClass *class;
G_BEGIN_DECLS
g_return_val_if_fail (E_IS_MAIL_JUNK_FILTER (junk_filter), FALSE);
typedef struct _EMJunkTarget EMJunkTarget;
typedef struct _EMJunkInterface EMJunkInterface;
class = E_MAIL_JUNK_FILTER_GET_CLASS (junk_filter);
g_return_val_if_fail (class->available != NULL, FALSE);
typedef void (*EMJunkHookFunc) (EPlugin *plugin, EMJunkTarget *data);
return class->available (junk_filter);
}
struct _EMJunkTarget {
CamelMimeMessage *m;
GError *error;
};
GtkWidget *
e_mail_junk_filter_new_config_widget (EMailJunkFilter *junk_filter)
{
EMailJunkFilterClass *class;
GtkWidget *widget = NULL;
struct _EMJunkInterface {
CamelJunkPlugin camel;
g_return_val_if_fail (E_IS_MAIL_JUNK_FILTER (junk_filter), NULL);
/* The hook forwards calls from Camel to the EPlugin. */
EPluginHook *hook;
class = E_MAIL_JUNK_FILTER_GET_CLASS (junk_filter);
/* These are symbol names in the EPlugin. */
gchar *check_junk;
gchar *report_junk;
gchar *report_notjunk;
gchar *commit_reports;
gchar *validate_binary;
if (class->new_config_widget != NULL)
widget = class->new_config_widget (junk_filter);
gchar *plugin_name;
};
return widget;
}
GQuark em_junk_error_quark (void);
gint
e_mail_junk_filter_compare (EMailJunkFilter *junk_filter_a,
EMailJunkFilter *junk_filter_b)
{
EMailJunkFilterClass *class_a;
EMailJunkFilterClass *class_b;
G_END_DECLS
class_a = E_MAIL_JUNK_FILTER_GET_CLASS (junk_filter_a);
class_b = E_MAIL_JUNK_FILTER_GET_CLASS (junk_filter_b);
#endif /* EM_JUNK_H */
return g_utf8_collate (class_a->display_name, class_b->display_name);
}
/*
* e-mail-junk-filter.h
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*/
#ifndef E_MAIL_JUNK_FILTER_H
#define E_MAIL_JUNK_FILTER_H
#include <gtk/gtk.h>
#include <e-util/e-extension.h>
/* Standard GObject macros */
#define E_TYPE_MAIL_JUNK_FILTER \
(e_mail_junk_filter_get_type ())
#define E_MAIL_JUNK_FILTER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST \
((obj), E_TYPE_MAIL_JUNK_FILTER, EMailJunkFilter))
#define E_MAIL_JUNK_FILTER_CLASS(cls) \
(G_TYPE_CHECK_CLASS_CAST \
((cls), E_TYPE_MAIL_JUNK_FILTER, EMailJunkFilterClass))
#define E_IS_MAIL_JUNK_FILTER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE \
((obj), E_TYPE_MAIL_JUNK_FILTER))
#define E_IS_MAIL_JUNK_FILTER_CLASS(cls) \
(G_TYPE_CHECK_CLASS_TYPE \
((cls), E_TYPE_MAIL_JUNK_FILTER))
#define E_MAIL_JUNK_FILTER_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS \
((obj), E_TYPE_MAIL_JUNK_FILTER, EMailJunkFilterClass))
G_BEGIN_DECLS
typedef struct _EMailJunkFilter EMailJunkFilter;
typedef struct _EMailJunkFilterClass EMailJunkFilterClass;
typedef struct _EMailJunkFilterPrivate EMailJunkFilterPrivate;
struct _EMailJunkFilter {
EExtension parent;
EMailJunkFilterPrivate *priv;
};
struct _EMailJunkFilterClass {
EExtensionClass parent_class;
const gchar *filter_name;
const gchar *display_name;
gboolean (*available) (EMailJunkFilter *junk_filter);
GtkWidget * (*new_config_widget) (EMailJunkFilter *junk_filter);
};
GType e_mail_junk_filter_get_type (void) G_GNUC_CONST;
gboolean e_mail_junk_filter_available (EMailJunkFilter *junk_filter);
GtkWidget * e_mail_junk_filter_new_config_widget
(EMailJunkFilter *junk_filter);
gint e_mail_junk_filter_compare (EMailJunkFilter *junk_filter_a,
EMailJunkFilter *junk_filter_b);
G_END_DECLS
#endif /* E_MAIL_JUNK_FILTER_H */
/*
* e-mail-junk-options.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*/
#include "e-mail-junk-options.h"
#include <config.h>
#include <glib/gi18n-lib.h>
#include <mail/e-mail-junk-filter.h>
#define E_MAIL_JUNK_OPTIONS_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE \
((obj), E_TYPE_MAIL_JUNK_OPTIONS, EMailJunkOptionsPrivate))
G_DEFINE_TYPE (
EMailJunkOptions,
e_mail_junk_options,
GTK_TYPE_GRID)
struct _EMailJunkOptionsPrivate {
EMailSession *session;
GtkWidget *label; /* not referenced */
GtkWidget *combo_box; /* not referenced */
GtkWidget *option_box; /* not referenced */
GPtrArray *widgets; /* not referenced */
GBinding *active_id_binding;
};
enum {
PROP_0,
PROP_SESSION
};
enum {
COLUMN_FILTER_NAME,
COLUMN_DISPLAY_NAME
};
static void
mail_junk_options_combo_box_changed_cb (GtkComboBox *combo_box,
EMailJunkOptions *options)
{
GPtrArray *array;
gint active;
guint ii;
array = options->priv->widgets;
active = gtk_combo_box_get_active (combo_box);
for (ii = 0; ii < array->len; ii++) {
GtkWidget *widget = GTK_WIDGET (array->pdata[ii]);
gtk_widget_set_visible (widget, ii == active);
}
}
static void
mail_junk_options_rebuild (EMailJunkOptions *options)
{
EMailSession *session;
GtkComboBox *combo_box;
GtkTreeModel *model;
GtkBox *option_box;
GList *list = NULL;
GList *link;
guint n_filters;
session = e_mail_junk_options_get_session (options);
combo_box = GTK_COMBO_BOX (options->priv->combo_box);
option_box = GTK_BOX (options->priv->option_box);
/* Remove the GtkComboBox:active-id binding so it doesn't
* affect EMailSession:junk-filter-name when we clear the
* combo box's list model. */
if (options->priv->active_id_binding != NULL) {
g_object_unref (options->priv->active_id_binding);
options->priv->active_id_binding = NULL;
}
model = gtk_combo_box_get_model (combo_box);
gtk_list_store_clear (GTK_LIST_STORE (model));
g_ptr_array_foreach (
options->priv->widgets,
(GFunc) gtk_widget_destroy, NULL);
g_ptr_array_set_size (options->priv->widgets, 0);
if (session != NULL)
list = e_mail_session_get_available_junk_filters (session);
for (link = list; link != NULL; link = g_list_next (link)) {
EMailJunkFilter *junk_filter;
EMailJunkFilterClass *class;
GtkWidget *widget;
GtkTreeIter iter;
junk_filter = E_MAIL_JUNK_FILTER (link->data);
class = E_MAIL_JUNK_FILTER_GET_CLASS (junk_filter);
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
gtk_list_store_set (
GTK_LIST_STORE (model), &iter,
COLUMN_FILTER_NAME, class->filter_name,
COLUMN_DISPLAY_NAME, class->display_name,
-1);
/* Create a configuration widget for this junk filter,
* or else just create an empty placeholder widget. */
widget = e_mail_junk_filter_new_config_widget (junk_filter);
if (widget == NULL)
widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
g_ptr_array_add (options->priv->widgets, widget);
/* Set extra padding to 12px, since only one child of
* 'option_box' is visible at a time, and we still want
* the extra padding if the first grid row is invisible. */
gtk_box_pack_start (option_box, widget, FALSE, FALSE, 12);
}
/* Synchronize the combo box with the active junk filter. */
if (session != NULL) {
GBinding *binding;
binding = g_object_bind_property (
session, "junk-filter-name",
combo_box, "active-id",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
options->priv->active_id_binding = binding;
}
/* Select the first combo box item if we need to. If there's
* no first item to select, this will silently do nothing. */
if (gtk_combo_box_get_active (combo_box) < 0)
gtk_combo_box_set_active (combo_box, 0);
/* Update visibility of widgets. */
n_filters = g_list_length (list);
gtk_widget_set_visible (GTK_WIDGET (options), n_filters > 0);
gtk_widget_set_visible (options->priv->label, n_filters > 1);
gtk_widget_set_visible (options->priv->combo_box, n_filters > 1);
g_list_free (list);
}
static void
mail_junk_options_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SESSION:
e_mail_junk_options_set_session (
E_MAIL_JUNK_OPTIONS (object),
g_value_get_object (value));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
mail_junk_options_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
switch (property_id) {
case PROP_SESSION:
g_value_set_object (
value,
e_mail_junk_options_get_session (
E_MAIL_JUNK_OPTIONS (object)));
return;
}
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
static void
mail_junk_options_dispose (GObject *object)
{
EMailJunkOptionsPrivate *priv;
priv = E_MAIL_JUNK_OPTIONS_GET_PRIVATE (object);
if (priv->session != NULL) {
g_object_unref (priv->session);
priv->session = NULL;
}
/* Chain up to parent's dispose() method. */
G_OBJECT_CLASS (e_mail_junk_options_parent_class)->dispose (object);
}
static void
mail_junk_options_finalize (GObject *object)
{
EMailJunkOptionsPrivate *priv;
priv = E_MAIL_JUNK_OPTIONS_GET_PRIVATE (object);
g_ptr_array_free (priv->widgets, TRUE);
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_mail_junk_options_parent_class)->finalize (object);
}
static void
mail_junk_options_constructed (GObject *object)
{
EMailJunkOptionsPrivate *priv;
GtkCellRenderer *cell_renderer;
GtkCellLayout *cell_layout;
GtkListStore *list_store;
GtkWidget *widget;
priv = E_MAIL_JUNK_OPTIONS_GET_PRIVATE (object);
/* XXX The margins we're using here are tailored to its
* placement in the Junk tab of Mail Preferences.
* EMailJunkOptions is not really reusable as is. */
/* Chain up to parent's constructed() method. */
G_OBJECT_CLASS (e_mail_junk_options_parent_class)->constructed (object);
gtk_grid_set_column_spacing (GTK_GRID (object), 6);
list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
/* Label + combo box has a 12px left margin so it's
* aligned with the junk mail options above it. */
widget = gtk_label_new (_("Junk filtering software:"));
gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
gtk_widget_set_margin_left (widget, 12);
gtk_grid_attach (GTK_GRID (object), widget, 0, 0, 1, 1);
priv->label = widget; /* not referenced */
gtk_widget_show (widget);
widget = gtk_combo_box_new_with_model (GTK_TREE_MODEL (list_store));
gtk_combo_box_set_id_column (
GTK_COMBO_BOX (widget), COLUMN_FILTER_NAME);
gtk_grid_attach (GTK_GRID (object), widget, 1, 0, 1, 1);
priv->combo_box = widget; /* not referenced */
gtk_widget_show (widget);
g_signal_connect (
widget, "changed",
G_CALLBACK (mail_junk_options_combo_box_changed_cb), object);
/* The config widgets that come from EMailJunkFilter have no
* left margin, since they usually include a bold header and
* interactive widgets with their own left margin. */
widget = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_grid_attach (GTK_GRID (object), widget, 0, 1, 2, 1);
priv->option_box = widget; /* not referenced */
gtk_widget_show (widget);
cell_layout = GTK_CELL_LAYOUT (priv->combo_box);
cell_renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (cell_layout, cell_renderer, FALSE);
gtk_cell_layout_add_attribute (
cell_layout, cell_renderer,
"text", COLUMN_DISPLAY_NAME);
g_object_unref (list_store);
}
static void
mail_junk_options_map (GtkWidget *widget)
{
/* Chain up to parent's map() method. */
GTK_WIDGET_CLASS (e_mail_junk_options_parent_class)->map (widget);
mail_junk_options_rebuild (E_MAIL_JUNK_OPTIONS (widget));
}
static void
e_mail_junk_options_class_init (EMailJunkOptionsClass *class)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
g_type_class_add_private (class, sizeof (EMailJunkOptionsPrivate));
object_class = G_OBJECT_CLASS (class);
object_class->set_property = mail_junk_options_set_property;
object_class->get_property = mail_junk_options_get_property;
object_class->dispose = mail_junk_options_dispose;
object_class->finalize = mail_junk_options_finalize;
object_class->constructed = mail_junk_options_constructed;
widget_class = GTK_WIDGET_CLASS (class);
widget_class->map = mail_junk_options_map;
g_object_class_install_property (
object_class,
PROP_SESSION,
g_param_spec_object (
"session",
NULL,
NULL,
E_TYPE_MAIL_SESSION,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
static void
e_mail_junk_options_init (EMailJunkOptions *options)
{
options->priv = E_MAIL_JUNK_OPTIONS_GET_PRIVATE (options);
options->priv->widgets = g_ptr_array_new ();
}
GtkWidget *
e_mail_junk_options_new (EMailSession *session)
{
g_return_val_if_fail (E_IS_MAIL_SESSION (session), NULL);
return g_object_new (
E_TYPE_MAIL_JUNK_OPTIONS, "session", session, NULL);
}
EMailSession *
e_mail_junk_options_get_session (EMailJunkOptions *options)
{
g_return_val_if_fail (E_IS_MAIL_JUNK_OPTIONS (options), NULL);
return options->priv->session;
}
void
e_mail_junk_options_set_session (EMailJunkOptions *options,
EMailSession *session)
{