ZoneO-tips for Mandriva Linux

Backup your imap mailbox for kmail

How do you backup an IMAP mailbox and read it with kmail?

 
 

I knew it was gonna happen... but still. Yesterday I recieved the following message:

D'aprés les informations de la base de données du personnel et des élèves de notre chère université, il s'avére que votre compte informatique dont les caractéristiques sont :
  • login : ******
  • Nom : Dude
  • Prénom : Big
Sera supprimé le : 02/09/03

Gee... I had that computer account this 1994, 9 years, and it was gonna be removed within three days. The problem was simple: all my important emails from the last 9 years were storred on a imap server and I had to back it up immediatly.

Well, after a few lookups on the internet I had a few solutions available

  • mailsync:"Mailsync is a way of synchronizing a collection of mailboxes. The algorithm is a 3-way diff. Two mailboxes are simultaneously compared to a record of the state of both mailboxes at last sync. New messages and message deletions are propagated between the two mailboxes."
  • offlineimap: " OfflineIMAP is a tool to simplify your e-mail reading. With OfflineIMAP, you can read the same mailbox from multiple computers. You get a current copy of your messages on each computer, and changes you make one place will be visible on all other systems."
  • imapcp: "imapcp is a simple tool to copy mailbox accounts"

Imapcp requires two imap accounts and I did not want to do that, since the accounts I had available had already stuff in them, performing a synchronisation would have been difficult. Mailsync looked powerfull but it required the c-client library which is part of a massive imap code, that meant a fews hours of work to figure out how to compile and run everything properly. On the other hand offlineimap worked immediatly, and within a few minutes I could create a full local backup of my imap account in the Maildir format. Here was my configuration file

[general]
accounts = Test
[Account Test]
localrepository = LocalExample
remoterepository = RemoteExample
[Repository LocalExample]
type = Maildir
localfolders = ~/Test
sep = /
[Repository RemoteExample]
type = IMAP
remotehost = imap.theserveur.fr
ssl = no
remoteuser = mylogin

Now came the next problem... For some reason the format that is being used by kmail is slightly different that the standard maildir that was generated by the backup. Luckily, it was not too hard to work around that one. Imagine that your mail directory structure is something like

  • INBOX
    • Perso
      • Steph
      • Mike
    • Work
      • University
      • Web
In that case the maildir backup will have the following structure
  • INBOX
    • cur
    • new
    • tmp
    • Perso
      • cur
      • new
      • tmp
      • Steph
        • cur
        • new
        • tmp
      • Mike
        • cur
        • new
        • tmp
    • Work
      • cur
      • new
      • tmp
      • University
        • cur
        • new
        • tmp
      • Web
        • cur
        • new
        • tmp
where the directory cur under INBOX contains the emails belonging to the INBOX folder, the directory cur under Perso contains the emails belonging to the Perso folder, and so on.

The next problem was that the version of kmail I had would only find the emails of the top folder (INBOX), and not the subfolders... The format used by kmail is slightly different, but it is not to hard to modify it. Basically, I had to create a directory called .INBOX.directory (watch for the dot), move the folders Perso and Work in there, and perform that same step for all nested folders. So my directory structure became

  • INBOX
    • cur
    • new
    • tmp
  • .INBOX.directory
    • Perso
      • cur
      • new
      • tmp
    • .Perso.directory
      • Steph
        • cur
        • new
        • tmp
      • Mike
        • cur
        • new
        • tmp
    • Work
      • cur
      • new
      • tmp
    • .Work.directory
      • University
        • cur
        • new
        • tmp
      • Web
        • cur
        • new
        • tmp
And that was it... I had a backup of all my emails from the last 9 years, and I could read it with kmail. The whole process did take some time, but still, it was much shorter than trying to transfer the content of each individual folders one by one!
08/2003
Edited and reformated 12/2005
 
© ZoneO-soft - Contact us - Start page