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
|
#ifndef SIEVE_STORAGE_PRIVATE_H
#define SIEVE_STORAGE_PRIVATE_H
#include "sieve.h"
#include "sieve-error-private.h"
#include "sieve-storage.h"
#define MAILBOX_ATTRIBUTE_PREFIX_SIEVE \
MAILBOX_ATTRIBUTE_PREFIX_DOVECOT_PVT_SERVER"sieve/"
#define MAILBOX_ATTRIBUTE_PREFIX_SIEVE_FILES \
MAILBOX_ATTRIBUTE_PREFIX_SIEVE"files/"
#define MAILBOX_ATTRIBUTE_SIEVE_DEFAULT \
MAILBOX_ATTRIBUTE_PREFIX_SIEVE"default"
#define MAILBOX_ATTRIBUTE_SIEVE_DEFAULT_LINK 'L'
#define MAILBOX_ATTRIBUTE_SIEVE_DEFAULT_SCRIPT 'S'
struct sieve_storage;
ARRAY_DEFINE_TYPE(sieve_storage_class, const struct sieve_storage *);
struct sieve_storage_vfuncs {
struct sieve_storage *(*alloc)(void);
void (*destroy)(struct sieve_storage *storage);
int (*init)(struct sieve_storage *storage, const char *const *options,
enum sieve_error *error_r);
int (*get_last_change)(struct sieve_storage *storage,
time_t *last_change_r);
void (*set_modified)(struct sieve_storage *storage, time_t mtime);
int (*is_singular)(struct sieve_storage *storage);
/* script access */
struct sieve_script *(*get_script)(struct sieve_storage *storage,
const char *name);
/* script sequence */
struct sieve_script_sequence *(*get_script_sequence)(
struct sieve_storage *storage, enum sieve_error *error_r);
struct sieve_script *(*script_sequence_next)(
struct sieve_script_sequence *seq, enum sieve_error *error_r);
void (*script_sequence_destroy)(struct sieve_script_sequence *seq);
/* active script */
int (*active_script_get_name)(struct sieve_storage *storage,
const char **name_r);
struct sieve_script *(*active_script_open)(
struct sieve_storage *storage);
int (*deactivate)(struct sieve_storage *storage);
int (*active_script_get_last_change)(struct sieve_storage *storage,
time_t *last_change_r);
/* listing scripts */
struct sieve_storage_list_context *(*list_init)(
struct sieve_storage *storage);
const char *(*list_next)(struct sieve_storage_list_context *lctx,
bool *active_r);
int (*list_deinit)(struct sieve_storage_list_context *lctx);
/* saving scripts */
// FIXME: simplify this API; reduce this mostly to a single save function
struct sieve_storage_save_context *(*save_alloc)(
struct sieve_storage *storage);
int (*save_init)(struct sieve_storage_save_context *sctx,
const char *scriptname, struct istream *input);
int (*save_continue)(struct sieve_storage_save_context *sctx);
int (*save_finish)(struct sieve_storage_save_context *sctx);
struct sieve_script *(*save_get_tempscript)(
struct sieve_storage_save_context *sctx);
void (*save_cancel)(struct sieve_storage_save_context *sctx);
int (*save_commit)(struct sieve_storage_save_context *sctx);
int (*save_as)(struct sieve_storage *storage, struct istream *input,
const char *name);
int (*save_as_active)(struct sieve_storage *storage,
struct istream *input, time_t mtime);
/* checking quota */
int (*quota_havespace)(struct sieve_storage *storage,
const char *scriptname, size_t size,
enum sieve_storage_quota *quota_r,
uint64_t *limit_r);
};
struct sieve_storage {
pool_t pool;
unsigned int refcount;
struct sieve_instance *svinst;
struct event *event;
const char *driver_name;
unsigned int version;
const struct sieve_storage *storage_class;
struct sieve_storage_vfuncs v;
uint64_t max_scripts;
uint64_t max_storage;
char *error;
enum sieve_error error_code;
const char *data;
const char *location;
const char *script_name;
const char *bin_dir;
const char *default_name;
const char *default_location;
struct sieve_storage *default_for;
struct mail_namespace *sync_inbox_ns;
enum sieve_storage_flags flags;
/* this is the main personal storage */
bool main_storage:1;
bool allows_synchronization:1;
bool is_default:1;
};
struct event *
sieve_storage_event_create(struct sieve_instance *svinst,
const struct sieve_storage *storage_class);
struct sieve_storage *
sieve_storage_alloc(struct sieve_instance *svinst, struct event *event,
const struct sieve_storage *storage_class, const char *data,
enum sieve_storage_flags flags, bool main) ATTR_NULL(2, 4);
int sieve_storage_setup_bindir(struct sieve_storage *storage, mode_t mode);
/*
* Active script
*/
int sieve_storage_active_script_is_default(struct sieve_storage *storage);
/*
* Listing scripts
*/
struct sieve_storage_list_context {
struct sieve_storage *storage;
bool seen_active:1; // Just present for assertions
bool seen_default:1;
};
/*
* Script sequence
*/
struct sieve_script_sequence {
struct sieve_storage *storage;
};
/*
* Saving scripts
*/
struct sieve_storage_save_context {
pool_t pool;
struct sieve_storage *storage;
struct event *event;
const char *scriptname, *active_scriptname;
struct sieve_script *scriptobject;
struct istream *input;
time_t mtime;
bool failed:1;
bool finished:1;
};
/*
* Storage class
*/
struct sieve_storage_class_registry;
void sieve_storages_init(struct sieve_instance *svinst);
void sieve_storages_deinit(struct sieve_instance *svinst);
void sieve_storage_class_register(struct sieve_instance *svinst,
const struct sieve_storage *storage_class);
void sieve_storage_class_unregister(struct sieve_instance *svinst,
const struct sieve_storage *storage_class);
const struct sieve_storage *
sieve_storage_find_class(struct sieve_instance *svinst, const char *name);
/*
* Built-in storage drivers
*/
/* data (currently only for internal use) */
#define SIEVE_DATA_STORAGE_DRIVER_NAME "data"
extern const struct sieve_storage sieve_data_storage;
/* file */
#define SIEVE_FILE_STORAGE_DRIVER_NAME "file"
extern const struct sieve_storage sieve_file_storage;
struct sieve_storage *
sieve_file_storage_init_legacy(struct sieve_instance *svinst,
const char *active_path,
const char *storage_path,
enum sieve_storage_flags flags,
enum sieve_error *error_r) ATTR_NULL(6);
/* dict */
#define SIEVE_DICT_STORAGE_DRIVER_NAME "dict"
extern const struct sieve_storage sieve_dict_storage;
/* ldap */
#define SIEVE_LDAP_STORAGE_DRIVER_NAME "ldap"
extern const struct sieve_storage sieve_ldap_storage;
/*
* Error handling
*/
void sieve_storage_set_internal_error(struct sieve_storage *storage);
void sieve_storage_copy_error(struct sieve_storage *storage,
const struct sieve_storage *source);
/*
* Synchronization
*/
int sieve_storage_sync_init(struct sieve_storage *storage,
struct mail_user *user);
void sieve_storage_sync_deinit(struct sieve_storage *storage);
int sieve_storage_sync_script_save(struct sieve_storage *storage,
const char *name);
int sieve_storage_sync_script_rename(struct sieve_storage *storage,
const char *oldname, const char *newname);
int sieve_storage_sync_script_delete(struct sieve_storage *storage,
const char *name);
int sieve_storage_sync_script_activate(struct sieve_storage *storage);
int sieve_storage_sync_deactivate(struct sieve_storage *storage);
#endif
|