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

lib-sieve: imap4flags extension: Made flag syntax checking available to other extensions.

parent 9d7a19d9
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "str.h" #include "str.h"
#include "str-sanitize.h" #include "str-sanitize.h"
#include "mail-storage.h" #include "mail-storage.h"
#include "imap-arg.h"
#include "sieve-common.h" #include "sieve-common.h"
#include "sieve-commands.h" #include "sieve-commands.h"
...@@ -21,12 +22,6 @@ ...@@ -21,12 +22,6 @@
#include "ext-imap4flags-common.h" #include "ext-imap4flags-common.h"
/*
* Forward declarations
*/
static bool flag_is_valid(const char *flag);
/* /*
* Tagged arguments * Tagged arguments
*/ */
...@@ -132,9 +127,9 @@ bool ext_imap4flags_command_validate ...@@ -132,9 +127,9 @@ bool ext_imap4flags_command_validate
ext_imap4flags_iter_init(&fiter, sieve_ast_argument_str(arg)); ext_imap4flags_iter_init(&fiter, sieve_ast_argument_str(arg));
while ( (flag=ext_imap4flags_iter_get_flag(&fiter)) != NULL ) { while ( (flag=ext_imap4flags_iter_get_flag(&fiter)) != NULL ) {
if ( !flag_is_valid(flag) ) { if ( !sieve_ext_imap4flags_flag_is_valid(flag) ) {
sieve_argument_validate_warning(valdtr, arg, sieve_argument_validate_warning(valdtr, arg,
"IMAP flag '%s' specified for the %s command is invalid " "IMAP flag '%s' specified for the %s command is invalid "
"and will be ignored (only first invalid is reported)", "and will be ignored (only first invalid is reported)",
str_sanitize(flag, 64), sieve_command_identifier(cmd)); str_sanitize(flag, 64), sieve_command_identifier(cmd));
break; break;
...@@ -265,7 +260,7 @@ const struct sieve_interpreter_extension imap4flags_interpreter_extension = { ...@@ -265,7 +260,7 @@ const struct sieve_interpreter_extension imap4flags_interpreter_extension = {
* flags, making the internal or variable flag list indefinitely long * flags, making the internal or variable flag list indefinitely long
*/ */
static bool flag_is_valid(const char *flag) bool sieve_ext_imap4flags_flag_is_valid(const char *flag)
{ {
if (*flag == '\\') { if (*flag == '\\') {
/* System flag */ /* System flag */
...@@ -288,20 +283,10 @@ static bool flag_is_valid(const char *flag) ...@@ -288,20 +283,10 @@ static bool flag_is_valid(const char *flag)
* Syntax (IMAP4rev1, RFC 3501, Section 9. Formal Syntax) : * Syntax (IMAP4rev1, RFC 3501, Section 9. Formal Syntax) :
* flag-keyword = atom * flag-keyword = atom
* atom = 1*ATOM-CHAR * atom = 1*ATOM-CHAR
* ATOM-CHAR = <any CHAR except atom-specials>
* atom-specials = "(" / ")" / "{" / SP / CTL / list-wildcards /
* quoted-specials / resp-specials
* CTL = %x00-1F / %x7F
* list-wildcards = "%" / "*"
* quoted-specials = DQUOTE / "\"
* resp-specials = "]"
*/ */
p = flag; p = flag;
while ( *p != '\0' ) { while ( *p != '\0' ) {
if ( *p == '(' || *p == ')' || *p == '{' || *p == ' ' || if ( !IS_ATOM_CHAR(*p) )
*p <= 0x1F || *p == 0x7F || *p == '%' || *p == '*' ||
*p == '"' || *p == '\\' || *p == ']' )
return FALSE; return FALSE;
p++; p++;
} }
...@@ -449,7 +434,8 @@ static void flags_list_add_flags ...@@ -449,7 +434,8 @@ static void flags_list_add_flags
ext_imap4flags_iter_init(&flit, flags); ext_imap4flags_iter_init(&flit, flags);
while ( (flg=ext_imap4flags_iter_get_flag(&flit)) != NULL ) { while ( (flg=ext_imap4flags_iter_get_flag(&flit)) != NULL ) {
if ( flag_is_valid(flg) && !flags_list_flag_exists(flags_list, flg) ) { if ( sieve_ext_imap4flags_flag_is_valid(flg) &&
!flags_list_flag_exists(flags_list, flg) ) {
if ( str_len(flags_list) != 0 ) if ( str_len(flags_list) != 0 )
str_append_c(flags_list, ' '); str_append_c(flags_list, ' ');
str_append(flags_list, flg); str_append(flags_list, flg);
......
...@@ -22,6 +22,12 @@ sieve_ext_imap4flags_require_extension ...@@ -22,6 +22,12 @@ sieve_ext_imap4flags_require_extension
(svinst, &imap4flags_extension, TRUE); (svinst, &imap4flags_extension, TRUE);
} }
/*
* Flag syntax
*/
bool sieve_ext_imap4flags_flag_is_valid(const char *flag);
/* /*
* Flag manipulation * Flag manipulation
*/ */
......
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.