Expressions in configuration files (untested)

This commit is contained in:
mdecimus
2024-01-18 18:18:32 +01:00
parent 4b5576cab4
commit 4551576e04
105 changed files with 5555 additions and 4157 deletions

View File

@@ -1,40 +1,34 @@
durations = [
{if = "sender", eq = "jdoe", then = "5d"},
{any-of = [{if = "priority", eq = -1}, {if = "rcpt", starts-with = "jane"}], then = "1h"},
{if = "sender = 'jdoe'", then = "5d"},
{if = "priority = -1 | starts_with(rcpt, 'jane')", then = "1h"},
{else = false}
]
string-list = [
{if = "sender", eq = "jdoe", then = ["From", "To", "Date"]},
{any-of = [{if = "priority", eq = -1}, {if = "rcpt", starts-with = "jane"}], then = "Other-ID"},
{else = []}
{if = "sender = 'jdoe'", then = "['From', 'To', 'Date']"},
{if = "priority = -1 | starts_with(rcpt, 'jane')", then = "'Other-ID'"},
{else = "[]"}
]
string-list-bis = [
{if = "sender", eq = "jdoe", then = ["From", "To", "Date"]},
{any-of = [{if = "priority", eq = -1}, {if = "rcpt", starts-with = "jane"}], then = []},
{else = ["ID-Bis"]}
{if = "sender = 'jdoe'", then = "['From', 'To', 'Date']"},
{if = "priority = -1 | starts_with(rcpt, 'jane')", then = "[]"},
{else = "['ID-Bis']"}
]
single-value = "hello world"
bad-multi-value = [
{if = "sender", eq = "jdoe", then = 100},
{any-of = [{if = "priority", eq = -1}, {if = "rcpt", starts-with = "jane"}], then = [1, 2, 3]},
{else = 2}
]
single-value = "'hello world'"
bad-if-without-then = [
{if = "sender", eq = "jdoe"},
{if = "sender = 'jdoe'"},
{else = 1}
]
bad-if-without-else = [
{if = "sender", eq = "jdoe", then = 1}
{if = "sender = 'jdoe'", then = 1}
]
bad-multiple-else = [
{if = "sender", eq = "jdoe", then = 1},
{if = "sender = 'jdoe'", then = 1},
{else = 1},
{else = 2}
]

View File

@@ -9,96 +9,55 @@ remote-ip = "A:B:C::D:E"
mx = "mx.somedomain.com"
authenticated-as = "john@foobar.org"
priority = -4
listener = 123
listener = "smtp"
helo-domain = "hi-domain.net"
[eval."eq"]
test = [
{if = "sender", eq = "bill@foo.net", then = "${0}"},
{if = "sender = 'bill@foo.net'", then = "sender"},
{else = false}
]
expect = "bill@foo.net"
[eval."starts-with"]
test = [
{if = "rcpt-domain", starts-with = "foo", then = "${0}${{0}}"},
{if = "starts_with(rcpt_domain, 'foo')", then = "'mx.' + rcpt_domain"},
{else = false}
]
expect = "foo.example.org${0}"
expect = "mx.foo.example.org"
[eval."regex"]
test = [
{if = "rcpt", matches = "^([^.]+)@([^.]+)\.(.+)$", then = "${1}+${2}@${3}"},
{if = "matches('^([^.]+)@([^.]+)\.(.+)$', rcpt)", then = "$1 + '+' + $2 + '@' + $3"},
{else = false}
]
expect = "user+foo@example.org"
[eval."regex-full"]
test = [
{if = "rcpt", matches = "^([^.]+)@([^.]+)\.(.+)$", then = "${0}"},
{if = "matches('^([^.]+)@([^.]+)\.(.+)$', rcpt)", then = "rcpt"},
{else = false}
]
expect = "user@foo.example.org"
[eval."envelope-match"]
test = [
{if = "authenticated-as", matches = "^([^.]+)@(.+)$", then = "rcpt ${rcpt} listener ${listener} ip ${local-ip} priority ${priority}"},
{if = "matches('^([^.]+)@(.+)$', authenticated_as)", then = "'rcpt ' + rcpt + ' listener ' + listener + ' ip ' + local_ip + ' priority ' + priority"},
{else = false}
]
expect = "rcpt user@foo.example.org listener 123 ip 192.168.9.3 priority -4"
expect = "rcpt user@foo.example.org listener smtp ip 192.168.9.3 priority -4"
[eval."static-match"]
test = [
{if = "authenticated-as", matches = "^([^.]+)@(.+)$", then = "hello world"},
{if = "matches('^([^.]+)@(.+)$', authenticated_as)", then = "'hello world'"},
{else = false}
]
expect = "hello world"
[eval."no-match"]
test = [
{if = "authenticated-as", matches = "^([^.]+)@([^.]+)\.(.+)$org", then = "${1}+${2}@${3}"},
{if = "matches('^([^.]+)@([^.]+)\.(.+)$org', authenticated_as)", then = "'test'"},
{else = false}
]
expect = false
[store."list_mx/domains"]
type = "memory"
format = "list"
values = ["mx"]
[store."list_foo/domains"]
type = "memory"
format = "list"
values = ["foo"]
[store."list_123/domains"]
type = "memory"
format = "list"
values = ["123"]
[maybe-eval."dyn_mx"]
test = [
{if = "mx", matches = "([^.]+)\.(.+)$", then = "list_${1}/domains"},
{else = false}
]
expect = "mx"
[maybe-eval."dyn_foo"]
test = [
{if = "sender-domain", matches = "([^.]+)\.(.+)$", then = "list_${1}/domains"},
{else = false}
]
expect = "foo"
[maybe-eval."static_mx"]
test = "list_mx/domains"
expect = "mx"
[maybe-eval."static_foo"]
test = "list_foo/domains"
expect = "foo"
[maybe-eval."dyn_123"]
test = "list_${listener}/domains"
expect = "123"

