From 33a119739233a7d4f234cc7f38f3ec5f21058e4f 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(-) (limited to 'b4/__init__.py') 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 -- cgit v1.2.3