summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/lib-sieve/sieve-message.h
blob: 4cb77ccb41ab11effc462d7d378f958382dc648f (plain)
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
268
269
270
271
272
273
274
275
276
277
278
279
280
#ifndef SIEVE_MESSAGE_H
#define SIEVE_MESSAGE_H

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

/*
 * Message transmission
 */

const char *sieve_message_get_new_id(const struct sieve_instance *svinst);

/*
 * Message context
 */

struct sieve_message_context;

struct sieve_message_context *sieve_message_context_create
	(struct sieve_instance *svinst, struct mail_user *mail_user,
		const struct sieve_message_data *msgdata);
void sieve_message_context_ref(struct sieve_message_context *msgctx);
void sieve_message_context_unref(struct sieve_message_context **msgctx);

void sieve_message_context_reset(struct sieve_message_context *msgctx);

pool_t sieve_message_context_pool
	(struct sieve_message_context *msgctx) ATTR_PURE;
void sieve_message_context_time(struct sieve_message_context *msgctx,
	struct timeval *time);

/* Extension support */

void sieve_message_context_extension_set
	(struct sieve_message_context *msgctx, const struct sieve_extension *ext,
		void *context);
const void *sieve_message_context_extension_get
	(struct sieve_message_context *msgctx, const struct sieve_extension *ext);

/* Envelope */

const struct smtp_address *sieve_message_get_final_recipient
	(struct sieve_message_context *msgctx);
const struct smtp_address *sieve_message_get_orig_recipient
	(struct sieve_message_context *msgctx);

const struct smtp_address *sieve_message_get_sender
	(struct sieve_message_context *msgctx);

/* Mail */

struct mail *sieve_message_get_mail
	(struct sieve_message_context *msgctx);

int sieve_message_substitute
	(struct sieve_message_context *msgctx, struct istream *input);
struct edit_mail *sieve_message_edit
	(struct sieve_message_context *msgctx);
void sieve_message_snapshot
	(struct sieve_message_context *msgctx);

/*
 * Header stringlist
 */

struct sieve_header_list {
	struct sieve_stringlist strlist;

	int (*next_item)
		(struct sieve_header_list *_hdrlist, const char **name_r,
			string_t **value_r) ATTR_NULL(2);
};

static inline int sieve_header_list_next_item
(struct sieve_header_list *hdrlist, const char **name_r,
	string_t **value_r) ATTR_NULL(2)
{
	return hdrlist->next_item(hdrlist, name_r, value_r);
}

static inline void sieve_header_list_reset
(struct sieve_header_list *hdrlist)
{
	sieve_stringlist_reset(&hdrlist->strlist);
}

static inline int sieve_header_list_get_length
(struct sieve_header_list *hdrlist)
{
	return sieve_stringlist_get_length(&hdrlist->strlist);
}

static inline void sieve_header_list_set_trace
(struct sieve_header_list *hdrlist, bool trace)
{
	sieve_stringlist_set_trace(&hdrlist->strlist, trace);
}

struct sieve_header_list *sieve_message_header_list_create
	(const struct sieve_runtime_env *renv,
		struct sieve_stringlist *field_names,
		bool mime_decode);

/*
 * Message override
 */

/* Header override object */

struct sieve_message_override_def {
	struct sieve_object_def obj_def;

	unsigned int sequence;

	/* Context coding */

	bool (*dump_context)
		(const struct sieve_message_override *svmo,
			const struct sieve_dumptime_env *denv, sieve_size_t *address);
	int (*read_context)
		(const struct sieve_message_override *svmo,
			const struct sieve_runtime_env *renv, sieve_size_t *address,
			void **se_context);

	/* Override */

	int (*header_override)
		(const struct sieve_message_override *svmo,
			const struct sieve_runtime_env *renv,
			bool mime_decode, struct sieve_stringlist **headers);
};

struct sieve_message_override {
	struct sieve_object object;

	const struct sieve_message_override_def *def;

	void *context;
};

ARRAY_DEFINE_TYPE(sieve_message_override,
	struct sieve_message_override);

