Pages

Friday, April 23, 2010

Ubuntu Tricks: Extract Attachments from Gmail

This is a repost from lovinglinux.

After a lot of research I finally figure out a simple way of doing this using IMAP and a shell script.

1. Install offlineimap and mpack
sudo apt-get install offlineimap mpack

2. Create a folder ~/mail for storing the Gmail messages

3. Create a text file and save it as ~/.offlineimaprc

This is the configuration file for offlineimap which will sync your Gmail with local maildir files, using IMAP. Add the following code to it:

[general]
accounts = GMail


ui = Noninteractive.Basic


[Account GMail]
localrepository = GMailLocalMaildirRepository
remoterepository = GMailServerRepository


[Repository GMailLocalMaildirRepository]
type = Maildir
localfolders = ~/mail/


[Repository GMailServerRepository]
type = IMAP
remotehost = imap.gmail.com
remoteuser = yourgmailaccount@gmail.com
remotepass = yourgmailpassword
ssl = yes

Then run the following command on a terminal:

offlineimap && munpack /home/yourusername/mail/LABEL/new/*

The offlineimap command will sync Gmail with local files and munpack will extract any new messages and attachments in the "LABEL" folder, where each folder (label) correspond to Gmail labels.

No comments:

Post a Comment