A user reports Apple Mail showing every message as unread, and folders appearing reshuffled. The cause is almost always Dovecot index corruption — the message store on disk is intact, but the index files Dovecot uses to track UIDs, flags, and sequence numbers got damaged (filesystem crash, disk full event, an interrupted reindex). The fix is to regenerate the index, but the regeneration changes UIDs unless you do it carefully, and that re-downloads everything on every client.
What’s happening
Dovecot keeps per-mailbox index files in /home/<user>/mail/<domain>/<user>/<folder>/dovecot.index* (or similar paths depending on cPanel version and maildir layout). The index maps every message in cur/ and new/ to a UID, a flag set, and a position. Clients cache messages by UID — when the index regenerates, UIDs may renumber, and clients re-download every message they thought they already had. On a 50GB mailbox with mobile clients, that’s a day of bandwidth and frustrated calls.
How to verify
Check the index health for a mailbox:
doveadm force-resync -u user@example.com -A
Without -A, runs on the inbox; with -A, all mailboxes. If Dovecot logs “Corrupted index file” or “Broken file header,” you have the diagnosis. Confirm with:
grep -i "corrupt\|broken" /var/log/dovecot.log | tail
The fix
-
Stop the user’s IMAP clients before touching indexes. If clients are connected during reindex, they get confused state. Have the user quit Mail and disable mobile sync.
-
Back up the affected indexes first. Copy
/home/<user>/mail/<domain>/<user>/<folder>/dovecot.index*to a safe place. If the regeneration loses data, you may need to compare. -
Run a controlled force-resync.
doveadm force-resync -u user@example.com 'INBOX' doveadm force-resync -u user@example.com '*'The second form rebuilds every mailbox.
-
Preserve UIDs if possible.
doveadm force-resynctries to preserve UIDs from the corrupted index when the data is readable. If the UIDs change, all clients re-download. Warn the user and schedule the work for off-hours. -
For severe corruption where force-resync fails, delete the dovecot.index files (the maildir’s
cur/andnew/directories are untouched), let Dovecot rebuild on next access. UIDs will renumber — accept the re-download cost.
For environments where mailbox integrity is part of the SLA, Stack Harbor monitors Dovecot index health and runs the recovery procedure under cPanel/WHM management.