aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-13 18:12:45 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2020-05-13 18:12:45 -0400
commit33a119739233a7d4f234cc7f38f3ec5f21058e4f (patch)
tree906085ba9874700f9ada7149d910183d87b2fde9
parentdd00e0fec2bb9fca72264754883dce655b5b411a (diff)
downloadb4-33a119739233a7d4f234cc7f38f3ec5f21058e4f.tar.gz
Don't fail when a message uses a weird charset
Found via auto-testing in: https://lore.kernel.org/linux-sgx/20200421215316.56503-13-jarkko.sakkinen@linux.intel.com/raw This is wrong on many levels: Content-Type: text/plain; charset=a Assume utf-8 when something like this happens and don't fail. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--b4/__init__.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index ecd746f..a3767bf 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -726,7 +726,13 @@ class LoreMessage:
pcharset = part.get_content_charset()
if not pcharset:
pcharset = mcharset
- payload = payload.decode(pcharset, errors='replace')
+ try:
+ payload = payload.decode(pcharset, errors='replace')
+ except LookupError:
+ # what kind of encoding is that?
+ # Whatever, we'll use utf-8 and hope for the best
+ payload = payload.decode('utf-8', errors='replace')
+ part.set_param('charset', 'utf-8')
if self.body is None:
self.body = payload
continue