Postfix supports 2 types of Mail Box formats
1. MBOX Format
2. MailDir Format
MBOX (/var/spool/mail/$user)
MBOX is the default storage method used in the Postfix. This is also the traditional Unix format to store the msgs. This appends the mails to a single file in sequential fashion. This file needs to be locked by any application for writing into it. In a high utilized servers there may be issues of locking and performance if you are using the MBOX format. Because only one application at a time is able to read and write the file same time. By default postfix delivers mail to the file object in the spool directory. (For Eg: For user root the MBOX file is /var/spool/mail/root). Most of the mail retrieving technologies such as imap and pop3 base servers are following this directory structure by default.
Spooling mails in same MBOX format to users home directory.
This will results the mail delivery in users home directory. There is a MAIL variable in users shell that defines the default location of the mails for the MUA. The following command shows the mail variable.
# echo $MAIL
# set |grep -i mail
Moving the MBOX to users home# set |grep -i mail
# vim /etc/postfix/main.cf
home_mailbox = Mailbox
# postfix reload
The default behavior of postfix is to spool the mail to the /var/spool/mail directory. By defining the home_mailbox postfix will delivers the mail to the users home directory. The file named "Mailbox" will be created by the Postfix daemon.home_mailbox = Mailbox
# postfix reload
Now change the mail variable for the user(recommended when localy installed MUA such as mutt, mail etc used).
# export MAIL=~/Mailbox
Make it permanent (following shows for bash shell)# vim /etc/bashrc
export MAIL=~/Mailbox
Now source the file and check the mail variableexport MAIL=~/Mailbox
# . /etc/bashrc
# echo $MAIL
Now the MUA will be able to get the mail from exact location.# echo $MAIL
Maildir
This is newer Unix standard to route the mail to a directory struchure. Maildir provides the superior scaling as well as "no locking issues".
Implementing Maildir
# vim /etc/postfix/main.cf
home_mailbox = Maildir/
# postfix reload
The above process will create a sub-directory in each users home directory called Maildir. Beneath this directory contains the structure that contains the msgs. Maildir is introduced by Qmail and recognized and supported by almost all the MUAs. Test sending a mail to any user in the system and trace the newly created directory inside the home.home_mailbox = Maildir/
# postfix reload
# ls ~/Maildir
cur
new
tmp
These are the three sub directories created by postfix. When a msg is spooled typically copied in to the "tmp" directory. "new" directory contains the unread mails. The mails containing in the directory "new" has a typical nomenclature for the identification of the msgs.cur
new
tmp
Eg:- 2214525412.v80osui654.destinedhost.
In the above file name the initial prefix (2214525412) is the unique identified that corresponds to the time after the epoc time 1970 (command "date +%s" shows the current epoc time). "v80osui654" is the identified added by postfix and followed by the destination host name of the mailbox."cur" (current) directory contains the read mails
The MAILDIR variable has to be set and MAIL variable has to be unset
# unset MAIL
# export MAILDIR=~/Maildir
The variable change need to be specified globally. if we are using any MUAs depends upon this variable, else the mails wont be able to process by MUAs.# export MAILDIR=~/Maildir
Set the variables globally
# vim /etc/bashrc
unset MAIL
export MAILDIR=~/Maildir
# . /etc/bashrc
unset MAIL
export MAILDIR=~/Maildir
# . /etc/bashrc