Ubuntu – Push entire account from one IMAP server to another IMAP server

imapthunderbirdubuntu 12.04

My institution recently reshuffled our email accounts. I'm forced to shift years worth of carefully currated email (= more chaos than a 3 year old's birthday party) from IMAP account_old to IMAP account_new which differ only in server names as far as I can tell.

Being IMAP, all my mail is held locally besides on the mail server, so I thought Thunderbird might allow me to create the IMAP account_new and then push the contents of my ~/.thunderbird profile onto the account_new IMAP server. Note also that the IMAP account_old is now offline.

My google searching has returned nothing on this approach and instead users appear to have to laboriously copy mail (by right clicking on folder > Copy To > relative/thunderbird/path), folder by folder, from one account to another. I was doing this until I discovered that, at some point, the attachments stopped being copied across correctly (but they were when I started the process). Specifically, the attachment file container is copied, but the contents appear absent since an error* is returned when attempting to open it. Same issue occurs using Move To on individual mail items. Right now I'm wondering if DavMail (for the Exchange account I use) is interfering with the copying of attachments using this approach.

* This attachment appears to be empty.
Please check with the person who sent this.
Often company firewalls or antivirus programs will destroy attachments.

No less, I'd like to know if there isn't a more robust and less labor intensive way to upload the entire local contents of an account to an IMAP server, with complete tree structure and metadata (fwd, reply, tags etc)? I'm using Thunderbird v17.0 on Ubuntu 12.04, 64bit, DavMail 4.1.0.

EDIT: I see imapsync should do the job. Any comments on this approach, i.e. are the metadata and attachments faithfully synced?

Best Answer

An alternative is to use mbsync from the isync project. Here is some example configuration for syncing mail from one IMAP server directly to another:

# The IMAP server you wish to copy mails from.
IMAPAccount imap-src-account
Host imap.host.ac.uk
User student0192
# Pass "xxxxx" # if you don't mind storing it in the file; otherwise will prompt
UseIMAPS yes
CertificateFile /etc/ssl/certs/ca-certificates.crt

 # The IMAP server you wish to copy mails to.
IMAPAccount imap-dest-account
Host zimbra.corporate.com
User worker@corporate.com
# Pass "xxxxx" # if you don't mind storing it in the file; otherwise will prompt
UseIMAPS yes
CertificateFile /etc/ssl/certs/ca-certificates.crt

 # Link IMAP server to remote used below
IMAPStore imap-src
Account imap-src-account

IMAPStore imap-dest
Account imap-dest-account

# ensures that dates of messages will be set correctly
CopyArrivalDate yes

Channel transfer
Master :imap-src:
Slave :imap-dest:
# Transfer all folders
Patterns *
Create Slave
Sync Pull
# important otherwise you will get 'Error: store ... does not support in-box sync state'
SyncState ~/.mail/imap-transfer

You can then run mbsync -l transfer to list which mail folders will be synchronized.

To actually run the transfer, run mbsync transfer. The nice thing about this is that you can run that periodically and it will do an efficient sync.

Further notes:

  • passwords: You can also specify a PassCmd to use a different method of getting the password (e.g. from a token ring).
  • backups: Most instructions online for mbsync are using this to backup to a local file system. You can even backup to the local file system and then push it to the new server, as described here, but that's more complicated than necessary if you just want to sync the servers
  • folder mapping: if you want to transfer folders to a subfolder in the target system (as I did), you can specify this by saying Slave ":imap-dest:parent-folder/" in the Channel configuration.
Related Question