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:

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