Skip to content

Commit

Permalink
JMAPSieve/sieve-test-extensive: Add more tests, and don't escape '\'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wolfsage committed Dec 20, 2024
1 parent 4985839 commit 453bc9b
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions cassandane/tiny-tests/JMAPSieve/sieve-test-extensive
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,40 @@
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",
'fileinto "foo";',
[ ['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";',
Expand Down Expand Up @@ -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) = @_;

Expand Down Expand Up @@ -114,13 +150,12 @@ sub new_sieve_blob {

xlog "create script";
my $fullscript = <<EOF;
require ["fileinto", "imap4flags", "copy", "variables", "mailbox", "mailboxid", "special-use"];
require ["fileinto", "imap4flags", "copy", "variables", "mailbox", "mailboxid", "special-use", "vnd.cyrus.log", "vnd.cyrus.jmapquery"];
$sieve
EOF

$fullscript =~ s/\r?\n/\r\n/gs;
$fullscript =~ s/\\/\\\\/gs;

my $res = $jmap->CallMethods([
['Blob/upload', {
Expand Down

0 comments on commit 453bc9b

Please sign in to comment.