diff roundup/anypy/email_.py @ 5761:cacef71b3a54 issue2551008

working branch for fixing https://issues.roundup-tracker.org/issue2551008
author John Rouillard <rouilj@ieee.org>
date Mon, 03 Jun 2019 20:50:58 -0400
parents 29346d92d80c
children 611737bc7261
line wrap: on
line diff
--- a/roundup/anypy/email_.py	Sun Jun 02 17:15:23 2019 -0400
+++ b/roundup/anypy/email_.py	Mon Jun 03 20:50:58 2019 -0400
@@ -3,6 +3,9 @@
 import email
 from email import quoprimime, base64mime
 
+from roundup.anypy.strings import bs2b
+from email import charset as _charset
+
 if str == bytes:
     message_from_bytes = email.message_from_string
     message_from_binary_file = email.message_from_file
@@ -45,11 +48,12 @@
     """
     # If it is a Header object, we can just return the encoded chunks.
     if hasattr(header, '_chunks'):
+        # no bs2b here. _charset._encode should return bytes
         return [(_charset._encode(string, str(charset)), str(charset))
                     for string, charset in header._chunks]
     # If no encoding, just return the header with no charset.
     if not ecre.search(header):
-        return [(header, None)]
+        return [(bs2b(header), None)]
     # First step is to parse all the encoded parts into triplets of the form
     # (encoded_string, encoding, charset).  For unencoded strings, the last
     # two parts will be None.
@@ -113,7 +117,7 @@
             last_word = word
             last_charset = charset
         elif charset != last_charset:
-            collapsed.append((last_word, last_charset))
+            collapsed.append((bs2b(last_word), last_charset))
             last_word = word
             last_charset = charset
         elif last_charset is None:
@@ -121,6 +125,6 @@
             last_word += BSPACE + word
         else:
             last_word += word
-    collapsed.append((last_word, last_charset))
+    collapsed.append((bs2b(last_word), last_charset))
     return collapsed
 

Roundup Issue Tracker: http://roundup-tracker.org/