]> git.donarmstrong.com Git - bin.git/blobdiff - learn_from_spam
use X if it exists
[bin.git] / learn_from_spam
index 92615ba2d39473db2771348432f4820d1687ae02..306b227c4e13975c49efc4bde800dda786910f22 100755 (executable)
@@ -1,13 +1,37 @@
 #!/bin/bash
 
-if [ $0 eq "learn_from_spam" ]; then 
+# these are for non-spamc setups
+SPAM_REPORT="spamassassin --report"
+HAM_REPORT="spamassassin --revoke"
+SPAM_CHECK="spamassassin -e"
+
+# these are for spamc
+SPAM_REPORT="spamc --learntype=spam"
+HAM_REPORT="spamc --learntype=ham"
+SPAM_CHECK="spamc -c"
+
+if [ "$(basename $0)" = "learn_from_spam" ]; then
     for file in "$@"; do
-        spamassassin -r < "$file";
-        spamassassin -R < "$file";
+        if ! formail -c < "$file"|grep -q '^List-Id'; then
+            $SPAM_REPORT < "$file" >/dev/null 2>&1;
+        fi;
+        formail -c < "$file" | grep -e '^From ' -e 'From: ' | spamassassin --add-to-blacklist >/dev/null 2>&1;
+        formail -c < "$file" | grep -e '^From ' -e 'From: ' | spamassassin --remove-from-whitelist >/dev/null 2>&1;
+        # check to see if it's still spam
+        if ! $SPAM_CHECK < "$file" >/dev/null 2>&1; then
+            # this message is still not spam; may need custom rules
+            spamc < "$file" > ~/Maildir/spam/needs_rules/cur/"$(basename "$file")" 2>/dev/null;
+        fi;
     done;
-elif [ $0 == "learn_from_ham" ]; then
+elif [ "$(basename $0)" = "learn_from_ham" ]; then
     for file in "$@"; do
-        spamassassin -k < "$file";
-        spamassassin -W < "$file";
+        $HAM_REPORT < "$file" >/dev/null 2>&1;
+        formail -c < "$file" |grep -e '^From ' -e 'From: ' -e 'To: ' -e 'Cc: '|spamassassin --add-to-whitelist >/dev/null 2>&1;
+        if $SPAM_CHECK < "$file" >/dev/null 2>&1; then
+            mkdir -p ~/Maildir/spam/needs_ham_rules/cur;
+            spamc < "$file" > ~/Maildir/spam/needs_ham_rules/cur/"$(basename "$file")" 2>/dev/null;
+        fi;
     done;
+else
+    "Called in a way this script cannot recognize";
 fi;