Thursday, December 3, 2009

How Can I Download Every Attachment From Gmail?

After a lot of research I finally figure out a simple way of doing this using IMAP and a shell script. I decided to post a step-by-step description if someone needs this.

1 - Install offlineimap and mpack

Code:
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:

Code:
[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:

Code:
offlineimap && munpack /home/user/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