1# Configuration files syntax23**Note:** This file is a technical document describing how4maddy parses configuration files.56Configuration consists of newline-delimited "directives". Each directive can7have zero or more arguments.89```10directive011directive1 arg0 arg112```1314Any line starting with # is ignored. Empty lines are ignored too.1516## Quoting1718Strings with whitespace should be wrapped into double quotes to make sure they19will be interpreted as a single argument.2021```22directive0 two arguments23directive1 "one argument"24```2526String wrapped in quotes may contain newlines and they will not be interpreted27as a directive separator.2829```30directive0 "one long big31argument for directive0"32```3334Quotes and only quotes can be escaped inside literals: \\"3536Backslash can be used at the end of line to continue the directve on the next37line.3839## Blocks4041A directive may have several subdirectives. They are written in a {-enclosed42block like this:43```44directive0 arg0 arg1 {45 subdirective0 arg0 arg146 subdirective1 etc47}48```4950Subdirectives can have blocks too.5152```53directive0 {54 subdirective0 {55 subdirective2 {56 a57 b58 c59 }60 }61 subdirective1 { }62}63```6465Level of nesting is limited, but you should never hit the limit with correct66configuration.6768In most cases, an empty block is equivalent to no block:69```70directive { }71directive2 # same as above72```7374## Environment variables7576Environment variables can be referenced in the configuration using either77{env:VARIABLENAME} syntax.7879Non-existent variables are expanded to empty strings and not removed from80the arguments list. In the following example, directive0 will have one argument81independently of whether VAR is defined.8283```84directive0 {env:VAR}85```8687Parse is forgiving and incomplete variable placeholder (e.g. '{env:VAR') will88be left as-is. Variables are expanded inside quotes too.8990## Snippets & imports9192You can reuse blocks of configuration by defining them as "snippets". Snippet93is just a directive with a block, declared tp top level (not inside any blocks)94and with a directive name wrapped in curly braces.9596```97(snippetname) {98 a99 b100 c101}102```103104The snippet can then be referenced using 'import' meta-directive.105106```107unrelated0108unrelated1109import snippetname110```111112The above example will be expanded into the following configuration:113114```115unrelated0116unrelated1117a118b119c120```121122Import statement also can be used to include content from other files. It works123exactly the same way as with snippets but the file path should be used instead.124The path can be either relative to the location of the currently processed125configuration file or absolute. If there are both snippet and file with the126same name - snippet will be used.127128```129# /etc/maddy/tls.conf130tls long_path_to_certificate long_path_to_private_key131132# /etc/maddy/maddy.conf133smtp tcp://0.0.0.0:25 {134 import tls.conf135}136```137138```139# Expanded into:140smtp tcp://0.0.0.0:25 {141 tls long_path_to_certificate long_path_to_private_key142}143```144145The imported file can introduce new snippets and they can be referenced in any146processed configuration file.147148## Duration values149150Directives that accept duration use the following format: A sequence of decimal151digits with an optional fraction and unit suffix (zero can be specified without152a suffix). If multiple values are specified, they will be added.153154Valid unit suffixes: "h" (hours), "m" (minutes), "s" (seconds), "ms" (milliseconds).155Implementation also accepts us and ns for microseconds and nanoseconds, but these156values are useless in practice.157158Examples:159```1601h1611h 5m1621h5m1630164```165166## Data size values167168Similar to duration values, but fractions are not allowed and suffixes are different.169170Valid unit suffixes: "G" (gibibyte, 1024^3 bytes), "M" (mebibyte, 1024^2 bytes),171"K" (kibibyte, 1024 bytes), "B" or "b" (byte).172173Examples:174```17532M1763M 5K1775b178```179180Also note that the following is not valid, unlike Duration values syntax:181```18232M5K183```184185## Address Definitions186187Maddy configuration uses URL-like syntax to specify network addresses.188189- `unix://file_path` – Unix domain socket. Relative paths are relative to runtime directory (`/run/maddy`).190- `tcp://ADDRESS:PORT` – TCP/IP socket.191- `tls://ADDRESS:PORT` – TCP/IP socket using TLS.192193## Dummy Module194195No-op module. It doesn't need to be configured explicitly and can be referenced196using "dummy" name. It can act as a delivery target or auth.197provider. In the latter case, it will accept any credentials, allowing any198client to authenticate using any username and password (use with care!).199200