1# SQL-indexed storage23The imapsql module implements database for IMAP index and message4metadata using SQL-based relational database.56Message contents are stored in an "blob store" defined by msg_store7directive. By default this is a file system directory under /var/lib/maddy.89Supported RDBMS:10- SQLite 3.25.011- PostgreSQL 9.6 or newer12- CockroachDB 20.1.5 or newer1314Account names are required to have the form of a email address (unless configured otherwise)15and are case-insensitive. UTF-8 names are supported with restrictions defined in the16PRECIS UsernameCaseMapped profile.1718```19storage.imapsql {20 driver sqlite321 dsn imapsql.db22 msg_store fs messages/23}24```2526imapsql module also can be used as a lookup table.27It returns empty string values for existing usernames. This might be useful28with `destination_in` directive e.g. to implement catch-all29addresses (this is a bad idea to do so, this is just an example):30```31destination_in &local_mailboxes {32 deliver_to &local_mailboxes33}34destination example.org {35 modify {36 replace_rcpt regexp ".*" "catchall@example.org"37 }38 deliver_to &local_mailboxes39}40```414243## Arguments4445Specify the driver and DSN.4647## Configuration directives4849### driver _string_50**Required.**<br>51Default: not specified5253Use a specified driver to communicate with the database. Supported values:54sqlite3, postgres.5556Should be specified either via an argument or via this directive.5758---5960### dsn _string_61**Required.**<br>62Default: not specified6364Data Source Name, the driver-specific value that specifies the database to use.6566For SQLite3 this is just a file path.67For PostgreSQL: [https://godoc.org/github.com/lib/pq#hdr-Connection\_String\_Parameters](https://godoc.org/github.com/lib/pq#hdr-Connection\_String\_Parameters)6869Should be specified either via an argument or via this directive.7071---7273### msg_store _store_74Default: `fs messages/`7576Module to use for message bodies storage.7778See "Blob storage" section for what you can use here.7980---8182### compression `off`<br>compression _algorithm_<br>compression _algorithm_ _level_83Default: `off`8485Apply compression to message contents.86Supported algorithms: `lz4`, `zstd`.8788---8990### appendlimit _size_91Default: `32M`9293Don't allow users to add new messages larger than 'size'.9495This does not affect messages added when using module as a delivery target.96Use `max_message_size` directive in SMTP endpoint module to restrict it too.9798---99100### debug _boolean_101Default: global directive value102103Enable verbose logging.104105---106107### junk_mailbox _name_108Default: `Junk`109110The folder to put quarantined messages in. Thishis setting is not used if user111does have a folder with "Junk" special-use attribute.112113---114115### disable_recent _boolean_116Default: `true`117118Disable RFC 3501-conforming handling of \Recent flag.119120This significantly improves storage performance when SQLite3 or CockroackDB is121used at the cost of confusing clients that use this flag.122123---124125### sqlite_cache_size _integer_126Default: defined by SQLite127128SQLite page cache size. If positive - specifies amount of pages (1 page - 4129KiB) to keep in cache. If negative - specifies approximate upper bound130of cache size in KiB.131132---133134### sqlite_busy_timeout _integer_135Default: `5000000`136137SQLite-specific performance tuning option. Amount of milliseconds to wait138before giving up on DB lock.139140---141142### imap_filter { ... }143Default: not set144145Specifies IMAP filters to apply for messages delivered from SMTP pipeline.146147Ex.148149```150imap_filter {151 command /etc/maddy/sieve.sh {account_name}152}153```154155---156157### delivery_map _table_158Default: `identity`159160Use specified table module to map recipient161addresses from incoming messages to mailbox names.162163Normalization algorithm specified in `delivery_normalize` is appied before164`delivery_map`.165166---167168### delivery_normalize _name_169Default: `precis_casefold_email`170171Normalization function to apply to email addresses before mapping them172to mailboxes.173174See `auth_normalize`.175176---177178### auth_map _table_179**Deprecated:** Use `storage_map` in imap config instead.<br>180Default: `identity`181182Use specified table module to map authentication183usernames to mailbox names.184185Normalization algorithm specified in auth_normalize is applied before186auth_map.187188---189190### auth_normalize _name_191**Deprecated:** Use `storage_map_normalize` in imap config instead.<br>192**Default**: `precis_casefold_email`193194Normalization function to apply to authentication usernames before mapping195them to mailboxes.196197Available options:198199- `precis_casefold_email` PRECIS UsernameCaseMapped profile + U-labels form for domain200- `precis_casefold` PRECIS UsernameCaseMapped profile for the entire string201- `precis_email` PRECIS UsernameCasePreserved profile + U-labels form for domain202- `precis` PRECIS UsernameCasePreserved profile for the entire string203- `casefold` Convert to lower case204- `noop` Nothing205206Note: On message delivery, recipient address is unconditionally normalized207using `precis_casefold_email` function.208