summaryrefslogtreecommitdiff
path: root/email-print-mime-structure
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2019-11-02 01:28:21 -0400
committerSean Whitton <spwhitton@spwhitton.name>2019-11-02 08:44:19 -0700
commit8dd6783b9bf37d0e12b343da6105cd92a5ebef1d (patch)
treed58381ff6fe67401a8c5245ee9df0cad10d1ed17 /email-print-mime-structure
parentabaf880e9bacd32f86c8210ab1489330320c2113 (diff)
downloadmailscripts-8dd6783b9bf37d0e12b343da6105cd92a5ebef1d.tar.gz
email-print-mime-structure: Pass parent and nth child info during walk
No functional change. This is preparatory work to be able to consider the structure of each part and determine whether we should consider trying to decrypt it. Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
Diffstat (limited to 'email-print-mime-structure')
-rwxr-xr-xemail-print-mime-structure14
1 files changed, 7 insertions, 7 deletions
diff --git a/email-print-mime-structure b/email-print-mime-structure
index 8fc8774..98b35fe 100755
--- a/email-print-mime-structure
+++ b/email-print-mime-structure
@@ -42,7 +42,7 @@ class MimePrinter(object):
def __init__(self, args:Namespace):
self.args = args
- def print_part(self, z:Message, prefix:str) -> None:
+ def print_part(self, z:Message, prefix:str, parent:Optional[Message], num:int) -> None:
ofname:Optional[str] = z.get_filename()
fname:str = '' if ofname is None else f' [{ofname}]'
ocharset:Union[Charset, str, None] = z.get_charset()
@@ -65,9 +65,9 @@ class MimePrinter(object):
print(f'{prefix}{z.get_content_type()}{cset}{disposition}{fname} {nbytes:d} bytes')
- def test(self, z:Message, prefix:str='') -> None:
+ def test(self, z:Message, prefix:str, parent:Optional[Message], num:int) -> None:
if (z.is_multipart()):
- self.print_part(z, prefix+'┬╴')
+ self.print_part(z, prefix+'┬╴', parent, num)
if prefix.endswith('└'):
prefix = prefix.rpartition('└')[0] + ' '
if prefix.endswith('├'):
@@ -77,12 +77,12 @@ class MimePrinter(object):
raise TypeError(f'parts was {type(parts)}, expected List[Message]')
i = 0
while (i < len(parts)-1):
- self.test(parts[i], prefix + '├')
+ self.test(parts[i], prefix + '├', z, i+1)
i += 1
- self.test(parts[i], prefix + '└')
+ self.test(parts[i], prefix + '└', z, i+1)
# FIXME: show epilogue?
else:
- self.print_part(z, prefix+'─╴')
+ self.print_part(z, prefix+'─╴', parent, num)
def main() -> None:
parser:ArgumentParser = ArgumentParser(description='Read RFC2822 MIME message from stdin and emit a tree diagram to stdout.',
@@ -92,7 +92,7 @@ def main() -> None:
if isinstance(msg, Message):
printer:MimePrinter = MimePrinter(args)
- printer.test(msg, '└')
+ printer.test(msg, '└', None, 0)
else:
logging.error('Input was not an e-mail message')