aboutsummaryrefslogtreecommitdiff
path: root/b4/__init__.py
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-03-30 18:07:47 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-03-30 18:07:47 -0400
commit7e035d16a7c6903b6f4ffa6cd41834367647ece6 (patch)
tree195d8905b609fefc700dd68f73ac7aefdf644161 /b4/__init__.py
parente123952efd144401a198ab1f8337eb2529e26f95 (diff)
downloadb4-7e035d16a7c6903b6f4ffa6cd41834367647ece6.tar.gz
Decode headers into utf-8 from QP
Since we aren't planning on sending any of this as actual emails, convert EVERYTHING into utf-8 before writing messages, including QP-escaped 7-bit headers. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Diffstat (limited to 'b4/__init__.py')
-rw-r--r--b4/__init__.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index 41f8dbc..acb3125 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -693,7 +693,18 @@ class LoreMessage:
@staticmethod
def clean_header(hdrval):
- new_hdrval = re.sub(r'\n?\s+', ' ', str(hdrval))
+ decoded = ''
+ for hstr, hcs in email.header.decode_header(hdrval):
+ if hcs is None:
+ hcs = 'utf-8'
+ try:
+ decoded += hstr.decode(hcs)
+ except LookupError:
+ # Try as utf-u
+ decoded += hstr.decode('utf-8', errors='replace')
+ except (UnicodeDecodeError, AttributeError):
+ decoded += hstr
+ new_hdrval = re.sub(r'\n?\s+', ' ', decoded)
return new_hdrval.strip()
@staticmethod