X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mimedecode.py;h=e7381f78cdb495bc9a1aa765ef4c2ca116098fc1;hb=ea094df666c1e2aa626d817d29dfd77acc52c5ea;hp=25d3db0efe83e1e5288442a79291acec9ca06eca;hpb=cc591fcbe8391644a364e9687a41f0e7ffb4c94d;p=mimedecode.git 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)