Skip to content
Snippets Groups Projects
Commit d039e98e authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Made header and exists tests executable.

parent cc7a4672
No related branches found
No related tags found
No related merge requests found
if address :is ["from", "to", "cc"] "sirius@drunksnipers.com { if address :is ["from", "to", "cc"] "sirius@drunksnipers.com" {
keep;
} elsif header :is ["subject"] "WrF" {
discard;
} elsif exists "X-Hufter" {
keep; keep;
} elsif size :under 4000 { } elsif size :under 4000 {
stop; stop;
......
...@@ -195,7 +195,11 @@ bool sieve_generator_emit_stringlist_argument ...@@ -195,7 +195,11 @@ bool sieve_generator_emit_stringlist_argument
(void) sieve_generator_emit_string(generator, sieve_ast_argument_str(arg)); (void) sieve_generator_emit_string(generator, sieve_ast_argument_str(arg));
return TRUE; return TRUE;
} else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) { } else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) {
(void) sieve_generator_emit_string_list(generator, arg); if ( sieve_ast_strlist_count(arg) == 1 )
sieve_generator_emit_string(generator,
sieve_ast_argument_str(sieve_ast_strlist_first(arg)));
else
(void) sieve_generator_emit_string_list(generator, arg);
return TRUE; return TRUE;
} }
......
...@@ -9,9 +9,10 @@ ...@@ -9,9 +9,10 @@
/* Opcodes */ /* Opcodes */
static bool tst_exists_opcode_dump(struct sieve_interpreter *interpreter); static bool tst_exists_opcode_dump(struct sieve_interpreter *interpreter);
static bool tst_exists_opcode_execute(struct sieve_interpreter *interpreter);
const struct sieve_opcode tst_exists_opcode = const struct sieve_opcode tst_exists_opcode =
{ tst_exists_opcode_dump, NULL }; { tst_exists_opcode_dump, tst_exists_opcode_execute };
/* Test validation */ /* Test validation */
...@@ -64,3 +65,40 @@ static bool tst_exists_opcode_dump(struct sieve_interpreter *interpreter) ...@@ -64,3 +65,40 @@ static bool tst_exists_opcode_dump(struct sieve_interpreter *interpreter)
return TRUE; return TRUE;
} }
/* Code execution */
static bool tst_exists_opcode_execute(struct sieve_interpreter *interpreter)
{
struct mail *mail = sieve_interpreter_get_mail(interpreter);
struct sieve_coded_stringlist *hdr_list;
string_t *hdr_item;
bool matched;
printf("?? EXISTS\n");
t_push();
/* Read header-list */
if ( (hdr_list=sieve_interpreter_read_stringlist_operand(interpreter)) == NULL ) {
t_pop();
return FALSE;
}
/* Iterate through all requested headers to match */
hdr_item = NULL;
matched = FALSE;
while ( !matched && sieve_coded_stringlist_next_item(hdr_list, &hdr_item) && hdr_item != NULL ) {
const char *const *headers;
if ( mail_get_headers_utf8(mail, str_c(hdr_item), &headers) >= 0 && headers[0] != NULL) {
matched = TRUE;
}
}
t_pop();
sieve_interpreter_set_test_result(interpreter, matched);
return TRUE;
}
...@@ -9,9 +9,10 @@ ...@@ -9,9 +9,10 @@
/* Opcodes */ /* Opcodes */
static bool tst_header_opcode_dump(struct sieve_interpreter *interpreter); static bool tst_header_opcode_dump(struct sieve_interpreter *interpreter);
static bool tst_header_opcode_execute(struct sieve_interpreter *interpreter);
const struct sieve_opcode tst_header_opcode = const struct sieve_opcode tst_header_opcode =
{ tst_header_opcode_dump, NULL }; { tst_header_opcode_dump, tst_header_opcode_execute };
/* Test registration */ /* Test registration */
...@@ -88,3 +89,52 @@ static bool tst_header_opcode_dump(struct sieve_interpreter *interpreter) ...@@ -88,3 +89,52 @@ static bool tst_header_opcode_dump(struct sieve_interpreter *interpreter)
return TRUE; return TRUE;
} }
/* Code execution */
static bool tst_header_opcode_execute(struct sieve_interpreter *interpreter)
{
struct mail *mail = sieve_interpreter_get_mail(interpreter);
struct sieve_coded_stringlist *hdr_list;
struct sieve_coded_stringlist *key_list;
string_t *hdr_item;
bool matched;
printf("?? HEADER\n");
t_push();
/* Read header-list */
if ( (hdr_list=sieve_interpreter_read_stringlist_operand(interpreter)) == NULL ) {
t_pop();
return FALSE;
}
/* Read key-list */
if ( (key_list=sieve_interpreter_read_stringlist_operand(interpreter)) == NULL ) {
t_pop();
return FALSE;
}
/* Iterate through all requested headers to match */
hdr_item = NULL;
matched = FALSE;
while ( !matched && sieve_coded_stringlist_next_item(hdr_list, &hdr_item) && hdr_item != NULL ) {
const char *const *headers;
if ( mail_get_headers_utf8(mail, str_c(hdr_item), &headers) >= 0 ) {
int i;
for ( i = 0; !matched && headers[i] != NULL; i++ ) {
if ( sieve_stringlist_match(key_list, headers[i]) )
matched = TRUE;
}
}
}
t_pop();
sieve_interpreter_set_test_result(interpreter, matched);
return TRUE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.