dbox mail location
|Deletions are marked like this.||Additions are marked like this.|
|Line 23:||Line 23:|
|mail_location = maildir:~/Maildir }}}||mail_location = maildir:~/Maildir
|Line 28:||Line 29:|
|mail_location = mbox:~/mail:INBOX=/var/mail/%u }}}||mail_location = mbox:~/mail:INBOX=/var/mail/%u
|Line 30:||Line 32:|
|or if you'd like to use the [wiki:self:MailboxFormat/dbox dbox] format:||or if you'd like to use the [:MailboxFormat/dbox:dbox] format:|
|Line 33:||Line 35:|
|mail_location = dbox:~/dbox }}}||mail_location = dbox:~/dbox
- For mbox-specific settings, see ["MailLocation/Mbox"]
- For Maildir-specific settings, see ["MailLocation/Maildir"]
There are three different places where the mail location is looked up from:
mail_location setting in dovecot.conf is used if nothing else overrides it. This setting used to be called default_mail_env in Dovecot versions earlier than v1.0.rc11.
mail userdb [:UserDatabase/ExtraFields:extra field] overrides mail_location setting.
location setting inside namespaces overrides everything. Usually this should be used only for public and shared namespaces.
By default the mail_location setting is empty, which means that Dovecot attempts to locate automatically where your mails are. This is done by looking at ~/Maildir, /var/mail/username, ~/mail and ~/Mail in that order. It's usually a good idea to explicitly specify where the mails are, even if the autodetection happens to work. Autodetection commonly fails for new users who don't have the mail directory created yet.
You can use several variables in the mail_location setting. See ["Variables"] for a full list, but the most commonly used ones are:
%u: Full username.
%n: User part in user@domain, same as %u if there's no domain.
%d: Domain part in user@domain, empty if there's no domain.
Typically with Maildir it would be set to:
mail_location = maildir:~/Maildir
mail_location = mbox:~/mail:INBOX=/var/mail/%u
or if you'd like to use the [:MailboxFormat/dbox:dbox] format:
mail_location = dbox:~/dbox
Use only absolute paths. Even if relative paths would appear to work, they might just as well break some day.
You can use two different kinds of hashes in [:Variables:variables]:
%H modifiers returns a 32bit hash of the given string as hex. For example %2.2H would return max. 256 different hashes in range 00 .. ff.
%M returns a MD5 hash of the string as hex. This can be used for two level hashing by getting substrings of the MD5 hash. For example %1Hu/%2.1u/%u returns directories from 0/0/user to f/f/user.
Index files are by default stored under the same directory as mails. With maildir they are stored in the actual maildirs, with mbox they are stored under .imap/ directory. You may want to change the index file location if you're using ["NFS"] or if you're setting up [:SharedMailboxes:shared mailboxes].
You can change the index file location by adding :INDEX=<path> to mail_location. For example:
mail_location = maildir:~/Maildir:INDEX=/var/indexes/%u
The index directories are created automatically, but note that it requires that Dovecot has actually access to create the directories. Either make sure that the index root directory (/var/indexes in the above example) is writable to the logged in user, or create the user's directory with proper permissions before the user logs in.
If you really want to, you can also disable the index files completely by appending :INDEX=MEMORY.
INBOX path can be specified to exist elsewhere than the rest of the mailboxes, for example:
mail_location = mbox:~/mail:INBOX=/var/mail/%u mail_location = maildir:~/Maildir:INBOX=~/Maildir/.INBOX
Note that it's still not possible to mix maildir and mbox formats this way. You need to use [:Namespaces:namespaces] for that.
Having a home directory for users is highly recommended. Dovecot's [:LDA/Sieve:Sieve plugin] already requires a home directory to work, and it probably won't be the last feature to require a home. See ["VirtualUsers#homedirs"] for more reasons why it's a good idea, and how to give Dovecot a home directory even if you don't have a "real home directory".
If you really don't want to set any home directory, you can use something like:
mail_location = maildir:/home/%u/Maildir
Per-user mail locations
It's possible to override the default mail_location for specific users by making the [:UserDatabase:user database] return mail [:UserDatabase/ExtraFields:extra field]. See the [:UserDatabase:user database] page for the specific userdb you're using for more information how to do this. Below are however a couple of examples.
Note that %h doesn't work in the userdb queries or templates. ~/ gets expanded later, so use it instead.
user_query = SELECT home, uid, gid, mail FROM users WHERE user = '%u'
user_attrs = homeDirectory=home,uidNumber=uid,gidNumber=gid,mailLocation=mail
Mixing mbox and maildir
It's possible to use both mboxes and maildirs for the same user by configuring multiple namespaces. See ["Namespaces"].
Having both mboxes and maildirs mixed within the same namespace isn't currently supported.
Custom mailbox location detection
Dovecot by default detects the mailboxes in this order:
- maildir: ~/Maildir
- mbox: ~/mail, and /var/mail/%u if it exists
- mbox: ~/Mail, and /var/mail/%u if it exists
If you need something else, you can override the mail_executable setting to run a script, which sets the MAIL environment properly. For example:
if [ -d $HOME/.maildir ]; then export MAIL=maildir:$HOME/.maildir else export MAIL=mbox:$HOME/mail:INBOX=/var/mail/$USER fi # Finally execute the imap/pop3. If you use both, you'll need two scripts. exec /usr/local/libexec/dovecot/imap $*
NOTE: If you're using namespaces, the MAIL environment is ignored. You'll need to set NAMESPACE_1 (and maybe _2, _3, etc. for each namespace) instead.