> -----Original Message-----
> From: owner-postfix-us...@postfix.org [mailto:owner-postfix-
> us...@postfix.org] On Behalf Of Bob Cohen
> Sent: Wednesday, October 14, 2009 1:26 PM
> To: users Postfix
> Subject: Emptying SPAM account
> 
> I have set up SpamAssissin with an account to collect rejected
> emails.  Is there a way to periodically empty the mail queue for that
> account with a cron job or some other such method that does not
> require human intervention

Bob, 

Not sure if this is helpful.  We use horde webmail and have it setup for people 
can mark ham/spam.  These messages are dropped into an IMAP account (name 
ham/spam).  We have a script (that originated somewhere on the net) that walks 
those mailboxes and performs the necessary actions.

Anyway, If these email messages are in a IMAP enabled mailbox, you could use 
the script to train, move, delete, whatever you want to do, on the messages 
there.  It python, but I think the default installs of python should be able to 
run it without any problems.  This particular script only does the ham.  Minor 
changes, makes it handle spam.

Hope this helps.

#!/usr/bin/env python
import commands, os, time
import imaplib
import sys, re
import string, random
import StringIO, rfc822


# Set required variables
PREFS = "/etc/mail/spamassassin/local.cf"
TMPFILE = "/var/tmp/salearn.tmp"
SALEARN = "/usr/bin/sa-learn"
SERVER = "myhostname"
USER  = "mylogin"
PASSWORD = "mypass"
LOGFILE = "/var/log/learn.ham.log"
log = file(LOGFILE, 'a+')
log.write("\n\nTraining SpamAssassin on %s at %s\n" % 
(time.strftime("%Y-%m-%d"),
time.strftime("%H:%M:%S")))

# connect to server
server = imaplib.IMAP4(SERVER)

# login
server.login(USER, PASSWORD)
server.select("INBOX")

# Get messages
typ, data = server.search(None, 'ALL')
for num in data[0].split():
        typ, data = server.fetch(num, '(RFC822)')
        tmp = file(TMPFILE, 'w+')
        tmp.write(data[0][1])
        tmp.close()
        log.write(commands.getoutput("%s --username=filter --prefs-file=%s 
--spam --forget %s" % \
                (SALEARN, PREFS, TMPFILE)))
        log.write("\n")
        log.write(commands.getoutput("%s --username=filter --prefs-file=%s 
--ham %s" % \
                (SALEARN, PREFS, TMPFILE)))
        log.write("\n")
        # Make a copy if it for testing at this time.
        # server.copy(num, 'Inbox/Processed') 
        # Mark learned ham as "Deleted"
        server.store(num, '+FLAGS', '\\Deleted')
# Delete messages marked as "Deleted" from server
server.expunge()
server.logout


Reply via email to