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:
- an "Outbox" that allows the client computers to send mail indirectly, by putting them in the Outbox mail folder, which then gets sent by the server at home whenever the email is sync'd. This way I don't have to worry anymore about changing my SMTP server setting as I use my handheld to send email from different networks; the email is always sent back to the server at home, and the server is connected through the home network and so can use my ISP's standard SMTP server.
- I have so many folders and so much saved mail that sync everything takes a minute or two. But you can tell offlineimap to only sync certain folders on certain runs, so I have it set to by default only sync the inbox and outbox, and then to sync the rest only when I tell it to.
Programs used
- mutt (mailreader) (Debian package "mutt")
- Courier (IMAP server) (Debian package "courier-imap")
- offlineimap (mail synchronizer) (Debian package "offlineimap")
- safecat (thingee for reading from STDIN and copying to a file, I think; used as part of the "Outbox" setup) (Debian package "safecat")
- mb2md (to convert mbox-format mailboxes to Maildir-format ones) (Debian package "mb2md")
Summary of what to do to set it up (if I remember correctly... don't blame me if this is wrong)
- "apt-get install" the five programs listed above
- 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.
- 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.
- 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).
- Since you changed its config file, you should restart the IMAP server with "/etc/init.d/courier-imap restart"
- 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").
- 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
- although I use ~/Mail as my mail folder, the Courier IMAP server needs it to be called ~/Maildir --- so I symlink ~/Maildir to ~/Mail
- The Courier IMAP server needs the folder names on the server Maildir to each start with a period. On the client computers, the "nametrans" config option strips the leading period from the folder names. This is most of why the .muttrc is different; on the server at home, the folder names all start with a period, elsewhere they don't
- You don't have to put your password in the config file; if you leave it out, offlineimap will prompt you for it at runtime
- The program mb2md will convert your mbox-format mailboxes (the type I had had by default, before I did this) to Maildir-format ones. I used "mb2md -s /home/bshanks/Mail -R" to convert all of the mailboxes at once
- I fetchmail every five minutes on the home server via a cron job so that I can read my email remotely just by syncing.
- To quickly sync mail (just the inbox and outbox), the command is "offlineimap". To sync all folders, the command is (using my setup) "offlineimap -a Home".
- Remember to restart the Courier IMAP server after editing its config file (to add Outbox capability); "/etc/init.d/courier-imap restart"
Useful links
Stuff that helped me while I was setting this up: