X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=devel%2Fprintmimestructure;h=70e0a5c0fc1c94216e50d732aeba1711959e0335;hb=1c8d9e172e57bad26ebb94a8cb22a959ebedb9a3;hp=34d12930b4c986b82252689b567517b729c6155b;hpb=71e1522da469d7034e97701c4169f5999bff4cef;p=notmuch diff --git a/devel/printmimestructure b/devel/printmimestructure index 34d12930..70e0a5c0 100755 --- a/devel/printmimestructure +++ b/devel/printmimestructure @@ -19,10 +19,12 @@ # If you want to number the parts, i suggest piping the output through # something like "cat -n" +from __future__ import print_function + import email import sys -def test(z, prefix=''): +def print_part(z, prefix): fname = '' if z.get_filename() is None else ' [' + z.get_filename() + ']' cset = '' if z.get_charset() is None else ' (' + z.get_charset() + ')' disp = z.get_params(None, header='Content-Disposition') @@ -33,8 +35,23 @@ def test(z, prefix=''): for d in disp: if d[0] in [ 'attachment', 'inline' ]: disposition = ' ' + d[0] + if z.is_multipart(): + nbytes = len(z.as_string()) + else: + nbytes = len(z.get_payload()) + + print('{}{}{}{}{} {:d} bytes'.format( + prefix, + z.get_content_type(), + cset, + disposition, + fname, + nbytes, + )) + +def test(z, prefix=''): if (z.is_multipart()): - print prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes' + print_part(z, prefix+'┬╴') if prefix.endswith('└'): prefix = prefix.rpartition('└')[0] + ' ' if prefix.endswith('├'): @@ -47,6 +64,6 @@ def test(z, prefix=''): test(parts[i], prefix + '└') # FIXME: show epilogue? else: - print prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes' + print_part(z, prefix+'─╴') test(email.message_from_file(sys.stdin), '└')