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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/* Copyright (c) 2009-2018 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "array.h"
#include "str-sanitize.h"
#include "mail-storage-private.h"
#include "mailbox-list-private.h"
#include "fail-mail-storage.h"
#define TEST_UID_VALIDITY 1
static bool fail_mailbox_is_readonly(struct mailbox *box ATTR_UNUSED)
{
return FALSE;
}
static int fail_mailbox_enable(struct mailbox *box,
enum mailbox_feature features)
{
box->enabled_features = features;
return -1;
}
static int fail_mailbox_exists(struct mailbox *box ATTR_UNUSED,
bool auto_boxes ATTR_UNUSED,
enum mailbox_existence *existence_r)
{
*existence_r = MAILBOX_EXISTENCE_NONE;
return 0;
}
static int fail_mailbox_open(struct mailbox *box)
{
mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
T_MAIL_ERR_MAILBOX_NOT_FOUND(box->vname));
return -1;
}
static void fail_mailbox_close(struct mailbox *box ATTR_UNUSED)
{
}
static void fail_mailbox_free(struct mailbox *box)
{
event_unref(&box->event);
}
static int
fail_mailbox_create(struct mailbox *box,
const struct mailbox_update *update ATTR_UNUSED,
bool directory ATTR_UNUSED)
{
mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
"Mailbox can't be created");
return -1;
}
static int
fail_mailbox_update(struct mailbox *box,
const struct mailbox_update *update ATTR_UNUSED)
{
mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
"Mailbox can't be updated");
return -1;
}
static int fail_mailbox_delete(struct mailbox *box)
{
mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
"Mailbox can't be deleted");
return -1;
}
static int fail_mailbox_rename(struct mailbox *src,
struct mailbox *dest ATTR_UNUSED)
{
mail_storage_set_error(src->storage, MAIL_ERROR_NOTPOSSIBLE,
"Mailbox can't be renamed");
return -1;
}
static int fail_mailbox_get_status(struct mailbox *box ATTR_UNUSED,
enum mailbox_status_items items ATTR_UNUSED,
struct mailbox_status *status_r)
{
status_r->uidvalidity = TEST_UID_VALIDITY;
status_r->uidnext = 1;
mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
T_MAIL_ERR_MAILBOX_NOT_FOUND(box->vname));
return -1;
}
static int
fail_mailbox_get_metadata(struct mailbox *box,
enum mailbox_metadata_items items ATTR_UNUSED,
struct mailbox_metadata *metadata_r ATTR_UNUSED)
{
mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND,
T_MAIL_ERR_MAILBOX_NOT_FOUND(box->vname));
return -1;
}
static int fail_mailbox_set_subscribed(struct mailbox *box,
bool set ATTR_UNUSED)
{
mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
"Mailbox can't be subscribed");
return -1;
}
static struct mailbox_sync_context *
fail_mailbox_sync_init(struct mailbox *box,
enum mailbox_sync_flags flags ATTR_UNUSED)
{
struct mailbox_sync_context *ctx;
ctx = i_new(struct mailbox_sync_context, 1);
ctx->box = box;
return ctx;
}
static bool
fail_mailbox_sync_next(struct mailbox_sync_context *ctx ATTR_UNUSED,
struct mailbox_sync_rec *sync_rec_r ATTR_UNUSED)
{
return FALSE;
}
static int
fail_mailbox_sync_deinit(struct mailbox_sync_context *ctx,
struct mailbox_sync_status *status_r ATTR_UNUSED)
{
mail_storage_set_error(ctx->box->storage, MAIL_ERROR_NOTFOUND,
T_MAIL_ERR_MAILBOX_NOT_FOUND(ctx->box->vname));
i_free(ctx);
return -1;
}
static void fail_mailbox_notify_changes(struct mailbox *box ATTR_UNUSED)
{
}
static struct mailbox_transaction_context *
fail_mailbox_transaction_begin(struct mailbox *box,
enum mailbox_transaction_flags flags,
const char *reason ATTR_UNUSED)
{
struct mailbox_transaction_context *ctx;
ctx = i_new(struct mailbox_transaction_context, 1);
ctx->box = box;
ctx->flags = flags;
i_array_init(&ctx->module_contexts, 5);
return ctx;
}
static void
fail_mailbox_transaction_rollback(struct mailbox_transaction_context *t)
{
array_free(&t->module_contexts);
i_free(t);
}
static int
fail_mailbox_transaction_commit(struct mailbox_transaction_context *t,
struct mail_transaction_commit_changes *changes_r)
{
changes_r->uid_validity = TEST_UID_VALIDITY;
fail_mailbox_transaction_rollback(t);
return 0;
}
static struct mail_search_context *
fail_mailbox_search_init(struct mailbox_transaction_context *t,
struct mail_search_args *args,
const enum mail_sort_type *sort_program ATTR_UNUSED,
enum mail_fetch_field wanted_fields ATTR_UNUSED,
struct mailbox_header_lookup_ctx *wanted_headers ATTR_UNUSED)
{
struct mail_search_context *ctx;
ctx = i_new(struct mail_search_context, 1);
ctx->transaction = t;
ctx->args = args;
i_array_init(&ctx->results, 5);
i_array_init(&ctx->module_contexts, 5);
return ctx;
}
static int fail_mailbox_search_deinit(struct mail_search_context *ctx)
{
array_free(&ctx->results);
array_free(&ctx->module_contexts);
i_free(ctx);
return 0;
}
static bool
fail_mailbox_search_next_nonblock(struct mail_search_context *ctx ATTR_UNUSED,
struct mail **mail_r, bool *tryagain_r)
{
*tryagain_r = FALSE;
*mail_r = NULL;
return FALSE;
}
static bool
fail_mailbox_search_next_update_seq(struct mail_search_context *ctx ATTR_UNUSED)
{
return FALSE;
}
static int
fail_mailbox_search_next_match_mail(struct mail_search_context *ctx ATTR_UNUSED,
struct mail *mail ATTR_UNUSED)
{
return -1;
}
static struct mail_save_context *
fail_mailbox_save_alloc(struct mailbox_transaction_context *t)
{
struct mail_save_context *ctx;
ctx = i_new(struct mail_save_context, 1);
ctx->transaction = t;
return ctx;
}
static int
fail_mailbox_save_begin(struct mail_save_context *ctx ATTR_UNUSED,
struct istream *input ATTR_UNUSED)
{
return -1;
}
static int
fail_mailbox_save_continue(struct mail_save_context *ctx ATTR_UNUSED)
{
return -1;
}
static int
fail_mailbox_save_finish(struct mail_save_context *ctx ATTR_UNUSED)
{
return -1;
}
static void
fail_mailbox_save_cancel(struct mail_save_context *ctx ATTR_UNUSED)
{
}
static int
fail_mailbox_copy(struct mail_save_context *ctx ATTR_UNUSED,
struct mail *mail ATTR_UNUSED)
{
return -1;
}
static bool fail_mailbox_is_inconsistent(struct mailbox *box ATTR_UNUSED)
{
return FALSE;
}
struct mailbox fail_mailbox = {
.v = {
fail_mailbox_is_readonly,
fail_mailbox_enable,
fail_mailbox_exists,
fail_mailbox_open,
fail_mailbox_close,
fail_mailbox_free,
fail_mailbox_create,
fail_mailbox_update,
fail_mailbox_delete,
fail_mailbox_rename,
fail_mailbox_get_status,
fail_mailbox_get_metadata,
fail_mailbox_set_subscribed,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
fail_mailbox_sync_init,
fail_mailbox_sync_next,
fail_mailbox_sync_deinit,
NULL,
fail_mailbox_notify_changes,
fail_mailbox_transaction_begin,
fail_mailbox_transaction_commit,
fail_mailbox_transaction_rollback,
NULL,
fail_mailbox_mail_alloc,
fail_mailbox_search_init,
fail_mailbox_search_deinit,
fail_mailbox_search_next_nonblock,
fail_mailbox_search_next_update_seq,
fail_mailbox_search_next_match_mail,
fail_mailbox_save_alloc,
fail_mailbox_save_begin,
fail_mailbox_save_continue,
fail_mailbox_save_finish,
fail_mailbox_save_cancel,
fail_mailbox_copy,
NULL,
NULL,
NULL,
fail_mailbox_is_inconsistent
}
};
struct mailbox *
fail_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
const char *vname, enum mailbox_flags flags)
{
struct mailbox *box;
pool_t pool;
pool = pool_alloconly_create("fail mailbox", 1024+512);
box = p_new(pool, struct mailbox, 1);
*box = fail_mailbox;
box->vname = p_strdup(pool, vname);
box->name = p_strdup(pool, mailbox_list_get_storage_name(list, vname));
box->storage = storage;
box->list = list;
box->pool = pool;
box->flags = flags;
box->event = event_create(box->storage->event);
event_add_category(box->event, &event_category_mailbox);
event_add_str(box->event, "mailbox", box->vname);
event_set_append_log_prefix(box->event,
t_strdup_printf("Mailbox %s: ", str_sanitize(box->vname, 128)));
p_array_init(&box->search_results, pool, 16);
p_array_init(&box->module_contexts, pool, 5);
return box;
}
|