Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding.to_message ignores multiline headers when there's non-ascii chars #30

Open
EmilStenstrom opened this issue Dec 3, 2013 · 4 comments

Comments

@EmilStenstrom
Copy link

>>> msg1 = email.message_from_string("To: Person1 <[email protected]>, Person2\n\t<[email protected]>")
>>> msg2 = email.message_from_string("To: =?utf-8?q?Emil_Stenstr=C3=B6m?= <[email protected]>, Person2\n\t<[email protected]>")
>>> print encoding.to_message(encoding.from_message(msg1))
From nobody Tue Dec  3 12:42:05 2013
MIME-Version: 1.0
To: Person1 <person1@domain.com>, Person2
    <person2@domain.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
>>> print encoding.to_message(encoding.from_message(msg2))
From nobody Tue Dec  3 12:42:09 2013
MIME-Version: 1.0
To: "=?utf-8?q?Emil_Stenstr=C3=B6m?=" <person1@domain.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

Note that the from_message step seems to work fine:

>>> print encoding.from_message(msg2)["to"]
Emil Stenström <person1@domain.com>, Person2
    <person2@domain.com>
@EmilStenstrom
Copy link
Author

The problem is on properly_encode_header. email.parseaddr just parses and returns the first address if there are more than one. Fix is to split the address on "," and then use email.getaddresses instead. Pull request on the way.

@EmilStenstrom
Copy link
Author

After this fix, the test case I gave above works fine:

>>> msg2 = email.message_from_string("To: =?utf-8?q?Emil_Stenstr=C3=B6m?= <[email protected]>, Person2\n\t<[email protected]>")
>>> print encoding.to_message(encoding.from_message(msg2))
From nobody Tue Dec  3 13:52:03 2013
MIME-Version: 1.0
To: "=?utf-8?q?Emil_Stenstr=C3=B6m?=" <person1@domain.com>,
 "=?utf-8?q?Person2?=" <person2@domain.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit

@EmilStenstrom
Copy link
Author

@zedshaw Any chance to get this merged so I can stop using my own fork?

@tino
Copy link
Contributor

tino commented Aug 27, 2014

Probably not. Look around, you'll see Zed abandoned this project. Please use https://github.com/moggers87/salmon/ as it is the best maintained fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants