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

Imap4flags: fixed bug in setflag command; when parameter was a stringlist,...

Imap4flags: fixed bug in setflag command; when parameter was a stringlist, only the last item was actually set.
parent 2faf5329
No related branches found
No related tags found
No related merge requests found
......@@ -241,17 +241,7 @@ static int cmd_flag_operation_execute
i_unreached();
}
/* Iterate through all flags and perform requested operation */
/* Perform requested operation */
while ( (ret=sieve_stringlist_next_item(flag_list, &flag_item)) > 0 ) {
if ( (ret=flag_op(renv, storage, var_index, flag_item)) <= 0)
return ret;
}
if ( ret < 0 ) {
sieve_runtime_trace_error(renv, "invalid flag-list item");
return SIEVE_EXEC_BIN_CORRUPT;
}
return SIEVE_EXEC_OK;
return flag_op(renv, storage, var_index, flag_list);
}
......@@ -457,27 +457,43 @@ static void flags_list_set_flags
flags_list_add_flags(flags_list, flags);
}
static void flags_list_clear_flags
(string_t *flags_list)
{
str_truncate(flags_list, 0);
}
int ext_imap4flags_set_flags
(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage,
unsigned int var_index, string_t *flags)
unsigned int var_index, struct sieve_stringlist *flags)
{
string_t *cur_flags;
if ( storage != NULL ) {
if ( !sieve_variable_get_modifiable(storage, var_index, &cur_flags) )
return SIEVE_EXEC_BIN_CORRUPT;
} else
} else {
cur_flags = _get_flags_string(renv->oprtn->ext, renv->result);
}
if ( cur_flags != NULL ) {
string_t *flags_item;
int ret;
if ( cur_flags != NULL )
flags_list_set_flags(cur_flags, flags);
flags_list_clear_flags(cur_flags);
while ( (ret=sieve_stringlist_next_item(flags, &flags_item)) > 0 ) {
flags_list_add_flags(cur_flags, flags_item);
}
if ( ret < 0 ) return SIEVE_EXEC_BIN_CORRUPT;
}
return SIEVE_EXEC_OK;
}
int ext_imap4flags_add_flags
(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage,
unsigned int var_index, string_t *flags)
unsigned int var_index, struct sieve_stringlist *flags)
{
string_t *cur_flags;
......@@ -486,16 +502,24 @@ int ext_imap4flags_add_flags
return SIEVE_EXEC_BIN_CORRUPT;
} else
cur_flags = _get_flags_string(renv->oprtn->ext, renv->result);
if ( cur_flags != NULL )
flags_list_add_flags(cur_flags, flags);
return SIEVE_EXEC_OK;
if ( cur_flags != NULL ) {
string_t *flags_item;
int ret;
while ( (ret=sieve_stringlist_next_item(flags, &flags_item)) > 0 ) {
flags_list_add_flags(cur_flags, flags_item);
}
if ( ret < 0 ) return SIEVE_EXEC_BIN_CORRUPT;
}
return SIEVE_EXEC_OK;
}
int ext_imap4flags_remove_flags
(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage,
unsigned int var_index, string_t *flags)
unsigned int var_index, struct sieve_stringlist *flags)
{
string_t *cur_flags;
......@@ -505,8 +529,16 @@ int ext_imap4flags_remove_flags
} else
cur_flags = _get_flags_string(renv->oprtn->ext, renv->result);
if ( cur_flags != NULL )
flags_list_remove_flags(cur_flags, flags);
if ( cur_flags != NULL ) {
string_t *flags_item;
int ret;
while ( (ret=sieve_stringlist_next_item(flags, &flags_item)) > 0 ) {
flags_list_remove_flags(cur_flags, flags_item);
}
if ( ret < 0 ) return SIEVE_EXEC_BIN_CORRUPT;
}
return SIEVE_EXEC_OK;
}
......
......@@ -90,17 +90,17 @@ const char *ext_imap4flags_iter_get_flag
typedef int (*ext_imapflag_flag_operation_t)
(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage,
unsigned int var_index, string_t *flags);
unsigned int var_index, struct sieve_stringlist *flags);
int ext_imap4flags_set_flags
(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage,
unsigned int var_index, string_t *flags);
unsigned int var_index, struct sieve_stringlist *flags);
int ext_imap4flags_add_flags
(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage,
unsigned int var_index, string_t *flags);
unsigned int var_index, struct sieve_stringlist *flags);
int ext_imap4flags_remove_flags
(const struct sieve_runtime_env *renv, struct sieve_variable_storage *storage,
unsigned int var_index, string_t *flags);
unsigned int var_index, struct sieve_stringlist *flags);
/* Flags access */
......
......@@ -104,6 +104,30 @@ test "Flag operations" {
}
}
test "Setflag; string list" {
setflag ["A B", "C D"];
if not hasflag "A" {
test_fail "hasflag misses A flag";
}
if not hasflag "B" {
test_fail "hasflag misses B flag";
}
if not hasflag "C" {
test_fail "hasflag misses C flag";
}
if not hasflag "D" {
test_fail "hasflag misses D flag";
}
if hasflag :comparator "i;ascii-numeric" :count "ne" "4" {
test_fail "hasflag sees incorrect number of flags";
}
}
test "Removal: one" {
setflag "\\seen";
......
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.