]> diplodocus.org Git - mdeliver/commitdiff
UNTESTED: Filter spam into 3 different folders based on score. master
authorepg@pretzelnet.org <>
Tue, 28 Apr 2009 05:58:49 +0000 (22:58 -0700)
committerepg@pretzelnet.org <>
Tue, 28 Apr 2009 05:58:49 +0000 (22:58 -0700)
(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 .

processor.c

index 66652d77865fc2a1c63021d9bf3bf2c104fbcd96..573c64011a3c967aff585ae3e513e1b74eb50ced 100644 (file)
@@ -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);