Friday, November 17, 2006
Sync IMAP with Gmail using Python
I route my email through Gmail to an IMAP account because I like using IMAP clients a little better than Gmail. One problem I have is that if I read emails in an IMAP client that doesn't get reflected in Gmail. I have written up an initial script which will sync a couple of IMAP folders with my Gmail inbox. It isn't fancy or complete, but seems to work for most of my messages. It is a one way sync -- only marks messages read in Gmail -- and is fairly conservative.
To use it:
You can download the script imap_gmail_sync.py
- Only looks at subjects from IMAP and Gmail messages.
- Only looks at recent messages.
- Won't mark a Gmail thread "read" unless entire thread is "read" in IMAP.
To use it:
- Download and install the Python Gmail package libgmail:
http://libgmail.sourceforge.net/ - Set configuration values in the imap_gmail_sync.py script:
# Configuration for IMAP server.
imap_server = 'localhost'
imap_user = 'user'
imap_pw = '******'
imap_folders = ['INBOX', 'X_Misc']
# Configuration for Gmail account.
gmail_session_file = os.path.join(os.environ['HOME'],
'.gmail_session')
gmail_user = 'user'
gmail_pw = '******' - Run the script. You can set the mode variable at the top to 'stdout'.
- Boy is the Blogger editor bad!
You can download the script imap_gmail_sync.py