ssoma-mda: Add compatibility decoding for the 'no' encoding
authorW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 08:32:25 +0000 (00:32 -0800)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 08:32:25 +0000 (00:32 -0800)
I'm not sure if this was a user error or a Git send-email error, but
notmuch has a message with:

  Subject: =?no?q?=5BPATCH=203/3=5D=20Add=20=27compose=27=20command?=
  ...
  Message-Id: <1291933972-7186-4-git-send-email-felipe.contreras@gmail.com>
  X-Mailer: git-send-email 1.7.3.2

Without this patch, that raises:

  LookupError: unknown encoding: no

ssoma-mda

index abbe7bc87b316ef24d784e3c358c608cdaf6c49d..484a51daa4b2b6782ce71f6f0fe424c2e3a34aa9 100755 (executable)
--- a/ssoma-mda
+++ b/ssoma-mda
@@ -229,12 +229,20 @@ def _decode_header(string):
     'Keld Jørn Simonsen'
     >>> _decode_header(string='Keld =?ISO-8859-1?Q?J=F8rn_Simonsen?=')
     'Keld Jørn Simonsen'
+
+    We also support a few non-standard cases for compatibility with
+    existing messages:
+
+    >>> _decode_header(string='=?no?q?=5BPATCH=203/3=5D=20Add=20=27compose=27=20command?=')
+    "[PATCH 3/3] Add 'compose' command"
     """
     chunks = []
     for decoded, charset in _email_header.decode_header(string):
         if isinstance(decoded, bytes) and not charset:
             charset = 'ASCII'
         if charset:
+            if charset in ['no']:
+                charset = 'ASCII'
             decoded = str(decoded, charset)
         chunks.append(decoded)
     return ''.join(chunks)