= Postfix/Emptying_and_processing_mail_in_maildirs = From http://archives.neohapsis.com/archives/postfix/2009-10/0470.html Someone asked how to process mails in a mailbox, eg. for spam processing, training filters, etc. ---- == Removing old messages == here's what I use: {{{ 5 1 * * * find /path/to/.SPAM/{cur,new} -type f -ctime +7 -exec rm {} \; }}} Deletes all the spam over 7 days old at 0105 daily. == Processing ham == {{{ > -----Original Message----- > From: owner-postfix-userspostfix.org [mailto:owner-postfix- > userspostfix.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 }}} 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's 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. {{{#!python #!/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() }}}