* [PATCH] devel: add dkg's printmimestructure script to notmuch devel scripts
@ 2013-05-20 15:59 david
2013-05-20 16:08 ` Daniel Kahn Gillmor
2013-05-21 14:15 ` Tomi Ollila
0 siblings, 2 replies; 5+ messages in thread
From: david @ 2013-05-20 15:59 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
From: David Bremner <bremner@debian.org>
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 <dkg@fifthhorseman.net>
+# 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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] devel: add dkg's printmimestructure script to notmuch devel scripts
2013-05-20 15:59 [PATCH] devel: add dkg's printmimestructure script to notmuch devel scripts david
@ 2013-05-20 16:08 ` Daniel Kahn Gillmor
2013-05-23 11:13 ` David Bremner
2013-05-21 14:15 ` Tomi Ollila
1 sibling, 1 reply; 5+ messages in thread
From: Daniel Kahn Gillmor @ 2013-05-20 16:08 UTC (permalink / raw)
To: david; +Cc: notmuch, David Bremner
[-- Attachment #1: Type: text/plain, Size: 681 bytes --]
On 05/20/2013 11:59 AM, david@tethera.net wrote:
> From: David Bremner <bremner@debian.org>
>
> 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'm happy to have this distributed with notmuch, and i'm glad it's been
useful for other people.
> +# Updates: git://lair.fifthhorseman.net/~dkg/printmimestructure
This line should probably be removed. If it's distributed with notmuch,
i'm happy with notmuch's repo being the canonical location for the tool;
i'll remove my personal dedicated git repo to avoid confusion.
--dkg
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 1027 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] devel: add dkg's printmimestructure script to notmuch devel scripts
2013-05-20 16:08 ` Daniel Kahn Gillmor
@ 2013-05-23 11:13 ` David Bremner
2013-05-23 15:15 ` Daniel Kahn Gillmor
0 siblings, 1 reply; 5+ messages in thread
From: David Bremner @ 2013-05-23 11:13 UTC (permalink / raw)
To: Daniel Kahn Gillmor; +Cc: notmuch
Daniel Kahn Gillmor <dkg@fifthhorseman.net> writes:
> On 05/20/2013 11:59 AM, david@tethera.net wrote:
>
>> +# Updates: git://lair.fifthhorseman.net/~dkg/printmimestructure
>
> This line should probably be removed. If it's distributed with notmuch,
> i'm happy with notmuch's repo being the canonical location for the tool;
> i'll remove my personal dedicated git repo to avoid confusion.
OK, I've pushed the script with that line removed. Thanks for the
contribution,
d
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] devel: add dkg's printmimestructure script to notmuch devel scripts
2013-05-20 15:59 [PATCH] devel: add dkg's printmimestructure script to notmuch devel scripts david
2013-05-20 16:08 ` Daniel Kahn Gillmor
@ 2013-05-21 14:15 ` Tomi Ollila
1 sibling, 0 replies; 5+ messages in thread
From: Tomi Ollila @ 2013-05-21 14:15 UTC (permalink / raw)
To: david, notmuch; +Cc: David Bremner
On Mon, May 20 2013, david@tethera.net wrote:
> From: David Bremner <bremner@debian.org>
>
> 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.
> ---
Good idea! +1
Tomi
>
> 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 <dkg@fifthhorseman.net>
> +# 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
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-05-23 15:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-20 15:59 [PATCH] devel: add dkg's printmimestructure script to notmuch devel scripts david
2013-05-20 16:08 ` Daniel Kahn Gillmor
2013-05-23 11:13 ` David Bremner
2013-05-23 15:15 ` Daniel Kahn Gillmor
2013-05-21 14:15 ` Tomi Ollila
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).