-
-
Save zoni/89e12741e44701c5cd04 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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