From dcae0e5120a6045d5ce866afe628b4bf14930757 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Wed, 13 May 2020 18:12:45 -0400 Subject: 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 --- b4/__init__.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/b4/__init__.py b/b4/__init__.py index ad417e6..2e12b60 100644 --- a/b4/__init__.py +++ b/b4/__init__.py @@ -682,7 +682,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 -- cgit v1.2.3