Wednesday, May 13, 2009

Migrating from KMail to Evolution

I've decided to give Gnome one more go (I've been a KDE user so far) so I installed Ubuntu 9.04 on my laptop. What's more is that I decided to use only GTK applications, nothing Qt whatsoever. At least for a while, to see how it goes : )

So far, nothing but confusion. What was notable though was the painful migration of my e-mails from KMail to Evolution.

Evolution can import inboxes... but only in a few formats.

In simple words, KMail uses the maildir format (each e-mail is an individual file), whereas Evolution uses the mailbox format (the inbox is one huge file where all e-mails are appended).

So, in order to import the e-mails from KMail into Evolution, I first had to convert the maildir-ed e-mails to a big mailbox.

First off, install procmail -- it provides formail (which is an e-mail (re)formatter):

sudo aptitude install procmail

Then, create the following simple script:


# $1 is the file name (e-mail in maildir format);
# $2 is the name of the resulting mbox file.

echo -n "."
cat "$1" | formail -ds >> "$2"

Save it as and make it executable:

chmod 755

What the script does is it accepts a first parameter (which is the path and file name of an e-mail in maildir format) and a second one (which is the name of the resulted mailbox file); it creates a big .mbox file.

Next, KMail keeps the e-mails in /home/yourusername/.kde/share/apps/kmail/mail. Now, we want to create a mailbox for each of the folders you've had in KMail and you're interested in.

Suppose we want to create 5 mailboxes (according to the folders from KMail that you need to import into Evolution): "tech", "announcements", "tasks", "meetings" and "offtopic".

What you need to do is:

for email_folder in tech announcements tasks meetings offtopic ; do echo "=== $email_folder ===" ; find /home/yourusername/.kde/share/apps/kmail/mail/"$email_folder" -type f -exec ./ "{}" "$email_folder.mbox" ";" ; echo ; done

If the above long line looks unreasonable to you, it's because I wrote it like that in order to allow a simple copy/paste in a console. If you feel more comfortable with a proper formatting, here's how it would look like as a script:


# You need to do 2 things here:
# 1. replace the list "tech announcements tasks meetings offtopic"
# with the list of folders in *your* KMail instance;
# 2. replace "/home/yourusername" with the location of your home
# directory and the actual user name you have.

for email_folder in tech announcements tasks meetings offtopic
echo "=== $email_folder ==="
find /home/yourusername/.kde/share/apps/kmail/mail/"$email_folder" -type f -exec ./ "{}" "$email_folder.mbox" ";"

That's it. Now, go to Evolution: File >> Import... >> Forward >> select the "Import a single file" radio button >> Forward >> click on the "Filename" drop-down and navigate to the place you created your brand new .mbox files and select one of them >> if it's not already selected, select the "Berkeley Mailbox (mbox)" option from the "File type" drop-down >> Forward >> choose the destination folder (where the .mbox will be imported >> Forward >> click "Import".


  1. thanks a lot for tip. It works perfectly


  2. I haven't tried this, but seems to be promising:

  3. Cool, it's a good idea to automatize such tedious tasks. Thanks for pointing out the link.

    I won't be testing the Cross Mail scripts in the near future, though: I only used Gnome (with Evolution) for six months, and now I'm back to KDE.

  4. Tnx U are life saver

  5. Or you could boot off a KDE live distro and import the emails into Kmail and then save them as an mbox file on your drive.