Skip to content

Instantly share code, notes, and snippets.

@masnick
Last active August 21, 2022 19:48
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masnick/5239278 to your computer and use it in GitHub Desktop.
Save masnick/5239278 to your computer and use it in GitHub Desktop.

Proceed at your own risk. Back up. Don't blame anyone but yourself if you lose all your email or send your personal information to a nefarious third party.

Source: http://hynek.me/articles/fleeing-from-gmail/

  1. On a VPS to increase speed (I used a Digital Ocean VPS):

     wget http://imaputils.googlecode.com/svn-history/r5/trunk/imapcopy.pl
    
  2. Create a text file called map with the following contents:

     [Gmail]/Sent Mail:Sent Items
     [Gmail]/All Mail:Archive
    
  3. Using screen, open up some stunnels. In two separate windows (so both continue to run):

     stunnel -c -f -d 1143 -r imap.gmail.com:993 -P ''
     stunnel -c -f -d 1144 -r fastmail.fm:993 -P ''
    

Note that you may need to replace fastmail.fm with mail.messagingengine.com.

  1. In yet another screen window run the following, replacing the user-specific stuff as necessary (including an app-specific password if you're using 2-factor authentication for Google):

     perl imapcopy.pl \
       -S localhost:1143/your.google.name@gmail.com/google.password \
       -D localhost:1144/your@new.account/new.password \
       -M map -m "[Gmail]/All Mail,[Gmail]/Sent Mail"
    
  2. Wait. This may take several hours (I left it running all night for 55,000+ messages). When you're done, change your Google and FastMail passwords for security purposes (or delete your app-specific Google password).

@davidmytton
Copy link

I found that on my UK Gmail account, the folder prefix [Gmail] didn't work.

Number of mailboxes to process: 2
unexpected response: 1 NO [NONEXISTENT] Unknown Mailbox: [Gmail]/All Mail (Failure)
   [Gmail]/All Mail mailbox is empty
unexpected response: 1 NO [NONEXISTENT] Unknown Mailbox: [Gmail]/Sent Mail (Failure)
   [Gmail]/Sent Mail mailbox is empty

Instead, I had to change this to [Google Mail]

perl imapcopy.pl \
        -S localhost:1143/your.google.name@gmail.com/google.password \
        -D localhost:1144/your@new.account/new.password \
        -M map -m "[Google Mail]/All Mail,[Google Mail]/Sent Mail"

@lorenzhs
Copy link

I had to use stunnel3 on Debian unstable (the stunnel4 package contains both and defaults to 4, which couldn't parse the options) to get it to work, and use the [Google Mail] prefix, too (German account).

@saidaspen
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment