Got Your Back (GYB) is a command line tool for backing up your Gmail messages to your local computer. It uses the standard IMAP protocol but also takes advantage of some custom Gmail IMAP extensions.
Here’s how I used it to move all my email messages from one gmail account to another one.
Download it from here:
Put it in your home folder in a filder called gyb.
python gyb.py --email firstname.lastname@example.org --action estimate
tells you what it will do
python gyb.py --email email@example.com --action backup
backs it all up, mine took 8GB
python gyb.py --email firstname.lastname@example.org --action restore --local-folder GYB-GMail-Backupemail@example.com --label-restored "old"
restores it from backup to a different google account and puts a label on it all called ‘old’