0

When I run the spamassassin command on an email, it properly identifies the email as spam and appears as if the headers have been added. But the file is not actually updated and the headers remain the same. Because of my reputation here, I cannot post the actual output of the commands. Any help is appreciated. Thank you.

To start, /etc/spamassassin/local.cf has 'report_safe 0'

Basically, I am running the following command on a single email, as an example.

mike@servo:/mnt/filestore/mail/mike$ spamassassin INBOX/cur/1476677884_0.3597.servo\,U\=678\,FMD5\=7e33429f656f1e6e9d79b29c3f82c57e:2\,

The result of this includes the entire email with the X-Spam headers visible. In this case, "X-Spam-Status: Yes, score=24.0 required=5.0" as an example.

I am then just viewing the file with 'more' afterwards. But the X-Spam headers are not visible. Nothing is changed.

mike@servo:/mnt/filestore/mail/mike$ more INBOX/cur/1476677884_0.3597.servo\,U\=678\,FMD5\=7e33429f656f1e6e9d79b29c3f82c57e:2\,

Edit: I also wanted to point out that using the spamc command instead of spamassassin results in the same. Unless I am totally mistaken on how this is supposed to behave - the commands should actually write the file not just output the result, correct? - then perhaps this is a permission issue? It appears that the user that was installed with spamassassin is debian-spamd, all of my mail is stored as -rw-rw-r-- mike:mike. I cannot find any logs to prove a permission error, however.

2 Answers2

0

When you grab an output for spamassassin, it will output your message to STDOUT, not the original file.

This is because spamassassin typically takes messages through STDIN, like when it's being used as a sieve for Postfix. Postfix passes the message through STDIN to spamassassin, who outputs it to STDOUT to the next process, so something like this:

[email] -> `spamassassin` / `spamc` ---[spam-sorted email]---> `somethingelse`

If you want to save the file, you need to write it, like so:

spamassassin mail.eml > mail-spamcheck.eml
Kaz Wolfe
  • 34,680
0

For anyone that may stumble upon this post with a similar question, below is how I solved this problem. I moved to fetchmail from offlineimap in order to pop messages into a separate directory and I added the below script to cron.

#!/bin/bash

#Mail directories. Do not include the trailing /.
NEWMAIL="/home/mike/.mailqueue"
INBOX="/mnt/filestore/mail/mike/INBOX/new"
JUNK="/mnt/filestore/mail/mike/.Junk/new"

#fetch new messages
fetchmail

#move any messages in new to cur
echo "Moving messages in /new to /cur"
mv $NEWMAIL/new/* $NEWMAIL/cur/

#check if directory contains files
if [ "$(ls -A $NEWMAIL/cur/)" ] ; then

  #move out files that already have spamassassin headers to the INBOX and Junk folders
  echo "Moving pre-processed files."
  grep -lIZ ^X-Spam-Status\:\ Yes \
    $NEWMAIL/cur/* |
    xargs -I '{}' -0 mv '{}' $JUNK/

  grep -lIZ ^X-Spam-Status\:\ No \
    $NEWMAIL/cur/* |
    xargs -I '{}' -0 mv '{}' $INBOX/

  #run spamassassin on each remainining file and append .processed to the filename
  for file in $NEWMAIL/cur/*
  do
    echo "Processing $file"
    spamassassin $file > $file.processed
  done

  #move the processed files to the INBOX and Junk folders
  echo "Moving processed files."
  grep -lIZ ^X-Spam-Status\:\ Yes \
    $NEWMAIL/cur/* |
    xargs -I '{}' -0 mv '{}' $JUNK/

  grep -lIZ ^X-Spam-Status\:\ No \
    $NEWMAIL/cur/* |
    xargs -I '{}' -0 mv '{}' $INBOX/

  #delete the remaining files
  echo "Deleting the remaining files."
  rm -Rf $NEWMAIL/cur/*

#no files in directory
else
  echo "Nothing to do."
fi