]> git.madduck.net Git - etc/mailfilter.git/blob - bin/train

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

05a768f70c4c9e71ec4dc153829804b6dde9c7f5
[etc/mailfilter.git] / bin / train
1 #!/bin/sh
2 set -eu
3
4 USER=${USER:-$LOGNAME}
5 DOMAIN=${DOMAIN:-$(hostname --fqdn)}
6
7 NICE='/usr/bin/nice -20'
8 MAILFILTER=$HOME/.etc/mailfilter
9 SA_PREFS="$MAILFILTER/spamassassin/user_prefs"
10 MAILREAVER="$NICE $HOME/spamfilter/mailreaver.crm -u $MAILFILTER/crm114/"
11 SPAMASSASSIN="$NICE /usr/bin/spamassassin -p $SA_PREFS"
12 #SPAMC="$NICE /usr/bin/spamc -lxu ${USER}@${DOMAIN}"
13 SA_REPORT="$SPAMASSASSIN --report"
14 SA_REVOKE="$SPAMASSASSIN --revoke"
15 SA_LEARN="$NICE /usr/bin/sa-learn -p $SA_PREFS"
16 SA_LEARN_HAM="$SA_LEARN --ham"
17 SA_LEARN_SPAM="$SA_LEARN --spam"
18 PRE_CLEANUP="$MAILFILTER/procmail/pre-spam-cleanup"
19
20 HAM=0
21 SPAM=0
22 FILE=
23
24 for i in "$@"; do
25   case "$i" in
26     --ham) HAM=1;;
27     --spam) SPAM=1;;
28     *)
29       if [ -n "$FILE" ]; then
30         echo "E: input file already specified: $i" >&2
31         exit 1
32       elif [ -r "$i" ]; then
33         FILE="$i"
34       else
35         echo "E: unknown argument: $i" >&2
36         exit 255
37       fi
38       ;;
39   esac
40 done
41
42 case "$HAM/$SPAM" in
43   0/0)
44     echo "E: you need to specify either --ham or --spam." >&2
45     exit 255
46     ;;
47   1/1)
48     echo "E: you cannot specify both --ham and --spam." >&2
49     exit 255
50     ;;
51 esac
52
53 TMPFILE="$(tempfile -p mailtrainer)"
54 trap "rm -f $TMPFILE" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
55
56 $PRE_CLEANUP < ${FILE:-/dev/stdin} > "$TMPFILE"
57
58 cd $HOME/.var/crm114
59
60 case "$HAM/$SPAM" in
61   1/0)
62     echo -n 'Training Spamassassin with ham: ' >&2
63     $SA_LEARN_HAM < "$TMPFILE" >&2
64     echo -n 'Revoking spam via Spamassassin: ' >&2
65     $SA_REVOKE < "$TMPFILE" >&2
66 #    [ "${CRM114_STATUS:-}" = GOOD ] || {
67       echo -n 'Training crm114 with ham: ' >&2
68       $MAILREAVER --good < "$TMPFILE" >/dev/null
69       echo 'done.' >&2
70 #    }
71     formail -I 'X-Trained-As: ham' < "$TMPFILE"
72     ;;
73   0/1)
74     echo -n 'Training Spamassassin with spam: ' >&2
75     $SA_LEARN_SPAM < "$TMPFILE" >&2
76     echo -n 'Reporting spam via Spamassassin: ' >&2
77     $SA_REPORT < "$TMPFILE" >&2
78 #    [ "${CRM114_STATUS:-}" = SPAM ] || {
79       echo -n 'Training crm114 with spam: ' >&2
80       $MAILREAVER --spam < "$TMPFILE" >/dev/null
81       echo 'done.' >&2
82 #    }
83     formail -I 'X-Trained-As: spam' < "$TMPFILE"
84     ;;
85 esac
86
87 rm -f $TMPFILE
88 trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
89
90 exit 0