[issue24218] Also support SMTPUTF8 in smtplib's send_message method.

Jens Troeger report at bugs.python.org
Tue Jul 31 08:21:42 EDT 2018


Jens Troeger <jens.troeger at gmail.com> added the comment:

I was about to open an issue when I found this one.

Consider an email message with the following:

message = EmailMessage()
message["From"] = Address(addr_spec="bar at foo.com", display_name="Jens Troeger")
message["To"] = Address(addr_spec="foo at bar.com", display_name="Martín Córdoba")

It’s important here that the email itself is `ascii` encodable, but the names are not. With that combination, send_message() falsely assumes plain text addresses (see https://github.com/python/cpython/blob/master/Lib/smtplib.py#L949 where it checks only email addresses, not display names!) and therefore the `international` flag stays False.

As a result of that, flattening the email object (https://github.com/python/cpython/blob/master/Lib/smtplib.py#L964) incorrectly inserts multiple linefeeds, thus breaking the email header, thus mangling the entire email:

flatmsg: b'From: Jens Troeger <jens at talaera.com>\r\nTo: Fernando =?utf-8?q?Mart=C3=ADn_C=C3=B3rdoba?= <foo at bar.com>\r\r\r\r\r\nSubject:\r\n Confirmation: …\r\n…'

I think a proper fix would be in line 949, where email addresses and display names should be checked for encoding.

The comment to that function should also be adjusted to mention display names?

Note also that the attached patch does not test the above scenario, and should probably be extended as well.

----------
nosy: +_savage

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue24218>
_______________________________________


More information about the Python-bugs-list mailing list