Skip to content

Instantly share code, notes, and snippets.

@bps
Last active August 22, 2024 21:54
Show Gist options
  • Save bps/7942b1b3022347e10131375947097ae1 to your computer and use it in GitHub Desktop.
Save bps/7942b1b3022347e10131375947097ae1 to your computer and use it in GitHub Desktop.
#!/usr/bin/zsh
# I get a lot of spam that scores just under the threshold upon delivery, but
# then scores way above a couple minutes later once the block lists start
# reporting. This script takes another look at those suspicious messages.
# Requires SpamAssassin's spamc and tools from the mblaze package.
# I run it in cron like:
# # */3 * * * * flock --nb /run/user/$(id -u)/sa-rescan /home/$(id -un)/bin/sa-rescan
sus_threshold=${1:-1.3}
maildir=${HOME}/Maildir
junkdir=${HOME}/Maildir/.Junk
for m in $(mlist $maildir); do
orig_sa_score=$(mhdr -h X-Spam-Status $m | awk '{split($2, fields, "="); print fields[2]}')
if (( ${orig_sa_score:-0} > $sus_threshold )); then
new_sa_score=$(spamc -c < $m); spamc_rc=$?
if (( $spamc_rc == 1 )) > /dev/null; then
# It's spam now
print $m
print $orig_sa_score
print $new_sa_score
mrefile -v $m $junkdir
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment