I recently signed up with ProtonMail — I wanted something secure, able to handle PGP encryption and with a nice webmail interface and Android app. After giving the free account a quick look, I upgraded to a paid account and moved two custom domains over. Everything was going great. Time to import my decade of emails into my ProtonMail account…

Table of contents

The import/export tool

Naturally I went and downloaded the import/export tool. Since there is, currently, no Linux version, I installed it on my virtual Windows 10 machine. I logged in with my ProtonMail account, clicked “Import from account” and signed in to my previous IMAP mail server. Everything was looking good, then I started the sync.

It looked good at first, then it just stopped — on message 175 of 9602. I waited for about 15 minutes before figuring out that it wasn’t going to keep going. I canceled and tried again. Same thing, it got a bit further, but not a lot. And annoyingly those 175 messages were now duplicated on my ProtonMail account.

The ProtonMail import tool just stopped at message 175

I sent an email to ProtonMail support, and after about a day and a half I got a reply;

Can you try importing the messages in smaller batches (folder by folder or set a specific import date) and let us know if it will work?

Hm, so since it stopped at message 175, maybe I should try batches of 150.

9602 messages
------------- ≈ 64 batches
150 per batch

Assuming that none of those batches fails of course. That solutions seemed very time-consuming and not practical at all.

The bridge

I have successfully moved emails between IMAP servers before, using imapsync. I figured I’d give that try. I downloaded the ProtonMail IMAP/SMTP bridge for Windows, I didn’t want to wait for beta access to the Linux bridge, and installed it on my virtual Windows 10 machine. Next I grabbed imapsync for Windows.

I logged into my ProtonMail account and used the IMAP credentials provided by the bridge to make a small bat script for imapsync. It looked something like this:

@imapsync ^
  --host1 imap.old-account.com --user1 my@email.com --password1 passw0rd ^
  --host2 127.0.0.1 --port2 1143 --user2 user@pm.me --password2 passw0rd ^
  --delete1

@PAUSE

Obviously you need to change these variables.

  • host1 is the IMAP server you want to import from
  • host2 is ProtonMail, the bridge will tell you all these values
  • delete1 will delete the message from host 1, when it has been successfully synced. This makes it a lot easier to restart the process should it fail. And any mail left after completion has not been synced correctly.

I put this script in the same folder as imapsync.exe and ran it. And it started syncing, without any issues 😄 It look a few hours, and in the end there were 18 messages that did not get synced. All due to either charset or mime errors.

Err 4/18: - msg INBOX/4223 {248550} could not append ( Subject:[Ordre], Date:["03-Sep-2017 20:02:01 +0200"], Size:[248550], Flags:[\Seen] )
    to folder INBOX: 2708 NO non-utf8 content without charset specification

Err 16/18: - msg INBOX/6975 {36071} could not append ( Subject:[], Date:["21-Feb-2018 13:50:15 +0100"], Size:[36071], Flags:[\Seen] )
    to folder INBOX: 4259 NO mime: duplicate parameter name

These emails were all left on my previous IMAP mail server, since the sync failed. I just left them, as they were not important.

Error: non-utf8 content without charset specification

I suspect the non-utf8 content without charset specification error might have something to do with the Content-Type header. The emails that got this error had Norwegian characters, without setting a charset in the Content-Type header. This article might shed some light on this: The Importance of Content-Type HTML Character Encoding in Email

I’ve had some mail correspondence with someone also having this problem, and according to him this works:

  • Export mail to .eml format
  • Edit it with with Notepad and change

from:

Content-Type: text/html
charset: ISO-8859-1

to:

Content-Type: text/html; charset="ISO-8859-1"
  • Import the message into ProtonMail using the import/export tool

For messages missing the Content-Type or charset headers completely — try adding them as shown above.

Ending notes

It looked like the message order was all screwed up in the ProtonMail Android app, but this turned out to be a caching issue and got resolved when I cleared the cache in the app. Seemed like it cached the order of the partially synced account, and did not update when newer emails were synced later on.

ProtonMail support did get back to me the next day, sounding much more interested in debugging and figuring out what was going wrong with the import/export tool. Unfortunately, having completed my migration I’m not sure I can be of much help now…

Some of my sent emails ended up in my inbox. This maybe because they were sent from an email address, and domain, which I am not using in ProtonMail. Not sure really.

Update, more errors migrating my wife’s email

When using imapsync to migrate my wive’s emails into ProtonMail I got a lot of this error:

malformed MIME header key: From 01020167a5c10cd2-e3f04633-9f69-48d5-9fc5-1a2b0b00484e-000000@eu-west-1.amazonses.com Thu Dec 13 05

Looking that the email source, I found that a lot of emails started with a From header, missing the colon. This makes the header invalid, just as the error stated. Furthermore I did find a correct From: header further down in the source. Not sure how that happened, but to remove it I used the regexmess option:

--regexmess "s/^From .*\n//"

This completely removed any lines starting with From. With this option I was able to copy all the malformed emails 😄

Last commit 2022-08-06, with message: add summary and emojies to older posts