From ea094df666c1e2aa626d817d29dfd77acc52c5ea Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 3 Aug 2016 18:22:45 +0300 Subject: [PATCH] Convert body to the current charset for mailcap filter Convert text body from mail charset to the current locale's charset before passing it to the mailcap filter. --- mimedecode.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mimedecode.py b/mimedecode.py index 25d3db0..e7381f7 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -218,6 +218,10 @@ def decode_body(msg, s): caps = mailcap.getcaps() content_type = msg.get_content_type() + if content_type.startswith('text/'): + charset = msg.get_content_charset() + else: + charset = None filename = tempfile.mktemp() command = None @@ -235,6 +239,8 @@ def decode_body(msg, s): return s outfile = open(filename, 'wb') + if charset and isinstance(s, bytes): + s = s.decode(charset, "replace") if not isinstance(s, bytes): s = s.encode(g.default_encoding, "replace") outfile.write(s) -- 2.39.5