diff options
-rw-r--r-- | antispam-plugin.c | 7 | ||||
-rw-r--r-- | antispam-plugin.h | 1 | ||||
-rw-r--r-- | antispam-storage-1.0.c | 51 | ||||
-rw-r--r-- | antispam.7 | 22 |
4 files changed, 76 insertions, 5 deletions
diff --git a/antispam-plugin.c b/antispam-plugin.c index cfec425..407b909 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -48,6 +48,7 @@ static char *default_spam_folders[] = { }; static char **spam_folders = default_spam_folders; static char **unsure_folders = NULL; +bool antispam_can_append_to_spam = FALSE; static bool mailbox_in_list(struct mailbox *box, char **list) { @@ -126,6 +127,12 @@ void PLUGIN_FUNCTION(init)(void) if (tmp) spam_folders = p_strsplit(global_pool, tmp, ";"); + tmp = get_setting("ALLOW_APPEND_TO_SPAM"); + if (tmp && strcasecmp(tmp, "yes") == 0) { + antispam_can_append_to_spam = TRUE; + debug("allowing APPEND to spam folders"); + } + if (spam_folders) { iter = spam_folders; while (*iter) { diff --git a/antispam-plugin.h b/antispam-plugin.h index 9b6bae5..98fed8f 100644 --- a/antispam-plugin.h +++ b/antispam-plugin.h @@ -50,5 +50,6 @@ bool mailbox_is_spam(struct mailbox *box); bool mailbox_is_trash(struct mailbox *box); bool mailbox_is_unsure(struct mailbox *box); const char *get_setting(const char *name); +bool antispam_can_append_to_spam; #endif /* _ANTISPAM_PLUGIN_H */ diff --git a/antispam-storage-1.0.c b/antispam-storage-1.0.c index e4ca9e8..e1b00fa 100644 --- a/antispam-storage-1.0.c +++ b/antispam-storage-1.0.c @@ -166,14 +166,55 @@ static int antispam_save_finish(struct mail_save_context *ctx, case MMT_UNINTERESTING: break; case MMT_APPEND: - /* Disallow APPENDs to SPAM/UNSURE folders. */ - if (mailbox_is_spam(save_dest_mail->box) || - mailbox_is_unsure(save_dest_mail->box)) { + /* Disallow APPENDs to UNSURE folders. */ + if (mailbox_is_unsure(save_dest_mail->box)) { ret = -1; mail_storage_set_error(save_dest_mail->box->storage, - "Cannot APPEND to this folder."); + "Cannot APPEND to an UNSURE folder."); + break; + } else if (mailbox_is_spam(save_dest_mail->box)) { + /* + * The client is APPENDing a message to a SPAM folder + * so we try to train the backend on it. For most of + * the backends, that can only succeed if the message + * contains appropriate information. + * + * This happens especially when offlineimap is used and + * the user moved a message to the SPAM folder while + * offline---offlineimap cannot reproduce the COPY but + * rather APPENDs the moved message on the next sync. + * + * This could be a bad if the spam headers were not + * generated on our server, but since the user can + * always APPEND to another folder and then COPY to a + * SPAM folder backends need to be prepared for cases + * like this anyway. With dspam, for example, the worst + * that can happen is that the APPEND fails with a + * training error from dspam. + * + * Unfortunately, we cannot handle the cases where + * (1) the user moved a message from one folder that + * contains SPAM to another folder containing SPAM + * (2) the user moved a message out of the SPAM folder + * (3) the user recovered a message from trash + * + * Because of these limitations, this behaviour needs + * to be enabled with an option. + */ + if (!antispam_can_append_to_spam) { + ret = -1; + mail_storage_set_error( + save_dest_mail->box->storage, + "Cannot APPEND to a SPAM folder."); + break; + } + asbox->movetype = MMT_TO_SPAM; + /* fall through to default case to invoke backend */ + } else { + /* neither UNSURE nor SPAM, regular folder */ + break; } - break; + /* fall through */ default: ret = backend_handle_mail(ctx->transaction, ast, save_dest_mail, move_to_class(asbox->movetype)); @@ -114,6 +114,11 @@ plugin { # semicolon-separated list of unsure folders (default unset i.e. none) # antispam_unsure = + # Whether to allow APPENDing to SPAM folders or not. Must be set to + # "yes" (case insensitive) to be activated. Before activating, please + # read the discussion below. + # antispam_allow_append_to_spam = no + ########################### # BACKEND SPECIFIC OPTIONS # @@ -161,6 +166,23 @@ plugin { } .fi +.SH ALLOWING APPENDS? + +You should be careful with allowing APPENDs to SPAM folders. The reason +for possibly allowing it is to allow not-SPAM --> SPAM transitions to work +with offlineimap. However, because with APPEND the plugin cannot know the +source of the message, multiple bad scenarios can happen: + +.IP " 1." 4 +SPAM --> SPAM transitions cannot be recognised and are trained + +.IP " 2." 4 +the same holds for Trash --> SPAM transitions + +.PP +Additionally, because we cannot recognise SPAM --> not-SPAM transitions, +training good messages will never work with APPEND. + .SH AUTHORS Johannes Berg, Frank Cusack, Benedikt Boehm, Andreas Schneider |