Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

SpamAssassin Integration into your IMAP Folder

Wiki MarkupIf you have Spamassassin working, but your main mailbox is on a remote Imap folder, you can use Roger Binns' Isbg (Imap Spam Be Gone). The software can be found \[at here\] , and an introduction to its use can be found at \[ here\].

SpamAssassin IMAP shared folders for groups of users

DMZS-sa-learn is a perl script that reads 2 imap folders, spam & not-spam and processes them through SpamAssassin sa-learn to learn bayesian classifications.

With many people all utilizing the same mail resources, a method for integrating the learning of all users spam that wasn't flagged properly was needed. Searching google I found several good resources on setting up & using imap and sa-learn, however all (that i have found) have the processing happen assuming Spamassassin & the imap server were located on the same machine. If you have a secured network or a large network, you will most likely have your MTA/Virus/Spam functions on separate servers from the users mail servers.

To solve this problem I integrated perl Mail::IMAPClient into a quick script that works with sa-learn. This allows your spamassassin host to be any server and connect to one (or many, easily modified...hmm) central imap server(s) and process spam & ham classifications according to the users of those systems.

Wiki Markup
There's also \[ this\] docu which might work, YMMV.

Quick fetchmail hack to provide "Learn Ham" and "Learn Spam" folders

I use SpamAssassin to filter mail as it comes through my MTA, before it hands the mail off to my Cyrus IMAP server. I wanted to provide my users a way to drag false-positives and false-negatives from their Junk Mail or Inbox to another folder or folders. The mail should be picked up from that folder, learned, and then re-deposited in the "corrrect" folder, either inbox for learned-ham or junk-mail for learned-spam. For false-positives which had previously been marked up as spam, the SpamAssassin markup should be removed so the "clean" message winds up in the inbox. In the end, this turns out to be a single-line fetchmail script for each folder:

/usr/bin/fetchmail -a -s -n -p IMAP --folder 'INBOX.Learn Spam' -m 'bash -c "/usr/bin/tee >(/usr/bin/sa-learn --spam --single > /dev/null)|/usr/bin/spamc|/usr/lib/cyrus-imapd/deliver $LOGNAME"'

/usr/bin/fetchmail -a -s -n -p IMAP --folder 'INBOX.Learn Ham' -m 'bash -c "/usr/bin/tee >(/usr/bin/sa-learn --ham --single > /dev/null)|/usr/bin/spamassassin -d|/usr/lib/cyrus-imapd/deliver $LOGNAME"'

If you're using something other than Cyrus, adjust the delivery step accordingly. Also, beware of message delivery deduplication on the server – you might lose mail if you have de-duping turned on, and because of learning the same message ends up delivered twice. I have those 2 lines in a cronjob which runs every 5 minutes. Now if spam arrives in my inbox, I just drag it to "Learn Junk" folder. It'll end up in my Junk Mail folder after fetchmail picks it up, passes it to sa-learn, then re-delivers it to cyrus tagged as spam (where a sieve script in cyrus will then file it into the right folder). For ham in my Junk Mail folder, I drag to "Learn Ham" and it'll be learned, cleaned, then deposited to my Inbox.