4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) version 3.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with the program; if not, see <http://www.gnu.org/licenses/>
18
* Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
22
#include "e-mail-junk-hook.h"
24
#include <glib/gi18n.h>
25
#include <camel/camel-junk-plugin.h>
27
#include "e-util/e-alert-dialog.h"
28
#include "shell/e-shell.h"
30
#include "mail/em-junk.h"
31
#include "mail/em-utils.h"
32
#include "mail/mail-session.h"
34
#define E_MAIL_JUNK_HOOK_GET_PRIVATE(obj) \
35
(G_TYPE_INSTANCE_GET_PRIVATE \
36
((obj), E_TYPE_MAIL_JUNK_HOOK, EMailJunkHookPrivate))
38
struct _EMailJunkHookPrivate {
39
EMJunkInterface interface;
43
const gchar *error_message;
47
static gpointer parent_class;
48
static GType mail_junk_hook_type;
51
mail_junk_hook_idle_cb (struct ErrorData *data)
55
widget = e_alert_dialog_new_for_args (e_shell_get_active_window (NULL),
56
data->error_message, data->error->message, NULL);
57
em_utils_show_error_silent (widget);
59
g_error_free (data->error);
60
g_slice_free (struct ErrorData, data);
66
mail_junk_hook_error (const gchar *error_message,
69
struct ErrorData *data;
71
g_return_if_fail (error != NULL);
73
data = g_slice_new (struct ErrorData);
74
data->error_message = error_message;
77
g_idle_add ((GSourceFunc) mail_junk_hook_idle_cb, data);
81
mail_junk_hook_get_name (CamelJunkPlugin *junk_plugin)
83
EMJunkInterface *interface;
85
interface = (EMJunkInterface *) junk_plugin;
87
if (!interface->hook->plugin->enabled)
90
return interface->hook->plugin->name;
94
mail_junk_hook_plugin_init (CamelJunkPlugin *junk_plugin)
96
EMJunkInterface *interface;
99
interface = (EMJunkInterface *) junk_plugin;
101
class = E_PLUGIN_GET_CLASS (interface->hook->plugin);
102
g_return_if_fail (class->enable != NULL);
104
class->enable (interface->hook->plugin, 1);
108
mail_junk_hook_check_junk (CamelJunkPlugin *junk_plugin,
109
CamelMimeMessage *mime_message)
111
EMJunkTarget target = { mime_message, NULL };
112
EMJunkInterface *interface;
115
interface = (EMJunkInterface *) junk_plugin;
117
if (!interface->hook->plugin->enabled)
120
result = e_plugin_invoke (
121
interface->hook->plugin,
122
interface->check_junk, &target);
124
if (target.error != NULL)
125
mail_junk_hook_error ("mail:junk-check-error", target.error);
127
return (result != NULL);
131
mail_junk_hook_report_junk (CamelJunkPlugin *junk_plugin,
132
CamelMimeMessage *mime_message)
134
EMJunkTarget target = { mime_message, NULL };
135
EMJunkInterface *interface;
137
interface = (EMJunkInterface *) junk_plugin;
139
if (!interface->hook->plugin->enabled)
143
interface->hook->plugin,
144
interface->report_junk, &target);
146
if (target.error != NULL)
147
mail_junk_hook_error ("mail:junk-report-error", target.error);
151
mail_junk_hook_report_notjunk (CamelJunkPlugin *junk_plugin,
152
CamelMimeMessage *mime_message)
154
EMJunkTarget target = { mime_message, NULL };
155
EMJunkInterface *interface;
157
interface = (EMJunkInterface *) junk_plugin;
159
if (!interface->hook->plugin->enabled)
163
interface->hook->plugin,
164
interface->report_notjunk, &target);
166
if (target.error != NULL)
167
mail_junk_hook_error (
168
"mail:junk-not-report-error", target.error);
172
mail_junk_hook_commit_reports (CamelJunkPlugin *junk_plugin)
174
EMJunkInterface *interface;
176
interface = (EMJunkInterface *) junk_plugin;
178
if (!interface->hook->plugin->enabled)
182
interface->hook->plugin,
183
interface->commit_reports, NULL);
187
mail_junk_hook_finalize (GObject *object)
189
EMailJunkHookPrivate *priv;
191
priv = E_MAIL_JUNK_HOOK_GET_PRIVATE (object);
193
g_free (priv->interface.check_junk);
194
g_free (priv->interface.report_junk);
195
g_free (priv->interface.report_notjunk);
196
g_free (priv->interface.commit_reports);
197
g_free (priv->interface.validate_binary);
198
g_free (priv->interface.plugin_name);
200
/* Chain up to parent's finalize() method. */
201
G_OBJECT_CLASS (parent_class)->finalize (object);
205
mail_junk_hook_construct (EPluginHook *hook,
209
EMailJunkHookPrivate *priv;
212
priv = E_MAIL_JUNK_HOOK_GET_PRIVATE (hook);
214
/* Chain up to parent's construct() method. */
215
if (E_PLUGIN_HOOK_CLASS (parent_class)->construct (hook, plugin, node) == -1)
218
if (!plugin->enabled)
221
node = xmlFirstElementChild (node);
226
if (g_strcmp0 ((gchar *) node->name, "interface") != 0)
229
property = e_plugin_xml_prop (node, "check_junk");
230
priv->interface.check_junk = property;
232
property = e_plugin_xml_prop (node, "report_junk");
233
priv->interface.report_junk = property;
235
property = e_plugin_xml_prop (node, "report_non_junk");
236
priv->interface.report_notjunk = property;
238
property = e_plugin_xml_prop (node, "commit_reports");
239
priv->interface.commit_reports = property;
241
property = e_plugin_xml_prop (node, "validate_binary");
242
priv->interface.validate_binary = property;
244
property = e_plugin_xml_prop (node, "name");
245
priv->interface.plugin_name = property;
247
if (priv->interface.check_junk == NULL)
250
if (priv->interface.report_junk == NULL)
253
if (priv->interface.report_notjunk == NULL)
256
if (priv->interface.commit_reports == NULL)
259
mail_session_add_junk_plugin (
260
priv->interface.plugin_name, &priv->interface.camel);
266
mail_junk_hook_class_init (EMailJunkHookClass *class)
268
GObjectClass *object_class;
269
EPluginHookClass *plugin_hook_class;
271
parent_class = g_type_class_peek_parent (class);
272
g_type_class_add_private (class, sizeof (EMailJunkHookPrivate));
274
object_class = G_OBJECT_CLASS (class);
275
object_class->finalize = mail_junk_hook_finalize;
277
plugin_hook_class = E_PLUGIN_HOOK_CLASS (class);
278
plugin_hook_class->construct = mail_junk_hook_construct;
279
plugin_hook_class->id = "org.gnome.evolution.mail.junk:1.0";
283
mail_junk_hook_init (EMailJunkHook *mail_junk_hook)
285
EMJunkInterface *interface;
287
mail_junk_hook->priv = E_MAIL_JUNK_HOOK_GET_PRIVATE (mail_junk_hook);
289
interface = &mail_junk_hook->priv->interface;
290
interface->camel.get_name = mail_junk_hook_get_name;
291
interface->camel.api_version = 1;
292
interface->camel.check_junk = mail_junk_hook_check_junk;
293
interface->camel.report_junk = mail_junk_hook_report_junk;
294
interface->camel.report_notjunk = mail_junk_hook_report_notjunk;
295
interface->camel.commit_reports = mail_junk_hook_commit_reports;
296
interface->camel.init = mail_junk_hook_plugin_init;
297
interface->hook = E_PLUGIN_HOOK (mail_junk_hook);
301
e_mail_junk_hook_get_type (void)
303
return mail_junk_hook_type;
307
e_mail_junk_hook_register_type (GTypeModule *type_module)
309
const GTypeInfo type_info = {
310
sizeof (EMailJunkHookClass),
311
(GBaseInitFunc) NULL,
312
(GBaseFinalizeFunc) NULL,
313
(GClassInitFunc) mail_junk_hook_class_init,
314
(GClassFinalizeFunc) NULL,
315
NULL, /* class_data */
316
sizeof (EMailJunkHook),
318
(GInstanceInitFunc) mail_junk_hook_init,
319
NULL /* value_table */
322
mail_junk_hook_type = g_type_module_register_type (
323
type_module, E_TYPE_PLUGIN_HOOK,
324
"EMailJunkHook", &type_info, 0);