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.
Eventually I may fix it to actually do a two way sync between the two systems.

To use it:
  1. Download and install the Python Gmail package libgmail:
    http://libgmail.sourceforge.net/
  2. 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 = '******'
  3. Run the script. You can set the mode variable at the top to 'stdout'.
  4. Boy is the Blogger editor bad!



You can download the script imap_gmail_sync.py

Comments: Post a Comment





<< Home

This page is powered by Blogger. Isn't yours?