diff options
Diffstat (limited to 'modules/mail')
-rw-r--r-- | modules/mail/Makefile.am | 2 | ||||
-rw-r--r-- | modules/mail/e-mail-junk-hook.c | 344 | ||||
-rw-r--r-- | modules/mail/e-mail-junk-hook.h | 66 | ||||
-rw-r--r-- | modules/mail/em-mailer-prefs.c | 164 | ||||
-rw-r--r-- | modules/mail/em-mailer-prefs.h | 6 | ||||
-rw-r--r-- | modules/mail/evolution-module-mail.c | 2 |
6 files changed, 19 insertions, 565 deletions
diff --git a/modules/mail/Makefile.am b/modules/mail/Makefile.am index 884d050d78..0bea9ac1a2 100644 --- a/modules/mail/Makefile.am +++ b/modules/mail/Makefile.am @@ -27,8 +27,6 @@ libevolution_module_mail_la_SOURCES = \ e-mail-config-web-view.h \ e-mail-event-hook.c \ e-mail-event-hook.h \ - e-mail-junk-hook.c \ - e-mail-junk-hook.h \ e-mail-shell-backend.c \ e-mail-shell-backend.h \ e-mail-shell-content.c \ diff --git a/modules/mail/e-mail-junk-hook.c b/modules/mail/e-mail-junk-hook.c deleted file mode 100644 index 4ccc404e8d..0000000000 --- a/modules/mail/e-mail-junk-hook.c +++ /dev/null @@ -1,344 +0,0 @@ -/* - * e-mail-junk-hook.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/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-mail-junk-hook.h" - -#include <glib/gi18n.h> - -#include "e-util/e-alert-dialog.h" -#include "shell/e-shell.h" - -#include "mail/em-junk.h" -#include "mail/em-utils.h" -#include "mail/e-mail-backend.h" -#include "mail/e-mail-session.h" - -struct _EMailJunkHookPrivate { - EMJunkInterface interface; -}; - -struct ErrorData { - const gchar *error_message; - GError *error; -}; - -static gpointer parent_class; -static GType mail_junk_hook_type; - -static gboolean -mail_junk_hook_idle_cb (struct ErrorData *data) -{ - EShell *shell; - EShellBackend *shell_backend; - - shell = e_shell_get_default (); - shell_backend = e_shell_get_backend_by_name (shell, "mail"); - - e_mail_backend_submit_alert ( - E_MAIL_BACKEND (shell_backend), - data->error_message, data->error->message, NULL); - - g_error_free (data->error); - g_slice_free (struct ErrorData, data); - - return FALSE; -} - -static void -mail_junk_hook_error (const gchar *error_message, - GError *error) -{ - struct ErrorData *data; - - g_return_if_fail (error != NULL); - - data = g_slice_new (struct ErrorData); - data->error_message = error_message; - data->error = error; - - g_idle_add ((GSourceFunc) mail_junk_hook_idle_cb, data); -} - -static const gchar * -mail_junk_hook_get_name (CamelJunkPlugin *junk_plugin) -{ - EMJunkInterface *interface; - - interface = (EMJunkInterface *) junk_plugin; - - if (!interface->hook->plugin->enabled) { - /* Translators: "None" for a junk hook name, - * when the junk plugin is not enabled. */ - return C_("mail-junk-hook", "None"); - } - - return interface->hook->plugin->name; -} - -static void -mail_junk_hook_plugin_init (CamelJunkPlugin *junk_plugin) -{ - EMJunkInterface *interface; - EPluginClass *class; - - interface = (EMJunkInterface *) junk_plugin; - - class = E_PLUGIN_GET_CLASS (interface->hook->plugin); - g_return_if_fail (class->enable != NULL); - - class->enable (interface->hook->plugin, 1); -} - -static gboolean -mail_junk_hook_check_junk (CamelJunkPlugin *junk_plugin, - CamelMimeMessage *mime_message) -{ - EMJunkTarget target = { mime_message, NULL }; - EMJunkInterface *interface; - gpointer result; - - interface = (EMJunkInterface *) junk_plugin; - - if (!interface->hook->plugin->enabled) - return FALSE; - - result = e_plugin_invoke ( - interface->hook->plugin, - interface->check_junk, &target); - - if (target.error != NULL) - mail_junk_hook_error ("mail:junk-check-error", target.error); - - return (result != NULL); -} - -static void -mail_junk_hook_report_junk (CamelJunkPlugin *junk_plugin, - CamelMimeMessage *mime_message) -{ - EMJunkTarget target = { mime_message, NULL }; - EMJunkInterface *interface; - - interface = (EMJunkInterface *) junk_plugin; - - if (!interface->hook->plugin->enabled) - return; - - e_plugin_invoke ( - interface->hook->plugin, - interface->report_junk, &target); - - if (target.error != NULL) - mail_junk_hook_error ("mail:junk-report-error", target.error); -} - -static void -mail_junk_hook_report_notjunk (CamelJunkPlugin *junk_plugin, - CamelMimeMessage *mime_message) -{ - EMJunkTarget target = { mime_message, NULL }; - EMJunkInterface *interface; - - interface = (EMJunkInterface *) junk_plugin; - - if (!interface->hook->plugin->enabled) - return; - - e_plugin_invoke ( - interface->hook->plugin, - interface->report_notjunk, &target); - - if (target.error != NULL) - mail_junk_hook_error ( - "mail:junk-not-report-error", target.error); -} - -static void -mail_junk_hook_commit_reports (CamelJunkPlugin *junk_plugin) -{ - EMJunkInterface *interface; - - interface = (EMJunkInterface *) junk_plugin; - - if (!interface->hook->plugin->enabled) - return; - - e_plugin_invoke ( - interface->hook->plugin, - interface->commit_reports, NULL); -} - -static void -mail_junk_hook_finalize (GObject *object) -{ - EMailJunkHookPrivate *priv; - - priv = E_MAIL_JUNK_HOOK (object)->priv; - - g_free (priv->interface.check_junk); - g_free (priv->interface.report_junk); - g_free (priv->interface.report_notjunk); - g_free (priv->interface.commit_reports); - g_free (priv->interface.validate_binary); - g_free (priv->interface.plugin_name); - - /* Chain up to parent's finalize() method. */ - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static gint -mail_junk_hook_construct (EPluginHook *hook, - EPlugin *plugin, - xmlNodePtr node) -{ - EMailJunkHookPrivate *priv; - EShell *shell; - EShellBackend *shell_backend; - EMailBackend *backend; - EMailSession *session; - gchar *property; - - priv = E_MAIL_JUNK_HOOK (hook)->priv; - - /* Chain up to parent's construct() method. */ - if (E_PLUGIN_HOOK_CLASS (parent_class)->construct (hook, plugin, node) == -1) - return -1; - - if (!plugin->enabled) - return -1; - - node = xmlFirstElementChild (node); - - if (node == NULL) - return -1; - - if (g_strcmp0 ((gchar *) node->name, "interface") != 0) - return -1; - - property = e_plugin_xml_prop (node, "check_junk"); - priv->interface.check_junk = property; - - property = e_plugin_xml_prop (node, "report_junk"); - priv->interface.report_junk = property; - - property = e_plugin_xml_prop (node, "report_non_junk"); - priv->interface.report_notjunk = property; - - property = e_plugin_xml_prop (node, "commit_reports"); - priv->interface.commit_reports = property; - - property = e_plugin_xml_prop (node, "validate_binary"); - priv->interface.validate_binary = property; - - property = e_plugin_xml_prop (node, "name"); - priv->interface.plugin_name = property; - - if (priv->interface.check_junk == NULL) - return -1; - - if (priv->interface.report_junk == NULL) - return -1; - - if (priv->interface.report_notjunk == NULL) - return -1; - - if (priv->interface.commit_reports == NULL) - return -1; - - shell = e_shell_get_default (); - shell_backend = e_shell_get_backend_by_name (shell, "mail"); - - backend = E_MAIL_BACKEND (shell_backend); - session = e_mail_backend_get_session (backend); - - mail_session_add_junk_plugin ( - session, priv->interface.plugin_name, - &priv->interface.camel); - - return 0; -} - -static void -mail_junk_hook_class_init (EMailJunkHookClass *class) -{ - GObjectClass *object_class; - EPluginHookClass *plugin_hook_class; - - parent_class = g_type_class_peek_parent (class); - g_type_class_add_private (class, sizeof (EMailJunkHookPrivate)); - - object_class = G_OBJECT_CLASS (class); - object_class->finalize = mail_junk_hook_finalize; - - plugin_hook_class = E_PLUGIN_HOOK_CLASS (class); - plugin_hook_class->construct = mail_junk_hook_construct; - plugin_hook_class->id = "org.gnome.evolution.mail.junk:1.0"; -} - -static void -mail_junk_hook_init (EMailJunkHook *mail_junk_hook) -{ - EMJunkInterface *interface; - - mail_junk_hook->priv = G_TYPE_INSTANCE_GET_PRIVATE ( - mail_junk_hook, E_TYPE_MAIL_JUNK_HOOK, EMailJunkHookPrivate); - - interface = &mail_junk_hook->priv->interface; - interface->camel.get_name = mail_junk_hook_get_name; - interface->camel.api_version = 1; - interface->camel.check_junk = mail_junk_hook_check_junk; - interface->camel.report_junk = mail_junk_hook_report_junk; - interface->camel.report_notjunk = mail_junk_hook_report_notjunk; - interface->camel.commit_reports = mail_junk_hook_commit_reports; - interface->camel.init = mail_junk_hook_plugin_init; - interface->hook = E_PLUGIN_HOOK (mail_junk_hook); -} - -GType -e_mail_junk_hook_get_type (void) -{ - return mail_junk_hook_type; -} - -void -e_mail_junk_hook_register_type (GTypeModule *type_module) -{ - const GTypeInfo type_info = { - sizeof (EMailJunkHookClass), - (GBaseInitFunc) NULL, - (GBaseFinalizeFunc) NULL, - (GClassInitFunc) mail_junk_hook_class_init, - (GClassFinalizeFunc) NULL, - NULL, /* class_data */ - sizeof (EMailJunkHook), - 0, /* n_preallocs */ - (GInstanceInitFunc) mail_junk_hook_init, - NULL /* value_table */ - }; - - mail_junk_hook_type = g_type_module_register_type ( - type_module, E_TYPE_PLUGIN_HOOK, - "EMailJunkHook", &type_info, 0); -} diff --git a/modules/mail/e-mail-junk-hook.h b/modules/mail/e-mail-junk-hook.h deleted file mode 100644 index f5882e66b3..0000000000 --- a/modules/mail/e-mail-junk-hook.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * e-mail-junk-hook.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/> - * - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef E_MAIL_JUNK_HOOK_H -#define E_MAIL_JUNK_HOOK_H - -#include <e-util/e-plugin.h> - -/* Standard GObject macros */ -#define E_TYPE_MAIL_JUNK_HOOK \ - (e_mail_junk_hook_get_type ()) -#define E_MAIL_JUNK_HOOK(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), E_TYPE_MAIL_JUNK_HOOK, EMailJunkHook)) -#define E_MAIL_JUNK_HOOK_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_CAST \ - ((cls), E_TYPE_MAIL_JUNK_HOOK, EMailJunkHookClass)) -#define E_IS_MAIL_JUNK_HOOK(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), E_TYPE_MAIL_JUNK_HOOK)) -#define E_IS_MAIL_JUNK_HOOK_CLASS(cls) \ - (G_TYPE_CHECK_CLASS_TYPE \ - ((cls), E_TYPE_MAIL_JUNK_HOOK)) -#define E_MAIL_JUNK_HOOK_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), E_TYPE_MAIL_JUNK_HOOK, EMailJunkHookClass)) - -G_BEGIN_DECLS - -typedef struct _EMailJunkHook EMailJunkHook; -typedef struct _EMailJunkHookClass EMailJunkHookClass; -typedef struct _EMailJunkHookPrivate EMailJunkHookPrivate; - -struct _EMailJunkHook { - EPluginHook parent; - EMailJunkHookPrivate *priv; -}; - -struct _EMailJunkHookClass { - EPluginHookClass parent_class; -}; - -GType e_mail_junk_hook_get_type (void); -void e_mail_junk_hook_register_type (GTypeModule *type_module); - -G_END_DECLS - -#endif /* E_MAIL_JUNK_HOOK_H */ diff --git a/modules/mail/em-mailer-prefs.c b/modules/mail/em-mailer-prefs.c index 8e2688e615..bbf65e36b5 100644 --- a/modules/mail/em-mailer-prefs.c +++ b/modules/mail/em-mailer-prefs.c @@ -37,18 +37,20 @@ #include "libedataserverui/e-cell-renderer-color.h" -#include "e-util/e-util.h" -#include "e-util/e-datetime-format.h" -#include "e-util/e-util-private.h" -#include "widgets/misc/e-charset-combo-box.h" -#include "shell/e-shell-utils.h" - -#include "e-mail-backend.h" -#include "e-mail-label-manager.h" -#include "e-mail-reader-utils.h" -#include "em-folder-selection-button.h" -#include "em-junk.h" -#include "em-config.h" +#include <e-util/e-util.h> +#include <e-util/e-datetime-format.h> +#include <e-util/e-util-private.h> + +#include <misc/e-charset-combo-box.h> +#include <misc/e-port-entry.h> +#include <shell/e-shell-utils.h> + +#include <mail/e-mail-backend.h> +#include <mail/e-mail-junk-options.h> +#include <mail/e-mail-label-manager.h> +#include <mail/e-mail-reader-utils.h> +#include <mail/em-folder-selection-button.h> +#include <mail/em-config.h> enum { HEADER_LIST_NAME_COLUMN, /* displayable name of the header (may be a translation) */ @@ -102,7 +104,6 @@ em_mailer_prefs_finalize (GObject *object) { EMMailerPrefs *prefs = (EMMailerPrefs *) object; - g_object_unref (prefs->session); g_object_unref (prefs->builder); if (prefs->labels_change_notify_id) { @@ -676,131 +677,8 @@ emmp_free (EConfig *ec, GSList *items, gpointer data) } static void -junk_plugin_changed (GtkWidget *combo, EMMailerPrefs *prefs) -{ - gchar *def_plugin; - const GList *plugins = mail_session_get_junk_plugins (prefs->session); - GtkTreeIter iter; - - g_return_if_fail (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter)); - - def_plugin = NULL; - gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo)), &iter, 0, &def_plugin, -1); - - gconf_client_set_string (prefs->gconf, "/apps/evolution/mail/junk/default_plugin", def_plugin, NULL); - while (plugins) { - EMJunkInterface *iface = plugins->data; - - if (iface->plugin_name && def_plugin && !strcmp (iface->plugin_name, def_plugin)) { - gboolean status; - - CAMEL_SESSION (prefs->session)->junk_plugin = - CAMEL_JUNK_PLUGIN (&iface->camel); - status = e_plugin_invoke (iface->hook->plugin, iface->validate_binary, NULL) != NULL; - if ((gboolean) status == TRUE) { - gchar *text, *html; - gtk_image_set_from_stock (prefs->plugin_image, "gtk-dialog-info", GTK_ICON_SIZE_MENU); - text = g_strdup_printf (_("%s plugin is available and the binary is installed."), iface->plugin_name); - html = g_strdup_printf ("<i>%s</i>", text); - gtk_label_set_markup (prefs->plugin_status, html); - g_free (html); - g_free (text); - } else { - gchar *text, *html; - gtk_image_set_from_stock (prefs->plugin_image, "gtk-dialog-warning", GTK_ICON_SIZE_MENU); - text = g_strdup_printf (_("%s plugin is not available. Please check whether the package is installed."), iface->plugin_name); - html = g_strdup_printf ("<i>%s</i>", text); - gtk_label_set_markup (prefs->plugin_status, html); - g_free (html); - g_free (text); - } - break; - } - plugins = plugins->next; - } - - g_free (def_plugin); -} - -static void -junk_plugin_setup (GtkComboBox *combo_box, EMMailerPrefs *prefs) -{ - GtkListStore *store; - GtkCellRenderer *cell; - gint index = 0; - gboolean def_set = FALSE; - const GList *plugins = mail_session_get_junk_plugins (prefs->session); - gchar *pdefault = gconf_client_get_string (prefs->gconf, "/apps/evolution/mail/junk/default_plugin", NULL); - - store = gtk_list_store_new (1, G_TYPE_STRING); - gtk_combo_box_set_model (combo_box, GTK_TREE_MODEL (store)); - - cell = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, - "text", 0, - NULL); - - if (!plugins || !g_list_length ((GList *) plugins)) { - GtkTreeIter iter; - - gtk_list_store_append (store, &iter); - gtk_list_store_set ( - store, &iter, 0, _("No junk plugin available"), -1); - gtk_combo_box_set_active (combo_box, 0); - gtk_widget_set_sensitive (GTK_WIDGET (combo_box), FALSE); - gtk_widget_hide (GTK_WIDGET (prefs->plugin_image)); - gtk_widget_hide (GTK_WIDGET (prefs->plugin_status)); - gtk_image_set_from_stock (prefs->plugin_image, NULL, 0); - g_free (pdefault); - - return; - } - - while (plugins) { - EMJunkInterface *iface = plugins->data; - GtkTreeIter iter; - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, 0, iface->plugin_name, -1); - if (!def_set && pdefault && iface->plugin_name && !strcmp (pdefault, iface->plugin_name)) { - gboolean status; - - def_set = TRUE; - gtk_combo_box_set_active (combo_box, index); - status = e_plugin_invoke (iface->hook->plugin, iface->validate_binary, NULL) != NULL; - if (status) { - gchar *text, *html; - gtk_image_set_from_stock (prefs->plugin_image, "gtk-dialog-info", GTK_ICON_SIZE_MENU); - /* May be a better text */ - text = g_strdup_printf (_("%s plugin is available and the binary is installed."), iface->plugin_name); - html = g_strdup_printf ("<i>%s</i>", text); - gtk_label_set_markup (prefs->plugin_status, html); - g_free (html); - g_free (text); - } else { - gchar *text, *html; - gtk_image_set_from_stock (prefs->plugin_image, "gtk-dialog-warning", GTK_ICON_SIZE_MENU); - /* May be a better text */ - text = g_strdup_printf (_("%s plugin is not available. Please check whether the package is installed."), iface->plugin_name); - html = g_strdup_printf ("<i>%s</i>", text); - gtk_label_set_markup (prefs->plugin_status, html); - g_free (html); - g_free (text); - } - } - plugins = plugins->next; - index++; - } - - g_signal_connect ( - combo_box, "changed", - G_CALLBACK (junk_plugin_changed), prefs); - g_free (pdefault); -} - -static void em_mailer_prefs_construct (EMMailerPrefs *prefs, + EMailSession *session, EShell *shell) { GSList *header_config_list, *header_add_list, *p; @@ -823,6 +701,7 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs, /* Make sure our custom widget classes are registered with * GType before we load the GtkBuilder definition file. */ + E_TYPE_MAIL_JUNK_OPTIONS; EM_TYPE_FOLDER_SELECTION_BUTTON; prefs->builder = gtk_builder_new (); @@ -1182,10 +1061,8 @@ em_mailer_prefs_construct (EMMailerPrefs *prefs, G_BINDING_SYNC_CREATE); emmp_empty_junk_init (prefs, GTK_COMBO_BOX (widget)); - prefs->default_junk_plugin = GTK_COMBO_BOX (e_builder_get_widget (prefs->builder, "default_junk_plugin")); - prefs->plugin_status = GTK_LABEL (e_builder_get_widget (prefs->builder, "plugin_status")); - prefs->plugin_image = GTK_IMAGE (e_builder_get_widget (prefs->builder, "plugin_image")); - junk_plugin_setup (prefs->default_junk_plugin, prefs); + widget = e_builder_get_widget (prefs->builder, "junk-module-options"); + e_mail_junk_options_set_session (E_MAIL_JUNK_OPTIONS (widget), session); prefs->junk_header_check = (GtkToggleButton *)e_builder_get_widget (prefs->builder, "junk_header_check"); prefs->junk_header_tree = (GtkTreeView *)e_builder_get_widget (prefs->builder, "junk_header_tree"); @@ -1238,11 +1115,8 @@ em_mailer_prefs_new (EPreferencesWindow *window) new = g_object_new (EM_TYPE_MAILER_PREFS, NULL); - /* FIXME This should be a constructor property. */ - new->session = g_object_ref (session); - /* FIXME Kill this function. */ - em_mailer_prefs_construct (new, shell); + em_mailer_prefs_construct (new, session, shell); return GTK_WIDGET (new); } diff --git a/modules/mail/em-mailer-prefs.h b/modules/mail/em-mailer-prefs.h index d28fd5f5e4..35ebec3bf7 100644 --- a/modules/mail/em-mailer-prefs.h +++ b/modules/mail/em-mailer-prefs.h @@ -26,7 +26,6 @@ #include <gtk/gtk.h> #include <gconf/gconf-client.h> #include <shell/e-shell.h> -#include <mail/e-mail-session.h> #include <widgets/misc/e-preferences-window.h> /* Standard GObject macros */ @@ -56,8 +55,6 @@ typedef struct _EMMailerPrefsClass EMMailerPrefsClass; struct _EMMailerPrefs { GtkVBox parent_object; - EMailSession *session; - GtkBuilder *builder; GConfClient *gconf; @@ -95,9 +92,6 @@ struct _EMMailerPrefs { GtkToggleButton *sa_local_tests_only; GtkToggleButton *sa_use_daemon; - GtkComboBox *default_junk_plugin; - GtkLabel *plugin_status; - GtkImage *plugin_image; GtkToggleButton *junk_header_check; GtkTreeView *junk_header_tree; diff --git a/modules/mail/evolution-module-mail.c b/modules/mail/evolution-module-mail.c index ddb9d8996b..bda0db5d95 100644 --- a/modules/mail/evolution-module-mail.c +++ b/modules/mail/evolution-module-mail.c @@ -27,7 +27,6 @@ #include "e-mail-config-hook.h" #include "e-mail-event-hook.h" -#include "e-mail-junk-hook.h" #include "e-mail-shell-backend.h" #include "e-mail-shell-content.h" @@ -52,7 +51,6 @@ e_module_load (GTypeModule *type_module) e_mail_config_hook_register_type (type_module); e_mail_event_hook_register_type (type_module); - e_mail_junk_hook_register_type (type_module); e_mail_shell_backend_register_type (type_module); e_mail_shell_content_register_type (type_module); |