Skip to content

Instantly share code, notes, and snippets.

@zoni
Created January 28, 2014 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoni/89e12741e44701c5cd04 to your computer and use it in GitHub Desktop.
Save zoni/89e12741e44701c5cd04 to your computer and use it in GitHub Desktop.
#!/bin/zsh
# Maildir location
MAILDIR=$HOME/.maildir
# Max age in days of mails to be considered (corresponds to find -mtime)
MAX_AGE=1
SPAMDIRS=(.Spam .Spam.Unsure .Spam.Certain)
EXCLUDEDIRS=(.Spam.ToReport .Spam.Reported .Trash .Duplicates)
for file in $MAILDIR $MAILDIR/.*
do
if [ ! -d $file ]; then
continue
fi
bn=$(basename $file)
# Test if $bn is present in $EXCLUDEDIRS
# Taken from http://stackoverflow.com/a/5203740
if [[ ${EXCLUDEDIRS[(r)$bn]} == $bn ]]; then
continue
fi
# Test if $bn is present in $SPAMDIRS
# Taken from http://stackoverflow.com/a/5203740
if [[ ${SPAMDIRS[(r)$bn]} == $bn ]]
then
learntype=spam
else
learntype=ham
fi
echo "Processing $file ($learntype)"
find $file/{cur,new} -type f -mtime -$MAX_AGE -print0 | xargs --null --no-run-if-empty sa-learn --$learntype --no-sync
echo
done
sa-learn --sync
for file in $MAILDIR/.Spam.ToReport/{cur,new}/*(N)
do
spamassassin -r $file
mv $file $HOME/.maildir/.Spam.Reported/cur/
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment