diff --git a/Makefile.am b/Makefile.am index e546a15044412c94342d7939ec7a900567613b2d..0a4f57f1f3b813a24369e7061f6369d90a917001 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,8 @@ endif if BUILD_ENOTIFY ENOTIFY_TESTS = \ - tests/extensions/enotify/basic.svtest + tests/extensions/enotify/basic.svtest \ + tests/extensions/enotify/execute.svtest endif TESTSUITE_BIN = $(top_srcdir)/src/testsuite/testsuite diff --git a/tests/extensions/enotify/execute.svtest b/tests/extensions/enotify/execute.svtest new file mode 100644 index 0000000000000000000000000000000000000000..d45cf04e7234ced2a1eb5df77943b7d50e619180 --- /dev/null +++ b/tests/extensions/enotify/execute.svtest @@ -0,0 +1,56 @@ +require "vnd.dovecot.testsuite"; + +/* + * Execution testing (currently just meant to trigger any segfaults) + */ + +test "RFC Example 1" { + if not test_compile "execute/draft-rfc-ex1.sieve" { + test_fail "script compile failed"; + } + + if not test_execute { + test_fail "script execute failed"; + } +} + +test "RFC Example 2" { + if not test_compile "execute/draft-rfc-ex2.sieve" { + test_fail "script compile failed"; + } + + if not test_execute { + test_fail "script execute failed"; + } +} + +test "RFC Example 3" { + if not test_compile "execute/draft-rfc-ex3.sieve" { + test_fail "script compile failed"; + } + + if not test_execute { + test_fail "script execute failed"; + } +} + +test "RFC Example 5" { + if not test_compile "execute/draft-rfc-ex5.sieve" { + test_fail "script compile failed"; + } + + if not test_execute { + test_fail "script execute failed"; + } +} + +/* +test "RFC Example 6" { + if not test_compile "execute/draft-rfc-ex6.sieve" { + test_fail "script compile failed"; + } + + if not test_execute { + test_fail "script execute failed"; + } +}*/ diff --git a/tests/extensions/enotify/execute/draft-rfc-ex1.sieve b/tests/extensions/enotify/execute/draft-rfc-ex1.sieve new file mode 100644 index 0000000000000000000000000000000000000000..6747d7b3cadd19e914a77c59dbe36cbac7766a25 --- /dev/null +++ b/tests/extensions/enotify/execute/draft-rfc-ex1.sieve @@ -0,0 +1,26 @@ +require ["enotify", "fileinto", "variables"]; + +if header :contains "from" "boss@example.org" { + notify :importance "1" + :message "This is probably very important" + "mailto:alm@example.com"; + # Don't send any further notifications + stop; +} + +if header :contains "to" "sievemailinglist@example.org" { + # :matches is used to get the value of the Subject header + if header :matches "Subject" "*" { + set "subject" "${1}"; + } + + # :matches is used to get the value of the From header + if header :matches "From" "*" { + set "from" "${1}"; + } + + notify :importance "3" + :message "[SIEVE] ${from}: ${subject}" + "mailto:alm@example.com"; + fileinto "INBOX.sieve"; +} diff --git a/tests/extensions/enotify/execute/draft-rfc-ex2.sieve b/tests/extensions/enotify/execute/draft-rfc-ex2.sieve new file mode 100644 index 0000000000000000000000000000000000000000..a5c6a267995f6c1e6090ea151f35f053cff52ff5 --- /dev/null +++ b/tests/extensions/enotify/execute/draft-rfc-ex2.sieve @@ -0,0 +1,22 @@ +require ["enotify", "fileinto", "variables", "envelope"]; + +if header :matches "from" "*@*.example.org" { + # :matches is used to get the MAIL FROM address + if envelope :all :matches "from" "*" { + set "env_from" " [really: ${1}]"; + } + + # :matches is used to get the value of the Subject header + if header :matches "Subject" "*" { + set "subject" "${1}"; + } + + # :matches is used to get the address from the From header + if address :matches :all "from" "*" { + set "from_addr" "${1}"; + } + + notify :message "${from_addr}${env_from}: ${subject}" + "mailto:alm@example.com"; +} + diff --git a/tests/extensions/enotify/execute/draft-rfc-ex3.sieve b/tests/extensions/enotify/execute/draft-rfc-ex3.sieve new file mode 100644 index 0000000000000000000000000000000000000000..a7b4a6435a3b617f7a4b202c11dbd9aa0a28f436 --- /dev/null +++ b/tests/extensions/enotify/execute/draft-rfc-ex3.sieve @@ -0,0 +1,31 @@ +require ["enotify", "variables"]; + +set "notif_method" + "xmpp:tim@example.com?message;subject=SIEVE;body=You%20got%20mail"; + +if header :contains "subject" "Your dog" { + set "notif_method" "tel:+14085551212"; +} + +if header :contains "to" "sievemailinglist@example.org" { + set "notif_method" ""; +} + +if not string :is "${notif_method}" "" { + notify "${notif_method}"; +} + +if header :contains "from" "boss@example.org" { + # :matches is used to get the value of the Subject header + if header :matches "Subject" "*" { + set "subject" "${1}"; + } + + # don't need high importance notification for + # a 'for your information' + if not header :contains "subject" "FYI:" { + notify :importance "1" :message "BOSS: ${subject}" + "tel:+14085551212"; + } +} + diff --git a/tests/extensions/enotify/execute/draft-rfc-ex5.sieve b/tests/extensions/enotify/execute/draft-rfc-ex5.sieve new file mode 100644 index 0000000000000000000000000000000000000000..c6b7dc64af892bb90dac0ae416cdd88f7d42a4d6 --- /dev/null +++ b/tests/extensions/enotify/execute/draft-rfc-ex5.sieve @@ -0,0 +1,11 @@ +require ["enotify"]; + +if notify_method_capability + "xmpp:tim@example.com?message;subject=SIEVE" + "Online" + "yes" { + notify :importance "1" :message "You got mail" + "xmpp:tim@example.com?message;subject=SIEVE"; +} else { + notify :message "You got mail" "tel:+14085551212"; +} diff --git a/tests/extensions/enotify/execute/draft-rfc-ex6.sieve b/tests/extensions/enotify/execute/draft-rfc-ex6.sieve new file mode 100644 index 0000000000000000000000000000000000000000..6a65c64eaa53eefc5cb0c3ad939132f17bbb17f3 --- /dev/null +++ b/tests/extensions/enotify/execute/draft-rfc-ex6.sieve @@ -0,0 +1,5 @@ +require ["enotify", "variables"]; + +set :encodeurl "body_param" "Safe body&evil=evilbody"; + +notify "mailto:tim@example.com?body=${body_param}";