Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 183E9431FBC for ; Mon, 20 May 2013 08:59:56 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5tq0XaJowOHB for ; Mon, 20 May 2013 08:59:48 -0700 (PDT) Received: from tempo.its.unb.ca (tempo.its.unb.ca [131.202.1.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 5B0DE431FB6 for ; Mon, 20 May 2013 08:59:48 -0700 (PDT) Received: from tesseract.cs.unb.ca (tesseract.cs.unb.ca [131.202.240.238]) by tempo.its.unb.ca (8.13.8/8.13.8) with ESMTP id r4KFxdDv008958; Mon, 20 May 2013 12:59:39 -0300 Received: from fctnnbsc30w-156034082078.dhcp-dynamic.fibreop.nb.bellaliant.net ([156.34.82.78] helo=zancas.localnet) by tesseract.cs.unb.ca with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1UeSUs-0007Yr-FR; Mon, 20 May 2013 12:59:39 -0300 Received: from bremner by zancas.localnet with local (Exim 4.80) (envelope-from ) id 1UeSUk-00083W-Nt; Mon, 20 May 2013 12:59:30 -0300 From: david@tethera.net To: notmuch@notmuchmail.org Subject: [PATCH] devel: add dkg's printmimestructure script to notmuch devel scripts Date: Mon, 20 May 2013 12:59:19 -0300 Message-Id: <1369065559-30788-1-git-send-email-david@tethera.net> X-Mailer: git-send-email 1.8.2.rc2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam_bar: - Cc: David Bremner X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Mon, 20 May 2013 15:59:56 -0000 From: David Bremner I find this script pretty useful when figuring out who to blame for MIME rendering problems. It currently isn't very widely known, so it seems worth distributing with notmuch. --- I did a small amount whitespace cleanup compared to version in dkg's git repo. devel/printmimestructure | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 devel/printmimestructure diff --git a/devel/printmimestructure b/devel/printmimestructure new file mode 100755 index 0000000..b8084a9 --- /dev/null +++ b/devel/printmimestructure @@ -0,0 +1,54 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# Author: Daniel Kahn Gillmor +# License: GPLv3+ + +# Updates: git://lair.fifthhorseman.net/~dkg/printmimestructure + +# This script reads a MIME message from stdin and produces a treelike +# representation on it stdout. + +# Example: +# +# 0 dkg@alice:~$ printmimestructure < 'Maildir/cur/1269025522.M338697P12023.monkey,S=6459,W=6963:2,Sa' +# └┬╴multipart/signed 6546 bytes +# ├─╴text/plain inline 895 bytes +# └─╴application/pgp-signature inline [signature.asc] 836 bytes +# 0 dkg@alice:~$ + + +# If you want to number the parts, i suggest piping the output through +# something like "cat -n" + +import email +import sys + +def test(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') + if (disp is None): + disposition = '' + else: + disposition = '' + for d in disp: + if d[0] in [ 'attachment', 'inline' ]: + disposition = ' ' + d[0] + if (z.is_multipart()): + print prefix + '┬╴' + z.get_content_type() + cset + disposition + fname, z.as_string().__len__().__str__() + ' bytes' + if prefix.endswith('└'): + prefix = prefix.rpartition('└')[0] + ' ' + if prefix.endswith('├'): + prefix = prefix.rpartition('├')[0] + '│' + parts = z.get_payload() + i = 0 + while (i < parts.__len__()-1): + test(parts[i], prefix + '├') + i += 1 + test(parts[i], prefix + '└') + # FIXME: show epilogue? + else: + print prefix + '─╴'+ z.get_content_type() + cset + disposition + fname, z.get_payload().__len__().__str__(), 'bytes' + +test(email.message_from_file(sys.stdin), '└') -- 1.8.2.rc2