[Mailman-Developers] modifying payload using same encoding and Content-Transfer-Encoding
Sylvain Viart
sylvain at opensource-expert.com
Tue May 13 16:14:37 CEST 2014
Hi,
Thanks for your reply. Unfortunately it doesn't work. I don't know why.
I did read the doc many times, without the expected result.
> 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>.
>
My code is inside this custom handler. It works, but not for keeping the
encoding.
https://github.com/Sylvain303/mailman-AttachmentMove/blob/master/AttachmentMove.py#L338
It could be related to this specific usage inside the recursive change…
To solve it, I've forced the encoding explicitly:
msg.set_payload(new_content)
del msg['content-transfer-encoding']
encoders.encode_7or8bit(msg)
I hope it will handle it correctly.
This code outside mailman is working: took from
http://bugs.python.org/issue1525919
from email.Message import Message
from email.Charset import Charset, QP
text = "="
msg = Message()
charset = Charset("utf-8")
charset.header_encoding = QP
charset.body_encoding = QP
msg.set_charset(charset)
msg.set_payload(text)
print msg.as_string()
I've tried with no success:
from email.Charset import Charset, QP, BASE64
[…]
del msg['content-transfer-encoding']
charset = Charset("utf-8")
charset.header_encoding = BASE64
charset.body_encoding = BASE64
msg.set_charset(charset)
msg.set_payload(new_content)
I got the output below. But it's not base64… just the plain new_content
I've produced.
I don't need the base64 encoding specially, just that the content match
what the header is saying.
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: base64
<html>
<head>[…]
If I call the encoding explicitly it works, in conjunction with
msg.set_charset(charset), I got header Content-Transfer-Encoding: twice.
msg.set_payload(new_content)
encoders.encode_base64(msg)
Regards,
Sylvain.
More information about the Mailman-Developers
mailing list