Skip to content

Conversation

@cmouse
Copy link
Contributor

@cmouse cmouse commented Dec 30, 2025

JIRA: DOV-8586

@github-actions

This comment has been minimized.

| `!~` | String inequality (pattern on value2, [POSIX Extended Regular Expression syntax](https://www.gnu.org/software/findutils/manual/html_node/find_html/posix_002dextended-regular-expression-syntax.html)). |

Examples:
Dovecot supports two kinds of conditional filter, the if and switch filter. The difference is that if can be used to do single comparison, and switch can do multiple comparisons.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • conditional filter -> conditional filters
  • the `if` and the `switch` filter
  • ` for the other if and switch too, here and below


::: warning
Nested if or switch statements will not work. You also cannot chain if or switch to emulate this.
If you need to do complicated if or switch statements, you should use passdb lua or passdb passwd-file instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link to passdb lua & passwd-file. Although not sure how passwd-file will help with complex statements .. maybe just link to lua?

postmaster@%{switch(userdb:tenant, 'eq', 'one', 'one.com', 'two', 'two.com', 'default.com')}
# Or provide variable as default (note the domain operator at the end since you can't use pipelines in values either
postmaster@%{switch(userdb:tenant, 'eq', 'one', '@one.com', 'two', '@two.com', user) | domain | default('default.com')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this exactly equivalent to the previous one, except using |default? Not sure what the comment is trying to say with "variable as default" either. Could this somehow be a more useful example?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really same.

the difference is that if you have userdb:tenant=three, user=user@something.com it'll come out as something.com

the first one comes out as default.com.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So comment could be: Or default to user variable's domain, if it's provided. (Note the domain operator at the end since you can't use pipelines in values either.)

# Select subdomain for tenant
postmaster@%{switch(userdb:tenant, 'eq', 'one', 'one.com', 'two', 'two.com', 'default.com')}
# Or provide variable as default (note the domain operator at the end since you can't use pipelines in values either
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing ) at the end

| `sha384(rounds=number, salt=string)` | Bytes | Bytes | Alias for hash with method sha384. |
| `sha512(rounds=number, salt=string)` | Bytes | Bytes | Alias for hash with method sha512. |
| `substr(offset, length)` | Any | Any | Extracts a substring out of input and returns it. First character is at offset zero. If offset is negative, starts that far back from the end of the string. If length is omitted, returns everything through the end of the string. If length is negative, leaves that many characters off the end of the string. |
| `switch(left, operator, condition, value, condition, value, ..., default)` | String | String | Evaluates given comparison and returns matching condition value or default. See [conditionals](#conditionals). |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think condition1, value1, condition2, value2[,...][, default]

| `sha512(rounds=number, salt=string)` | Bytes | Bytes | Alias for hash with method sha512. |
| `substr(offset, length)` | Any | Any | Extracts a substring out of input and returns it. First character is at offset zero. If offset is negative, starts that far back from the end of the string. If length is omitted, returns everything through the end of the string. If length is negative, leaves that many characters off the end of the string. |
| `switch(left, operator, condition, value, condition, value, ..., default)` | String | String | Evaluates given comparison and returns matching condition value or default. See [conditionals](#conditionals). |
| `switch(operator, right, true, false)` | String | String | Evaluates given comparison and returns matching condition value or default. See [conditionals](#conditionals). |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this about using foo | switch() to provide the left value? But isn't the syntax still otherwise the same as the above switch? Why is it saying "right, true, false" here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants