Bulk move local messages and folders to a server

emailimapmail.app

I'm helping a friend migrate his email off of a Macbook and onto an imap server. I've created an imap account on a server to hold the emails.

Is there a way to bulk-copy the contents of local folders ("On My Mac") to the imap server? My friend has folders within folders. Something like this:

  • House
    • message
    • message
    • message
    • Plumbing
      • message
      • message
      • Bills
        • message
      • message
    • Electrical
      • message
      • message
  • Vacation
    • message
    • message
    • Schedules
      • message
      • message
  • Jokes
    • message
    • message

and so forth. Probably around 50 top-level folders and I have no idea how many subfolders. 2G of email total.

I want to bulk-copy the entire lot to a server so he can access them from his iPad instead. Let's assume he won't be accessing the local folders on his Mac once we get this figured out.

Can this be done, or are we doomed to create the folders one by one and then copy the individual emails?


More information as I experimented:

The server is Dovecot

I was transferring folders to the server by simply dragging them within Mail.app. This worked fine in most cases.

Some piece of software in the chain doesn't like dots in folder names, so the folder "Dr.Who" got changed to "Dr" with the subfolder " Who" and then errors occurred. After I spent some time searching for folders with '.' in their names, and renaming them, things went better.

Sometimes when I dragged a folder that contained both messages and subfolders, it went smoothly. Sometimes the top-level folder would be empty and would not allow messages to be stored in it. When that happened, I could look around and find the folder named "folder (Messages)" which contained the missing messages. I would then be able to recombine the two folders and rename and I'd be good.

Mail.app really needs a "sort folders alphabetically" function. I found that I could do this manually by quitting Mail, deleting .mboxCache.plist, and restarting Mail.

The imap-upload tool would have been perfect for my needs if it had worked. I might look into debugging it.

I'll leave the question open for a while to see if anybody finds a real answer.


One more data point: as an experiment, I tried creating the subfolder "Dr. Who" from Thunderbird instead of Mail.app. It created the folder "Dr" with the subfolder " Who". I believe Mail.app uses dots as subfolder specifiers when talking to an IMAP server, but uses slashes for folders on the local system. Thus, a folder name with a dot in it is perfectly acceptable for a local folder, it causes issues when pushed to an IMAP server.

Best Answer

Informational post.

So … I've been reading up on the IMAP protocol. It seems to me that IMAP doesn't really have a formal concept of subfolders. If you want to name one mailbox "House" and another one "House.Plumbing", that's entirely up to you. It just happens that Mail.app, and probably many other email clients choose to present these folders to you in a hierarchical form.

That also explains why I encountered some higher-level folders that wouldn't accept any messages — if you were to create, e.g. "House.Plumbing" but not "House", Mail.app would show you the un-writable virtual folder "House" with the subfolder "Plumbing". But as far as the IMAP server is concerned, it's just a folder named "House.Plumbing".

(This isn't to say that the IMAP server itself won't store the folders in a hierarchical way, but the standard doesn't say either way, AFAIK.)