Skip to content

Commit e137845

Browse files
committed
design: Add variable expansion design document
1 parent 7796c69 commit e137845

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

docs/core/design/var_expand.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
layout: doc
3+
title: Variable expansion design
4+
dovecotlinks:
5+
var_expand: variable expansion design
6+
---
7+
8+
# Variable expansion design
9+
10+
Dovecot comes with powerful variable expansion system, which allows constructing reuseable text templates.
11+
This has been upgraded since v2.3 to a more flexible system.
12+
13+
## Syntax
14+
15+
```
16+
<var> ::= <expression-list>
17+
<expression-list> ::= <expression-list> <expression>
18+
<expression> ::= <VALUE>, "{" <filter-list> "}", "%"
19+
<filter-list> ::= <filter-list> "|" <filter>, <filter>
20+
<filter> ::= <func> <math-list>
21+
<math-list> ::= <math>
22+
<math> ::= <operator> <number>, <operator> <NAME>
23+
<number> ::= "-" <NUMBER>, <NUMBER>
24+
<operator> ::= "+", "-", "*", "/"
25+
<func> ::= <NAME> <arguments>
26+
<arguments> ::= "(" <argument-list> ")"
27+
<argument-list> ::= <argument-list> "," <argument>
28+
<argument> ::= <VALUE>, <NAME>, <number>, <key> "=" <number>, <key> "=" <NAME>, <key> "=" <VALUE>
29+
30+
NAME = string
31+
VALUE = "string" or 'string'
32+
NUMBER = [0-9]+
33+
```
34+
35+
## Design
36+
37+
The system uses programs to perform the actual expansion. All expressions are first parsed into a program that can then be executed one or more times with parameters.
38+
39+
Program parameters consists from variable table(s), provider(s) and escape function. A program can be executed with different parameters.
40+
41+
## Parameters
42+
43+
Parameters are provided via `struct var_expand_params`. Key-value mappings are provided via `const struct var_expand_table` array, which is `VAR_EXPAND_TABLE_END` terminated list of
44+
key-value mappings. Key's value can also be provided by a function.
45+
46+
Providers are used to handle scoped variables, such as passdb, ldap etc. There are also global providers which are always available.
47+
48+
Providers can be provide with `const struct var_expand_provider` array which contains prefix and provider function, and is `VAR_EXPAND_TABLE_END` terminated.
49+
50+
It is also possible to provide escape function, which is applied to each %{pipeline} output.
51+
52+
Key functions and providers use the same context.
53+
54+
Key-value tables and providers can also be provided as arrays of arrays, which must be NULL terminated.
55+
Contexts for these must be provided in an array that is `VAR_EXPAND_CONTEXTS_END` terminated.
56+
57+
When these arrays are used, first match wins.
58+
59+
## Missing values
60+
61+
If there is no key in table or provider, error will occur. This error can be negated with `default(value)` filter.

0 commit comments

Comments
 (0)