updated: Evolution to IMAP

Hi guys,

as you might noticed, I’m a little bit pissed about Evolution. I’ve tried some e-mail clients and found Claws Mail an useful alternative. Migrating an local stored mbox based maildir is a god damn pain in the ass. It is even worst if you try it manualy.

Good news again, I’ve found a cool python script, which allows you to upload a mbox file to an IMAP box. The tool can be found here. To give you a little “startup” I’ll give you some examples:

Usage: python imap_upload.py [options] MBOX [DEST]

Will upload the mbox file MBOX to the INBOX IMAP box. The default destination is the INBOX.

To upload a mbox file located in ~/.local/share/evolution/mail/local/ (evolutions’ default location) you need to provide the path like this:

python imap_upload.py ~/.local/share/evolution/mail/local/<em><mbox file></em> [<em>targetfolder</em>]

Where <mbox file> is the mbox (e.g. inbox, draft, sent etc.) and targetfolder is the optional targetfolder. If you prefer a secure connection you should add a –ssl as option.

python imap_upload.py --ssl ~/.local/share/evolution/mail/local/<em><mbox file></em> [<em>targetfolder</em>]

If you do not enter any more information the script will ask you for:

  • server
  • login
  • pass

You should consider to pass these information to the script like this:

python imap_upload.py --ssl --host=mail.example.com --user=MeMySelfAndI --pass=MySecretPassWord ~/.local/share/evolution/mail/local/<em><mbox file></em> [<em>targetfolder</em>]

I passed these parameters to imap_upload.py:

  • –ssl
    use SSL
  • –host
    passes the host to the script
  • –user
    passes the username to the script which should be used to log-in
  • –box
    passes the destionation / target box on the IMAP server

All in all it looked like this (uploading my inbox – mbox – file to the INBOX box on the IMAP server):

python imap_upload.py --ssl --host=mail.example.com --user=MeMySelfAndI --pass=MySecretPassWord --box=INBOX ~/.local/share/evolution/mail/local/inbox

Well, this took a huge amount of time. My inbox contained more the 5000 mails of a decade.
I’ve read a little about IMAP, which was very interesting (if you like you can find the rfc right here). One thing was very critical for my project. IMAP supports two types of boxes:

  • mail boxes (non-inferior)
    boxes which cannot contain other boxes, but can contain mails
  • “folder” boxes
    boxes which can contain inferior boxes, but cannot contain mails

I’ve checked my local folders and found some conflicts. I’ve mixed these types and needed to change them. The most annoying fact was that the INBOX does not allow sub folders.

My current local mail dir contains round about 93 mbox files. As you might imagine, I don’t want to create them one by one. I’ve written a script therefore, which will loop through my local mbox store and list all my mbox files in hierarchical order and configures the imap_upload.py script to upload the mbox to the folder. In order to do this, I’ve needed to create the corresponding boxes on the IMAP server.

I’ve used python, a cool, very powerful language to communicate with my IMAP server. Python comes with a lot of libs, one of them the so called imaplib.

A very simple example is given here. In order to create an IMAP box, you just need to do a imap.create(‘boxname‘). You can pass a box hierarchy to the create method, like this:

imap.create('<em>top/c1/c2</em>')

(Note: my IMAP server is provided by my ISP and uses a slash as delimiter, most examples use a period as delimiter)

You can download my script here. You’ll need to modify the script in the declaration part. As you might see, I’m not that familiar with python and did a lot of dirty stuff.

server_hostname = 'mail.example.com'
server_user = 'username'
server_password = 'password'
 
evolution_rootdir = '~/.local/share/evolution/mail/local'
 
imap_rootdir = 'imported' # use something else than 'INBOX'
imap_delimiter = '/'
imap_use_SSL = True

The variables are named -more or less- after their function. Change your imap_delimiter to the corresponding delimiter of your IMAP server.

The script is provided “AS-IS” and I don’t take responsibility for any damages done by this script!

Requirements:

  • imap_upload.py
    please copy the script to the same location as my script
  • >= python2.6

Download my script here.

This entry was posted in Gentoo, misc, python, updated and tagged , , , , , . Bookmark the permalink.

Leave a Reply