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 3C8276DE16C1 for ; Tue, 12 Jun 2018 14:21:17 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.013 X-Spam-Level: X-Spam-Status: No, score=-0.013 tagged_above=-999 required=5 tests=[AWL=-0.023, RCVD_IN_DNSWL_NONE=-0.0001, T_SPF_PERMERROR=0.01] 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 gITI-s8hvHWH for ; Tue, 12 Jun 2018 14:21:16 -0700 (PDT) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTPS id E2E8B6DE16BA for ; Tue, 12 Jun 2018 14:21:15 -0700 (PDT) Received: from fifthhorseman.net (unknown [38.109.115.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by che.mayfirst.org (Postfix) with ESMTPSA id A04E5F99D; Tue, 12 Jun 2018 17:21:14 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id 32EB220233; Tue, 12 Jun 2018 17:21:10 -0400 (EDT) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH v2 2/3] minor cleanup to printmimestructure Date: Tue, 12 Jun 2018 17:21:09 -0400 Message-Id: <20180612212110.32533-2-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180612212110.32533-1-dkg@fifthhorseman.net> References: <20180612212110.32533-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 21:21:17 -0000 From: Jameson Graef Rollins 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