[Mailman-Developers] modifying payload using same encoding and Content-Transfer-Encoding
Mark Sapiro
mark at msapiro.net
Tue May 13 04:50:47 CEST 2014
On 05/12/2014 09:03 AM, Sylvain Viart wrote:
>
> I don't manage to figure out how to keep the same
> Content-Transfer-Encoding, while rewriting the content?
Do you really want that? That's not what your example code does.
> msg.set_payload() doesn't seems to trigger any encoding, base64 for
> example was set.
It will if there is a charset parameter and the message contains no
Content-Transfer-Encoding: header.
See
<https://docs.python.org/2/library/email.message.html#email.message.Message.set_payload>
and the implicit
<https://docs.python.org/2/library/email.message.html#email.message.Message.set_charset>.
> not using decode=True, return a base64 bloc… I just want to write it back.
> I should be able to know that the payload was encoded…
>
>
> related = MIMEMultipart('related')
>
> html_footer = HTML_ATTACHMENT_HOLDER % {'HTML_HERE':
> html_attach}
> html_footer += '</body>'
> old_content = msg.get_payload(decode=True)
> new_content = re.sub(r'</body>', html_footer, old_content)
> if old_content != new_content:
> syslog('debug', 'add html footer')
> else:
> syslog('debug', 'no html footer added')
>
> charset = msg.get_content_charset()
> syslog('debug', 'get_content_charset: %s,
> Content-Transfer-Encoding: %s', charset, msg['Content-Transfer-Encoding'])
>
Here, add
del msg['content-transfer-encoding']
Don't delete Content-Type or it will get set to text/plain.
> msg.set_payload(new_content, charset)
> related.attach(msg)
> related.attach(clip_payload)
>
>
> The output produced must be wrong:
...
--
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-Developers
mailing list