View File

@@ -8,163 +8,27 @@ remote-ip = "A:B:C::D:E"
mx = "mx.somedomain.com"
authenticated-as = "john@foobar.org"
priority = -4
listener = 123
listener = "smtp"
helo-domain = "hi-domain.net"
[rule]
"eq-true" = {if = "rcpt-domain", eq = "example.org"}
"eq-false" = {if = "rcpt-domain", eq = "example.com"}
"listener-eq-true" = {if = "listener", eq = "smtp"}
"listener-eq-false" = {if = "listener", eq = "smtps"}
"ip-eq-true" = {if = "local-ip", eq = "192.168.9.0/24"}
"ip-eq-false" = {if = "remote-ip", eq = "A:B:C::D:F/128"}
"ne-true" = {if = "authenticated-as", ne = ""}
"ne-false" = {if = "authenticated-as", ne = "john@foobar.org"}
"starts-with-true" = {if = "mx", starts-with = "mx.some"}
"starts-with-false" = {if = "mx", starts-with = "enchilada"}
"ends-with-true" = {if = "sender", ends-with = "@foo.net"}
"ends-with-false" = {if = "sender", ends-with = "chimichanga"}
"in-list-true" = {if = "sender-domain", in-list = "list/domains"}
"in-list-false" = {if = "rcpt-domain", in-list = "list/domains"}
"not-in-list-true" = {if = "rcpt-domain", not-in-list = "list/domains"}
"not-in-list-false" = {if = "sender-domain", not-in-list = "list/domains"}
"regex-true" = {if = "sender", matches = "^(.+)@(.+)$"}
"regex-false" = {if = "mx", matches = "/^\\S+@\\S+\\.\\S+$/"}
"any-of-true" = { any-of = [
{if = "authenticated-as", ne = "john@foobar.org"},
{if = "rcpt-domain", eq = "example.org"},
{if = "mx", starts-with = "mx.some"},
]}
"any-of-false" = { any-of = [
{if = "authenticated-as", eq = "something else"},
{if = "rcpt-domain", eq = "something else"},
{if = "mx", starts-with = "something else"},
]}
"all-of-true" = { all-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]}
"all-of-false" = { all-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "something else"}
]}
"none-of-true" = { none-of = [
{if = "authenticated-as", eq = "something else"},
{if = "rcpt-domain", eq = "something else"},
{if = "mx", starts-with = "something else"},
]}
"none-of-false" = { none-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]}
nested-any-of-true = { any-of = [
{ all-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "something else"}
]},
{ none-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]},
{ any-of = [
{if = "authenticated-as", ne = "john@foobar.org"},
{if = "rcpt-domain", eq = "example.org"},
{if = "mx", starts-with = "mx.some"},
]}
]}
nested-any-of-false = { any-of = [
{ none-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]},
{ all-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "something else"}
]},
{ any-of = [
{if = "authenticated-as", eq = "something else"},
{if = "rcpt-domain", eq = "something else"},
{if = "mx", starts-with = "something else"},
]}
]}
nested-all-of-true = { all-of = [
{ any-of = [
{if = "authenticated-as", ne = "john@foobar.org"},
{if = "rcpt-domain", eq = "example.org"},
{if = "mx", starts-with = "mx.some"},
]},
{ all-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]},
{ none-of = [
{if = "authenticated-as", eq = "something else"},
{if = "rcpt-domain", eq = "something else"},
{if = "mx", starts-with = "something else"},
]}
]}
nested-all-of-false = { all-of = [
{ any-of = [
{if = "authenticated-as", ne = "john@foobar.org"},
{if = "rcpt-domain", eq = "example.org"},
{if = "mx", starts-with = "mx.some"},
]},
{ all-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]},
{ none-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]}
]}
nested-none-of-true = { none-of = [
{ none-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]},
{ all-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "something else"}
]},
{ any-of = [
{if = "authenticated-as", eq = "something else"},
{if = "rcpt-domain", eq = "something else"},
{if = "mx", starts-with = "something else"},
]}
]}
nested-none-of-false = { none-of = [
{ any-of = [
{if = "authenticated-as", ne = "john@foobar.org"},
{if = "rcpt-domain", eq = "example.org"},
{if = "mx", starts-with = "mx.some"},
]},
{ all-of = [
{if = "rcpt-domain", eq = "example.org"},
{if = "listener", eq = "smtp"},
{if = "mx", starts-with = "mx.some"}
]},
{ none-of = [
{if = "authenticated-as", eq = "something else"},
{if = "rcpt-domain", eq = "something else"},
{if = "mx", starts-with = "something else"},
]}
]}
[store."list/domains"]
type = "memory"
format = "list"
values = ["mydomain1.org", "foo.net", "otherdomain.net"]
"eq-true" = "rcpt_domain = 'example.org'"
"eq-false" = "rcpt_domain = 'example.com'"
"listener-eq-true" = "listener = 'smtp'"
"listener-eq-false" = "listener = 'smtps'"
"ip-eq-true" = "local_ip = '192.168.9.3'"
"ip-eq-false" = "remote_ip = 'A:B:C::D:E'"
"ne-true" = "!is_empty(authenticated_as)"
"ne-false" = "authenticated_as != 'john@foobar.org'"
"starts-with-true" = "starts_with(mx, 'mx.some')"
"starts-with-false" = "starts_with(mx, 'enchilada')"
"ends-with-true" = "ends_with(sender, '@foo.net')"
"ends-with-false" = "ends_with(sender, 'chimichanga')"
"regex-true" = "matches('^(.+)@(.+)$', sender)"
"regex-false" = "matches('/^\\S+@\\S+\\.\\S+$/', mx)"
"any-of-true" = "authenticated_as != 'john@foobar.org' | rcpt_domain = 'example.org' | starts_with(mx, 'mx.some')"
"any-of-false" = "authenticated_as = 'something else' | rcpt_domain = 'something else' | starts_with(mx, 'something else')"
"all-of-true" = "rcpt_domain = 'example.org' & listener = 'smtp' & starts_with(mx, 'mx.some')"
"all-of-false" = "rcpt_domain = 'example.org' & listener = 'smtp' & starts_with(mx, 'something else')"
"none-of-true" = "!(authenticated_as = 'something else' | rcpt_domain = 'something else' | starts_with(mx, 'something else'))"
"none-of-false" = "!(rcpt_domain = 'example.org' | listener = 'smtp' | starts_with(mx, 'mx.some'))"