This documentation is for Dovecot v2.x, see wiki1 for v1.x documentation.
Differences between revisions 1 and 31 (spanning 30 versions)
Revision 1 as of 2005-03-05 20:24:41
Size: 1998
Editor: TimoSirainen
Comment:
Revision 31 as of 2008-02-20 10:01:52
Size: 5065
Editor: ns1
Comment: small bug
Deletions are marked like this. Additions are marked like this.
Line 3: Line 3:
In configuration file the default mail location is set using `default_mail_env` setting.  * For mbox-specific settings, see ["MailLocation/Mbox"]
 * For Maildir-specific settings, see ["MailLocation/Maildir"]
Line 5: Line 6:
You can use some variables in the value: There are three different places where the mail location is looked up from:
Line 7: Line 8:
 * %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
 * %h - home directory
 1. {{{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.
 1. {{{mail}}} userdb [:UserDatabase/ExtraFields:extra field] overrides {{{mail_location}}} setting.
 1. {{{location}}} setting inside namespaces overrides everything. Usually this should be used only for public and shared namespaces.
Line 12: Line 12:
In 1.0-test versions there are more, see [wiki:Variables Variables]. 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.
Line 14: Line 14:
Typically with maildir this would be set to: 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.
 * `%h`: Home directory. ~/ works also.

Typically with Maildir it would be set to:
Line 17: Line 24:
default_mail_env = maildir:%h/Maildir
}}}
mail_location = maildir:~/Maildir }}}
Line 23: Line 29:
default_mail_env = mbox:%h/mail:INBOX=/var/mail/%u mail_location = mbox:~/mail:INBOX=/var/mail/%u }}}

Use only absolute paths. Even if relative paths would appear to work, they might just as well break some day.

[[Anchor(indexfiles)]]
== Index files ==

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
Line 26: Line 44:
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 can change these by adding `:INDEX=location` to location string. For example: 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}}}.

== Homeless users ==

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:
Line 29: Line 55:
default_mail_env = mbox:%h/mail:INBOX=/var/mail/%u:INDEX=%h/indexes 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.

=== SQL ===

{{{
user_query = SELECT home, uid, gid, mail FROM users WHERE user = '%u' }}}

=== LDAP ===

{{{
user_attrs = homeDirectory=home,uidNumber=uid,gidNumber=gid,mailLocation=mail }}}

=== Passwd-file ===

{{{
user:{PLAIN}password:1000:1000::/home/user::userdb_mail=mbox:~/mail:INBOX=/var/mail/%u }}}

== 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:

 1. maildir: ~/Maildir
 1. mbox: ~/mail, and /var/mail/%u if it exists
 1. 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:

{{{
#!/bin/sh

if [ -f $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
Line 32: Line 107:
If you didn't set home directory, %h can't be used. Instead you can do something like:

{{{
default_mail_env = maildir:/home/%u/Maildir
}}}

With virtual users the mail and home directories are probably the same. In that case you would just do:

{{{
default_mail_env = maildir:%h
}}}

= Per-user mail locations =

It's possible to override `default_mail_env` for specific users in authentication userdb.

== SQL ==

Return `mail` field in `user_query`, for example:

{{{
user_query = SELECT home, uid, gid, mail FROM users WHERE user = '%u'
}}}

== LDAP ==

Specify mail attribute in `user_attrs`, for example:

{{{
user_attrs = uid,homeDirectory,mailLocation,,uidNumber,gidNumber
}}}

== passwd-file ==

The mail attribute is set as last field in passwd-file, for example:

{{{
user:{PLAIN}password:1000:1000::/home/user:/bin/false::mbox:%h/mail:INBOX=/var/mail/%u
}}}

= Mixing mbox and maildir =

With 1.0-tests it's possible to use both mboxes and maildirs for same user with namespaces. See [wiki:Namespaces Namespaces].
'''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.

Mail location

  • 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:

  1. 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.

  2. mail userdb [:UserDatabase/ExtraFields:extra field] overrides mail_location setting.

  3. 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.

  • %h: Home directory. ~/ works also.

Typically with Maildir it would be set to:

mail_location = maildir:~/Maildir 

or with mbox:

mail_location = mbox:~/mail:INBOX=/var/mail/%u 

Use only absolute paths. Even if relative paths would appear to work, they might just as well break some day.

Anchor(indexfiles)

Index files

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.

Homeless users

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.

SQL

user_query = SELECT home, uid, gid, mail FROM users WHERE user = '%u' 

LDAP

user_attrs = homeDirectory=home,uidNumber=uid,gidNumber=gid,mailLocation=mail 

Passwd-file

user:{PLAIN}password:1000:1000::/home/user::userdb_mail=mbox:~/mail:INBOX=/var/mail/%u 

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:

  1. maildir: ~/Maildir
  2. mbox: ~/mail, and /var/mail/%u if it exists
  3. 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 [ -f $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.

None: MailLocation (last edited 2019-09-11 14:05:46 by MichaelSlusarz)