1
/* Copyright (c) 2002-2009 Dovecot Sieve authors, see the included COPYING file
6
#include "sieve-common.h"
7
#include "sieve-commands.h"
8
#include "sieve-extensions.h"
9
#include "sieve-validator.h"
10
#include "sieve-generator.h"
16
* Syntax: require <capabilities: string-list>
19
static bool cmd_require_validate
20
(struct sieve_validator *validator, struct sieve_command_context *cmd);
22
const struct sieve_command cmd_require = {
35
static bool cmd_require_validate
36
(struct sieve_validator *validator, struct sieve_command_context *cmd)
39
struct sieve_ast_argument *arg;
40
struct sieve_command_context *prev_context =
41
sieve_command_prev_context(cmd);
43
/* Check valid command placement */
44
if ( !sieve_command_is_toplevel(cmd) ||
45
( !sieve_command_is_first(cmd) && prev_context != NULL &&
46
prev_context->command != &cmd_require ) )
48
sieve_command_validate_error(validator, cmd,
49
"require commands can only be placed at top level "
50
"at the beginning of the file");
54
/* Check argument and load specified extension(s) */
56
arg = cmd->first_positional;
57
if ( sieve_ast_argument_type(arg) == SAAT_STRING ) {
59
const struct sieve_extension *ext = sieve_validator_extension_load
60
(validator, cmd, arg, sieve_ast_argument_str(arg));
62
if ( ext == NULL ) result = FALSE;
64
} else if ( sieve_ast_argument_type(arg) == SAAT_STRING_LIST ) {
66
struct sieve_ast_argument *stritem = sieve_ast_strlist_first(arg);
68
while ( stritem != NULL ) {
69
const struct sieve_extension *ext = sieve_validator_extension_load
70
(validator, cmd, stritem, sieve_ast_strlist_str(stritem));
72
if ( ext == NULL ) result = FALSE;
74
stritem = sieve_ast_strlist_next(stritem);
78
sieve_argument_validate_error(validator, arg,
79
"the require command accepts a single string or string list argument, "
81
sieve_ast_argument_name(arg));