Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
share|improve this question

2 Answers 2

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!

share|improve this answer
up vote 1 down vote accepted

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)
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.