[PATCH mailscripts 3/3] email-print-mime-structure: decryption/unwrapping uses BOX_DRAWINGS
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed Jul 16 23:05:28 BST 2025
The symbols ↧ and ⇩ were used for decryption and unwrapping,
respectively, but they are not included in very many fonts.
By switching the tree structure to only use characters from the BOX
DRAWINGS subset of Unicode, we have a better chance of producing
reliable renderings in different fonts.
See also discussion at
https://github.com/ietf-tools/xml2rfc/issues/1245#issuecomment-3014573118
which motivated this cleanup.
Note that redrawing the tree this way needs an adjustment in the line
above the "(decrypts to)" or "(unwraps to)" line, so we handle that as
well.
Signed-off-by: Daniel Kahn Gillmor <dkg at fifthhorseman.net>
---
email-print-mime-structure | 16 +++++++++++++---
tests/email-print-mime-structure/encrypted.out | 4 ++--
.../smime-encrypted.out | 4 ++--
.../email-print-mime-structure/smime-signed.out | 4 ++--
4 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/email-print-mime-structure b/email-print-mime-structure
index 7e0133f..99f3376 100755
--- a/email-print-mime-structure
+++ b/email-print-mime-structure
@@ -108,7 +108,7 @@ class MimePrinter(object):
if cryptopayload is not None:
newprefix = prefix[:-3] + ' '
- print(f'{newprefix}↧ (decrypts to)')
+ print(f'{newprefix}╧ (decrypts to)')
self.print_tree(cryptopayload, newprefix + '└', z, 0)
else:
if z.get_content_type().lower() == 'application/pkcs7-mime' and \
@@ -118,7 +118,7 @@ class MimePrinter(object):
unwrapped = self.pipe_transform(bodypart, ['certtool', '--p7-show-data', '--p7-info', '--inder'])
if unwrapped:
newprefix = prefix[:-3] + ' '
- print(f'{newprefix}⇩ (unwraps to)')
+ print(f'{newprefix}┴ (unwraps to)')
self.print_tree(unwrapped, newprefix + '└', z, 0)
else:
logging.warning(f'Unable to unwrap one-part PKCS#7 signed message (maybe try "apt install gnutls-bin")')
@@ -199,7 +199,17 @@ class MimePrinter(object):
self.print_tree(msg, prefix + '└', z, i+1)
# FIXME: show epilogue?
else:
- self.print_part(z, prefix+'─╴', parent, num)
+ # if we're going to decrypt or unwrap, extend the tree
+ if (self.try_pgp_decrypt and \
+ z.get_content_type().lower() == 'application/octet-stream' and \
+ parent is not None and \
+ parent.get_content_type().lower() == 'multipart/encrypted') or \
+ (z.get_content_type().lower() == 'application/pkcs7-mime' and \
+ (str(z.get_param('smime-type')).lower() == 'signed-data' or
+ self.try_cms_decrypt)):
+ self.print_part(z, prefix+'┬╴', parent, num)
+ else:
+ 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.',
diff --git a/tests/email-print-mime-structure/encrypted.out b/tests/email-print-mime-structure/encrypted.out
index a2db072..0d75154 100644
--- a/tests/email-print-mime-structure/encrypted.out
+++ b/tests/email-print-mime-structure/encrypted.out
@@ -1,7 +1,7 @@
└┬╴multipart/encrypted 1366 bytes
├─╴application/pgp-encrypted 11 bytes
- └─╴application/octet-stream 971 bytes
- ↧ (decrypts to)
+ └┬╴application/octet-stream 971 bytes
+ ╧ (decrypts to)
└┬╴multipart/mixed 415 bytes
├┬╴multipart/alternative 234 bytes
│├─╴text/plain 26 bytes
diff --git a/tests/email-print-mime-structure/smime-encrypted.out b/tests/email-print-mime-structure/smime-encrypted.out
index 071be70..6853d62 100644
--- a/tests/email-print-mime-structure/smime-encrypted.out
+++ b/tests/email-print-mime-structure/smime-encrypted.out
@@ -1,5 +1,5 @@
-└─╴application/pkcs7-mime 1196 bytes
- ↧ (decrypts to)
+└┬╴application/pkcs7-mime 1196 bytes
+ ╧ (decrypts to)
└┬╴multipart/mixed 415 bytes
├┬╴multipart/alternative 234 bytes
│├─╴text/plain 26 bytes
diff --git a/tests/email-print-mime-structure/smime-signed.out b/tests/email-print-mime-structure/smime-signed.out
index 293a271..a9867b7 100644
--- a/tests/email-print-mime-structure/smime-signed.out
+++ b/tests/email-print-mime-structure/smime-signed.out
@@ -1,5 +1,5 @@
-└─╴application/pkcs7-mime 2538 bytes
- ⇩ (unwraps to)
+└┬╴application/pkcs7-mime 2538 bytes
+ ┴ (unwraps to)
└┬╴multipart/mixed 415 bytes
├┬╴multipart/alternative 234 bytes
│├─╴text/plain 26 bytes
--
2.47.2
More information about the sgo-software-discuss
mailing list