From ffbf072f64581f8f7776e2806846cf45c7a64045 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 15 May 2021 15:28:01 +0200 Subject: db/message: override missing content-type charset to utf-8 Strictly speaking it should be inferred to be us-ascii when missing, but utf-8 is a safer (and compatible) choice. --- alot/db/message.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/alot/db/message.py b/alot/db/message.py index 74139315..f22db54b 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -149,16 +149,17 @@ class _MimeTree: def _fixup_charset(self): """ - If a text MIME part declares an invalid charset, replace it with UTF-8 + If a text MIME part declares an invalid or no charset, replace it + with UTF-8. """ charset = self._part.get_param('charset') - if charset is None: - return + if charset is not None: + try: + return codecs.lookup(charset) + except LookupError: + pass - try: - codecs.lookup(charset) - except LookupError: - self._part.set_param('charset', 'utf-8') + self._part.set_param('charset', 'utf-8') def render_str(self, alt_preference = None): if self.children is not None: -- cgit v1.2.3