Escape regexes within matches() (#155)
This commit is contained in:
@@ -130,7 +130,7 @@ impl Expression {
|
||||
captures.clear();
|
||||
let value = stack.pop().unwrap_or_default().into_string();
|
||||
|
||||
for captures_ in regex.captures_iter(value.as_ref()) {
|
||||
if let Some(captures_) = regex.captures(value.as_ref()) {
|
||||
for capture in captures_.iter() {
|
||||
captures.push(capture.map_or("", |m| m.as_str()).to_string());
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ catch-all = true
|
||||
#catch-all = [ { if = "matches('(.+)@(.+)$', address)", then = "'info@' + $2" },
|
||||
# { else = false } ]
|
||||
subaddressing = true
|
||||
#subaddressing = [ { if = "matches('^([^.]+)\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" },
|
||||
#subaddressing = [ { if = "matches('^([^.]+)\\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" },
|
||||
# { else = false } ]
|
||||
|
||||
[directory."internal".cache]
|
||||
|
||||
@@ -30,7 +30,7 @@ catch-all = true
|
||||
#catch-all = [ { if = "matches('(.+)@(.+)$', address)", then = "'info@' + $2" },
|
||||
# { else = false } ]
|
||||
subaddressing = true
|
||||
#subaddressing = [ { if = "matches('^([^.]+)\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" },
|
||||
#subaddressing = [ { if = "matches('^([^.]+)\\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" },
|
||||
# { else = false } ]
|
||||
|
||||
[directory."ldap".pool]
|
||||
|
||||
@@ -11,7 +11,7 @@ catch-all = true
|
||||
#catch-all = [ { if = "matches('(.+)@(.+)$', address)", then = "'info@' + $2" },
|
||||
# { else = false } ]
|
||||
subaddressing = true
|
||||
#subaddressing = [ { if = "matches('^([^.]+)\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" },
|
||||
#subaddressing = [ { if = "matches('^([^.]+)\\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" },
|
||||
# { else = false } ]
|
||||
|
||||
[[directory."memory".principals]]
|
||||
|
||||
@@ -12,7 +12,7 @@ catch-all = true
|
||||
#catch-all = [ { if = "matches('(.+)@(.+)$', address)", then = "'info@' + $2" },
|
||||
# { else = false } ]
|
||||
subaddressing = true
|
||||
#subaddressing = [ { if = "matches('^([^.]+)\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" },
|
||||
#subaddressing = [ { if = "matches('^([^.]+)\\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" },
|
||||
# { else = false } ]
|
||||
|
||||
[directory."sql".cache]
|
||||
|
||||
@@ -49,14 +49,14 @@ wait = "5s"
|
||||
|
||||
[session.mail]
|
||||
#script = "mail-from"
|
||||
#rewrite = [ { if = "listener != 'smtp' & matches('^([^.]+)@([^.]+)\.(.+)$', rcpt)", then = "$1 + '@' + $3" },
|
||||
#rewrite = [ { if = "listener != 'smtp' & matches('^([^.]+)@([^.]+)\\.(.+)$', rcpt)", then = "$1 + '@' + $3" },
|
||||
# { else = false } ]
|
||||
|
||||
[session.rcpt]
|
||||
#script = "greylist"
|
||||
relay = [ { if = "!is_empty(authenticated_as)", then = true },
|
||||
{ else = false } ]
|
||||
#rewrite = [ { if = "is_local_domain('%{DEFAULT_DIRECTORY}%', rcpt_domain) & matches('^([^.]+)\.([^.]+)@(.+)$', rcpt)", then = "$1 + '+' + $2 + '@' + $3" },
|
||||
#rewrite = [ { if = "is_local_domain('%{DEFAULT_DIRECTORY}%', rcpt_domain) & matches('^([^.]+)\\.([^.]+)@(.+)$', rcpt)", then = "$1 + '+' + $2 + '@' + $3" },
|
||||
# { else = false } ]
|
||||
max-recipients = 25
|
||||
directory = "'%{DEFAULT_DIRECTORY}%'"
|
||||
|
||||
@@ -620,23 +620,27 @@ async fn address_mappings() {
|
||||
catch-all = true
|
||||
subaddressing = true
|
||||
expected-sub = "john.doe@example.org"
|
||||
expected-sub-nomatch = "jane@example.org"
|
||||
expected-catch = "@example.org"
|
||||
|
||||
[disable]
|
||||
catch-all = false
|
||||
subaddressing = false
|
||||
expected-sub = "john.doe+alias@example.org"
|
||||
expected-sub-nomatch = "jane@example.org"
|
||||
expected-catch = false
|
||||
|
||||
[custom]
|
||||
catch-all = [{if = "matches('(.+)@(.+)$', address)", then = "'info@' + $2"}, {else = false}]
|
||||
subaddressing = [{ if = "matches('^([^.]+)\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" }, {else = false}]
|
||||
subaddressing = [{ if = "matches('^([^.]+)\\.([^.]+)@(.+)$', address)", then = "$2 + '@' + $3" }, {else = false}]
|
||||
expected-sub = "doe+alias@example.org"
|
||||
expected-sub-nomatch = "jane@example.org"
|
||||
expected-catch = "info@example.org"
|
||||
"#;
|
||||
|
||||
let config = utils::config::Config::new(MAPPINGS).unwrap();
|
||||
const ADDR: &str = "john.doe+alias@example.org";
|
||||
const ADDR_NO_MATCH: &str = "jane@example.org";
|
||||
|
||||
for test in ["enable", "disable", "custom"] {
|
||||
let catch_all = AddressMapping::from_config(&config, (test, "catch-all")).unwrap();
|
||||
@@ -648,6 +652,14 @@ async fn address_mappings() {
|
||||
"failed subaddress for {test:?}"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
subaddressing.to_subaddress(ADDR_NO_MATCH).await,
|
||||
config
|
||||
.value_require((test, "expected-sub-nomatch"))
|
||||
.unwrap(),
|
||||
"failed subaddress no match for {test:?}"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
catch_all.to_catch_all(ADDR).await,
|
||||
config
|
||||
|
||||
@@ -45,7 +45,7 @@ script = [ { if = "sender_domain = 'foobar.org'", then = "'mail'" },
|
||||
{ else = false } ]
|
||||
|
||||
[session.rcpt]
|
||||
rewrite = [ { if = "rcpt_domain = 'foobar.net' & matches('^([^.]+)\.([^.]+)@(.+)$', rcpt)", then = "$1 + '+' + $2 + '@' + $3"},
|
||||
rewrite = [ { if = "rcpt_domain = 'foobar.net' & matches('^([^.]+)\\.([^.]+)@(.+)$', rcpt)", then = "$1 + '+' + $2 + '@' + $3"},
|
||||
{ else = false } ]
|
||||
script = [ { if = "rcpt_domain = 'foobar.org'", then = "'rcpt'" },
|
||||
{ else = false } ]
|
||||
|
||||
Reference in New Issue
Block a user