Dovecot Dictionary

 

 

 


Example Code

dict {
    ...
    lastlogin = mysql:/etc/dovecot/dovecot-last-login.conf
}

plugin {
  # last_login configuration
  last_login_dict = proxy::lastlogin
  last_login_key = last-login/%u/%d
  ...
}

# dovecot-last-login.conf

connect = host=127.0.0.1 port=3306 dbname=vmail user=vmail password=my_secret_password

map {
    pattern = shared/last-login/$user/$domain
    table = last_login
    value_field = last_login
    value_type = uint

    fields {
        username = $user
        domain = $domain
    }
}

SQL Dictionaries

lastlogin = mysql:/etc/dovecot/dovecot-last-login.conf

<sql driver>:<path to dict-sql config>

sql driver: "mysql", "pgsql", "sqlite" or "cassandra"

proxy:[<dict path>]:<destination dict>

Proxying is used to perform all dictionary accessing via the dict processes.

(The dict processes exist only if dict proxying is used.)

This is especially useful with backends where their initialization is relatively expensive, such as SQL.

dict path

If <dict path> is specified, it points to the socket where the dict server is answering.

(The default is to use $base_dir/dict)

If all users share a single UNIX UID (e.g. "vmail"),

you could make the dict socket accessible only to it:

service dict {
  unix_listener dict {
    mode = 0600
    user = vmail
  }
}

destination dict

The <destination dict> contains the dict name in the dict { .. } settings.

Plugin Setting

last_login_key = ...

SQL Connect String

connect = host=127.0.0.1 port=3306 dbname=vmail user=vmail password=my_secret_password

SQL mapping

It is done with a dict key pattern and fields.

Dovecot goes through all the maps and uses the first one whose pattern matches the dict key.

dovecot.conf

dict {
    quotadict = mysql:/etc/dovecot/dovecot-used-quota.conf
}

dovecot-used-quota.conf

connect = host=127.0.0.1 port=3306 dbname=vmail user=vmailadmin password=??????
map {
    pattern = priv/quota/storage
    table = used_quota
    username_field = username
    value_field = bytes
}
map {
    pattern = priv/quota/messages
    table = used_quota
    username_field = username
    value_field = messages
}

pattern

The dict key must match exactly "shared/last-login/$user/$domain"

The dict keys are hardcoded in the Dovecot code,

so depending on what functionality you're configuring you need to know the available dict keys used it.

private dict key ("priv/" prefix)

which means that there must be a username_field.

shared dict key ("shared/" prefix)

?

extra fields

dovecot.conf

# Default: "last_login_key = last-login/%u"
last_login_key = last-login/%u/%d

dovecot-last-login.conf

shared/last-login/$user/$domain

Typically the extra fields would be part of the primary key.