]> 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:

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