This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aldwinaldwin
Recipients aldwinaldwin, barry, r.david.murray, yunlee
Date 2019-07-10.04:36:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1562733410.07.0.879647794751.issue37532@roundup.psfhosted.org>
In-reply-to
Content
Maybe a solution, if no charset defined, then encode it as utf-8 in decode_header, because it's Python3's default encoding?


diff --git a/Lib/email/header.py b/Lib/email/header.py
index 4ab0032bc6..8dbfe58a57 100644
--- a/Lib/email/header.py
+++ b/Lib/email/header.py
@@ -135,7 +135,10 @@ def decode_header(header):
     collapsed = []
     last_word = last_charset = None
     for word, charset in decoded_words:
-        if isinstance(word, str):
+        if not charset and isinstance(word, str):
+            word = word.encode('utf-8')
+            charset = 'utf-8'
+        elif isinstance(word, str):
             word = bytes(word, 'raw-unicode-escape')
         if last_word is None:
             last_word = word



Python 3.9.0a0 (heads/master:110a47c4f4, Jul 10 2019, 11:32:53) 
[GCC 7.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import email.header
>>> header = "Your booking at Voyager Int'l Hostel,=?UTF-8?B?IFBhbmFtw6EgQ2l0eQ==?=,   Panamá- Casco Antiguo"
>>> print(email.header.make_header(email.header.decode_header(header)))
Your booking at Voyager Int'l Hostel, Panamá City,   Panamá- Casco Antiguo
>>>
History
Date User Action Args
2019-07-10 04:36:50aldwinaldwinsetrecipients: + aldwinaldwin, barry, r.david.murray, yunlee
2019-07-10 04:36:50aldwinaldwinsetmessageid: <1562733410.07.0.879647794751.issue37532@roundup.psfhosted.org>
2019-07-10 04:36:50aldwinaldwinlinkissue37532 messages
2019-07-10 04:36:49aldwinaldwincreate