41753d949a2307009304d0c3a899558fd9fec4f7
[claws.git] / src / plugins / spamassassin / spamassassin.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 the Claws Mail Team
4  *
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 3 of the License, or
8  * (at your option) any later version.
9  *
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <sys/types.h>
28 #include <sys/wait.h>
29
30 #include <glib.h>
31 #include <glib/gi18n.h>
32
33 #if HAVE_LOCALE_H
34 #  include <locale.h>
35 #endif
36
37 #include "common/claws.h"
38 #include "common/version.h"
39 #include "plugin.h"
40 #include "common/utils.h"
41 #include "hooks.h"
42 #include "procmsg.h"
43 #include "folder.h"
44 #include "prefs.h"
45 #include "prefs_gtk.h"
46
47 #include "libspamc.h"
48 #include "spamassassin.h"
49 #include "inc.h"
50 #include "log.h"
51 #include "prefs_common.h"
52 #include "alertpanel.h"
53 #include "addr_compl.h"
54
55 #ifdef HAVE_SYSEXITS_H
56 #include <sysexits.h>
57 #endif
58 #ifdef HAVE_ERRNO_H
59 #include <errno.h>
60 #endif
61 #ifdef HAVE_SYS_ERRNO_H
62 #include <sys/errno.h>
63 #endif
64 #ifdef HAVE_TIME_H
65 #include <time.h>
66 #endif
67 #ifdef HAVE_SYS_TIME_H
68 #include <sys/time.h>
69 #endif
70 #ifdef HAVE_SIGNAL_H
71 #include <signal.h>
72 #endif
73 #ifdef HAVE_PWD_H
74 #include <pwd.h>
75 #endif
76
77 #define PLUGIN_NAME (_("SpamAssassin"))
78
79 enum {
80     CHILD_RUNNING = 1 << 0,
81     TIMEOUT_RUNNING = 1 << 1,
82 };
83
84 static guint hook_id = -1;
85 static int flags = SPAMC_RAW_MODE | SPAMC_SAFE_FALLBACK | SPAMC_CHECK_ONLY;
86 static MessageCallback message_callback;
87
88 static SpamAssassinConfig config;
89
90 static PrefParam param[] = {
91         {"enable", "FALSE", &config.enable, P_BOOL,
92         NULL, NULL, NULL},
93         {"transport", "0", &config.transport, P_INT,
94          NULL, NULL, NULL},
95         {"hostname", "localhost", &config.hostname, P_STRING,
96          NULL, NULL, NULL},
97         {"port", "783", &config.port, P_INT,
98          NULL, NULL, NULL},
99         {"socket", "", &config.socket, P_STRING,
100          NULL, NULL, NULL},
101         {"process_emails", "TRUE", &config.process_emails, P_BOOL,
102          NULL, NULL, NULL},
103         {"receive_spam", "TRUE", &config.receive_spam, P_BOOL,
104          NULL, NULL, NULL},
105         {"save_folder", NULL, &config.save_folder, P_STRING,
106          NULL, NULL, NULL},
107         {"max_size", "250", &config.max_size, P_INT,
108          NULL, NULL, NULL},
109         {"timeout", "30", &config.timeout, P_INT,
110          NULL, NULL, NULL},
111         {"username", "", &config.username, P_STRING,
112          NULL, NULL, NULL},
113         {"mark_as_read", "TRUE", &config.mark_as_read, P_BOOL,
114          NULL, NULL, NULL},
115         {"whitelist_ab", "FALSE", &config.whitelist_ab, P_BOOL,
116          NULL, NULL, NULL},
117         {"whitelist_ab_folder", N_("Any"), &config.whitelist_ab_folder, P_STRING,
118          NULL, NULL, NULL},
119
120         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
121 };
122
123 gboolean timeout_func(gpointer data)
124 {
125         gint *running = (gint *) data;
126
127         if (*running & CHILD_RUNNING)
128                 return TRUE;
129
130         *running &= ~TIMEOUT_RUNNING;
131         return FALSE;
132 }
133
134 typedef enum {
135         MSG_IS_HAM = 0,
136         MSG_IS_SPAM = 1,
137         MSG_FILTERING_ERROR = 2
138 } MsgStatus;
139
140 static MsgStatus msg_is_spam(FILE *fp)
141 {
142         struct transport trans;
143         struct message m;
144         gboolean is_spam = FALSE;
145
146         if (!config.enable)
147                 return MSG_IS_HAM;
148
149         transport_init(&trans);
150         switch (config.transport) {
151         case SPAMASSASSIN_TRANSPORT_LOCALHOST:
152                 trans.type = TRANSPORT_LOCALHOST;
153                 trans.port = config.port;
154                 break;
155         case SPAMASSASSIN_TRANSPORT_TCP:
156                 trans.type = TRANSPORT_TCP;
157                 trans.hostname = config.hostname;
158                 trans.port = config.port;
159                 break;
160         case SPAMASSASSIN_TRANSPORT_UNIX:
161                 trans.type = TRANSPORT_UNIX;
162                 trans.socketpath = config.socket;
163                 break;
164         default:
165                 return MSG_IS_HAM;
166         }
167
168         if (transport_setup(&trans, flags) != EX_OK) {
169                 log_error(LOG_PROTOCOL, _("SpamAssassin plugin couldn't connect to spamd.\n"));
170                 debug_print("failed to setup transport\n");
171                 return MSG_FILTERING_ERROR;
172         }
173
174         m.type = MESSAGE_NONE;
175         m.max_len = config.max_size * 1024;
176         m.timeout = config.timeout;
177
178         if (message_read(fileno(fp), flags, &m) != EX_OK) {
179                 debug_print("failed to read message\n");
180                 message_cleanup(&m);
181                 return MSG_FILTERING_ERROR;
182         }
183
184         if (message_filter(&trans, config.username, flags, &m) != EX_OK) {
185                 log_error(LOG_PROTOCOL, _("SpamAssassin plugin filtering failed.\n"));
186                 debug_print("filtering the message failed\n");
187                 message_cleanup(&m);
188                 return MSG_FILTERING_ERROR;
189         }
190
191         if (m.is_spam == EX_ISSPAM)
192                 is_spam = TRUE;
193
194         message_cleanup(&m);
195
196         return is_spam ? MSG_IS_SPAM:MSG_IS_HAM;
197 }
198
199 static gboolean sa_found_in_addressbook(const gchar *address)
200 {
201         gchar *addr = NULL;
202         gboolean found = FALSE;
203         gint num_addr = 0;
204         
205         if (!address)
206                 return FALSE;
207         
208         addr = g_strdup(address);
209         extract_address(addr);
210         num_addr = complete_address(addr);
211         if (num_addr > 1) {
212                 /* skip first item (this is the search string itself) */
213                 int i = 1;
214                 for (; i < num_addr && !found; i++) {
215                         gchar *caddr = get_complete_address(i);
216                         extract_address(caddr);
217                         if (strcasecmp(caddr, addr) == 0)
218                                 found = TRUE;
219                         g_free(caddr);
220                 }
221         }
222         g_free(addr);
223         return found;
224 }
225
226 static gboolean mail_filtering_hook(gpointer source, gpointer data)
227 {
228         MailFilteringData *mail_filtering_data = (MailFilteringData *) source;
229         MsgInfo *msginfo = mail_filtering_data->msginfo;
230         gboolean is_spam = FALSE, error = FALSE;
231         static gboolean warned_error = FALSE;
232         FILE *fp = NULL;
233         int pid = 0;
234         int status;
235
236         /* SPAMASSASSIN_DISABLED : keep test for compatibility purpose */
237         if (!config.enable || config.transport == SPAMASSASSIN_DISABLED) {
238                 log_warning(LOG_PROTOCOL, _("SpamAssassin plugin is disabled by its preferences.\n"));
239                 return FALSE;
240         }
241         debug_print("Filtering message %d\n", msginfo->msgnum);
242         if (message_callback != NULL)
243                 message_callback(_("SpamAssassin: filtering message..."));
244
245         if ((fp = procmsg_open_message(msginfo)) == NULL) {
246                 debug_print("failed to open message file\n");
247                 return FALSE;
248         }
249
250         if (config.whitelist_ab) {
251                 gchar *ab_folderpath;
252                 gboolean whitelisted = FALSE;
253
254                 if (*config.whitelist_ab_folder == '\0' ||
255                         strcasecmp(config.whitelist_ab_folder, "Any") == 0) {
256                         /* match the whole addressbook */
257                         ab_folderpath = NULL;
258                 } else {
259                         /* match the specific book/folder of the addressbook */
260                         ab_folderpath = config.whitelist_ab_folder;
261                 }
262
263                 start_address_completion(ab_folderpath);
264                 if (msginfo->from && 
265                     sa_found_in_addressbook(msginfo->from))
266                                 whitelisted = TRUE;
267                 end_address_completion();
268                 
269                 if (whitelisted) {
270                         debug_print("message is ham (whitelisted)\n");
271                         fclose(fp);
272                         return FALSE;
273                 }
274         }
275         pid = fork();
276         if (pid == 0) {
277                 _exit(msg_is_spam(fp));
278         } else {
279                 gint running = 0;
280
281                 running |= CHILD_RUNNING;
282
283                 g_timeout_add(50, timeout_func, &running);
284                 running |= TIMEOUT_RUNNING;
285
286                 while(running & CHILD_RUNNING) {
287                         int ret;
288
289                         ret = waitpid(pid, &status, WNOHANG);
290                         if (ret == pid) {
291                                 if (WIFEXITED(status)) {
292                                         MsgStatus result = MSG_IS_HAM;
293                                         running &= ~CHILD_RUNNING;
294                                         result = WEXITSTATUS(status);
295                                         is_spam = (result == MSG_IS_SPAM) ? TRUE : FALSE;
296                                         error = (result == MSG_FILTERING_ERROR);
297                                 }
298                         } if (ret < 0) {
299                                 running &= ~CHILD_RUNNING;
300                         } /* ret == 0 continue */
301             
302                         g_main_context_iteration(NULL, TRUE);
303                 }
304
305                 while (running & TIMEOUT_RUNNING)
306                         g_main_context_iteration(NULL, TRUE);
307         }
308
309         fclose(fp);
310
311         if (is_spam) {
312                 debug_print("message is spam\n");
313                 procmsg_msginfo_set_flags(msginfo, MSG_SPAM, 0);
314                 if (config.receive_spam) {
315                         FolderItem *save_folder = NULL;
316
317                         if ((!config.save_folder) ||
318                             (config.save_folder[0] == '\0') ||
319                             ((save_folder = folder_find_item_from_identifier(config.save_folder)) == NULL)) {
320                                 if (mail_filtering_data->account && mail_filtering_data->account->set_trash_folder) {
321                                         save_folder = folder_find_item_from_identifier(
322                                                 mail_filtering_data->account->trash_folder);
323                                         if (save_folder)
324                                                 debug_print("found trash folder from account's advanced settings\n");
325                                 }
326                                 if (save_folder == NULL && mail_filtering_data->account &&
327                                     mail_filtering_data->account->folder) {
328                                         save_folder = mail_filtering_data->account->folder->trash;
329                                         if (save_folder)
330                                                 debug_print("found trash folder from account's trash\n");
331                                 }
332                                 if (save_folder == NULL && mail_filtering_data->account &&
333                                     !mail_filtering_data->account->folder)  {
334                                         if (mail_filtering_data->account->inbox) {
335                                                 FolderItem *item = folder_find_item_from_identifier(
336                                                         mail_filtering_data->account->inbox);
337                                                 if (item && item->folder->trash) {
338                                                         save_folder = item->folder->trash;
339                                                         debug_print("found trash folder from account's inbox\n");
340                                                 }
341                                         } 
342                                         if (!save_folder && mail_filtering_data->account->local_inbox) {
343                                                 FolderItem *item = folder_find_item_from_identifier(
344                                                         mail_filtering_data->account->local_inbox);
345                                                 if (item && item->folder->trash) {
346                                                         save_folder = item->folder->trash;
347                                                         debug_print("found trash folder from account's local_inbox\n");
348                                                 }
349                                         }
350                                 }
351                                 if (save_folder == NULL) {
352                                         debug_print("using default trash folder\n");
353                                         save_folder = folder_get_default_trash();
354                                 }
355                         }
356                         if (config.mark_as_read)
357                                 procmsg_msginfo_unset_flags(msginfo, ~0, 0);
358                         procmsg_msginfo_set_flags(msginfo, MSG_SPAM, 0);
359                         msginfo->filter_op = IS_MOVE;
360                         msginfo->to_filter_folder = save_folder;
361                 } else {
362                         folder_item_remove_msg(msginfo->folder, msginfo->msgnum);
363                 }
364
365                 return TRUE;
366         } else {
367                 debug_print("message is ham\n");
368                 procmsg_msginfo_unset_flags(msginfo, MSG_SPAM, 0);
369         }
370         
371         if (error) {
372                 gchar *msg = _("The SpamAssassin plugin couldn't filter "
373                                            "a message. The probable cause of the error "
374                                            "is an unreachable spamd daemon. Please make "
375                                            "sure spamd is running and accessible.");
376                 if (!prefs_common.no_recv_err_panel) {
377                         if (!warned_error) {
378                                 alertpanel_error("%s", msg);
379                         }
380                         warned_error = TRUE;
381                 } else {
382                         log_error(LOG_PROTOCOL, "%s\n", msg);
383                 }
384         }
385         
386         return FALSE;
387 }
388
389 SpamAssassinConfig *spamassassin_get_config(void)
390 {
391         return &config;
392 }
393
394 gchar* spamassassin_create_tmp_spamc_wrapper(gboolean spam)
395 {
396         gchar *contents;
397         gchar *fname = get_tmp_file();
398
399         if (fname != NULL) {
400                 contents = g_strdup_printf(
401                                                 "spamc -d %s -p %u -u %s -t %u -s %u -L %s<\"$*\";exit $?",
402                                                 config.hostname, config.port, 
403                                                 config.username, config.timeout,
404                                                 config.max_size * 1024, spam?"spam":"ham");
405                 if (str_write_to_file(contents, fname) < 0) {
406                         g_free(fname);
407                         fname = NULL;
408                 }
409                 g_free(contents);
410         }
411         /* returned pointer must be free'ed by caller */
412         return fname;
413 }
414
415 int spamassassin_learn(MsgInfo *msginfo, GSList *msglist, gboolean spam)
416 {
417         gchar *cmd = NULL;
418         gchar *file = NULL;
419         const gchar *shell = g_getenv("SHELL");
420         gchar *spamc_wrapper = NULL;
421
422         if (msginfo == NULL && msglist == NULL) {
423                 return -1;
424         }
425
426         if (config.transport == SPAMASSASSIN_TRANSPORT_TCP
427         &&  prefs_common.work_offline
428         &&  !inc_offline_should_override(TRUE,
429                 _("Claws Mail needs network access in order "
430                   "to feed this mail(s) to the remote learner."))) {
431                 return -1;
432         }
433
434         if (msginfo) {
435                 file = procmsg_get_message_file(msginfo);
436                 if (file == NULL) {
437                         return -1;
438                 }
439                 if (config.transport == SPAMASSASSIN_TRANSPORT_TCP) {
440                         spamc_wrapper = spamassassin_create_tmp_spamc_wrapper(spam);
441                         if (spamc_wrapper != NULL) {
442                                 cmd = g_strconcat(shell?shell:"sh", " ",
443                                                                 spamc_wrapper, " ", file, NULL);
444                         }
445                 } else {
446                         cmd = g_strdup_printf("sa-learn -u %s%s %s %s",
447                                                         config.username,
448                                                         prefs_common.work_offline?" -L":"",
449                                                         spam?"--spam":"--ham", file);
450                 }
451         }
452         if (msglist) {
453                 GSList *cur = msglist;
454                 MsgInfo *info;
455
456                 if (config.transport == SPAMASSASSIN_TRANSPORT_TCP) {
457                         /* execute n-times the spamc command */
458                         for (; cur; cur = cur->next) {
459                                 info = (MsgInfo *)cur->data;
460                                 gchar *tmpcmd = NULL;
461                                 gchar *tmpfile = get_tmp_file();
462
463                                 if (spamc_wrapper == NULL) {
464                                         spamc_wrapper = spamassassin_create_tmp_spamc_wrapper(spam);
465                                 }
466
467                                 if (spamc_wrapper && tmpfile &&
468                                 copy_file(procmsg_get_message_file(info), tmpfile, TRUE) == 0) {
469                                         tmpcmd = g_strconcat(shell?shell:"sh", " ", spamc_wrapper, " ",
470                                                                                 tmpfile, NULL);
471                                         debug_print("%s\n", tmpcmd);
472                                         execute_command_line(tmpcmd, FALSE);
473                                         g_free(tmpcmd);
474                                 }
475                                 g_free(tmpfile);
476                         }
477                         g_free(spamc_wrapper);
478                         return 0;
479                 } else {
480                         cmd = g_strdup_printf("sa-learn -u %s%s %s",
481                                         config.username,
482                                         prefs_common.work_offline?" -L":"",
483                                         spam?"--spam":"--ham");
484
485                         /* concatenate all message tmpfiles to the sa-learn command-line */
486                         for (; cur; cur = cur->next) {
487                                 info = (MsgInfo *)cur->data;
488                                 gchar *tmpcmd = NULL;
489                                 gchar *tmpfile = get_tmp_file();
490
491                                 if (tmpfile &&
492                                 copy_file(procmsg_get_message_file(info), tmpfile, TRUE) == 0) {                        
493                                         tmpcmd = g_strconcat(cmd, " ", tmpfile, NULL);
494                                         g_free(cmd);
495                                         cmd = tmpcmd;
496                                 }
497                                 g_free(tmpfile);
498                         }
499                 }
500         }
501         if (cmd == NULL) {
502                 return -1;
503         }
504         debug_print("%s\n", cmd);
505         /* only run sync calls to sa-learn/spamc to prevent system lockdown */
506         execute_command_line(cmd, FALSE);
507         g_free(cmd);
508         g_free(spamc_wrapper);
509
510         return 0;
511 }
512
513 void spamassassin_save_config(void)
514 {
515         PrefFile *pfile;
516         gchar *rcpath;
517
518         debug_print("Saving SpamAssassin Page\n");
519
520         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
521         pfile = prefs_write_open(rcpath);
522         g_free(rcpath);
523         if (!pfile || (prefs_set_block_label(pfile, "SpamAssassin") < 0))
524                 return;
525
526         if (prefs_write_param(param, pfile->fp) < 0) {
527                 g_warning("Failed to write SpamAssassin configuration to file\n");
528                 prefs_file_close_revert(pfile);
529                 return;
530         }
531         if (fprintf(pfile->fp, "\n") < 0) {
532                 FILE_OP_ERROR(rcpath, "fprintf");
533                 prefs_file_close_revert(pfile);
534         } else
535                 prefs_file_close(pfile);
536 }
537
538 gboolean spamassassin_check_username(void)
539 {
540         if (config.username == NULL || config.username[0] == '\0') {
541                 config.username = (gchar*)g_get_user_name();
542                 if (config.username == NULL) {
543                         if (hook_id != -1) {
544                                 spamassassin_unregister_hook();
545                         }
546                         procmsg_unregister_spam_learner(spamassassin_learn);
547                         procmsg_spam_set_folder(NULL, NULL);
548                         return FALSE;
549                 }
550         }
551         return TRUE;
552 }
553
554 void spamassassin_set_message_callback(MessageCallback callback)
555 {
556         message_callback = callback;
557 }
558
559 gint plugin_init(gchar **error)
560 {
561         gchar *rcpath;
562
563         hook_id = -1;
564
565         if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
566                                 VERSION_NUMERIC, PLUGIN_NAME, error))
567                 return -1;
568
569         prefs_set_default(param);
570         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
571         prefs_read_config(param, "SpamAssassin", rcpath, NULL);
572         g_free(rcpath);
573         if (!spamassassin_check_username()) {
574                 *error = g_strdup(_("Failed to get username"));
575                 return -1;
576         }
577         spamassassin_gtk_init();
578                 
579         debug_print("SpamAssassin plugin loaded\n");
580
581         if (config.process_emails) {
582                 spamassassin_register_hook();
583         }
584
585         if (!config.enable || config.transport == SPAMASSASSIN_DISABLED) {
586                 log_warning(LOG_PROTOCOL, _("SpamAssassin plugin is loaded but disabled by its preferences.\n"));
587         }
588         else {
589                 if (config.transport == SPAMASSASSIN_TRANSPORT_TCP)
590                         debug_print("Enabling learner with a remote spamassassin server requires spamc/spamd 3.1.x\n");
591                 procmsg_register_spam_learner(spamassassin_learn);
592                 procmsg_spam_set_folder(config.save_folder, spamassassin_get_spam_folder);
593         }
594
595         return 0;
596         
597 }
598
599 gboolean plugin_done(void)
600 {
601         if (hook_id != -1) {
602                 spamassassin_unregister_hook();
603         }
604         g_free(config.hostname);
605         g_free(config.save_folder);
606         spamassassin_gtk_done();
607         procmsg_unregister_spam_learner(spamassassin_learn);
608         procmsg_spam_set_folder(NULL, NULL);
609         debug_print("SpamAssassin plugin unloaded\n");
610         return TRUE;
611 }
612
613 const gchar *plugin_name(void)
614 {
615         return PLUGIN_NAME;
616 }
617
618 const gchar *plugin_desc(void)
619 {
620         return _("This plugin can check all messages that are received from an "
621                  "IMAP, LOCAL or POP account for spam using a SpamAssassin "
622                  "server. You will need a SpamAssassin Server (spamd) running "
623                  "somewhere.\n"
624                  "\n"
625                  "It can also be used for marking messages as Ham or Spam.\n"
626                  "\n"
627                  "When a message is identified as spam it can be deleted or "
628                  "saved in a specially designated folder.\n"
629                  "\n"
630                  "Options can be found in /Configuration/Preferences/Plugins/SpamAssassin");
631 }
632
633 const gchar *plugin_type(void)
634 {
635         return "GTK2";
636 }
637
638 const gchar *plugin_licence(void)
639 {
640         return "GPL3+";
641 }
642
643 const gchar *plugin_version(void)
644 {
645         return VERSION;
646 }
647
648 struct PluginFeature *plugin_provides(void)
649 {
650         static struct PluginFeature features[] = 
651                 { {PLUGIN_FILTERING, N_("Spam detection")},
652                   {PLUGIN_FILTERING, N_("Spam learning")},
653                   {PLUGIN_NOTHING, NULL}};
654         return features;
655 }
656
657 void spamassassin_register_hook(void)
658 {
659         if (hook_id == -1)
660                 hook_id = hooks_register_hook(MAIL_FILTERING_HOOKLIST, mail_filtering_hook, NULL);
661         if (hook_id == -1) {
662                 g_warning("Failed to register mail filtering hook");
663                 config.process_emails = FALSE;
664         }
665 }
666
667 void spamassassin_unregister_hook(void)
668 {
669         if (hook_id != -1) {
670                 hooks_unregister_hook(MAIL_FILTERING_HOOKLIST, hook_id);
671         }
672         hook_id = -1;
673 }
674
675 FolderItem *spamassassin_get_spam_folder(MsgInfo *msginfo)
676 {
677         FolderItem *item = folder_find_item_from_identifier(config.save_folder);
678
679         if (item || msginfo == NULL || msginfo->folder == NULL)
680                 return item;
681
682         if (msginfo->folder->folder &&
683             msginfo->folder->folder->account && 
684             msginfo->folder->folder->account->set_trash_folder) {
685                 item = folder_find_item_from_identifier(
686                         msginfo->folder->folder->account->trash_folder);
687         }
688
689         if (item == NULL && 
690             msginfo->folder->folder &&
691             msginfo->folder->folder->trash)
692                 item = msginfo->folder->folder->trash;
693                 
694         if (item == NULL)
695                 item = folder_get_default_trash();
696                 
697         debug_print("SA spam dir: %s\n", folder_item_get_path(item));
698         return item;
699 }
700