Posts Tagged IMAP

Migrate Gmail to Gmail

If you created a new Gmail account and wished you could migrate all your mail from an old Gmail account across, or if you yearned to make a seamless switch from Gmail to Google Apps, then this will provide a solution for you.

The Solution: imapsync

This method uses imapsync and preserves labels and mail, including Sent items. imapsync is available in many linux distributions.

You must have enabled IMAP access on both your source and destination Gmail accounts. If you have enabled the IMAP-Controls feature in Gmail labs you must ensure all labels have been tagged “Show in IMAP”

This script will sync all labels and mail from user1 to user2. The process is done in two steps, first all labels are created, then the mail is copied. Mail from Trash and Spam is excluded.

It requires you have your passwords in $HOME/.imap/passfile1 and passfile2 for authentication.

#!/bin/bash
 
user1='username1@gmail.com'
user2='username2@gmail.com'
 
# escape the @ symbols
user1e=${user1//@/\\@}
user2e=${user2//@/\\@}
 
# Create folders/labels first
imapsync --host1 imap.gmail.com \
--port1 993 --user1 "$user1" \
--passfile1 $HOME/.imap/passfile1 --ssl1 \
--host2 imap.gmail.com \
--port2 993 --user2 "$user2" \
--passfile2 $HOME/.imap/passfile2 --ssl2 \
--syncinternaldates --split1 100 --split2 100 \
--authmech1 LOGIN --authmech2 LOGIN \
--exclude "\[Gmail\].*" \
--justfolders --nofoldersizes
 
# Sync mail, only copy new items
imapsync --host1 imap.gmail.com \
--port1 993 --user1 "$user1" \
--passfile1 $HOME/.imap/passfile1 --ssl1 \
--host2 imap.gmail.com \
--port2 993 --user2 "$user2" \
--passfile2 $HOME/.imap/passfile2 --ssl2 \
--syncinternaldates --split1 100 --split2 100 \
--authmech1 LOGIN --authmech2 LOGIN \
--useheader "Message-ID" --skipsize --allowsizemismatch \
--exclude "\[Gmail\]\/Spam|\[Gmail\]\/Trash" \
--regexmess "s/Delivered-To: $user1e/Delivered-To: $user2e/g"

References

Gmail to Google Apps Email Migration

Migrate email from Gmail to Google Apps

Other Options

Gmail-Backup (not tested)

Python migration script (not tested)

Tags: , , , ,

Deleting in Gmail IMAP

Getting “Delete” to work as expected in Gmail IMAP was surprisingly complicated.

The default action when a client deletes a message is to archive it (ie: move it to “All Mail”). I didn’t like this because then if I accessed the account from POP the deleted mail would still be downloaded.

Recommended IMAP settings tells you all the things NOT to do, but doesn’t give any useful advice on how to setup clients.

Eventually after trying many different settings I realised the simplest method was to tell the client to MOVE the message to the Gmail Trash folder when it is deleted. To do this in Thunderbird2 required manually editing the prefs.js file to specify a custom IMAP trash folder:

user_pref("mail.server.server#.trash_folder_name", "[Gmail]/Trash");

Note that the case of the trash folder name IS important.

Tags: , , ,