summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJameson Graef Rollins <jrollins@finestructure.net>2018-06-12 17:21:09 -0400
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>2019-09-14 14:58:06 -0400
commitd79249f2b04d3f75b5cd7fbfe2cdcbddd25411f1 (patch)
tree8793b3088d12cad0f73a97c27ea6a8b87de60751
parent4aa83c9d18252c44814668cdd4a39b65f8f54234 (diff)
downloadmailscripts-d79249f2b04d3f75b5cd7fbfe2cdcbddd25411f1.tar.gz
minor cleanup to printmimestructure
make the source slightly easier to read. no functional change. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
-rwxr-xr-xprintmimestructure21
1 files changed, 18 insertions, 3 deletions
diff --git a/printmimestructure b/printmimestructure
index a5fc83e..70e0a5c 100755
--- a/printmimestructure
+++ b/printmimestructure
@@ -24,7 +24,7 @@ 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')
@@ -35,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('├'):
@@ -49,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), '└')