PINE, Perl, pipes, and attachmentsby brian_d_foy (Abbot)
|on Jul 25, 2004 at 01:25 UTC||Need Help??|
I read my mail in PINE, on a remote server. I've been doing it that way for years and it works for me. I never know where I might be or which computer I might be using, but I can usually telnet or ssh to this shell account.
Attachments, however, can be a pain in the butt. PINE is just a text thing. It isn't going to show me pictures or translate Word documents. Since I read this stuff on a remote account, I have to save the attachments then transfer them to my laptop. That can be a lot of steps, including choosing a file name then typing all the stuff that scp needs.
It really wasn't so much work that I felt very motivated to fix it, though. Well, until recently anyway. Lately I've received a lot of attachments that I want to save (opposed to the sorts that are trojans or virii).
Most of the mail with attachments ended up in my "to-do" mail folder, so I wrote a script to go through all of the messages in an mbox and extract all of the attachments. They end up in a sub-directory named after the email address of the sender.
That works, but then I thought of an easier way. Why not just pipe the message directly to a program to do it as I read them, rather than having to stop reading mail and process the mbox file?
With PINE this is fairly easy. I have to turn on the enable-full-header-and-text option to make this work: while reading a message, type "h" to show all the gory details, then "|" to pipe the message to an external program, then "a", the name of my attachment extracter (which has to be in my PATH). The "a" program uses MIME::Parser which does all of the work, including figuring out the right filenames and saving the bits.
The files end up in one of my private web directories, so I go to that URL, which is just a directory listing, then choose the link to the email address of the message. There are my attachments. It's not as easy as clicking a link in web mail, but now everything that everyone sends me gets stored in an easily-accessible web directory.
The next step is a bit scary. Am I smart enough to let procmail do all of this for me? In that case I might consider ditching Perl in favor of munpack, which I saw in Wireless Hacks
brian d foy <email@example.com>