marrow / mailer

A light-weight, modular, message representation and mail delivery framework for Python.
MIT License
276 stars 62 forks source link

using unicode_literals in message.py prevents expanding and collapsing headers from being inverses #71

Closed stevenbuccini closed 7 years ago

stevenbuccini commented 7 years ago

In message.py we have from __future__ import unicode literals. This is the reason I had to encode strings back into ASCII here, although I didn't realize it at the time.

However, 'Content-Type' and 'attachment' headers are both Unicode strings due to the import statement at the top of the filer. Since add_header() eventually joins all the arguments and the type of joining a Unicode literal and an ASCII literal in Python 2.7 is a Unicode string, the result is a Unicode string.

As referenced in the documentation, get_param() and email.utils.collapse_rfc2231_value() are inverses. But in Python 2.7, get_param() returns a Unicode string due to the above issue and collapse_rfc2231_value() requires an ASCII string, you get an error.

I think this could be fixed by encoding the fixed strings here and here as ASCII.