[Mailman-Developers] Modifying mailman to filter archived
messages
Barry A. Warsaw
barry@zope.com
Wed, 24 Jul 2002 00:48:06 -0400
>>>>> "LB" == Laurence Berland <laurence@digitalpulp.com> writes:
>> ... from Mailman.Handlers import OurStatusMunger ... if
>> getattr(mlist, 'munge_status_p', 0):
>> OurStatusMunger.process(mlist, msg, msgdata)
>> ...
>>
LB> I'm mostly following this, but am having a little trouble at
LB> the point where I write the process function. Looking at
LB> other handlers I've determined I can get a header by
LB> msg.gtheader(header-name-string) and get the body by msg.body.
LB> I've also determined you can alter headers by setting
LB> msg[header-name-string] but what I haven't figured out it what
LB> I can do to set the body to something. The idea is to apply a
LB> regular expression on the body of the message.
Ouch, if you're using MM2.0.x then it gets pretty painful to do these
kinds of message manipulation. Any chance you can be coaxed into
using MM2.1?
There, you've got the email package at your disposal, so modifying
message headers and payloads (email package parlance for message
bodies), is much more regular and predictable.
E.g. you'd do msg.get(fieldname) to get the contents of a header, and
"del msg[fieldname] ; msg[fieldname] = value" to replace the contents
of a header. msg.attach(attachment) or msg.set_payload(body) to
manipulate the body of a message, etc.
The Python 2.2 documentation is helpful for the basics of the email
package, however it has undergone significant extension and API
improvements. The documentation has not yet caught up, so you should
use the source for the most up-to-date information.
-Barry