Following an outage, I've ended up with 2 mailboxes for each of my users, on separate machines. I've shut the interim machine down now, and put the mailboxes on the real server in /srv/scratch/$username/Maildir/...
, and need to integrate the messages from them, ideally preserving read/seen state, into the users' canonical mailboxes, /srv/mail/$username/Maildir/...
. I have no preference for whether this is as a sub-folder, or in their main inbox, however I am confident none of the temporary mailboxes contain sub-folders themselves. (If they do, more fool the users, who were explicitly told not to do this on the temporary accounts!)
Is there a good way to do this which minimises risk of loss of mail, and means their clients will automatically pick up the new folder/messages (whichever it needs to be) when they reconnect? Alternatively, what do I need to do to tell Dovecot about the new messages after dumping them into the Maildirs?
Both servers were built using Exim4 for delivery and Dovecot for IMAP.
I'd script moving the files into place using almost the Maildir delivery specification, which involves using the tmp/ dir and then renaming into the new/ dir, but for this you'd rename into the cur/ or new/ dir, depending upon where the original file was.
Given that the filenames embed timestamps, you should have very few (zero) collisions, but paranoia is good. Write the file into tmp/; if this was a cur/ file, save away the state suffix outside the filename; whether moving to new/ or cur/ check both for existence of the same name in new/ or the same prefix in cur/; then rename as appropriate.
Be careful not to lose the suffix on the cur/-in-tmp/ through a memory crash; a logfile journal of all actions taken will help you reconstruct if something goes wrong.