2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 Hiroyuki Yamamoto and the Sylpheed-Claws Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include "common/utils.h"
39 #ifdef HAVE_SYSEXITS_H
45 #ifdef HAVE_SYS_ERRNO_H
46 #include <sys/errno.h>
51 #ifdef HAVE_SYS_TIME_H
63 static int flags = SPAMC_RAW_MODE | SPAMC_SAFE_FALLBACK | SPAMC_CHECK_ONLY;
64 static gchar *hostname = NULL;
67 static gboolean mail_filtering_hook(gpointer source, gpointer data)
69 MailFilteringData *mail_filtering_data = (MailFilteringData *) source;
70 MsgInfo *msginfo = mail_filtering_data->msginfo;
71 gboolean is_spam = FALSE;
75 gchar *username = NULL, *oldlocale = NULL;
78 debug_print("Filtering message %d\n", msginfo->msgnum);
80 oldlocale = g_strdup(setlocale(LC_ALL, NULL));
81 if (oldlocale == NULL)
84 setlocale(LC_ALL, "C");
86 ret = lookup_host(hostname, port, &addr);
90 m.type = MESSAGE_NONE;
93 username = g_get_user_name();
97 fp = procmsg_open_message(msginfo);
101 ret = message_read(fileno(fp), flags, &m);
105 ret = message_filter(&addr, username, flags, &m);
106 if ((ret == EX_OK) && (m.is_spam == EX_ISSPAM))
113 if (oldlocale != NULL) {
114 setlocale(LC_ALL, oldlocale);
119 debug_print("Message is spam\n");
121 folder_item_move_msg(folder_get_default_trash(), msginfo);
128 static void spamassassin_read_config()
131 hostname = "127.0.0.1";
135 gint plugin_init(gchar **error)
137 hook_id = hooks_register_hook(MAIL_FILTERING_HOOKLIST, mail_filtering_hook, NULL);
139 *error = g_strdup("Failed to register mail filtering hook");
143 spamassassin_read_config();
145 debug_print("Spamassassin plugin loaded\n");
153 hooks_unregister_hook(MAIL_FILTERING_HOOKLIST, hook_id);
155 debug_print("Spamassassin plugin unloaded\n");
158 const gchar *plugin_name()
160 return "Spamassassin Plugin";
163 const gchar *plugin_desc()
165 return "Check incoming mails for spam with spamassassin";