From 8ec259d84c40cd9832869edfab901ce4d48c7179 Mon Sep 17 00:00:00 2001 From: Daniel Kahn Gillmor Date: Thu, 21 Nov 2019 14:30:20 +0800 Subject: email-print-mime-structure: prepare for multiple forms of decryption As we prepare for S/MIME decryption, we want to identify pgp decryption as just one type of decryption. There is no functional change here. Signed-off-by: Daniel Kahn Gillmor Acked-by: Sean Whitton --- email-print-mime-structure | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/email-print-mime-structure b/email-print-mime-structure index 4f165b1..27fb532 100755 --- a/email-print-mime-structure +++ b/email-print-mime-structure @@ -78,15 +78,16 @@ class MimePrinter(object): nbytes = len(payload) print(f'{prefix}{z.get_content_type()}{cset}{disposition}{fname} {nbytes:d} bytes') - try_decrypt:bool = self.args.pgpkey or self.args.use_gpg_agent + cryptopayload:Optional[Message] = None + ciphertext:Union[List[Message],str,bytes,None] = None + try_pgp_decrypt:bool = self.args.pgpkey or self.args.use_gpg_agent - if try_decrypt and \ + if try_pgp_decrypt and \ (parent is not None) and \ (parent.get_content_type().lower() == 'multipart/encrypted') and \ (str(parent.get_param('protocol')).lower() == 'application/pgp-encrypted') and \ (num == 2): - cryptopayload:Optional[Message] = None - ciphertext:Union[List[Message],str,bytes,None] = z.get_payload() + ciphertext = z.get_payload() if not isinstance(ciphertext, str): logging.warning('encrypted part was not a leaf mime part somehow') return @@ -97,6 +98,8 @@ class MimePrinter(object): if cryptopayload is None: logging.warning(f'Unable to decrypt') return + + if cryptopayload is not None: newprefix = prefix[:-3] + ' ' print(f'{newprefix}↧ (decrypts to)') self.print_tree(cryptopayload, newprefix + '└', z, 0) -- cgit v1.2.3