I'm migrating my mails from an old server to a new one, the configuration is good (mysql virtual accounts & imap only), with dovecot and postfix. It's already running for other users, I just want to merge old accounts from the old server to the new one.

The migration went fine, I just wanted to know how I could "show" all the old mails in UA Clients. I mean, is there any dovecot index file or such that could be re-created, destroyed, so that all old mails are "flagged" as new ?

  • Are you using mbox or maildir format for the email store?
    – Paul
    Jan 31, 2012 at 22:23
  • Actually maildir Jan 31, 2012 at 22:25

4 Answers 4


Maildir actually uses a unique format that makes this quite easy. Simply place the mail in new/ directory inside the mail users mailroot if you want it to show up as new. Otherwise it goes in the cur/ directory.

  • 1
    Is the ,S flag appended to the file name that makes the Seen status for IMAP and POP3. cur and new folders are kept only for efficiency matters Oct 20, 2015 at 20:44
  • I suppose it depends on the MUA implementation but as I understand it (admittedly not having read the source for Dovecot) is that flags such as S are not read when emails are in new/ and are instead added when the MUA moves the file from new/ to cur/. I've not come across anything that considers these two directories as vestigial; every Maildir implementation I've run into uses them. See: cr.yp.to/proto/maildir.html
    – Garrett
    Oct 21, 2015 at 0:29
  • 1
    while all these comments re:filenames+folder-structure are pretty valid, they're not universally true - from one dovecot to the next it went from ".Sent" to "Sent" (no dot) for our setups. dovecot import and dovecot sync should be more robust solutions. See my answer @ serverfault.com/a/866298/300859
    – flowtron
    Aug 1, 2017 at 14:51

I tried the accepted answer and it failed - the dovecot versions in play are probably too far apart and we also switched the underlying MTA. So here is a more robust solution: doveadm import

Assuming you're hosting emails for the domain hosted.tld and an account exists for the login [email protected] (or maybe simply ruth) and the backup from the previous server is in MailDir format and available inside a folder structure like /tmp/TRANSFER/domain/account/Maildir then you can import them to your new dovecot hosting with

$ doveadm import -u [email protected] maildir:/tmp/TRANSFER/hosted.tld/local.account/Maildir "" all

more generally speaking:

$ doveadm import -u LOCAL_USER FORMAT:PATH "" all

All of which can be gleened from the fine manual. It took two tries to find out simply using "" (empty destination mailbox) was what we really wanted ;-)

You may even have more luck than us without needing to transfer the files beforehand - if old and new server are running at the same time and your accounts are set up appropriately using doveadm sync.

  • I know this is a while ago but.. do you know how to specify a root level destination folder other than "INBOX" (i.e. "")? If I try "Test" it automatically gets appended with ".INBOX". So the destination folder is ".Test.INBOX" and in the UI (Roundcube) I get a folder hierarchy: Test -> INBOX. I was just hoping for Test!!
    – racitup
    Jun 13, 2022 at 0:25
  • For anyone else, since the mails were already in Maildir format, I ended up just moving the folder to ".Test" in the users mailbox and 'chown -R mail:mail' ing the destination
    – racitup
    Jun 13, 2022 at 0:36

For Maildir messages, such flags are stored in the file name. For example:


The letters FS after the comma mean Flagged and Seen. To mark the message as "unseen", either remove the S flag...

for msg in maildir/cur/*; do
    mv -v "$msg" "$msgbase,$flags"

...or simply throw the messages into the new folder:

mv maildir/cur/* maildir/new/
  • Thank you for your answer, but Garret & Paul answered right before you ! ;) Jan 31, 2012 at 22:48
  • 1
    Deserves a +1 just because of the nifty BaSH-ery! :)
    – Garrett
    Jan 31, 2012 at 23:00

The Maildir format consists of a series of directories - matching the IMAP folder structure, within which are the emails, one file per email.

In order to copy emails from one email system to another, you can simply copy the directories and files, and ensure the permissions for those directories and files are correct at the destination.

The Maildir structure looks like this:


This shows the INBOX folder (cur, new, tmp) and another folder called "personal". Note the dot prefix showing that this folder is hidden, so this should be accounted for in your transfer.

The new folder contains any emails that have not been seen by a client, and the cur folder contains current emails. The tmp folder should be empty if the mail server is not operating.

  • 1
    @grawity - just so you are aware, the actual name of the mail directory varies across distributions - I used the placeholder "Maildir" to signify the maildir folder, not necessarily that it is called that (I should have noted this of course, and incidentally, on some of my mail servers it actually is Maildir)
    – Paul
    Jan 31, 2012 at 23:20
  • @Paul: Many configurations do call it "Maildir", which often causes confusion -- people think that Maildir-format mailboxes are always located in ~/Maildir, or they don't know when someone is talking about the path versus the format... that's the reason why I changed your example. (On the second thought, I probably shouldn't have.) Jan 31, 2012 at 23:37
  • @grawity No, hang on, you are right - I generally have mailboxes in ~ but this is definitely not always the case and I didn't consider that. The edit makes sense.
    – Paul
    Jan 31, 2012 at 23:45
  • After playing with files remember to delete dovecot-uidlist and courierimapuiddb files otherwise mail clients won't see changes inmediately Oct 21, 2015 at 15:56
  • Just make sure file permissions / owner:group match
    – Bogdan
    Feb 26, 2020 at 13:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .