File: sieve-actions.h

package info (click to toggle)
dovecot 1:2.2.13-12~deb8u4
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 38,792 kB
  • sloc: ansic: 341,472; sh: 16,920; makefile: 5,393; cpp: 1,474; perl: 265; xml: 44; python: 34; pascal: 27
file content (267 lines) | stat: -rw-r--r-- 6,791 bytes parent folder | download | duplicates (3)
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/* Copyright (c) 2002-2013 Pigeonhole authors, see the included COPYING file
 */

#ifndef __SIEVE_ACTIONS_H
#define __SIEVE_ACTIONS_H

#include "lib.h"
#include "mail-storage.h"

#include "sieve-common.h"
#include "sieve-objects.h"
#include "sieve-extensions.h"

/*
 * Action execution environment
 */

struct sieve_action_exec_env {
	struct sieve_instance *svinst;

	struct sieve_result *result;
	struct sieve_error_handler *ehandler;

	const struct sieve_message_data *msgdata;
	struct sieve_message_context *msgctx;
	const struct sieve_script_env *scriptenv;
	struct sieve_exec_status *exec_status;
};

const char *sieve_action_get_location(const struct sieve_action_exec_env *aenv);

/*
 * Action flags
 */

enum sieve_action_flags {
	SIEVE_ACTFLAG_TRIES_DELIVER = (1 << 0),
	SIEVE_ACTFLAG_SENDS_RESPONSE = (1 << 1)
};

/*
 * Action definition
 */

struct sieve_action_def {
	const char *name;
	unsigned int flags;

	bool (*equals)
		(const struct sieve_script_env *senv, const struct sieve_action *act1,
			const struct sieve_action *act2);

	/* Result verification */

	int (*check_duplicate)
		(const struct sieve_runtime_env *renv,
			const struct sieve_action *act,
			const struct sieve_action *act_other);
	int (*check_conflict)
		(const struct sieve_runtime_env *renv,
			const struct sieve_action *act,
			const struct sieve_action *act_other);

	/* Result printing */

	void (*print)
		(const struct sieve_action *action,
			const struct sieve_result_print_env *penv, bool *keep);

	/* Result execution */

	int (*start)
		(const struct sieve_action *action,
			const struct sieve_action_exec_env *aenv, void **tr_context);
	int (*execute)
		(const struct sieve_action *action,
			const struct sieve_action_exec_env *aenv, void *tr_context);
	int (*commit)
		(const struct sieve_action *action,
			const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep);
	void (*rollback)
		(const struct sieve_action *action,
			const struct sieve_action_exec_env *aenv, void *tr_context, bool success);
};

/*
 * Action instance
 */

struct sieve_action {
	const struct sieve_action_def *def;
	const struct sieve_extension *ext;

	const char *location;
	void *context;
	struct mail *mail;
	bool executed;
};

#define sieve_action_is(act, definition) \
	( (act)->def == &(definition) )

/*
 * Action side effects
 */

/* Side effect object */

struct sieve_side_effect_def {
	struct sieve_object_def obj_def;

	/* The action it is supposed to link to */

	const struct sieve_action_def *to_action;

	/* Context coding */

	bool (*dump_context)
		(const struct sieve_side_effect *seffect,
			const struct sieve_dumptime_env *renv, sieve_size_t *address);
	int (*read_context)
		(const struct sieve_side_effect *seffect,
			const struct sieve_runtime_env *renv, sieve_size_t *address,
			void **se_context);

	/* Result verification */

	int (*merge)
		(const struct sieve_runtime_env *renv, const struct sieve_action *action,
			const struct sieve_side_effect *old_seffect,
			const struct sieve_side_effect *new_seffect, void **old_context);

	/* Result printing */

	void (*print)
		(const struct sieve_side_effect *seffect, const struct sieve_action *action,
			const struct sieve_result_print_env *penv, bool *keep);

	/* Result execution */

