[Mailman-Users] handler to auto detach attachment and link it to a website keeping html

Mark Sapiro mark at msapiro.net
Wed Apr 16 16:01:39 CEST 2014


On 04/15/2014 09:08 AM, Sylvain Viart wrote:
> 
> I borrowed a code from Mailman/Handlers/MimeDel.py
> 
> def reset_payload(msg, txt, fname, url):
>     # Reset payload of msg to contents of subpart, and fix up content
> headers
>     msg.set_payload(txt)
>     del msg['content-type']
>     del msg['content-transfer-encoding']
>     del msg['content-disposition']
>     del msg['content-description']
> 
>     msg.add_header('X-Mailman-Part', 'Attachment-moved', url=url)
>     msg.add_header('Content-Type', 'text/plain', charset='UTF-8',
> name=fname)
>     msg.add_header('Content-Transfer-Encoding', '8bit')
>     msg.add_header('Content-Disposition', 'attachment', filename=fname)
>     msg.add_header('Content-Description', "Attachment-moved by Mailman")
> 
> 
> Is it the correct way to use email.message.Message
> <https://docs.python.org/2/library/email.message.html>
> in order to replace an attachment with a dummy text file containing the
> link?


It isn't really important in this case, but 'msg' is a
Mailman.Message.Message instance. Mailman.Message.Message is a subclass
of email.message.Message, but it mostly just adds a few methods. It
doesn't change the behavior of any methods documented at
<https://docs.python.org/2/library/email.html>.

You can use code like the above to manipulate the sub-part headers, but


> No other way to, remove all header in oneshot, or replace with a fresh
> parsed attachment?


if you wish to remove the subpart all together you can just 'del' it and
use methods documented at
<https://docs.python.org/2/library/email.mime.html> to create new
sub-parts and use the Message.attach() method to attach them.


> But I will publish the source.
> 
> Is there a preferred repository or procedure?


Yes. This will change in the future, but the preferred method is to
create a bzr branch containing your change, register at launchpad and
then push your branch to <https://code.launchpad.net/mailman>.

But whatever you do, post a note here so we know.

-- 
Mark Sapiro <mark at msapiro.net>        The highway is for gamblers,
San Francisco Bay Area, California    better use your sense - B. Dylan


More information about the Mailman-Users mailing list