summaryrefslogtreecommitdiffstats
path: root/bin/tozt/learn_spam
blob: 128ca9aebaf3e7d049200d6fa6064eb8f219d016 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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