PDA

View Full Version : Programmatically moving mail into Junk folder


Mandler
04-07-2010, 04:10 PM
For the past few years, primarily based on info that Sheila has provided in her postings, I have been using conditional redirects to send SPAM to a secondary email account (e.g., junk@mydomainname.com).

I have three tests. The first two check text files for bad "from's" and "subjects" that I have collected over the years.

condredirect junk@mydomainname.com sh -c '822field from | grep -qiFf "/big/dom/xmydomainname/email_filters/alan/bad_from.txt"'

condredirect junk@mydomainname.com sh -c '822field from | grep -qiFf "/big/dom/xmydomainname/email_filters/alan/bad_subject.txt"'

The third runs a little python script that looks for various phrases inside of the message.

condredirect junk@mydomainname.com /usr/bin/env python /big/dom/xmydomainname/email_filters/alan/filter.py

These have worked really well for me. A piece of junk mail gets through maybe once every other week, if that often.

Here's my question:

Rather than redirecting mail to a Junk account, is there a way to programmatically mark the message as "SPAM" and move it to a Junk folder within the same account?

I'm asking because I'd like to give other users on my domain the same benefit as I'm receiving without setting up secondary email accounts for everyone.

sheila
04-09-2010, 01:50 AM
It would be possible to do this, but you would have to use IMAP protocol for that part of your program. You'd have to have your script do something like this... (I say "something like"...because I have no personal experience with programming using IMAP protocol)...

Either: Having a script that runs at delivery time (as you do now) have the script somehow stop delivery of the email in question so that it does not go into the INBOX at all, and then it connects to the IMAP server and somehow writes that email into the Junk folder. I say "somehow" again because I have no experience with actually writing such programs.

Or else: Have a script that is invoked as a cron job and periodically scans the INBOX for new emails delivered within the last x time-period, and if some of them are found to be "spam" then have them moved or copied via IMAP protocol to the Junk folder and deleted from the INBOX.

I'm sure there are other methods for solving this type of problem as well, but again...I have no experience with them. IMAP is a much more complicated protocol than POP3 and we have no built-in tools in our filter mechanism for interacting with IMAP.

Mandler
04-09-2010, 03:23 AM
Thanks, Sheila. Sounds like more than I've got time (or the smarts) to take on.