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

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:

hardcode var location
[etc/mailfilter.git] / bin / retrain
1 #!/bin/sh
2 set -eu
3
4 NICE='/usr/bin/nice -20'
5 NICE=''
6
7 RESUBMIT="$NICE $HOME/.etc/mailfilter/bin/resubmit"
8
9 PAUSETIME=10
10
11 HAM=0
12 SPAM=0
13 MAILDIR=
14
15 for i in "$@"; do
16   case "$i" in
17     --ham) HAM=1;;
18     --spam) SPAM=1;;
19     *)
20       if [ -n "$MAILDIR" ]; then
21         echo "E: Maildir already specified: $i" >&2
22         exit 1
23       elif [ -d "$i"/cur ] && [ -d "$i"/new ] && [ -d "$i"/tmp ]; then
24         MAILDIR="$i"
25       else
26         echo "E: unknown argument: $i" >&2
27         exit 255
28       fi
29       ;;
30   esac
31 done
32
33 ARG=
34 case "$HAM/$SPAM" in
35   0/0)
36     echo "E: you need to specify either --ham or --spam." >&2
37     exit 255
38     ;;
39   1/1)
40     echo "E: you cannot specify both --ham and --spam." >&2
41     exit 255
42     ;;
43   0/1) ARG=--spam;;
44   1/0) ARG=--ham;;
45 esac
46
47 LOCKFILE="$MAILDIR/.retrain.lock"
48 trap "rm -f $LOCKFILE" 1 2 3 4 5 6 7 8 10 11 12 13 14 15
49 if ! lockfile -0 -r0 -l 3600 "$LOCKFILE" 2>/dev/null; then
50   echo "E: another retrain process is already running over that Maildir." >&2
51   exit 1
52 fi
53
54 find $MAILDIR/cur $MAILDIR/new -type f | while read msg; do
55   $NICE ${0%/*}/train $ARG "$msg" | $RESUBMIT || ret=$?
56   case "${ret:-0}" in
57     0|75) :;;
58     *)
59       echo "E: resubmission returned with exit code $ret" >&2
60       continue
61       ;;
62   esac
63   rm -f "$msg"
64   sleep $PAUSETIME
65 done
66
67 rm -f "$LOCKFILE"
68 trap - 1 2 3 4 5 6 7 8 10 11 12 13 14 15
69
70 exit 0