X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mimedecode.py;h=b82d12f96ee5dc945ebe593d3a2dd5c61026002b;hb=51b00f3c1674ff5995e11d9da108ce3da96e1bb2;hp=0e15fe015d3bcaaaed707cd50e8f7fb5ae6ae81c;hpb=9c35fa7761509941014db31c46ad7a6e5a6e8817;p=mimedecode.git diff --git a/mimedecode.py b/mimedecode.py index 0e15fe0..b82d12f 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -46,7 +46,7 @@ def recode(s, charset): return unicode(s, charset, "replace").encode(gopts.default_encoding, "replace") -def recode2(s, charset): +def recode_if_needed(s, charset): if charset and charset.lower() <> gopts.default_encoding: s = recode(s, charset) return s @@ -69,7 +69,7 @@ def _decode_header(s): if charset is None: rtn.append(atom) else: - rtn.append(recode2(atom, charset)) + rtn.append(recode_if_needed(atom, charset)) rtn.append(' ') del rtn[-1] # remove the last space @@ -89,7 +89,7 @@ def decode_header(msg, header): def _decode_header_param(s): - return recode2(s[2], s[0]) + return recode_if_needed(s[2], s[0]) def decode_header_param(msg, header, param): @@ -133,7 +133,6 @@ def set_content_type(msg, newtype, charset=None): msg.set_param("charset", charset, "Content-Type") - caps = None # Globally stored mailcap database; initialized only if needed def decode_body(msg, s): @@ -182,7 +181,7 @@ def recode_charset(msg, s): save_charset = charset = msg.get_content_charset() if charset and charset.lower() <> gopts.default_encoding: - s = recode2(s, charset) + s = recode_if_needed(s, charset) content_type = msg.get_content_type() set_content_type(msg, content_type, gopts.default_encoding) msg["X-MIME-Autoconverted"] = "from %s to %s by %s id %s" % (save_charset, gopts.default_encoding, gopts.host_name, me) @@ -193,7 +192,7 @@ def totext(msg, instring): "Convert instring content to text" if msg.is_multipart(): # Recursively decode all parts of the multipart message - newfile = StringIO(str(msg)) + newfile = StringIO(msg.as_string()) newfile.seek(0) decode_file(newfile) return @@ -276,7 +275,7 @@ def decode_file(infile): decode_part(msg) else: # Not a message, just text - copy it literally - output(str(msg)) + output(msg.as_string()) class GlobalOptions: