4

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 ?

migrated from superuser.com Feb 15 '12 at 12:14

This question came from our site for computer enthusiasts and power users.

  • Are you using mbox or maildir format for the email store? – Paul Jan 31 '12 at 22:23
  • Actually maildir – lovethebomb Jan 31 '12 at 22:25
1

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.

  • 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 – Marco Marsala Oct 20 '15 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 '15 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 '17 at 14:51
4

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

1328040798.M558634P29803.equal,S=17876,W=18294:2,FS

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
    msgbase=${msg%,*}
    flags=${msg##*,}
    flags=${flags//S/}
    mv -v "$msg" "$msgbase,$flags"
done

...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 ! ;) – lovethebomb Jan 31 '12 at 22:48
  • 1
    Deserves a +1 just because of the nifty BaSH-ery! :) – Garrett Jan 31 '12 at 23:00
4

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 local.account@hosted.tld (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 local.account@hosted.tld 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.

3

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:

mail/cur/
mail/new/
mail/tmp/
mail/.personal/cur/
mail/.personal/new/
mail/.personal/tmp/

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 '12 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.) – grawity Jan 31 '12 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 '12 at 23:45
  • After playing with files remember to delete dovecot-uidlist and courierimapuiddb files otherwise mail clients won't see changes inmediately – Marco Marsala Oct 21 '15 at 15:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.