17
17
* Test_mailbox command
20
20
* test_mailbox ( :create / :delete ) <mailbox: string>
23
23
static bool cmd_test_mailbox_registered
24
(struct sieve_validator *valdtr, const struct sieve_extension *ext,
24
(struct sieve_validator *valdtr, const struct sieve_extension *ext,
25
25
struct sieve_command_registration *cmd_reg);
26
26
static bool cmd_test_mailbox_validate
27
27
(struct sieve_validator *valdtr, struct sieve_command *cmd);
28
28
static bool cmd_test_mailbox_generate
29
29
(const struct sieve_codegen_env *cgenv, struct sieve_command *ctx);
31
const struct sieve_command_def cmd_test_mailbox = {
31
const struct sieve_command_def cmd_test_mailbox = {
34
34
1, 0, FALSE, FALSE,
35
cmd_test_mailbox_registered,
35
cmd_test_mailbox_registered,
37
cmd_test_mailbox_validate,
38
cmd_test_mailbox_generate,
37
cmd_test_mailbox_validate,
38
cmd_test_mailbox_generate,
46
46
static bool cmd_test_mailbox_operation_dump
47
47
(const struct sieve_dumptime_env *denv, sieve_size_t *address);
48
48
static int cmd_test_mailbox_operation_execute
49
49
(const struct sieve_runtime_env *renv, sieve_size_t *address);
51
51
/* Test_mailbox_create operation */
53
const struct sieve_operation_def test_mailbox_create_operation = {
53
const struct sieve_operation_def test_mailbox_create_operation = {
54
54
"TEST_MAILBOX_CREATE",
56
56
TESTSUITE_OPERATION_TEST_MAILBOX_CREATE,
57
cmd_test_mailbox_operation_dump,
58
cmd_test_mailbox_operation_execute
57
cmd_test_mailbox_operation_dump,
58
cmd_test_mailbox_operation_execute
61
61
/* Test_mailbox_delete operation */
63
const struct sieve_operation_def test_mailbox_delete_operation = {
63
const struct sieve_operation_def test_mailbox_delete_operation = {
64
64
"TEST_MAILBOX_DELETE",
66
66
TESTSUITE_OPERATION_TEST_MAILBOX_DELETE,
67
cmd_test_mailbox_operation_dump,
68
cmd_test_mailbox_operation_execute
67
cmd_test_mailbox_operation_dump,
68
cmd_test_mailbox_operation_execute
72
72
* Compiler context data
75
75
enum test_mailbox_operation {
88
88
const char *folder;
95
95
static bool cmd_test_mailbox_validate_tag
96
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
96
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
97
97
struct sieve_command *cmd);
99
static const struct sieve_argument_def test_mailbox_create_tag = {
99
static const struct sieve_argument_def test_mailbox_create_tag = {
102
102
cmd_test_mailbox_validate_tag,
106
static const struct sieve_argument_def test_mailbox_delete_tag = {
106
static const struct sieve_argument_def test_mailbox_delete_tag = {
109
109
cmd_test_mailbox_validate_tag,
113
113
static bool cmd_test_mailbox_registered
114
114
(struct sieve_validator *valdtr, const struct sieve_extension *ext,
115
struct sieve_command_registration *cmd_reg)
115
struct sieve_command_registration *cmd_reg)
117
117
/* Register our tags */
118
118
sieve_validator_register_tag
119
(valdtr, cmd_reg, ext, &test_mailbox_create_tag, 0);
119
(valdtr, cmd_reg, ext, &test_mailbox_create_tag, 0);
120
120
sieve_validator_register_tag
121
(valdtr, cmd_reg, ext, &test_mailbox_delete_tag, 0);
121
(valdtr, cmd_reg, ext, &test_mailbox_delete_tag, 0);
126
126
static bool cmd_test_mailbox_validate_tag
127
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
127
(struct sieve_validator *valdtr, struct sieve_ast_argument **arg,
128
128
struct sieve_command *cmd)
130
struct cmd_test_mailbox_context_data *ctx_data =
131
(struct cmd_test_mailbox_context_data *) cmd->data;
130
struct cmd_test_mailbox_context_data *ctx_data =
131
(struct cmd_test_mailbox_context_data *) cmd->data;
133
133
if ( ctx_data != NULL ) {
134
134
sieve_argument_validate_error
135
135
(valdtr, *arg, "exactly one of the ':create' or ':delete' tags must be "
136
136
"specified for the test_mailbox command, but more were found");
141
141
(sieve_command_pool(cmd), struct cmd_test_mailbox_context_data, 1);
142
142
cmd->data = ctx_data;
144
if ( sieve_argument_is(*arg, test_mailbox_create_tag) )
144
if ( sieve_argument_is(*arg, test_mailbox_create_tag) )
145
145
ctx_data->mailbox_op = MAILBOX_OP_CREATE;
147
147
ctx_data->mailbox_op = MAILBOX_OP_DELETE;
159
159
static bool cmd_test_mailbox_validate
160
(struct sieve_validator *valdtr, struct sieve_command *cmd)
160
(struct sieve_validator *valdtr, struct sieve_command *cmd)
162
162
struct sieve_ast_argument *arg = cmd->first_positional;
164
164
if ( cmd->data == NULL ) {
165
sieve_command_validate_error(valdtr, cmd,
165
sieve_command_validate_error(valdtr, cmd,
166
166
"the test_mailbox command requires either the :create or the :delete tag "
167
167
"to be specified");
171
171
if ( !sieve_validate_positional_argument
172
172
(valdtr, cmd, arg, "mailbox", 1, SAAT_STRING) ) {
176
176
return sieve_validator_argument_activate(valdtr, cmd, arg, FALSE);
183
183
static bool cmd_test_mailbox_generate
184
184
(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
186
186
struct cmd_test_mailbox_context_data *ctx_data =
187
(struct cmd_test_mailbox_context_data *) cmd->data;
187
(struct cmd_test_mailbox_context_data *) cmd->data;
189
189
i_assert( ctx_data->mailbox_op < MAILBOX_OP_LAST );
191
191
/* Emit operation */
192
192
sieve_operation_emit(cgenv->sbin, cmd->ext,
193
193
test_mailbox_operations[ctx_data->mailbox_op]);
195
195
/* Generate arguments */
196
196
if ( !sieve_generate_arguments(cgenv, cmd, NULL) )
206
206
static bool cmd_test_mailbox_operation_dump
207
207
(const struct sieve_dumptime_env *denv, sieve_size_t *address)
209
209
const struct sieve_operation *op = &denv->oprtn;
211
211
sieve_code_dumpf(denv, "%s:", sieve_operation_mnemonic(op));
213
213
sieve_code_descend(denv);
215
215
return sieve_opr_string_dump(denv, address, "mailbox");