Extract all attachments from unix mailbox file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Extract all attachments from unix mailbox file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 06-24-2008
raynor raynor is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 9 April 2013, 8:00 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Extract all attachments from unix mailbox file

Hi guys,

I wondering if someone already wrote a script for this, it looks easy for the first shot but I would say it's a bit advanced.

I want to extract all my email attachments from /var/mail/username (Unix mail format) + from my local mails (Maildir format) to a directory with the original filename, and rename it automatically if 2 attachments have the same name. Thunderbird has an extension for it but I would like to do it with shellscript.

If noone knows script for this (tried googling of course) then I write my own.
Pbly sed would be sufficient to process the whole mailbox file and find the attachments as records.

Thanks

Last edited by raynor; 06-24-2008 at 01:21 AM..
Sponsored Links
    #2  
Old 06-24-2008
unSpawn unSpawn is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 12 April 2014, 4:10 AM EDT
Posts: 67
Thanks: 0
Thanked 2 Times in 2 Posts
Quote:
Originally Posted by raynor View Post
(.. )Pbly sed would be sufficient to process the whole mailbox file and find the attachments as records.
Doing ops on e-mail is IMHO better (safer) using tools that understand e-mail (just like you don't write your MBR with a hex editor). In this case you could use "munpack":

Code:
find dir containing files | while read file; do
 create tempdir and copy file there
 run munpack on file and copy attachments elsewhere
 destroy tempdir (contents)
done

Sponsored Links
    #3  
Old 06-24-2008
Ygor's Avatar
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 2 May 2014, 7:14 AM EDT
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 111 Times in 98 Posts
Something similar here...

Perl script to save an email attachment to disk - -General UNIX discussion FAQ - Tek-Tips
    #4  
Old 06-24-2008
raynor raynor is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 9 April 2013, 8:00 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
thx

Hi,

Thanks for the answers. Actually both of you give an answer which is part of the solution. I was thinking that someone must wrote a tool like munpack for it.

The only problem with munpack that it can't process a single mailbox file, eg: thunderbird's inbox. It only works if I make a test.txt which containst only a single mail which starts with:

From <sender> Mon Jun 16 20:42:11 2008
...
and ends with
--------------=CODE--

So I still have to cut this file apart to single mails in order to extract the attachments from them but I can do it from here. Thx guys.
Sponsored Links
    #5  
Old 06-25-2008
unSpawn unSpawn is offline
Registered User
 
Join Date: Feb 2008
Last Activity: 12 April 2014, 4:10 AM EDT
Posts: 67
Thanks: 0
Thanked 2 Times in 2 Posts
Quote:
Originally Posted by raynor View Post
The only problem with munpack that it can't process a single mailbox file, eg: thunderbird's inbox.
Yeah, I read over that in your OP. You could automate separating e-mails and processing them individually with munpack using a procmail recipe.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
unix email attachments in web mail gi.srinivas Shell Programming and Scripting 10 02-29-2012 01:57 PM
Aix Unix Mailx Attachments darioa AIX 3 01-07-2009 12:09 PM
Reading a mailbox and sending new messages to a text file rsw626 Shell Programming and Scripting 1 04-17-2008 01:35 PM
sending attachments via unix Abhishek Ghose UNIX for Advanced & Expert Users 6 09-30-2005 04:49 PM
Mailbox file format exile UNIX for Advanced & Expert Users 1 09-18-2001 09:44 AM



All times are GMT -4. The time now is 02:16 PM.