From 453bc9bd434070e07eabdbfe7521b9820f210d06 Mon Sep 17 00:00:00 2001 From: Matthew Horsfall Date: Fri, 20 Dec 2024 12:26:18 -0500 Subject: [PATCH] JMAPSieve/sieve-test-extensive: Add more tests, and don't escape '\' The escaping of '\' was surprising and problematic when doing other types of tests, like inline jmapquery expressions. Rather than using that, escape manually when needed. --- .../tiny-tests/JMAPSieve/sieve-test-extensive | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/cassandane/tiny-tests/JMAPSieve/sieve-test-extensive b/cassandane/tiny-tests/JMAPSieve/sieve-test-extensive index 175f085cc9..1848fc0ac7 100644 --- a/cassandane/tiny-tests/JMAPSieve/sieve-test-extensive +++ b/cassandane/tiny-tests/JMAPSieve/sieve-test-extensive @@ -2,6 +2,31 @@ use Cassandane::Tiny; use Sub::Install; +### basic variable support +add_sieve_tests( + "variables_set_get", + 'set "foo" "bar"; log "foo: ${foo}";', + [ + [ 'log', {}, [ 'foo: bar' ] ], + [ 'keep', {}, [] ], + ], +); + +### jmapquery +add_sieve_tests( + "jmapquery_matches", + 'if jmapquery "{\"from\" : \"sam\"}" { + fileinto "Matched"; + }', + [ [ 'fileinto', {}, [ 'Matched' ] ] ], + + "jmapquery_does_not_match", + 'if jmapquery "{\"from\" : \"bugs\"}" { + fileinto "Matched"; + }', + [ [ 'keep', {}, [] ] ], +); + ### fileinto add_sieve_tests( "fileinto_basic", @@ -9,8 +34,8 @@ add_sieve_tests( [ ['fileinto', {}, [ 'foo' ] ] ], "fileinto_specialuse", - 'fileinto :specialuse "\\junk" "Trash";', - [ ['fileinto', { specialuse => '\\junk' }, [ 'Trash' ] ] ], + 'fileinto :specialuse "\\\\junk" "Trash";', + [ ['fileinto', { specialuse => '\junk' }, [ 'Trash' ] ] ], "fileinto_mailboxid", 'fileinto :mailboxid "a-b-c-d" "Alphabet";', @@ -44,6 +69,17 @@ add_sieve_tests( ], ); +### exists +add_sieve_tests( + "exists", + 'if exists ["From"] { fileinto "FromHeaderFound"; }', + [ ['fileinto', {}, [ 'FromHeaderFound' ] ] ], + + "exists_not", + 'if not exists ["From"] { fileinto "FromHeaderFound"; }', + [ ['keep', {}, [] ] ], +); + sub add_sieve_tests { my (@tests) = @_; @@ -114,13 +150,12 @@ sub new_sieve_blob { xlog "create script"; my $fullscript = <CallMethods([ ['Blob/upload', {