Skip to content

Mailbox migration from cPanel to cPanel preserving flags and metadata

How to move a Dovecot mailbox between cPanel servers in a way that preserves Seen, Flagged, Deleted, Recent, and custom labels so the user does not see hundreds of "unread" messages on the new host.

A cPanel-to-cPanel mailbox migration that just copies the maildir is a partial migration. The messages move, but Seen, Flagged, Deleted, and any custom labels live in Dovecot’s index files — which are tied to UIDs and don’t transplant cleanly. After the cutover, the user opens their inbox and every message is marked unread. For a power user with thousands of messages, that’s a workday of re-classification. A proper migration preserves the flag state.

What’s happening

Maildir stores messages as files in cur/, new/, and tmp/ directories. Per-message flags are encoded in the filename (the :2,FRS suffix indicates Flagged, Recent, Seen). Dovecot also keeps an index that adds custom labels and tracks deletes. A naive rsync of the maildir preserves the on-disk flags but doesn’t transfer the Dovecot index — and on the new host, Dovecot rebuilds the index from the maildir, which works but loses custom labels and changes UIDs.

How to verify

Look at the source mailbox’s maildir layout:

ls -la /home/<user>/mail/<domain>/<user>/cur/ | head
ls /home/<user>/mail/<domain>/<user>/dovecot.* 2>/dev/null

Confirm whether the user has custom labels or flag patterns by spot-checking filenames — :2,RS means Recent+Seen, :2,FRS means Flagged+Recent+Seen, :2,a means custom keyword ‘a’.

The fix

  1. Use doveadm sync between the two cPanel hosts — it’s the supported, flag-preserving migration tool. From the destination host:

    doveadm sync -u user@example.com remote:imap://user@example.com:port

    This pulls the source mailbox and replicates flags, custom labels, and UIDs into Dovecot’s index on the new host.

  2. Configure the source mailbox to allow doveadm access (admin user with the right ACLs) or use IMAP credentials in the sync URL.

  3. Run a first sync while the source is live, then a delta sync during the cutover window. The delta picks up anything new since the first sync — minimizing the downtime.

  4. Verify on the new host by mounting the user’s account in a test mail client. Flags should be preserved. Custom labels should appear. UIDs may differ — for some clients that means a re-download, but the flags and labels survive.

  5. For very large mailboxes, consider a doveadm backup and doveadm restore pair instead of sync — those use Dovecot’s own dump format and are slightly faster for one-shot moves.

  6. Don’t use rsync alone for production-quality migration. It loses too much state. Save rsync for read-only archives and edge cases where you accept the loss.

For environments where mailbox-by-mailbox migration is part of a larger move and the flag preservation matters to power users, Stack Harbor runs the migration as part of migration projects.