diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-05-15 15:28:01 +0200 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-05-15 15:28:01 +0200 |
commit | ffbf072f64581f8f7776e2806846cf45c7a64045 (patch) | |
tree | bdb5bf69f64156358837ec9f7ce0193f7223b0ad | |
parent | 1e2779f9cd5e4f0c048c9bc3ef71247e7104c4e3 (diff) |
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.
-rw-r--r-- | alot/db/message.py | 15 |
1 files 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: |