Do you use let's encrypt?





4075 votes ~ 17 comments

 

XML logo

visualizing MIME structure
Posted by dkg on Tue 29 Jan 2013 at 16:16
Better debugging tools can help us understand what's going on with MIME messages. A python scrap i wrote a couple years ago named printmimestructure has been very useful to me, so i thought i'd share it.

It reads a message from stdin, and prints a visualisation of its structure, like this:

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:~$ 
It is being published in the notmuch repository, under devel/
git clone git://notmuchmail.org/git/notmuch
ls -l notmuch/devel/printmimestructure
It feels silly to treat this ~30 line script as its own project, but i don't know of another simple tool that does this. If you know of one, or of something similar, i'd love to hear about it in the comments (or by sending me e-mail if you prefer).

If it's useful for others, I'd be happy to contribute printmimestructure to a project of like-minded tools. Does such a project exist? Or if people think it would be handy to have in debian, i can also package it up, though that feels like it might be overkill.

and oh yeah, as always: bug reports, suggestions, complaints, and patches are welcome :)

(2013-10-09: updated to note change of location of the script, thanks to the notmuch team for adopting it)

 

Comments on this Entry

Re: visualizing MIME structure
Posted by Anonymous (141.24.xx.xx) on Tue 29 Jan 2013 at 16:30
mutt can do this. ;-)

[ Parent | Reply to this comment ]

Re: visualizing MIME structure
Posted by dkg (108.58.xx.xx) on Tue 29 Jan 2013 at 16:59
[ View dkg's Scratchpad | View Weblogs ]
Cool, how would i ask mutt to do that?

And wouldn't i need to set up and configure mutt to do that? last time i tried to configure mutt, it was a daylong project and i felt i'd only scratched the surface. Hopefully it's gotten better since then, though :)

Thanks for the suggestion!

[ Parent | Reply to this comment ]

Re: visualizing MIME structure
Posted by Anonymous (89.247.xx.xx) on Tue 29 Jan 2013 at 17:36
Per default, "v" is mapped to view-attachments (show MIME attachments) in mutt. The latest USN shows similiarily to this:
I 1 <no description> [multipa/signed, 7bit, 3.3K]
I 2 --><no description> [text/plain, quoted, iso-8859-1, 2.0K]
A 3 -->OpenPGP digital signature [applica/pgp-signat, 7bit, 0.9K]
I 4 <no description> [text/plain, 7bit, us-ascii, 0.2K]

However, I normally use something like

#!/usr/bin/perl

use strict;
use warnings;
use Email::MIME;

my $email = join('', <STDIN>);
my $mime = Email::MIME->new($email);
print $mime->debug_structure;

when I need to access the MIME structure ...

[ Parent | Reply to this comment ]

Re: visualizing MIME structure
Posted by Anonymous (87.106.xx.xx) on Tue 29 Jan 2013 at 21:40
If you are looking for a project/package where this might fit, m(un)pack comes to mind. Created by Robert Leslie and currently maintained by Richard Braakman (Debian Maintainer is Anibal Monsalve Salazar). I am not affiliated with either of them, but they are whom I'd ask for something like that (and yes, your 30 lines are extremely useful to me :))

[ Parent | Reply to this comment ]

Re: visualizing MIME structure
Posted by Anonymous (58.178.xx.xx) on Wed 30 Jan 2013 at 09:35
package nmh has mhlist ...

mhlist -f ~/spool/p1
 msg part  type/subtype              size description                         
   0       multipart/mixed           149K
     1     multipart/alternative      10K
     1.1   text/html                 8046
     1.2   text/plain                2052
     2     application/octet-stream  102K 16_November.pdf                     
     3     text/plain                 165

[ Parent | Reply to this comment ]

Re: visualizing MIME structure
Posted by dkg (108.58.xx.xx) on Thu 31 Jan 2013 at 16:17
[ View dkg's Scratchpad | View Weblogs ]
Interesting, thanks. I installed nmh, but it didn't put mhlist anywhere in my $PATH. It's in /usr/bin/mh/mhlist, apparently, and when i try to run it, i get:
0 dkg@alice:/tmp$ /usr/bin/mh/mhlist -f - < /tmp/Ticket-6787.eml
mhlist: Doesn't look like nmh is installed.  Run install-mh to do so.
1 dkg@alice:/tmp$ 
and install-mh isn't in my $PATH either. Reading install-mh(8) makes it sound like i have to configure a mail user agent just to use this tool, which goes back to my earlier objection about mutt. :(

These seem like silly hoops to have to jump through for a program that just needs to read from stdin and write to stdout.

[ Parent | Reply to this comment ]