6
6
#include "sieve-common.h"
7
7
#include "sieve-commands.h"
8
8
#include "sieve-extensions.h"
9
#include "sieve-validator.h"
9
#include "sieve-validator.h"
10
10
#include "sieve-generator.h"
16
16
* Syntax: require <capabilities: string-list>
19
19
static bool cmd_require_validate
20
20
(struct sieve_validator *valdtr, struct sieve_command *cmd);
22
const struct sieve_command_def cmd_require = {
22
const struct sieve_command_def cmd_require = {
25
25
1, 0, FALSE, FALSE,
35
35
static bool cmd_require_validate
36
(struct sieve_validator *valdtr, struct sieve_command *cmd)
36
(struct sieve_validator *valdtr, struct sieve_command *cmd)
38
38
bool result = TRUE;
39
39
struct sieve_ast_argument *arg;
40
40
struct sieve_command *prev = sieve_command_prev(cmd);
42
42
/* Check valid command placement */
43
43
if ( !sieve_command_is_toplevel(cmd) ||
44
44
( !sieve_command_is_first(cmd) && prev != NULL &&
45
!sieve_command_is(prev, cmd_require) ) )
47
sieve_command_validate_error(valdtr, cmd,
45
!sieve_command_is(prev, cmd_require) ) )
47
sieve_command_validate_error(valdtr, cmd,
48
48
"require commands can only be placed at top level "
49
49
"at the beginning of the file");
53
53
/* Check argument and load specified extension(s) */
55
55
arg = cmd->first_positional;
56
56
if ( sieve_ast_argument_type(arg) == SAAT_STRING ) {
57
57
/* Single string */
58
58
const struct sieve_extension *ext = sieve_validator_extension_load_by_name
59
(valdtr, cmd, arg, sieve_ast_argument_strc(arg));
59
(valdtr, cmd, arg, sieve_ast_argument_strc(arg));
61
61
if ( ext == NULL ) result = FALSE;
63
63
} else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) {
65
65
struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg);
67
67
while ( stritem != NULL ) {
68
68
const struct sieve_extension *ext = sieve_validator_extension_load_by_name
69
69
(valdtr, cmd, stritem, sieve_ast_strlist_strc(stritem));
71
71
if ( ext == NULL ) result = FALSE;
73
73
stritem = sieve_ast_strlist_next(stritem);
76
76
/* Something else */
77
sieve_argument_validate_error(valdtr, arg,
77
sieve_argument_validate_error(valdtr, arg,
78
78
"the require command accepts a single string or string list argument, "
80
80
sieve_ast_argument_name(arg));