Difference Between Mail in /var/mail vs /home/user/mail on Ubuntu

dovecotpostfixUbuntu

I have an Ubuntu server using Postfix and Dovecot to manage approx. 5 email accounts.

If I look in /var/mail, I can see one (large) file per email address. Looking at the contents of these files, they contain inbox messages only (i.e. not Sent mails, nor mails which have been manually sorted from the Inbox into other folders in Thunderbird (IMAP)).

If I look in e.g. /home/contact/mail, I can see the Sent and other folder mails (one file per mail folder), but no inbox.

Should the mails in /var/mail be sorted into /home/.... also? i.e. should /var/mail be normally empty?

At the moment, inbox mails appear to be in /var/mail, and other folder mails in /home/<user>/mail.

I'm trying to work out how to migrate to a new mail server (again Postfix + Dovecot) so would like to first understand what the different files are for.

Best Answer

The single big file for each user in /var/mail is known as an "mbox" file. It was the first (common) mailbox format, and whilst it's relatively simple, it suffers from any number of limitations -- including, as you've identified, that you can't (easily) have a hierarchy of mail folders, as mail clients (and more modern mail access protocols such as IMAP) have come to expect.

To address some of the limitations in the mbox format (mostly around concurrency safety and performance) the "Maildir" format was created, which is almost certainly what it under /home/<user>/mail. Whilst subfolders aren't actually part of the standard, it's a lot easier to support them using maildir, and so IMAP servers and the like tend to use that format by default.

As to how you should do the migration: to be perfectly frank, if what you've got at the moment is working, I wouldn't actually change the setup on the new server. You're as likely to make a huge mess and lose mail as you are to make anything better. Just duplicate the config onto the new server, copy across both /home and /var/mail, and be done with it. It's not that converting to all-Maildir is hard (it's how I've got my own mail server setup), or even "doing it properly" and going all-virtual (which is how I recommend doing it in any sort of professional capacity), it's just a change, and change, along with assumption, is the mother of all outages.