1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
|
/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
*/
/* Extension imapflags
* --------------------
*
* Authors: Stephan Bosch
* Specification: draft-melnikov-sieve-imapflags-03.txt
* Implementation: full, but deprecated; provided for backwards compatibility
* Status: testing
*
*/
#include "lib.h"
#include "mempool.h"
#include "str.h"
#include "sieve-common.h"
#include "sieve-ast.h"
#include "sieve-code.h"
#include "sieve-extensions.h"
#include "sieve-actions.h"
#include "sieve-commands.h"
#include "sieve-validator.h"
#include "sieve-generator.h"
#include "sieve-interpreter.h"
#include "ext-imap4flags-common.h"
/*
* Commands
*/
static bool cmd_mark_validate
(struct sieve_validator *valdtr, struct sieve_command *cmd);
/* Mark command
*
* Syntax:
* mark
*/
static const struct sieve_command_def cmd_mark = {
.identifier = "mark",
.type = SCT_COMMAND,
.positional_args = 0,
.subtests = 0,
.block_allowed = FALSE,
.block_required = FALSE,
.validate = cmd_mark_validate
};
/* Unmark command
*
* Syntax:
* unmark
*/
static const struct sieve_command_def cmd_unmark = {
.identifier = "unmark",
.type = SCT_COMMAND,
.positional_args = 0,
.subtests = 0,
.block_allowed = FALSE,
.block_required = FALSE,
.validate = cmd_mark_validate
};
/*
* Extension
*/
static bool ext_imapflags_load
(const struct sieve_extension *ext, void **context);
static bool ext_imapflags_validator_load
(const struct sieve_extension *ext, struct sieve_validator *valdtr);
static bool ext_imapflags_interpreter_load
(const struct sieve_extension *ext, const struct sieve_runtime_env *renv,
sieve_size_t *address);
const struct sieve_extension_def imapflags_extension = {
.name = "imapflags",
.load = ext_imapflags_load,
.validator_load = ext_imapflags_validator_load,
.interpreter_load = ext_imapflags_interpreter_load
};
static bool ext_imapflags_load
(const struct sieve_extension *ext, void **context)
{
if ( *context == NULL ) {
/* Make sure real extension is registered, it is needed by the binary */
*context = (void *)
sieve_extension_require(ext->svinst, &imap4flags_extension, FALSE);
}
return TRUE;
}
/*
* Validator
*/
static bool ext_imapflags_validator_check_conflict
(const struct sieve_extension *ext,
struct sieve_validator *valdtr, void *context,
struct sieve_ast_argument *require_arg,
const struct sieve_extension *other_ext,
bool required);
static bool ext_imapflags_validator_validate
(const struct sieve_extension *ext,
struct sieve_validator *valdtr, void *context,
struct sieve_ast_argument *require_arg,
bool required);
const struct sieve_validator_extension
imapflags_validator_extension = {
.ext = &imapflags_extension,
.check_conflict = ext_imapflags_validator_check_conflict,
.validate = ext_imapflags_validator_validate
};
static bool ext_imapflags_validator_load
(const struct sieve_extension *ext, struct sieve_validator *valdtr)
{
sieve_validator_extension_register
(valdtr, ext, &imapflags_validator_extension, NULL);
return TRUE;
}
static bool ext_imapflags_validator_check_conflict
(const struct sieve_extension *ext,
struct sieve_validator *valdtr, void *context ATTR_UNUSED,
struct sieve_ast_argument *require_arg,
const struct sieve_extension *ext_other,
bool required ATTR_UNUSED)
{
const struct sieve_extension *master_ext =
(const struct sieve_extension *) ext->context;
if ( ext_other == master_ext ) {
sieve_argument_validate_error(valdtr, require_arg,
"the (deprecated) imapflags extension cannot be used "
"together with the imap4flags extension");
return FALSE;
}
return TRUE;
}
static bool ext_imapflags_validator_validate
(const struct sieve_extension *ext,
struct sieve_validator *valdtr, void *context ATTR_UNUSED,
struct sieve_ast_argument *require_arg ATTR_UNUSED,
bool required ATTR_UNUSED)
{
const struct sieve_extension *master_ext =
(const struct sieve_extension *) ext->context;
/* No conflicts */
/* Register commands */
sieve_validator_register_command(valdtr, master_ext, &cmd_setflag);
sieve_validator_register_command(valdtr, master_ext, &cmd_addflag);
sieve_validator_register_command(valdtr, master_ext, &cmd_removeflag);
sieve_validator_register_command(valdtr, master_ext, &cmd_mark);
sieve_validator_register_command(valdtr, master_ext, &cmd_unmark);
/* Attach flags side-effect to keep and fileinto actions */
sieve_ext_imap4flags_register_side_effect(valdtr, master_ext, "keep");
sieve_ext_imap4flags_register_side_effect(valdtr, master_ext, "fileinto");
return TRUE;
}
/*
* Interpreter
*/
static bool ext_imapflags_interpreter_load
(const struct sieve_extension *ext, const struct sieve_runtime_env *renv,
sieve_size_t *address ATTR_UNUSED)
{
const struct sieve_extension *master_ext =
(const struct sieve_extension *) ext->context;
sieve_ext_imap4flags_interpreter_load(master_ext, renv);
return TRUE;
}
/*
* Command validation
*/
static bool cmd_mark_validate
(struct sieve_validator *valdtr, struct sieve_command *cmd)
{
if ( sieve_command_is(cmd, cmd_mark) )
cmd->def = &cmd_addflag;
else
cmd->def = &cmd_removeflag;
cmd->first_positional = sieve_ast_argument_cstring_create
(cmd->ast_node, "\\flagged", cmd->ast_node->source_line);
if ( !sieve_validator_argument_activate
(valdtr, cmd, cmd->first_positional, FALSE) )
return FALSE;
return TRUE;
}
|