Emptying SPAM account

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Emptying SPAM account

Bob Cohen-3
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
Reply | Threaded
Open this post in threaded view
|

Re: Emptying SPAM account

Dan Schaefer-3
Bob Cohen wrote:
> 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
What is the purpose to collect the rejected mail if you are going to
have an automated process to delete them?

--
Dan Schaefer
Web Developer/Systems Analyst
Performance Administration Corp.

Reply | Threaded
Open this post in threaded view
|

Re: Emptying SPAM account

Brian Mathis-2
On Wed, Oct 14, 2009 at 4:31 PM, Dan Schaefer <[hidden email]> wrote:

> Bob Cohen wrote:
>>
>> 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
>
> What is the purpose to collect the rejected mail if you are going to have an
> automated process to delete them?
>
> --
> Dan Schaefer


That's pretty obvious... to maintain a cache in case anyone is looking
for a message in the past X number of days, and then assume that if no
one missed it in X days, delete it.

As for the original question, it sounds like you need to be looking at
things that interact with the mailstore, not queues.  Once the message
is delivered, postfix does not handle it anymore.  You also have some
terminology mixed up, as what you are calling a "mail queue" is not
what postfix calls a mail queue.  You just happen to be using a
mailbox as a mail "queue", which is not the same as a postfix mail
queue.

As far as software to actually do that, I'm not sure.  Maybe if you
have mail setup through IMAP you could use sieve.  Not sure if
procmail could do it.  You're probably looking at a custom script.
Reply | Threaded
Open this post in threaded view
|

Re: Emptying SPAM account

mouss-4
In reply to this post by Bob Cohen-3
Bob Cohen a écrit :
> I have set up SpamAssissin with an account to collect rejected emails.

There's a terminology problem here. you can't collect _rejected_ mail.
here, reject means the transaction is refused, so you don't see the message.

you probably mean mail tagged as spam by spamassassin.

> 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

yes, but it depends on where and how you store mail. in short, this is
not postfix related (postfix only handles transport. as soon as the
message is delivered to a mailbox, postfix is out).

if you use maildir, you can simply delete "old" files. I would however
recommend using a two step process: first move to a "to delete" place,
then after another delay, purge the "to delete" mail. this gives an
additional security option, should your script have a bug.

Reply | Threaded
Open this post in threaded view
|

Re: Emptying SPAM account

@lbutlr
In reply to this post by Bob Cohen-3
On 14-Oct-2009, at 14:25, Bob Cohen wrote:
> 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

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.


--
And, while it was regarded as pretty good evidence of criminality
        to be living in a slum, for some reason owning a whole street
        of them merely got you invited to the very best social
        occasions.

Reply | Threaded
Open this post in threaded view
|

RE: Emptying SPAM account

Gary Smith-20
In reply to this post by Bob Cohen-3
> -----Original Message-----
> From: [hidden email] [mailto:owner-postfix-
> [hidden email]] 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