diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-13 18:12:45 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2020-05-13 18:14:14 -0400 |
commit | dcae0e5120a6045d5ce866afe628b4bf14930757 (patch) | |
tree | 27db230af48bc68bf3d1d424c21cb62f3d256ef4 | |
parent | f8b5ba9a6dafc56822c3ac31053d3e94795108eb (diff) | |
download | b4-dcae0e5120a6045d5ce866afe628b4bf14930757.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__.py | 8 |
1 files changed, 7 insertions, 1 deletions
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 |