From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH v2 2/3] minor cleanup to printmimestructure
Date: Tue, 12 Jun 2018 17:21:09 -0400 [thread overview]
Message-ID: <20180612212110.32533-2-dkg@fifthhorseman.net> (raw)
In-Reply-To: <20180612212110.32533-1-dkg@fifthhorseman.net>
From: Jameson Graef Rollins <jrollins@finestructure.net>
make the source slightly easier to read. no functional change.
---
devel/printmimestructure | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/devel/printmimestructure b/devel/printmimestructure
index a5fc83e7..70e0a5c0 100755
--- a/devel/printmimestructure
+++ b/devel/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), '└')
--
2.17.1
next prev parent reply other threads:[~2018-06-12 21:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-12 21:21 [PATCH v2 1/3] devel: make printmimestructure py3 compatible Daniel Kahn Gillmor
2018-06-12 21:21 ` Daniel Kahn Gillmor [this message]
2018-06-12 21:21 ` [PATCH v2 3/3] use #!/usr/bin/env python consistently Daniel Kahn Gillmor
2018-06-12 21:32 ` Tomi Ollila
2018-06-12 22:55 ` [PATCH v2 1/3] devel: make printmimestructure py3 compatible David Bremner
2018-06-14 23:46 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180612212110.32533-2-dkg@fifthhorseman.net \
--to=dkg@fifthhorseman.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).