[linux-elitists] mailman, bogofilter, and exim

Nick Moffitt nick@zork.net
Tue May 13 21:54:30 PDT 2003

So zork.net just upgraded to mailman 2.1.1 as it hit testing.  I had
to muck with exim a bit to get it to work properly (hint: the
daturbase file is now "config.pck", making your requirefile directives
turn up blank on new lists -- and the upgrade asks you to create a new
list called "mailman" for over-arching maintenance purposes!)

I was delighted to see that mailman now offers e-mail based moderation
actions.  The problem with this is that it sends the messages through
to you as message/rfc822 attachments, along with a similar attachment
for the confirmation ticket.  This meant that for each spam that went
to one of my mailing lists, in mutt I had to type:

    vjj|bogofilter -Ns
    jjj(or however many down the next attachment is)r

and then index back out.  It was maddening.  So I created the
following python script to automate this.  It requires python2.2 for
the email module, but I probably could have used the old 2.1 rfc822
module (I'm just not as familiar with it).

Note also that bogofilter changed the semantics, so that your scripts
that were doing "bogofilter -S" did the OPPOSITE of what they did a
version back.  That's HORRIBLE and NASTY and only the sort of thing a
big smelly man with a Ron Jeremy moustache like ESR would do.

so anyway, I now have this in my .muttrc (sorry about the long lines!):

macro index M "<enter-command>unset wait_key\n<tag-prefix><pipe-entry>/home/nick/bin/spamman.py\n<enter-command>set wait_key\n<tag-prefix><delete-message>"
macro pager M "<enter-command>unset wait_key\n<pipe-entry>/home/nick/bin/spamman.py\n<enter-command>set wait_key\n<delete-message>"

So I hit M and it kills a submitted spam.  Note that I force it all to
be tag-based for the index, since there's no real way to propagate a
tag-prefix down into multiple pieces of a macro (and the mutt folks
aren't too quick to take outside feedback).

The script assumes that there are only two attachments in the wrapper
mail of major type "message", so it's probably not the most robust
analysis of the structure.

# ex:ts=4 sw=4 tw=72

import email
import sys, os

def bogokill(part):
	bogocommand = "/usr/bin/bogofilter -Ns"
	fp = os.popen(bogocommand, 'w')

def mailmankill(part):
	msg = email.message_from_string(part.get_payload(decode=1).__str__())
	del msg['To']
	msg['To'] = msg['From']
	del msg['From']
	msg['From'] = "Nick Moffitt <nick@zork.net>"
	del msg['Sender']
	msg['Sender'] = msg['From']
	subject = msg['Subject'][:]
	del msg['Subject']
	msg['Subject'] = "Re: " + subject

	from smtplib import SMTP

	s = SMTP()
	s.sendmail(msg['From'], msg['To'], msg.as_string(0))

def kill_spambounce(msg):
	l = []
	for part in msg.walk():
		if part.get_main_type() == 'message':

	assert(len(l) == 2)


if __name__ == "__main__":
	msg = email.message_from_file(sys.stdin)


Faster, pussycat, KILL!  KILL!



More information about the linux-elitists mailing list