Re: [Mailman-Developers] Modifying mailman to filter archived messages
On Wednesday 24 July 2002 12:39 pm, Barry A. Warsaw wrote:
"LB" == Laurence Berland laurence@digitalpulp.com writes: LB> Just to clarify, body=msg.get_payload() sets body to the msg LB> payload, and msg.set_payload(body) sets the msg payload to LB> body, right?
Basically, yes, as long as (in the set_payload() situation) you've got a text/plain message. Whether to use set_payload() or attach() depends on whether the container is multipart or not.
Ouch-I guess I missed this little detail. I'm trying to get an idea of how best to do this. Does this work? (easier in pcode than english):
if not msg.is_multipart and msg_type=="text/plain": bod=msg.get_payload() <do transform on bod> msg.set_payload(bod) elif msg.get_type() == 'multipart/mixed': for part in msg.walk() if part_type == "text/plain": bod=part.get_payload() <do transform on bod> part.set_payload(bod)
I've sort of cobbled this together on the fly here, so if it's totally off please forgive my ignorance, stupidity, lack of sleep, etc...
Laurence
"LB" == Laurence Berland laurence@digitalpulp.com writes:
LB> Ouch-I guess I missed this little detail. I'm trying to get an
LB> idea of how best to do this. Does this work? (easier in pcode
LB> than english):
If all you care about is modifying text/plain parts, this should be much simpler:
from email.Iterators import typed_subpart_iterator
...
def munge(msg): for part in typed_subpart_iterator(msg, 'text', 'plain'): body = part.get_payload() newbody = hack_body(body) part.set_payload(newbody)
Cheers, -Barry
participants (2)
-
barry@zope.com
-
Laurence Berland