Content from 2012-03
Why, oh why?
Using IMAP, of course. There's a couple of articles on the web describing how to do that, but they all have one problem. They tell you to copy your emails from the "All Mail" folder in the gmail account, which means that you will lose all your labels, and that's probably not acceptable for someone with thousands of conversation threads all placed in the boxes they belong to. I have written a couple of python scripts that should help solving this problem. You can get them from github. Remember: You use them at your own risk. Read on, if you want to know what they do.
Problem with labels
There are some issues with labels when accessing gmail through IMAP. Since the labels are mapped to the IMAP folders, you might, at first, expect that, when you open the folder and browse it, you will see all the emails in all the conversations bearing the label. This is not true. GMail operates and labels things at the level of conversations, IMAP, however, operates at the level of messages, so you will only see the messages that were part of the conversation when you assigned the label but not the new ones. This makes some sense if you use gmail with a normal IMAP client, ie. you don't see the same new messages arriving in many folders, an you avoid having the archived messages back in the IMAP inbox when somebody responds to a message in an archived conversation.
This is a real problem when you'd like to move your nicely sorted conversations out of gmail to some other service. There is a suggestion at the Google Product Forums on how to deal with it: you should go to the web browser, open the conversation, remove the label, and then re-apply it. It's not really a viable solution if you have more than a couple of conversations, fortunately Google provides an API that will enable us to do that auto-magically.
This is what the gmail_label_remap.py does, it finds every conversation and re-applies the labels. You should see something like this when you run it from your terminal:
]==> ./gmail_label_remap.py username (won't be echoed): password (won't be echoed): [i] Identify the IMAP folder name for "All Mail"... [i] Done: [Gmail]/Tous les messages [i] Opening [Gmail]/Tous les messages [i] [Gmail]/Tous les messages contains 15299 messages [i] Identify all the threads (may take some time) [i] Found 4182 threads [i] Processing thread 4182 of 4182 [i] Orphaned threads: 414 [i] Sent only threads: 255 [i] ALL DONE
It will create two extra labels:
- orphaned - for the conversations without labels
- sent_only - for the emails that you have sent but got no answer to them, so they have no assigned label
Moving emails to a different IMAP account
Now that all the label issues are sorted out, you need to copy the emails. You may use an IMAP client of your preference, or the imap_copy.py script. Using the script you may get the list of all your IMAP folders:
]==> ./imap_copy.py --list --source=imap.gmail.com:993 imap.gmail.com's username (won't be echoed): imap.gmail.com's password (won't be echoed): Fun (1641) INBOX (114) Private (484) Work (1010) [Gmail]/Brouillons (0) [Gmail]/Corbeille (563) [Gmail]/Important (5204) [Gmail]/Messages envoy&AOk-s (4440) [Gmail]/Spam (16) [Gmail]/Suivis (59) [Gmail]/Tous les messages (14736)
It will also let you copy the messages from one IMAP account to another:
]==> ./imap_copy.py --copy=INBOX.gmail-inbox,Fun \ --source=imap.gmail.com:993 \ --destination=imap.somewhere.else:993 imap.gmail.com's username (won't be echoed): imap.gmail.com's password (won't be echoed): imap.somewhere.else's username (won't be echoed): imap.somewhere.else's password (won't be echoed): Copying INBOX => gmail-inbox Copying 114 of 114 Copying Fun => Fun Copying 1641 of 1641 ALL DONE
What you specify after the 'equal' sign of the --copy parameter is a comma separated list of folders. It may just be a folder name, like Fun in the example above. Or something like: INBOX.gmail-inbox which will take the INBOX folder at the source and copy its contents to the gmail-inbox folder at the destination.
For the time being I will use KMail for e-mails and Psi for jabber, they are pretty decent, but I liked having everything (conversation history, settings, contacts) in one place on the web, so I will probably look for, or help developing, a solution that will give me all that and more. RoundCube looks promising.
Edit 28-04-2012: Continuation post has been added.