summaryrefslogtreecommitdiffstats
path: root/local/.bin/tozt/learn_spam
diff options
context:
space:
mode:
Diffstat (limited to 'local/.bin/tozt/learn_spam')
-rwxr-xr-xlocal/.bin/tozt/learn_spam38
1 files changed, 38 insertions, 0 deletions
diff --git a/local/.bin/tozt/learn_spam b/local/.bin/tozt/learn_spam
new file mode 100755
index 0000000..75e500a
--- /dev/null
+++ b/local/.bin/tozt/learn_spam
@@ -0,0 +1,38 @@
+#!/bin/sh
+set -eu
+set -o pipefail
+
+MAILDIR=~/Maildir
+OPTS="--no-sync"
+SALEARN=/usr/bin/vendor_perl/sa-learn
+
+if [ "$1" = "-q" ]; then
+ OPTS="$OPTS"
+ OUTFILE="/dev/null"
+else
+ OPTS="$OPTS --showdots"
+ OUTFILE="/dev/stdout"
+fi
+
+if [ ! "$1" = "-q" ]; then
+ echo "$(date): Learning ham..."
+fi
+nice find $MAILDIR -type f |
+ perl -nl0e'chomp; ($ts) = /(\d{10})/; $now = time; print if m{/(new|cur)/} && !m{/(\.old|\.spam)/} && $ts > $now - 60*60*24*30' |
+ xargs -n1000 -0 $SALEARN "$OPTS" --ham >$OUTFILE
+
+if [ ! "$1" = "-q" ]; then
+ echo "$(date): Learning spam..."
+fi
+nice find $MAILDIR -type f |
+ perl -nl0e'chomp; ($ts) = /(\d{10})/; $now = time; print if m{/(new|cur)/} && m{/\.spam/} && $ts > $now - 60*60*24*30' |
+ xargs -n1000 -0 $SALEARN "$OPTS" --spam >$OUTFILE
+
+if [ ! "$1" = "-q" ]; then
+ echo "$(date): Syncing..."
+fi
+nice $SALEARN --sync >$OUTFILE
+
+if [ ! "$1" = "-q" ]; then
+ echo "$(date): Done!"
+fi