2

Say you have a directory with tens of thousands of messages in it. And you want to separate the spam from the non-spam.

Specifically, you would like to:

  1. Run spamassassin against the directory, tagging each message with an X-Spam-Flag: YES if it thinks it's spam
  2. Have a tcsh shell or perl one-liner grep all mail with the flag and move those mails to /tmp/spam

What command can you run to accomplish this? For example, some pseudocode:

/usr/local/bin/spamassassin -eL ./Maildir/cur/* | grep "X-Spam-Flag: YES" | mv %1 /tmp/spam

2 Answers 2

6

Your first guess was pretty close :-)

I made a bash script to scan a whole maildir against spam

#!/bin/bash

DIR="/home/vmail/example.net/exampleuser/cur/"

for f in $(ls $DIR); do
    spamassassin -Le "$DIR/$f" > /dev/null
    ERR=$?
    echo $ERR
    if [ $ERR -gt 0 ]; then 
        mv "$DIR/$f" /tmp/spam/
    else
        echo "This was no spam."
    fi
done

Save this as mailcleanup.sh somewhere, put the path of the folder you want to scan as DIR, set it +x and run it.

Good luck!

1

Ended up doing this the long way, without using spamassassin:

  1. Download all headers via an IMAP client.
  2. Search headers for common spammy subjects and from addresses.
  3. Delete & purge spam en masse. (instead of moving to a new directory)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .