Strip email attachments based on the subject line?
January 30, 2006 6:22 AM   Subscribe

Email attachments - I want to strip attachments based on the email subject line and then save the attachment to disk under Linux or using Outlook. How can I do this?

When I receive an email with a certain, exact subject line, I'd like to automatically save the attachment (a word document, usually) to a certain directory on the disk. I have root access to my domain, so server side solutions are fine. Also, I currently use Outlook for Windows, but I'm strongly considering switching to Kubuntu, so solutions involving any Linux email client would also be fine.

I appreciate any suggestions that you all might have. I've spent several hours fruitlessly googling on this, but I don't even know the right way to approach the problem, so it's difficult to find what I'm looking for.
posted by gd779 to Technology (9 answers total)
 
I know this will not help you but I just yesterday found a ready script to do this on Entourage for Mac OS X. Just in case anybody else is interested.
posted by keijo at 6:26 AM on January 30, 2006


If you have access to Perl, you could use MIME::Parser to extract the attachments from your message spool file and save them to your file system. Google will help find MIME parsers for other languages, if you prefer a different scripting language.
posted by Rothko at 6:57 AM on January 30, 2006


On your Linux box you could use the following Procmail recipe (put this in a file named .procmailrc in your home directory):
:0 c
* ^Subject: your subject line
| munpack -q -C /home/gd779/files/
Be sure to test this carefully though -- procmail has a nasty habit of eating your mail if anything goes wrong. You only want to use Procmail if nobody offers a better solution :)
posted by reynaert at 7:12 AM on January 30, 2006


Maybe EZDetach?
posted by staggernation at 7:16 AM on January 30, 2006


Client-side, this can be done in Outlook using a combination of the Outlook Rules Wizard and VBA. The script is written in VBA. Then in the Rules Wizard, you indicate you want to run that script on incoming mail.

This is the reference for creating a script with the correct parms so that it will be accessible to the Rules Wizard.

It's not really too complicated, but you do need to know a little bit of VBA.
posted by SuperSquirrel at 7:51 AM on January 30, 2006


Best answer: This page has code for a script that will do what you want - it saves the attachments to a directory you specify, and appends a digit to the filename if necessary. In Outlook 2002 or later, call the script from a rule that searches the subject line for specific words. You could create different versions of the script that save to different directories, and call them from different rules. I don't think it deletes the attachments after saving.

If you don't mind paying for a solution, the LBE Toolbox has an attachment stripper for about $20.
posted by fochsenhirt at 8:25 AM on January 30, 2006


I used a tiny little program called ripmime to do this on HP-UX. I'd have used the perl solution above if I'd known about it.
posted by exhilaration at 9:34 AM on January 30, 2006


Best answer: In conjuction with a .procmailrc that contained this:

:0
* ^Subject: lookatme [a-zA-Z][-a-zA-Z0-9_]*$
| /home/jason/.procmail/lookatme

I wrote a Perl script ("lookatme") that used MIME::Parser to automatically pull photos out of messages that matched the subject line pattern, optimized them with jpegtran, and regenerated the thumbnail index with htmlthumbnail. Here's the lookatme script if you're interested in tweaking it to meet your needs.
posted by xiojason at 10:15 AM on January 30, 2006


Response by poster: Thanks, all. I'll try these suggestions, and see what I can get to work.
posted by gd779 at 4:02 PM on January 30, 2006


« Older Hybrid music?   |   Cheap safety razor in Toronto Newer »
This thread is closed to new comments.