require "vnd.stalwart.testsuite"; require "vnd.stalwart.expressions"; require "relational"; require "body"; require "include"; require "variables"; require "regex"; test_set "message" text: From: Giovanni Doe To: Guglielmo Doe Subject: Pranzo d'acqua fa volti sghembi V kožuščku hudobnega fanta stopiclja mizar . ; test "Address :name extension" { if not address :localpart :contains ["from"] "john" { test_fail "failed to match local address part"; } if not address :name :contains ["from"] "Giovanni" { test_fail "failed to match name address part"; } if address :name :contains ["from"] "john" { test_fail "address part matched in name"; } if address :localpart :contains ["from"] "Giovanni" { test_fail "address part matched in name"; } } test "Body :subject extension" { if not body :contains "fanta" { test_fail "failed to match body"; } if not body :subject :contains "Pranzo" { test_fail "failed to match subject"; } if body :contains "Pranzo" { test_fail "subject matched without :subject tag"; } } test "Variable scopes" { global "test"; set "test" "test"; set "local_test" "local_test"; if true { if not string :is "${test}" "test" { test_fail "failed to match global variable"; } if not string :is "${local_test}" "local_test" { test_fail "failed to match local variable"; } } if true { set :local "inner_scope" "yes"; } if true { set "scope_a" "a"; if true { set "scope_b" "b"; if true { set "scope_c" "c"; if true { set :local "deep_inner_scope" "abc"; set "local_scope" "xyz"; } if not string :is "${scope_c}" "c" { test_fail "variable contents were cleared = '${scope_c}'"; } } if not string :is "${scope_b}" "b" { test_fail "variable contents were cleared = '${scope_b}'"; } } if not string :is "${scope_a}" "a" { test_fail "variable contents were cleared = '${scope_a}'"; } } if not string :is "${inner_scope}" "yes" { test_fail "failed to match inner scope variable = '${inner_scope}'"; } if not string :is "${deep_inner_scope}" "abc" { test_fail "failed to match deep inner scope variable = '${deep_inner_scope}'"; } if not string :is "${local_scope}" "" { test_fail "matched out of scope variable = '${local_scope}'"; } # Names captures if address :regex :all "To" "(?.*)" { set :local "ADDR" "${1}"; } if not string :is "${ADDR}" "bill.doe@example.net" { test_fail "match group failed = '${ADDR}'"; } } test_set "message" text: From: Giovanni To: bill.doe@example.net Cc: User , invalid, User2 Bcc: Test , Test 1 Bcc: Test 2 , Test 3 X-Confirm-Reading-To: Subject: Pranzo d'acqua fa volti sghembi V kožuščku hudobnega fanta stopiclja mizar . ; test "Header addresses" { if not eval "header.from.addr == '' && header.from.name == 'Giovanni'" { test_fail "failed header.from.addr == '' && header.from.name == 'Giovanni'"; } if not eval "header.to.addr == 'bill.doe@example.net' && header.to.name == ''" { test_fail "header.to.addr == 'bill.doe@example.net' && header.to.name == ''"; } if not eval "header.X-Confirm-Reading-To.addr == 'bill@example.net'" { test_fail "header.X-Confirm-Reading-To.addr != 'bill@example.net'"; } let "addr" "header.from:to:cc:bcc:X-Confirm-Reading-To[*].addr[*]"; if not eval "addr == ['', 'bill.doe@example.net', 'user@domain.org', '', 'user2@domain.org', 'test@test.org', 'test1@test1.org', 'test2@test2.org', 'test3@test3.org', 'bill@example.net']" { test_fail "header.from:to:cc:bcc:X-Confirm-Reading-To[*].addr[*] = [${addr}]"; } }