So I found myself in a conversation the other day about some things from a previous life. I knew I had some details about it somewhere in old email archives and started grepping for it. I found a lot of stuff but not the right stuff. Since it wasn’t critical, I left it sit, but thought that it sure would be nice to have all of my old email on my mail server, where I can then use the search functionality of my email client. That’s where it got to be interesting …
There are quite a few tools out there that claim to synchronize and copy and move email messages amongst different places. For example mailutil which is part of the UW IMAP tool kit suggests it can do this. The there are various imapcopy, copyimap, imapsync, syncimap, etc tools that google turns up and I spent quite a bit of time trying to either find them or getting them to work. In the end here is what actually worked for me: setup a UW IMAP server on my laptop and then using imapsync to move the files.
Installing the IMAP server was pretty easy since there is an Ubuntu package:
sudo apt-get install uw-imapd
It wants to run via xinetd and so you need to create a file name /etc/xinet.d/imaps with the following contents:
service imaps { socket_type = stream wait = no user = root server = /usr/sbin/imapd log_on_success += DURATION USERID log_on_failure += USERID disable = no }
Then restart xinetd (/etc/init.d/xinetd restart as root)
I had tried using the non-encrypted version, but it seems that the daemon was compiled to require secure authentication. Since I was only interested in moving some email, that was the path of least resistance.
I did some testing using my mail client and then moved on to the copy phase using imapcopy. It’s pretty easy to use although the plethora of command line options might lead on to think otherwise.
imapsync --host1 laptop --port1 993 --host2 server --user1 matthias --user2 matthias --passfile1 ./laptopt.txt --passfile2 ./server.txt --authmech1 LOGIN --ssl1 --authmech2 LOGIN --ssl2 --folderrec OldEmail --prefix1 OldEmail --prefix2 INBOX.Archives.OldEmail
That copied all of the mbox files from the OldEmail directory in my home dir to my real IMAP server in the folder INBOX.Archives.OldMail. My IMAP server isrunning Cyrus and on a different IMAP server it may not be a ‘.’ separating the path.
\\@matthias