From e0a10f38cd617c4483d4c67b564165a65bb46de2 Mon Sep 17 00:00:00 2001 From: Johannes Berg Date: Mon, 1 Oct 2007 22:32:10 +0200 Subject: introduce 'unsure' folder feature, fix bug from previous commit --- README | 11 ++++++++++- antispam-plugin.c | 19 +++++++++++++++++++ antispam-plugin.h | 1 + antispam-storage-1.0.c | 31 +++++++++++++++++++++++++------ 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/README b/README index c9c4e06..2951653 100644 --- a/README +++ b/README @@ -28,6 +28,12 @@ DESCRIPTION The advantage of this approach is that the mail ends up in the right target folder directly and needs not be touched twice. + When other classifiers like crm114 that have an 'unsure' state are used, + the plugin can also help, it supports an 'unsure' folder feature. The + unsure folder cannot be written to, but moving out from there into a + folder that is considered a spam folder will learn as spam, any other + folder (except trashes) will cause learning as not-spam. + INSTALLATION First copy the 'defconfig' file to '.config' and edit it as necessary. @@ -87,9 +93,12 @@ CONFIGURATION # antispam_trash = # antispam_trash = trash;Trash;Deleted Items - # semicolon-separarted list of spam folders + # semicolon-separated list of spam folders antispam_spam = SPAM + # semicolon-separated list of unsure folders (default unset i.e. none) + # antispam_unsure = + ########################### # BACKEND SPECIFIC OPTIONS # diff --git a/antispam-plugin.c b/antispam-plugin.c index 9a84c07..ea7e426 100644 --- a/antispam-plugin.c +++ b/antispam-plugin.c @@ -47,6 +47,7 @@ static char *default_spam_folders[] = { NULL }; static char **spam_folders = default_spam_folders; +static char **unsure_folders = NULL; static bool mailbox_in_list(struct mailbox *box, char **list) { @@ -72,6 +73,11 @@ bool mailbox_is_trash(struct mailbox *box) return mailbox_in_list(box, trash_folders); } +bool mailbox_is_unsure(struct mailbox *box) +{ + return mailbox_in_list(box, unsure_folders); +} + void antispam_plugin_init(void) { char *tmp, **iter; @@ -106,6 +112,19 @@ void antispam_plugin_init(void) } else debug("antispam: no spam folders\n"); + tmp = getenv("ANTISPAM_UNSURE"); + if (tmp) + unsure_folders = p_strsplit(global_pool, tmp, ";"); + + if (unsure_folders) { + iter = unsure_folders; + while (*iter) { + debug("antispam: \"%s\" is unsure folder\n", *iter); + iter++; + } + } else + debug("antispam: no unsure folders\n"); + backend_init(global_pool); antispam_next_hook_mail_storage_created = hook_mail_storage_created; diff --git a/antispam-plugin.h b/antispam-plugin.h index 7719262..a660b9d 100644 --- a/antispam-plugin.h +++ b/antispam-plugin.h @@ -44,5 +44,6 @@ void antispam_mail_storage_created(struct mail_storage *storage); void (*antispam_next_hook_mail_storage_created)(struct mail_storage *storage); bool mailbox_is_spam(struct mailbox *box); bool mailbox_is_trash(struct mailbox *box); +bool mailbox_is_unsure(struct mailbox *box); #endif /* _ANTISPAM_PLUGIN_H */ diff --git a/antispam-storage-1.0.c b/antispam-storage-1.0.c index e8aa6bb..f93a5b3 100644 --- a/antispam-storage-1.0.c +++ b/antispam-storage-1.0.c @@ -27,10 +27,22 @@ struct antispam_mail_storage { enum mailbox_move_type { MMT_UNINTERESTING, - MMT_FROM_SPAM, + MMT_TO_CLEAN, MMT_TO_SPAM, }; +enum classification move_to_class(enum mailbox_move_type tp) +{ + switch (tp) { + case MMT_TO_CLEAN: + return CLASS_NOTSPAM; + case MMT_TO_SPAM: + return CLASS_SPAM; + default: + i_assert(0); + } +} + struct antispam_mailbox { struct mailbox_vfuncs super; @@ -63,14 +75,21 @@ antispam_copy(struct mailbox_transaction_context *t, struct mail *mail, asbox->save_hack = FALSE; asbox->movetype = MMT_UNINTERESTING; + if (mailbox_is_unsure(t->box)) { + mail_storage_set_error(t->box->storage, + "Cannot copy to unsure folder"); + return -1; + } + if (!mailbox_is_trash(mail->box) && !mailbox_is_trash(t->box)) { bool src_spam = mailbox_is_spam(mail->box); bool dst_spam = mailbox_is_spam(t->box); + bool src_unsu = mailbox_is_unsure(mail->box); - if (src_spam && !dst_spam) - asbox->movetype = MMT_FROM_SPAM; - else if (!src_spam && dst_spam) + if ((src_spam || src_unsu) && !dst_spam) + asbox->movetype = MMT_TO_CLEAN; + else if ((!src_spam || src_unsu) && dst_spam) asbox->movetype = MMT_TO_SPAM; } @@ -84,7 +103,7 @@ antispam_copy(struct mailbox_transaction_context *t, struct mail *mail, ret = 0; else ret = backend_handle_mail(t, ast, copy_dest_mail, - asbox->movetype == MMT_FROM_SPAM); + move_to_class(asbox->movetype)); if (copy_dest_mail != dest_mail) mail_free(©_dest_mail); @@ -113,7 +132,7 @@ static int antispam_save_finish(struct mail_save_context *ctx, asbox->save_hack = TRUE; if (asbox->movetype != MMT_UNINTERESTING) ret = backend_handle_mail(ctx->transaction, ast, save_dest_mail, - asbox->movetype == MMT_FROM_SPAM); + move_to_class(asbox->movetype)); else ret = 0; -- cgit v1.2.3