]> git.donarmstrong.com Git - bin.git/blob - learn_from_spam
use formail -c to handle from and to addresses
[bin.git] / learn_from_spam
1 #!/bin/bash
2
3 # these are for non-spamc setups
4 SPAM_REPORT="spamassassin --report"
5 HAM_REPORT="spamassassin --revoke"
6 SPAM_CHECK="spamassassin -e"
7
8 # these are for spamc
9 SPAM_REPORT="spamc --learntype=spam"
10 HAM_REPORT="spamc --learntype=ham"
11 SPAM_CHECK="spamc -c"
12
13 if [ "$(basename $0)" = "learn_from_spam" ]; then
14     for file in "$@"; do
15         $SPAM_REPORT < "$file" >/dev/null;
16         formail -c < "$file" | grep -e '^From ' -e 'From: ' | spamassassin -R >/dev/null;
17         # check to see if it's still spam
18         if ! spamc -c < "$file" >/dev/null; then
19             # this message is still not spam; may need custom rules
20             spamc "$file" > ~/Maildir/spam/needs_rules/cur/"$(basename "$file")";
21         fi;
22     done;
23 elif [ "$(basename $0)" = "learn_from_ham" ]; then
24     for file in "$@"; do
25         $HAM_REPORT < "$file" >/dev/null;
26         formail -c < "$file" |grep -e '^From ' -e 'From: ' -e 'To: ' -e 'Cc: '|spamassassin -W>/dev/null;
27     done;
28 else
29     "Called in a way this script cannot recognize";
30 fi;