/*
 * Message override operand
 */

#define SIEVE_EXT_DEFINE_MESSAGE_OVERRIDE(SVMO) SIEVE_EXT_DEFINE_OBJECT(SVMO)
#define SIEVE_EXT_DEFINE_MESSAGE_OVERRIDES(SVMOS) SIEVE_EXT_DEFINE_OBJECTS(SMOS)

#define SIEVE_OPT_MESSAGE_OVERRIDE (-2)

extern const struct sieve_operand_class
	sieve_message_override_operand_class;

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

bool sieve_opr_message_override_dump
	(const struct sieve_dumptime_env *denv, sieve_size_t *address);
int sieve_opr_message_override_read
	(const struct sieve_runtime_env *renv, sieve_size_t *address,
		struct sieve_message_override *svmo);

/*
 * Optional operands
 */

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

int sieve_message_opr_optional_read
	(const struct sieve_runtime_env *renv, sieve_size_t *address,
		signed int *opt_code, int *exec_status,
		struct sieve_address_part *addrp, struct sieve_match_type *mcht,
		struct sieve_comparator *cmp, 
		ARRAY_TYPE(sieve_message_override) *svmos);

/*
 * Message header
 */

int sieve_message_get_header_fields
	(const struct sieve_runtime_env *renv,
		struct sieve_stringlist *field_names,
		ARRAY_TYPE(sieve_message_override) *svmos,
		bool mime_decode, struct sieve_stringlist **fields_r);

/*
 * Message part
 */

struct sieve_message_part;

struct sieve_message_part_data {
	const char *content_type;
	const char *content_disposition;

	const char *content;
	unsigned long size;
};

struct sieve_message_part *sieve_message_part_parent
	(struct sieve_message_part *mpart) ATTR_PURE;
struct sieve_message_part *sieve_message_part_next
	(struct sieve_message_part *mpart) ATTR_PURE;
struct sieve_message_part *sieve_message_part_children
	(struct sieve_message_part *mpart) ATTR_PURE;

const char *sieve_message_part_content_type
	(struct sieve_message_part *mpart) ATTR_PURE;
const char *sieve_message_part_content_disposition
	(struct sieve_message_part *mpart) ATTR_PURE;

int sieve_message_part_get_first_header
	(struct sieve_message_part *mpart, const char *field,
		const char **value_r);

void sieve_message_part_get_data
	(struct sieve_message_part *mpart,
		struct sieve_message_part_data *data, bool text);

/*
 * Message body
 */

int sieve_message_body_get_content
	(const struct sieve_runtime_env *renv,
		const char * const *content_types,
		struct sieve_message_part_data **parts_r);
int sieve_message_body_get_text
	(const struct sieve_runtime_env *renv,
		struct sieve_message_part_data **parts_r);
int sieve_message_body_get_raw
	(const struct sieve_runtime_env *renv,
		struct sieve_message_part_data **parts_r);

/*
 * Message part iterator
 */

struct sieve_message_part_iter {
	const struct sieve_runtime_env *renv;
	struct sieve_message_part *root;
	unsigned int index, offset;
};

int sieve_message_part_iter_init
(struct sieve_message_part_iter *iter,
	const struct sieve_runtime_env *renv);
void sieve_message_part_iter_subtree(struct sieve_message_part_iter *iter,
	struct sieve_message_part_iter *subtree);
void sieve_message_part_iter_children(struct sieve_message_part_iter *iter,
	struct sieve_message_part_iter *child);

struct sieve_message_part *sieve_message_part_iter_current
(struct sieve_message_part_iter *iter);
struct sieve_message_part *sieve_message_part_iter_next
(struct sieve_message_part_iter *iter);

void sieve_message_part_iter_reset
(struct sieve_message_part_iter *iter);

/*
 * MIME header list
 */

struct sieve_header_list *sieve_mime_header_list_create
(const struct sieve_runtime_env *renv,
	struct sieve_stringlist *field_names,
	struct sieve_message_part_iter *part_iter,
	bool mime_decode, bool children);

#endif