Hi All,

Last night at a technical talk I lamented the loss around 5 years ago
from Fedora of command-line tools to extract email attachments from a
BASH script and a colleague told me Mutt can do this.

I installed Mutt, checked out the man pages, went through the
documentation, spent an hour or more searching the archives and it is
not at all readily apparent that Mutt can do this, or how.

Just to be clear what my goals are: I'm trying to automate processing
of inbound email for a particular job. I have the mail server
(postfix) using the .forward ability to pipe to a script, which has
the advantage of running as the owner of the script. The script dumps
the mail into a particular directory - no other contents. It's just
the one file. From there, I need to extract all the MIME parts /
attachments, in order. Encoded parts need to be decoded - lots of
images are expected, perhaps some HTML, etc.

I fired up mutt on an example file and it opens it up just fine, the
problem is having a user drive the user interface defeats the whole
purpose; it must be done programatically. So, I've been looking into
the various libraries that handle MIME - I understand Perl and Python
both have good libraries, though I've been more interested in the Java
one because there are some synergies there - but nevermind all that.

My supposition is that if mutt can do it, the only way is to define a
macro, as documented on this page:


(A brief but hopefully helpful digression is that I've spent a good
bit of time in the documentation and other materials and apparently
there's some tiny little assumption made about macros that is too
obvious to the documentation writer to bother documenting but is
unknwon to a newbie about how / where macros are defined. There's
nothing in the man page, nothing on the on-screen help, and the
documentation apparently assumes you already know how they're defined!
The best help I found so far is the "(ab)use "macros" as variables" on
the wiki under "ConfigTricks" - from that I can probably figure it

So.. that example was:

macro attach W <save-entry><kill-line>/home/gawron/attachments/ macro
attach E <save-entry><kill-line>/home/gawron/attachments/<enter>

It's not clear why there are two bindings here, but anyway, this
wouldn't work because a concurrent mail deilivery would have a race
condition and screw up the processing but the script could cd into the
directory first...

So, maybe the macro would be:

macro attach A <save-entry><kill-line>.<enter>

...I'm guessing... And I'd launch it like this:

$ cd /dir/where/email/is
$ echo A | mutt -f mailfile.name

...Am I on the right track? What do I expect in the directory? Any
other guidance, please?


Reply via email to