Cable, Stamp, Lock offlineimap allows you to keep a local copy of your emails, and synchronize it with the IMAP folders on the server. Not only handy for offline use, but also for dealing with slow mail servers and unreliable network connections.

Unfortunately, offlineimap exits with an error from time to time and needs to be restarted. The restarts are easily done with a script, but each time you restart it, offlineimap requires the IMAP server's password. offlineimap allows you to store the unencrypted password in a file, but that should not be an option if you care about security.

On Fedora 9, there's a better way to hand the password to offlineimap: gnome-keyring


First, install the Python bindings for gnome-keyring:

yum install gnome-python2-gnomekeyring

Download the file ~/.offlineimap.py and add the following settings in ~/.offlineimaprc. This assumes that you use a local IMAP server.

[general]

pythonfile = ~/.offlineimap.py

[Repository localhost]

type = IMAP
remotehost = localhost
remoteusereval = get_username("localhost")
remotepasseval = get_password("localhost")

[Repository Zimbra]

type = IMAP
remotehost = mail.example.com
remoteusereval = get_username("mail.example.com")
remotepasseval = get_password("mail.example.com")

Download the script imap-passwords and run it to add the IMAP usernames and passwords to your keyring. It will prompt you for server, username and password - use the same host names as in .offlineimaprc.

Now you can run offlineimap in a loop to automatically restart it in the case of some unrecoverable error, like so:

#!/bin/bash

while true; do
  /usr/bin/offlineimap
  echo Restarting in 60 seconds ...
  sleep 60
done

During the first run, gnome-keyring will ask you to authorize offlineimap to access your IMAP authentication data in the default keyring.

Thanks to Sebastian Rittau for the Keyring Python module.

22:17, 22 Sep 2008 by Carsten Clasohm Permalink

Comments

Thanks

That is great. Thanks a lot of documenting this.

by Anonymous Visitor, 12 Nov 2008

Another thanks

Really nice! works flawlessly and makes the use of offlineimap much smoother.

by Anonymous Visitor, 26 Feb 2011

imap-password patch

Thanks! I've made an improvement to imap-password:


--- a/imap-passwords
+++ b/imap-passwords
@@ -36,9 +36,14 @@ class Keyring(object):

server = raw_input("Server: ")
username = raw_input("Username: ")
-password = getpass.getpass(prompt="Password: ")
-print

-keyring = Keyring("offlineimap", server, "imap")
+while True:
+      password = getpass.getpass(prompt="Password: ")
+      p2 = getpass.getpass(prompt="Verify Password: ")
+      if p2 != password:
+              print "Passwords don't match."
+      else:
+              break

+keyring = Keyring("offlineimap", server, "imap")

by Anonymous Visitor, 12 May 2011

Add a Comment

Comments are reviewed before they appear on this page.

Title:

Comment:

Text above is