	int (*pre_execute)
		(const struct sieve_side_effect *seffect, const struct sieve_action *action,
			const struct sieve_action_exec_env *aenv, void **context,
			void *tr_context);
	int (*post_execute)
		(const struct sieve_side_effect *seffect, const struct sieve_action *action,
			const struct sieve_action_exec_env *aenv, void *tr_context);
	void (*post_commit)
		(const struct sieve_side_effect *seffect, const struct sieve_action *action,
			const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep);
	void (*rollback)
		(const struct sieve_side_effect *seffect, const struct sieve_action *action,
			const struct sieve_action_exec_env *aenv, void *tr_context, bool success);
};

struct sieve_side_effect {
	struct sieve_object object;

	const struct sieve_side_effect_def *def;

	void *context;
};

/*
 * Side effect operand
 */

#define SIEVE_EXT_DEFINE_SIDE_EFFECT(SEF) SIEVE_EXT_DEFINE_OBJECT(SEF)
#define SIEVE_EXT_DEFINE_SIDE_EFFECTS(SEFS) SIEVE_EXT_DEFINE_OBJECTS(SEFS)

#define SIEVE_OPT_SIDE_EFFECT (-1)

extern const struct sieve_operand_class sieve_side_effect_operand_class;

static inline void sieve_opr_side_effect_emit
(struct sieve_binary_block *sblock, const struct sieve_extension *ext,
	const struct sieve_side_effect_def *seff)
{
	sieve_opr_object_emit(sblock, ext, &seff->obj_def);
}

bool sieve_opr_side_effect_read
	(const struct sieve_runtime_env *renv, sieve_size_t *address,
		struct sieve_side_effect *seffect);

bool sieve_opr_side_effect_dump
	(const struct sieve_dumptime_env *denv, sieve_size_t *address);

/*
 * Optional operands
 */

int sieve_action_opr_optional_dump
	(const struct sieve_dumptime_env *denv, sieve_size_t *address,
		signed int *opt_code);

int sieve_action_opr_optional_read
	(const struct sieve_runtime_env *renv, sieve_size_t *address,
		signed int *opt_code, int *exec_status,
		struct sieve_side_effects_list **list);

/*
 * Core actions
 */

extern const struct sieve_action_def act_redirect;
extern const struct sieve_action_def act_store;
extern const struct sieve_action_def act_discard;

/*
 * Store action
 */

struct act_store_context {
	/* Folder name represented in utf-8 */
	const char *mailbox;
};

struct act_store_transaction {
	struct act_store_context *context;
	struct mailbox *box;
	struct mailbox_transaction_context *mail_trans;
	struct mail *dest_mail;

	const char *error;
	enum mail_error error_code;

	enum mail_flags flags;
	ARRAY_TYPE(const_string) keywords;

	unsigned int flags_altered:1;
	unsigned int disabled:1;
	unsigned int redundant:1;
};

int sieve_act_store_add_to_result
	(const struct sieve_runtime_env *renv,
		struct sieve_side_effects_list *seffects, const char *folder);

void sieve_act_store_add_flags
	(const struct sieve_action_exec_env *aenv, void *tr_context,
		const char *const *keywords, enum mail_flags flags);

void sieve_act_store_get_storage_error
	(const struct sieve_action_exec_env *aenv, struct act_store_transaction *trans);

/*
 * Action utility functions
 */

/* Checking for duplicates */

bool sieve_action_duplicate_check_available
	(const struct sieve_script_env *senv);
int sieve_action_duplicate_check
	(const struct sieve_script_env *senv, const void *id, size_t id_size);
void sieve_action_duplicate_mark
	(const struct sieve_script_env *senv, const void *id, size_t id_size,
		time_t time);

/* Rejecting mail */

bool sieve_action_reject_mail
(const struct sieve_action_exec_env *aenv,
	const char *sender, const char *recipient, const char *reason);

#endif /* __SIEVE_ACTIONS_H */