diff --git a/Makefile.am b/Makefile.am index 0582d8aadb0a6eb6e3699eeb33c4fc3eb5575ae1..b953e43ceb240a1d3885c05b457b8a6efff75d5d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -26,7 +26,6 @@ test_cases = \ tests/match-types/is.svtest \ tests/match-types/contains.svtest \ tests/match-types/matches.svtest \ - tests/match-types/relational.svtest \ tests/address-parts/subaddress.svtest \ tests/extensions/encoded-character.svtest \ tests/extensions/envelope.svtest \ @@ -45,8 +44,11 @@ test_cases = \ tests/extensions/body/match-values.svtest \ tests/extensions/regex/basic.svtest \ tests/extensions/regex/errors.svtest \ + tests/extensions/relational/basic.svtest \ + tests/extensions/relational/rfc.svtest \ + tests/extensions/relational/errors.svtest \ tests/compile/compile.svtest \ - tests/compile/compile-examples.svtest \ + tests/compile/examples.svtest \ tests/compile/errors.svtest $(test_cases): diff --git a/sieve/examples/relational.rfc5231.sieve b/sieve/examples/relational.rfc5231.sieve new file mode 100644 index 0000000000000000000000000000000000000000..81c66d379095738e3ef84cec71eb28c45a5f7ee9 --- /dev/null +++ b/sieve/examples/relational.rfc5231.sieve @@ -0,0 +1,33 @@ +require ["relational", "comparator-i;ascii-numeric", "fileinto"]; + +if header :value "lt" :comparator "i;ascii-numeric" + ["x-priority"] ["3"] +{ + fileinto "Priority"; +} + +elsif address :count "gt" :comparator "i;ascii-numeric" + ["to"] ["5"] +{ + # everything with more than 5 recipients in the "to" field + # is considered SPAM + fileinto "SPAM"; +} + +elsif address :value "gt" :all :comparator "i;ascii-casemap" + ["from"] ["M"] +{ + fileinto "From N-Z"; +} else { + fileinto "From A-M"; +} + +if allof ( + address :count "eq" :comparator "i;ascii-numeric" + ["to", "cc"] ["1"] , + address :all :comparator "i;ascii-casemap" + ["to", "cc"] ["me@foo.example.com"] ) +{ + fileinto "Only me"; +} + diff --git a/tests/compile/compile-examples.svtest b/tests/compile/examples.svtest similarity index 86% rename from tests/compile/compile-examples.svtest rename to tests/compile/examples.svtest index b8ad1978035e7e4a1b849f7f24960cfdba8b956f..21d0742a856a89dccd5825e9dd78b215ae4c3093 100644 --- a/tests/compile/compile-examples.svtest +++ b/tests/compile/examples.svtest @@ -49,3 +49,9 @@ test "Sanjay example" { test_fail "could not compile"; } } + +test "Relational extension (RFC5231) example" { + if not test_compile "../../sieve/examples/relational.rfc5231.sieve" { + test_fail "could not compile"; + } +} diff --git a/tests/match-types/relational.svtest b/tests/extensions/relational/basic.svtest similarity index 100% rename from tests/match-types/relational.svtest rename to tests/extensions/relational/basic.svtest diff --git a/tests/extensions/relational/errors.svtest b/tests/extensions/relational/errors.svtest new file mode 100644 index 0000000000000000000000000000000000000000..ed9f268ecfe2537281bb25b0adaa0b5230b1570a --- /dev/null +++ b/tests/extensions/relational/errors.svtest @@ -0,0 +1,15 @@ +require "vnd.dovecot.testsuite"; + +# A bit awkward to test the extension with itself +require "relational"; +require "comparator-i;ascii-numeric"; + +test "Validation errors" { + if test_compile "errors/validation.sieve" { + test_fail "compile should have failed"; + } + + if test_error :count "ne" "3" { + test_fail "wrong number of errors reported"; + } +} diff --git a/tests/extensions/relational/errors/validation.sieve b/tests/extensions/relational/errors/validation.sieve new file mode 100644 index 0000000000000000000000000000000000000000..e632a46f76447b9bfba860adb6652b05bb533b6f --- /dev/null +++ b/tests/extensions/relational/errors/validation.sieve @@ -0,0 +1,11 @@ +require "relational"; + +# Not a valid relation (1) +if header :value "gr" "from" "ah" { + keep; +} + +# Not a valid relation (1) +if header :count "lf" "from" "eek" { + keep; +} diff --git a/tests/extensions/relational/rfc.svtest b/tests/extensions/relational/rfc.svtest new file mode 100644 index 0000000000000000000000000000000000000000..f092931931041b09f6f2a2a51bb92ad09e837421 --- /dev/null +++ b/tests/extensions/relational/rfc.svtest @@ -0,0 +1,71 @@ +require "vnd.dovecot.testsuite"; + +require "relational"; +require "comparator-i;ascii-numeric"; + +test_set "message" text: +Received: ... +Received: ... +Subject: example +To: foo@example.com, baz@example.com +CC: qux@example.com + +RFC Example +. +; + +test "Example 1" { + # The test: + + if not address :count "ge" :comparator "i;ascii-numeric" + ["to", "cc"] ["3"] { + + test_fail "should have counted three addresses"; + } + + # would evaluate to true, and the test + + if anyof ( + address :count "ge" :comparator "i;ascii-numeric" + ["to"] ["3"], + address :count "ge" :comparator "i;ascii-numeric" + ["cc"] ["3"] + ) { + + test_fail "should not have counted three addresses"; + } + + # would evaluate to false. + + # To check the number of received fields in the header, the following + # test may be used: + + if header :count "ge" :comparator "i;ascii-numeric" + ["received"] ["3"] { + + test_fail "should not have counted three received headers"; + } + + # This would evaluate to false. But + + if not header :count "ge" :comparator "i;ascii-numeric" + ["received", "subject"] ["3"] { + + test_fail "should have counted three headers"; + } + + # would evaluate to true. + + # The test: + + if header :count "ge" :comparator "i;ascii-numeric" + ["to", "cc"] ["3"] { + + test_fail "should not have counted three to or cc headers"; + } + + # will always evaluate to false on an RFC 2822 compliant message + # [RFC2822], since a message can have at most one "to" field and at + # most one "cc" field. This test counts the number of fields, not the + # number of addresses. +}