From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 9F8896DE1686 for ; Mon, 11 Jun 2018 19:00:01 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -2.102 X-Spam-Level: X-Spam-Status: No, score=-2.102 tagged_above=-999 required=5 tests=[AWL=0.198, RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 7tjLI2RfHUQW for ; Mon, 11 Jun 2018 19:00:01 -0700 (PDT) Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu [131.215.239.19]) by arlo.cworth.org (Postfix) with ESMTPS id E79516DE1684 for ; Mon, 11 Jun 2018 19:00:00 -0700 (PDT) Received: from smtp01.caltech.edu (localhost [127.0.0.1]) by smtp02.caltech.edu (Postfix) with ESMTP id ADE936C0975 for ; Mon, 11 Jun 2018 19:00:00 -0700 (PDT) X-Spam-Scanned: at Caltech-IMSS on smtp01.caltech.edu by amavisd-new Received: from finestructure.net (gwave-71.ligo.caltech.edu [131.215.114.71]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jrollins) by smtp-server.its.caltech.edu (Postfix) with ESMTPSA id 622A86C05C6 for ; Mon, 11 Jun 2018 19:00:00 -0700 (PDT) Received: by finestructure.net (Postfix, from userid 1000) id 5289861986; Mon, 11 Jun 2018 19:00:00 -0700 (PDT) From: Jameson Graef Rollins To: notmuch@notmuchmail.org Subject: [PATCH] minor cleanup to printmimestructure Date: Mon, 11 Jun 2018 19:00:00 -0700 Message-Id: <20180612020000.19607-1-jrollins@finestructure.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180611232244.27207-1-dkg@fifthhorseman.net> References: <20180611232244.27207-1-dkg@fifthhorseman.net> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Jun 2018 02:00:01 -0000 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 afa0590e..ab2a6673 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