Skip to content

Commit

Permalink
SieveScript/test: Support environment tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfsage committed Jan 22, 2025
1 parent 46f3923 commit 7b461be
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
11 changes: 10 additions & 1 deletion cassandane/tiny-tests/JMAPSieve/sieve-test-extensive
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,15 @@ add_sieve_tests(
],
);

### environment
add_sieve_tests(
"environment",
'if environment :contains "phase" "during" { discard; }',
[
[ 'discard', {}, [] ],
],
);

### someInThreadHaveKeyword
sub test_sieve_test_extensive_some_in_thread_have_keyword
:min_version_3_3 :JMAPExtensions
Expand Down Expand Up @@ -244,7 +253,7 @@ sub new_sieve_blob {

xlog "create script";
my $fullscript = <<EOF;
require ["fileinto", "extlists", "imap4flags", "copy", "variables", "mailbox", "mailboxid", "special-use", "vnd.cyrus.log", "vnd.cyrus.jmapquery", "vnd.cyrus.imip", "duplicate"];
require ["fileinto", "extlists", "imap4flags", "copy", "variables", "mailbox", "mailboxid", "special-use", "vnd.cyrus.log", "vnd.cyrus.jmapquery", "vnd.cyrus.imip", "duplicate", "environment"];
$sieve
EOF
Expand Down
46 changes: 46 additions & 0 deletions imap/jmap_sieve.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,6 +1374,51 @@ static int getenvelope(void *mc, const char *field, const char ***contents)
}
}

static int getenvironment(void *sc __attribute__((unused)),
const char *keyname, char **res)
{
*res = NULL;

switch (*keyname) {
case 'd':
if (!strcmp(keyname, "domain")) {
const char *domain = strchr(config_servername, '.');

if (domain) domain++;
else domain = "";

*res = xstrdup(domain);
}
break;

case 'h':
if (!strcmp(keyname, "host")) *res = xstrdup(config_servername);
break;

case 'l':
if (!strcmp(keyname, "location")) *res = xstrdup("MDA");
break;

case 'n':
if (!strcmp(keyname, "name")) *res = xstrdup("Cyrus LMTP");
break;

case 'p':
if (!strcmp(keyname, "phase")) *res = xstrdup("during");
break;

/* Not supporting remote host or ip since they'd be the jmap client, not
the lmtp client */

case 'v':
if (!strcmp(keyname, "version")) *res = xstrdup(CYRUS_VERSION);
break;
}

return (*res ? SIEVE_OK : SIEVE_FAIL);
}


static int getsize(void *mc, int *size)
{
message_data_t *m = (message_data_t *) mc;
Expand Down Expand Up @@ -2200,6 +2245,7 @@ static int jmap_sieve_test(struct jmap_req *req)
sieve_register_header(interp, getheader);
sieve_register_headersection(interp, getheadersection);
sieve_register_envelope(interp, getenvelope);
sieve_register_environment(interp, &getenvironment);
sieve_register_size(interp, getsize);
sieve_register_body(interp, getbody);
sieve_register_mailboxexists(interp, &getmailboxexists);
Expand Down

0 comments on commit 7b461be

Please sign in to comment.