diff options
-rw-r--r-- | antispam-plugin.h | 21 | ||||
-rw-r--r-- | dspam-exec.c | 16 | ||||
-rw-r--r-- | mailtrain.c | 25 | ||||
-rw-r--r-- | signature-log.c | 14 | ||||
-rw-r--r-- | signature.c | 4 | ||||
-rw-r--r-- | signature.h | 6 |
6 files changed, 58 insertions, 28 deletions
diff --git a/antispam-plugin.h b/antispam-plugin.h index de5dca3..7719262 100644 --- a/antispam-plugin.h +++ b/antispam-plugin.h @@ -9,18 +9,23 @@ struct antispam_transaction_context; -/* - * Call backend giving - * - pool: dovecot memory pool, will be freed afterwards - * - spam: whether mail comes from spam folder or not - * - sigs: signatures, next == NULL terminates list - * - - */ +enum classification { + CLASS_NOTSPAM, + CLASS_SPAM, +}; + void backend_init(pool_t pool); void backend_exit(void); +/* + * Handle mail; parameters are + * - t: transaction context + * - ast: transaction context from backend_start() + * - mail: the message + * - wanted: the wanted classification determined by the user + */ int backend_handle_mail(struct mailbox_transaction_context *t, struct antispam_transaction_context *ast, - struct mail *mail, bool from_spam); + struct mail *mail, enum classification wanted); struct antispam_transaction_context *backend_start(struct mailbox *box); void backend_rollback(struct antispam_transaction_context *ast); int backend_commit(struct mailbox_transaction_context *ctx, diff --git a/dspam-exec.c b/dspam-exec.c index 0d02a24..f0b1824 100644 --- a/dspam-exec.c +++ b/dspam-exec.c @@ -35,7 +35,7 @@ static int extra_args_num = 0; #define FIXED_ARGS_NUM 6 -static int call_dspam(const char *signature, bool from_spam) +static int call_dspam(const char *signature, enum classification wanted) { pid_t pid; const char *class_arg; @@ -43,10 +43,14 @@ static int call_dspam(const char *signature, bool from_spam) int pipes[2]; sign_arg = t_strconcat("--signature=", signature, NULL); - if (from_spam) + switch (wanted) { + case CLASS_NOTSPAM: class_arg = t_strconcat("--class=", "innocent", NULL); - else + break; + case CLASS_SPAM: class_arg = t_strconcat("--class=", "spam", NULL); + break; + } /* * For dspam stderr; dspam seems to not always exit with a @@ -167,7 +171,7 @@ int backend_commit(struct mailbox_transaction_context *ctx, int ret = 0; while (item) { - if (call_dspam(item->sig, item->from_spam)) { + if (call_dspam(item->sig, item->wanted)) { ret = -1; mail_storage_set_error(ctx->box->storage, "Failed to call dspam"); @@ -183,9 +187,9 @@ int backend_commit(struct mailbox_transaction_context *ctx, int backend_handle_mail(struct mailbox_transaction_context *t, struct antispam_transaction_context *ast, - struct mail *mail, bool from_spam) + struct mail *mail, enum classification want) { - return signature_extract_to_list(t, mail, &ast->siglist, from_spam); + return signature_extract_to_list(t, mail, &ast->siglist, want); } void backend_init(pool_t pool) diff --git a/mailtrain.c b/mailtrain.c index ec8f066..cdb522e 100644 --- a/mailtrain.c +++ b/mailtrain.c @@ -35,12 +35,21 @@ static const char *hamaddr = NULL; static const char *sendmail_binary = "/usr/sbin/sendmail"; static const char *tmpdir = "/tmp"; -static int run_sendmail(int mailfd, bool from_spam) +static int run_sendmail(int mailfd, enum classification wanted) { - const char *dest = from_spam ? hamaddr : spamaddr; + const char *dest; pid_t pid; int status; + switch (wanted) { + case CLASS_SPAM: + dest = spamaddr; + break; + case CLASS_NOTSPAM: + dest = hamaddr; + break; + } + if (!dest) return -1; @@ -96,7 +105,7 @@ static int process_tmpdir(struct mailbox_transaction_context *ctx, int cnt = ast->count; int fd; char *buf; - bool from_spam; + enum classification wanted; t_push(); @@ -108,9 +117,9 @@ static int process_tmpdir(struct mailbox_transaction_context *ctx, ast->tmpdir, cnt); fd = open(buf, O_RDONLY); - read(fd, &from_spam, sizeof(bool)); + read(fd, &wanted, sizeof(wanted)); - if (run_sendmail(fd, from_spam)) { + if (run_sendmail(fd, wanted)) { mail_storage_set_error(ctx->box->storage, "failed to send mail"); return -1; @@ -174,7 +183,7 @@ int backend_commit(struct mailbox_transaction_context *ctx, int backend_handle_mail(struct mailbox_transaction_context *t, struct antispam_transaction_context *ast, - struct mail *mail, bool from_spam) + struct mail *mail, enum classification wanted) { struct istream *mailstream; struct ostream *outstream; @@ -224,8 +233,8 @@ int backend_handle_mail(struct mailbox_transaction_context *t, goto out_close; } - if (o_stream_send(outstream, &from_spam, sizeof(from_spam)) - != sizeof(from_spam)) { + if (o_stream_send(outstream, &wanted, sizeof(wanted)) + != sizeof(wanted)) { ret = -1; mail_storage_set_error(t->box->storage, "Failed to write marker to temp file"); diff --git a/signature-log.c b/signature-log.c index bddca5b..6d697d6 100644 --- a/signature-log.c +++ b/signature-log.c @@ -85,10 +85,11 @@ int backend_commit(struct mailbox_transaction_context *ctx, int backend_handle_mail(struct mailbox_transaction_context *t, struct antispam_transaction_context *ast, - struct mail *mail, bool from_spam) + struct mail *mail, enum classification wanted) { const char *signature; int ret; + int inc; if (!ast->dict) { mail_storage_set_error(t->box->storage, @@ -98,6 +99,15 @@ int backend_handle_mail(struct mailbox_transaction_context *t, signature = signature_extract(t, mail); + switch (wanted) { + case CLASS_SPAM: + inc = 1; + break; + case CLASS_NOTSPAM: + inc = -1; + break; + } + /* * We really should have a global transaction as implemented * by the code that is commented out with C99 comments (//). @@ -110,7 +120,7 @@ int backend_handle_mail(struct mailbox_transaction_context *t, */ ast->dict_ctx = dict_transaction_begin(ast->dict); signature = t_strconcat("priv/", signature, NULL); - dict_atomic_inc(ast->dict_ctx, signature, from_spam ? -1 : 1); + dict_atomic_inc(ast->dict_ctx, signature, inc); ret = dict_transaction_commit(ast->dict_ctx); if (ret) mail_storage_set_error(t->box->storage, diff --git a/signature.c b/signature.c index 1014ed3..3af5e34 100644 --- a/signature.c +++ b/signature.c @@ -16,7 +16,7 @@ void signature_init(void) int signature_extract_to_list(struct mailbox_transaction_context *t, struct mail *mail, struct siglist **list, - bool from_spam) + enum classification wanted) { const char *const *signatures; struct siglist *item; @@ -33,7 +33,7 @@ int signature_extract_to_list(struct mailbox_transaction_context *t, item = i_new(struct siglist, 1); item->next = *list; - item->from_spam = from_spam; + item->wanted = wanted; item->sig = i_strdup(signatures[0]); *list = item; diff --git a/signature.h b/signature.h index 9135aee..fb3a098 100644 --- a/signature.h +++ b/signature.h @@ -4,16 +4,18 @@ #include "lib.h" #include "client.h" +#include "antispam-plugin.h" + struct siglist { struct siglist *next; char *sig; - bool from_spam; + enum classification wanted; }; void signature_init(void); int signature_extract_to_list(struct mailbox_transaction_context *t, struct mail *mail, struct siglist **list, - bool from_spam); + enum classification wanted); const char *signature_extract(struct mailbox_transaction_context *t, struct mail *mail); void signature_list_free(struct siglist **list); |