ssoma-mda: Fix RFC-2047 decoding for partially-encoded strings
[ssoma-mda.git] / ssoma-mda
index d3b54063eb40abae52e97cf7bccda842e44ece02..abbe7bc87b316ef24d784e3c358c608cdaf6c49d 100755 (executable)
--- a/ssoma-mda
+++ b/ssoma-mda
@@ -227,9 +227,13 @@ def _decode_header(string):
     'hello'
     >>> _decode_header(string='=?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?=')
     'Keld Jørn Simonsen'
+    >>> _decode_header(string='Keld =?ISO-8859-1?Q?J=F8rn_Simonsen?=')
+    'Keld Jørn Simonsen'
     """
     chunks = []
     for decoded, charset in _email_header.decode_header(string):
+        if isinstance(decoded, bytes) and not charset:
+            charset = 'ASCII'
         if charset:
             decoded = str(decoded, charset)
         chunks.append(decoded)