notes-computer-oqo-emailSync

Intro

I have a server which is almost always at home, turned on and plugged into the network, and an OQO handheld. I want to be able to check and sort my email at my server when I'm at home, and on the OQO when I'm not at home. I save lots of my emails into a large hierarchy of folders, and so I can't really "do my email" just by reading it, I have to be able to save it into the folders too.

So, I synchronize my email, saved folders and all, between my two computers. I also synchronize some of it with my computer at work (and the system I use is easily scalable to more). All of the computers run Debian GNU/Linux.

I use mutt to read my mail.

The synchronization system I use is a program called offlineimap, combined with an IMAP server on the server computer. Basically, each computer has a local copy of all of the email folders, stored in Maildir format. Periodically, I run offlineimap to synchronize these folders with the IMAP server which is running on the server computer at home.

Neat features:

Programs used

Summary of what to do to set it up (if I remember correctly... don't blame me if this is wrong)

  1. "apt-get install" the five programs listed above
  2. do "mb2md -s ~/Mail -R" to convert all of your mbox-format email folders (stored in ~/Mail) to Maildir format ones (stored in Maildir). Don't worry, it doesn't alter the old mbox mailboxes, it just copies them.
  3. either "mv ~/Mail ~/Mail-mbox; ln -s /home/YOURLOGINNAME/Maildir /home/YOURLOGINNAME/Mail", or be sure to change the config files I provided to reference ~/Maildir where I said ~/Mail.
  4. Edit/install the relevant config files as I've instructed in the section "My config files" (be sure to change /home/bshanks to /home/YOURLOGINNAME).
  5. Since you changed its config file, you should restart the IMAP server with "/etc/init.d/courier-imap restart"
  6. You have to create some Maildir folders where various programs expect them. "mkdir ~/Maildir/cur; mkdir ~/Maildir/tmp; mkdir ~/Maildir/new" on the server, and "mkdir ~/Mail" on the client (if you already have a "~/Mail" on the client, move it out of the way first with something like "mv ~/Mail ~/Mail-old", and then do "mkdir ~/Mail").
  7. OK, now try it. Go to the client computer, and run the command "offlineimap -a Home". If all goes well, this will connect to the IMAP server and make a copy of everything. "offlineimap" is the command to do a quick sync (only the inbox and outbox folders). Try sending an email to yourself using "mutt" on the client, then running "offlineimap" (to copy the email to the server, which will actually send it), then waiting five minutes (or running fetchmail on the server), then running "offlineimap" again (to copy the presumably received email to the client), and then running "mutt" on the client, and see if you received your test email.

My config files

Relevant parts of ~/.muttrc (on IMAP server computer)

set mbox_type=Maildir

set folder="~/Mail/"
set mask=""
set postponed="+.Drafts"
set spoolfile="~/Mail/.incoming/"

Also, symlink ~/Mail/sent-mail to ~/Mail/.sent-mail. (I started out just changing the "record" variable in .muttrc on the server, but that's bad: if you do that, then when you postpone something and then finish it and then send it on the client, the Fcc: won't work because it'll still be Fcc: ~/Mail/.sent-mail, but that won't exist on the client.

Relevant parts of ~/.muttrc (on client computers)

set mbox_type=Maildir

set folder="~/Mail/"
set mask="!^\\.[^.]"
set postponed="+Drafts"
set record= =sent-mail
set spoolfile="~/Mail/incoming/"


set sendmail="/home/bshanks/bin/mailout"

~/.offlineimaprc (only on the client computers)

[general]
accounts = HomeFast

[Account HomeFast]
maxconnections = 3
localrepository = LocalHome
remoterepository = HomeFast

[Account Home]
maxconnections = 3
localrepository = LocalHome
remoterepository = Home

[Repository LocalHome]
type = Maildir
localfolders = ~/Mail

[Repository Home]
type = IMAP
remotehost = myhostname.dyndns.org
remoteuser = myusername
remotepass = mypassword
nametrans = lambda foldername: re.sub('^INBOX.', '', foldername)


[Repository HomeFast]
type = IMAP
remotehost = myhostname.dyndns.org
remoteuser = myusername
remotepass = mypassword
nametrans = lambda foldername: re.sub('^INBOX.', '', foldername)
folderfilter = lambda foldername: foldername in ['INBOX', 'Outbox']

relevant parts of /etc/courier/imapd

You have to uncomment the line "OUTBOX=.Outbox" to turn on the outbox

relevant parts of /etc/procmailrc

MAILDIR=$HOME/Mail
DEFAULT=.incoming/

the contents of file /etc/cron.d/fetchmail (which I added)

00,05,10,15,20,25,30,35,40,45,50,55 *     * * *     bshanks   /usr/bin/fetchmail > /dev/null

the contents of file /home/bshanks/bin/mailout (which I added)

#!/bin/sh
echo "Saving to Outbox..."
safecat /home/bshanks/Mail/Outbox/tmp /home/bshanks/Mail/Outbox/new

Notes

Useful links

Stuff that helped me while I was setting this up: