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);