From cc7374e87575f123b656f3aa70162afa8c664278 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 7 Nov 2014 00:58:34 -0800 Subject: [PATCH] ssoma-mda: Add compatibility decoding for the '\x10\x10' encoding I'm not sure if this was a user error or a Git send-email error, but notmuch has a message with: Subject: =?\x10\x10?q?=5BPATCH=20v7=203/3=5D=20Use=20the=20structured=20formatters=20in=20notmuch-search=2Ec=2E?= ... Message-Id: <1342766173-1344-4-git-send-email-craven@gmx.net> X-Mailer: git-send-email 1.7.11.2 Without this patch, that raises: LookupError: unknown encoding: --- ssoma-mda | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ssoma-mda b/ssoma-mda index 484a51d..76f2242 100755 --- a/ssoma-mda +++ b/ssoma-mda @@ -65,6 +65,10 @@ _LOG.addHandler(_logging.StreamHandler()) _COMMIT_MESSAGE_ENCODING = 'UTF-8' _FOLDING_WHITESPACE_REGEX = _re.compile('\s*\n\s*') +_FALLBACK_ENCODINGS = { # support non-standard RFC 2047 encodings + 'no': 'ASCII', + '\x10\x10': 'ASCII', + } class DirtyIndex(RuntimeError): @@ -241,8 +245,8 @@ def _decode_header(string): if isinstance(decoded, bytes) and not charset: charset = 'ASCII' if charset: - if charset in ['no']: - charset = 'ASCII' + if charset in _FALLBACK_ENCODINGS: + charset = _FALLBACK_ENCODINGS[charset] decoded = str(decoded, charset) chunks.append(decoded) return ''.join(chunks) -- 2.26.2