devel: make printmimestructure py3 compatible

Make printmimestructure work in python3 as well as python2.
This commit is contained in:
Daniel Kahn Gillmor 2018-06-12 17:21:08 -04:00 committed by David Bremner
parent ea36e70d7a
commit 8ca911d13b

View file

@ -19,6 +19,8 @@
# If you want to number the parts, i suggest piping the output through # If you want to number the parts, i suggest piping the output through
# something like "cat -n" # something like "cat -n"
from __future__ import print_function
import email import email
import sys import sys
@ -34,7 +36,7 @@ def test(z, prefix=''):
if d[0] in [ 'attachment', 'inline' ]: if d[0] in [ 'attachment', 'inline' ]:
disposition = ' ' + d[0] disposition = ' ' + d[0]
if (z.is_multipart()): if (z.is_multipart()):
print prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes' print(prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes')
if prefix.endswith('└'): if prefix.endswith('└'):
prefix = prefix.rpartition('└')[0] + ' ' prefix = prefix.rpartition('└')[0] + ' '
if prefix.endswith('├'): if prefix.endswith('├'):
@ -47,6 +49,6 @@ def test(z, prefix=''):
test(parts[i], prefix + '└') test(parts[i], prefix + '└')
# FIXME: show epilogue? # FIXME: show epilogue?
else: else:
print prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes' print(prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes')
test(email.message_from_file(sys.stdin), '└') test(email.message_from_file(sys.stdin), '└')