X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=mimedecode.py;h=64281715ac0a213f584eb66e41ea20936bde1bd7;hb=fa2d7bb797e9f0735f299cd19192ac3782475a96;hp=c85bb8dbe89fe048fd320f1f94b2341e000ce514;hpb=607e68504d32244e26d4a4c01532f5168f03f4e8;p=mimedecode.git diff --git a/mimedecode.py b/mimedecode.py index c85bb8d..6428171 100755 --- a/mimedecode.py +++ b/mimedecode.py @@ -291,9 +291,9 @@ def decode_part(msg): encoding = msg["Content-Transfer-Encoding"] if left_binary or encoding in (None, '', '7bit', '8bit', 'binary'): - outstring = str(msg.get_payload()) + outstring = msg.get_payload() else: # Decode from transfer ecoding to text or binary form - outstring = str(msg.get_payload(decode=1)) + outstring = msg.get_payload(decode=1) set_header(msg, "Content-Transfer-Encoding", "8bit") msg["X-MIME-Autoconverted"] = "from %s to 8bit by %s id %s" % (encoding, gopts.host_name, me) @@ -325,12 +325,19 @@ def decode_multipart(msg): if msg.preamble: # Preserve the first part, it is probably not a RFC822-message output(msg.preamble) # Usually it is just a few lines of text (MIME warning) + if msg.preamble is not None: + output("\n") + first_subpart = True boundary = msg.get_boundary() for subpart in msg.get_payload(): if boundary: - output("\n--%s\n" % boundary) + if first_subpart: + first_subpart = False + else: + output("\n") + output("--%s\n" % boundary) # Recursively decode all parts of the subpart decode_message(subpart) @@ -391,7 +398,7 @@ class GlobalOptions: gopts = GlobalOptions -def get_opt(): +def get_opts(): from getopt import getopt, GetoptError try: @@ -456,7 +463,7 @@ def get_opt(): if __name__ == "__main__": - arguments = get_opt() + arguments = get_opts() la = len(arguments) if la == 0: