From: epg@pretzelnet.org <> Date: Tue, 28 Apr 2009 05:58:49 +0000 (-0700) Subject: UNTESTED: Filter spam into 3 different folders based on score. X-Git-Url: https://diplodocus.org/git/mdeliver/commitdiff_plain/refs/heads/master?ds=inline;hp=999768b8b43253d81cb50d3067aaea1fe17707ed UNTESTED: Filter spam into 3 different folders based on score. (spam_level): Rename from is_spam . Return 0 for not spam, and 1, 2, or 3 for exceeding 1, 2, or 3 * the user's configured threshold. (process): Construct spam folder name with the spam_level . --- diff --git a/processor.c b/processor.c index 66652d7..573c640 100644 --- a/processor.c +++ b/processor.c @@ -143,50 +143,57 @@ get_message(char *fn, struct message *m) return true; } -static bool -is_spam(char *message) +static int +spam_level(char *message) { struct transport t; struct message m; int status; if (!get_transport(&t)) { - return false; + return 0; } if (!get_message(message, &m)) { - return false; + return 0; } if ((status = message_filter(&t, logname(), flags, &m)) != EX_OK) { warnx("non-fatal: message_filter"); - return false; + return 0; } if (m.is_spam == EX_ISSPAM) { - return true; + if (m.score > m.threshold * 3) { + return 3; + } else if (m.score > m.threshold * 2) { + return 2; + } + return 1; } else if (m.is_spam == EX_NOTSPAM) { - return false; + return 0; } warnx("non-fatal: message_filter returned %d", m.is_spam); - return false; + return 0; } static int process(char *tmp) { size_t len = strlen(tmp); - errfn = malloc(len + 1); - /* 5 for spam/ and 1 for terminating null */ - char *new = malloc(len + 5 + 1); + /* 6 for spamN/ and 1 for terminating null */ + char *new = malloc(len + 6 + 1); + int level = spam_level(tmp); /* Nothing to do about a malloc failure but dump core. */ + errfn = malloc(len + 1); strcpy(errfn, "err"); strcat(errfn, tmp + 3); - new[0] = '\0'; - if (is_spam(tmp)) { - strcpy(new, "spam/"); + if (level > 0) { + snprintf(new, 7, "spam%d/", level); + } else { + new[0] = '\0'; } strcat(new, "new"); strcat(new, tmp + 3);