[New-bugs-announce] [issue15115] Duplicated Content-Transfer-Encoding header when applying email.encoders

Sergei Stolyarov report at bugs.python.org
Wed Jun 20 12:38:31 CEST 2012


New submission from Sergei Stolyarov <sergei at regolit.com>:

Here is the test script:

--------------
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email import encoders

msg = MIMEMultipart()
msg['Subject'] = 'Bug test'

text_part = MIMEText('actual content doesnt matter')
text_part.set_charset('utf-8')
msg.attach(text_part)

xml_part = MIMEText(b'<xml>aaa</xml>')
xml_part.set_type('text/xml')
xml_part.set_charset('utf-8')
encoders.encode_base64(xml_part)
msg.attach(xml_part)

print(msg.as_string())
--------------------------

It prints the following:
--------------------------
Content-Type: multipart/mixed; boundary="===============2584752675366770986=="
MIME-Version: 1.0
Subject: Bug test

--===============2584752675366770986==
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset="utf-8"

actual content doesnt matter
--===============2584752675366770986==
Content-Transfer-Encoding: 7bit
MIME-Version: 1.0
Content-Type: text/xml; charset="utf-8"
Content-Transfer-Encoding: base64

PHhtbD5hYWE8L3htbD4=

--===============2584752675366770986==--
--------------------------

And that's incorrect: the header "Content-Transfer-Encoding" set twice. As workaround you can use:

del xml_part['Content-Transfer-Encoding']

----------
components: email
messages: 163266
nosy: barry, cancel, r.david.murray
priority: normal
severity: normal
status: open
title: Duplicated Content-Transfer-Encoding header when applying email.encoders
versions: Python 2.7, Python 3.1, Python 3.2

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15115>
_______________________________________


More information about the New-bugs-announce mailing list