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

Added support for reading an entire stringlist into memory. Also fixed various...

Added support for reading an entire stringlist into memory. Also fixed various identical bugs in stringlist-related error handling.
parent 80274dca
No related branches found
No related tags found
No related merge requests found
......@@ -206,6 +206,7 @@ static bool ext_envelope_opcode_execute
(const struct sieve_opcode *opcode ATTR_UNUSED,
const struct sieve_runtime_env *renv, sieve_size_t *address)
{
bool result = TRUE;
const struct sieve_comparator *cmp = &i_octet_comparator;
const struct sieve_match_type *mtch = &is_match_type;
const struct sieve_address_part *addrp = &all_address_part;
......@@ -241,7 +242,8 @@ static bool ext_envelope_opcode_execute
/* 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 ) {
while ( !matched && (result=sieve_coded_stringlist_next_item(hdr_list, &hdr_item))
&& hdr_item != NULL ) {
const char *const *fields;
if ( ext_envelope_get_fields(renv->msgdata, str_c(hdr_item), &fields) >= 0 ) {
......@@ -258,7 +260,8 @@ static bool ext_envelope_opcode_execute
t_pop();
sieve_interpreter_set_test_result(renv->interp, matched);
if ( result )
sieve_interpreter_set_test_result(renv->interp, matched);
return TRUE;
return result;
}
......@@ -68,6 +68,7 @@ static bool cmd_addflag_opcode_execute
(const struct sieve_opcode *opcode ATTR_UNUSED,
const struct sieve_runtime_env *renv, sieve_size_t *address)
{
bool result = TRUE;
string_t *flag_item;
struct sieve_coded_stringlist *flag_list;
......@@ -82,7 +83,7 @@ static bool cmd_addflag_opcode_execute
}
/* Iterate through all requested headers to match */
while ( sieve_coded_stringlist_next_item(flag_list, &flag_item) &&
while ( (result=sieve_coded_stringlist_next_item(flag_list, &flag_item)) &&
flag_item != NULL ) {
ext_imapflags_add_flags(renv->interp, flag_item);
}
......@@ -91,5 +92,5 @@ static bool cmd_addflag_opcode_execute
printf(" FLAGS: %s\n", ext_imapflags_get_flags_string(renv->interp));
return TRUE;
return result;
}
......@@ -70,6 +70,7 @@ static bool cmd_removeflag_opcode_execute
(const struct sieve_opcode *opcode ATTR_UNUSED,
const struct sieve_runtime_env *renv, sieve_size_t *address)
{
bool result = TRUE;
string_t *flag_item;
struct sieve_coded_stringlist *flag_list;
......@@ -84,7 +85,7 @@ static bool cmd_removeflag_opcode_execute
}
/* Iterate through all requested headers to match */
while ( sieve_coded_stringlist_next_item(flag_list, &flag_item) &&
while ( (result=sieve_coded_stringlist_next_item(flag_list, &flag_item)) &&
flag_item != NULL ) {
ext_imapflags_remove_flags(renv->interp, flag_item);
}
......@@ -93,5 +94,5 @@ static bool cmd_removeflag_opcode_execute
printf(" FLAGS: %s\n", ext_imapflags_get_flags_string(renv->interp));
return TRUE;
return result;
}
......@@ -67,6 +67,7 @@ static bool cmd_setflag_opcode_execute
(const struct sieve_opcode *opcode ATTR_UNUSED,
const struct sieve_runtime_env *renv, sieve_size_t *address)
{
bool result = TRUE;
string_t *flag_item;
struct sieve_coded_stringlist *flag_list;
......@@ -81,7 +82,7 @@ static bool cmd_setflag_opcode_execute
}
/* Iterate through all requested headers to match */
while ( sieve_coded_stringlist_next_item(flag_list, &flag_item) &&
while ( (result=sieve_coded_stringlist_next_item(flag_list, &flag_item)) &&
flag_item != NULL ) {
ext_imapflags_set_flags(renv->interp, flag_item);
}
......@@ -90,6 +91,6 @@ static bool cmd_setflag_opcode_execute
printf(" FLAGS: %s\n", ext_imapflags_get_flags_string(renv->interp));
return TRUE;
return result;
}
......@@ -138,6 +138,7 @@ static bool seff_flags_read_context
const struct sieve_runtime_env *renv, sieve_size_t *address,
void **se_context)
{
bool result = TRUE;
pool_t pool = sieve_result_pool(renv->result);
struct seff_flags_context *ctx;
ARRAY_DEFINE(keywords, const char *);
......@@ -157,7 +158,7 @@ static bool seff_flags_read_context
/* Unpack */
flags_item = NULL;
while ( sieve_coded_stringlist_next_item(flag_list, &flags_item) &&
while ( (result=sieve_coded_stringlist_next_item(flag_list, &flags_item)) &&
flags_item != NULL ) {
const char *flag;
struct ext_imapflags_iter flit;
......@@ -190,7 +191,7 @@ static bool seff_flags_read_context
t_pop();
return TRUE;
return result;
}
static void seff_flags_print
......
......@@ -92,6 +92,32 @@ inline sieve_size_t sieve_coded_stringlist_get_current_offset
return strlist->current_offset;
}
bool sieve_coded_stringlist_read_all
(struct sieve_coded_stringlist *strlist, pool_t pool,
const char * const **list_r)
{
bool result = FALSE;
ARRAY_DEFINE(items, const char *);
string_t *item;
sieve_coded_stringlist_reset(strlist);
p_array_init(&items, pool, 4);
item = NULL;
while ( (result=sieve_coded_stringlist_next_item(strlist, &item)) &&
item != NULL ) {
const char *stritem = p_strdup(pool, str_c(item));
array_append(&items, &stritem, 1);
}
(void)array_append_space(&items);
*list_r = array_idx(&items, 0);
return result;
}
/*
* Operand functions
*/
......@@ -481,6 +507,7 @@ struct sieve_coded_stringlist *sieve_opr_stringlist_read
static bool opr_stringlist_dump
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
{
bool result = TRUE;
struct sieve_coded_stringlist *strlist;
if ( (strlist=opr_stringlist_read(denv->sbin, address)) != NULL ) {
......@@ -493,14 +520,15 @@ static bool opr_stringlist_dump
sieve_code_mark_specific(denv,
sieve_coded_stringlist_get_current_offset(strlist));
sieve_code_descend(denv);
while ( sieve_coded_stringlist_next_item(strlist, &stritem) && stritem != NULL ) {
while ( (result=sieve_coded_stringlist_next_item(strlist, &stritem)) &&
stritem != NULL ) {
_dump_string(denv, stritem);
sieve_code_mark_specific(denv,
sieve_coded_stringlist_get_current_offset(strlist));
}
sieve_code_ascend(denv);
return TRUE;
return result;
}
return FALSE;
......
#ifndef __SIEVE_CODE_H
#define __SIEVE_CODE_H
#include <lib.h>
#include <buffer.h>
#include <array.h>
#include "lib.h"
#include "buffer.h"
#include "mempool.h"
#include "array.h"
#include "sieve-common.h"
......@@ -11,12 +12,20 @@
struct sieve_coded_stringlist;
bool sieve_coded_stringlist_next_item(struct sieve_coded_stringlist *strlist, string_t **str);
void sieve_coded_stringlist_reset(struct sieve_coded_stringlist *strlist);
inline int sieve_coded_stringlist_get_length(struct sieve_coded_stringlist *strlist);
inline sieve_size_t sieve_coded_stringlist_get_end_address(struct sieve_coded_stringlist *strlist);
inline sieve_size_t sieve_coded_stringlist_get_current_offset(struct sieve_coded_stringlist *strlist);
bool sieve_coded_stringlist_next_item
(struct sieve_coded_stringlist *strlist, string_t **str);
void sieve_coded_stringlist_reset
(struct sieve_coded_stringlist *strlist);
bool sieve_coded_stringlist_read_all
(struct sieve_coded_stringlist *strlist, pool_t pool,
const char * const **list_r);
inline int sieve_coded_stringlist_get_length
(struct sieve_coded_stringlist *strlist);
inline sieve_size_t sieve_coded_stringlist_get_end_address
(struct sieve_coded_stringlist *strlist);
inline sieve_size_t sieve_coded_stringlist_get_current_offset
(struct sieve_coded_stringlist *strlist);
/* Operand: argument to an opcode */
......
......@@ -132,6 +132,7 @@ static bool tst_address_opcode_execute
(const struct sieve_opcode *opcode ATTR_UNUSED,
const struct sieve_runtime_env *renv, sieve_size_t *address)
{
bool result = TRUE;
const struct sieve_comparator *cmp = &i_octet_comparator;
const struct sieve_match_type *mtch = &is_match_type;
const struct sieve_address_part *addrp = &all_address_part;
......@@ -167,7 +168,8 @@ static bool tst_address_opcode_execute
/* 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 ) {
while ( !matched && (result=sieve_coded_stringlist_next_item(hdr_list, &hdr_item))
&& hdr_item != NULL ) {
const char *const *headers;
if ( mail_get_headers_utf8(renv->msgdata->mail, str_c(hdr_item), &headers) >= 0 ) {
......@@ -184,7 +186,8 @@ static bool tst_address_opcode_execute
t_pop();
sieve_interpreter_set_test_result(renv->interp, matched);
if ( result )
sieve_interpreter_set_test_result(renv->interp, matched);
return TRUE;
return result;
}
......@@ -97,6 +97,7 @@ static bool tst_exists_opcode_execute
(const struct sieve_opcode *opcode ATTR_UNUSED,
const struct sieve_runtime_env *renv, sieve_size_t *address)
{
bool result = TRUE;
struct sieve_coded_stringlist *hdr_list;
string_t *hdr_item;
bool matched;
......@@ -114,8 +115,8 @@ static bool tst_exists_opcode_execute
/* 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 ) {
while ( !matched && (result=sieve_coded_stringlist_next_item(hdr_list, &hdr_item))
&& hdr_item != NULL ) {
const char *const *headers;
if ( mail_get_headers_utf8
......@@ -127,7 +128,8 @@ static bool tst_exists_opcode_execute
t_pop();
sieve_interpreter_set_test_result(renv->interp, matched);
if ( result )
sieve_interpreter_set_test_result(renv->interp, matched);
return TRUE;
return result;
}
......@@ -155,6 +155,7 @@ static bool tst_header_opcode_execute
(const struct sieve_opcode *opcode ATTR_UNUSED,
const struct sieve_runtime_env *renv, sieve_size_t *address)
{
bool result = TRUE;
int opt_code = 1;
const struct sieve_comparator *cmp = &i_octet_comparator;
const struct sieve_match_type *mtch = &is_match_type;
......@@ -206,7 +207,8 @@ static bool tst_header_opcode_execute
/* 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 ) {
while ( !matched && (result=sieve_coded_stringlist_next_item(hdr_list, &hdr_item))
&& hdr_item != NULL ) {
const char *const *headers;
if ( mail_get_headers_utf8(renv->msgdata->mail, str_c(hdr_item), &headers) >= 0 ) {
......@@ -223,7 +225,8 @@ static bool tst_header_opcode_execute
t_pop();
sieve_interpreter_set_test_result(renv->interp, matched);
if ( result )
sieve_interpreter_set_test_result(renv->interp, matched);
return TRUE;
return result;
}
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.