Mercurial > dovecot > core-2.2
annotate src/lib-storage/mail-storage.c @ 15272:ca10d2e8d8e3
lib-storage: Moved mail attribute dict to struct mail_storage.
This also means that index_storage_destroy() must always be called, so
removed now unnecessary mail_storage.destroy=NULL checks.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 29 Oct 2012 14:50:11 +0200 |
parents | 40e6e734cd5e |
children | 1b46c1bf9d1e |
rev | line source |
---|---|
14133
ba770cba5598
Updated copyright notices to include year 2012.
Timo Sirainen <tss@iki.fi>
parents:
14057
diff
changeset
|
1 /* Copyright (c) 2002-2012 Dovecot authors, see the included COPYING file */ |
0 | 2 |
3 #include "lib.h" | |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
4 #include "ioloop.h" |
3470
346a494c2feb
Moved array declaration to array-decl.h and include it in lib.h. So array.h
Timo Sirainen <tss@iki.fi>
parents:
3282
diff
changeset
|
5 #include "array.h" |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
6 #include "llist.h" |
12629
02370eda76f8
lib-storage: Mailbox virtual names are now in UTF-8 format, not IMAP mUTF-7.
Timo Sirainen <tss@iki.fi>
parents:
12626
diff
changeset
|
7 #include "unichar.h" |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
8 #include "istream.h" |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
9 #include "eacces-error.h" |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
10 #include "mkdir-parents.h" |
13924
d4c506d8f534
Use t_strflocaltime() where possible.
Timo Sirainen <tss@iki.fi>
parents:
13906
diff
changeset
|
11 #include "time-util.h" |
4445
13350093fa1b
MAIL_STORAGE_FLAG_KEEP_HEADER_MD5 flag was supposed to be set if
Timo Sirainen <tss@iki.fi>
parents:
4395
diff
changeset
|
12 #include "var-expand.h" |
4453
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4451
diff
changeset
|
13 #include "mail-index-private.h" |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
10653
diff
changeset
|
14 #include "mail-index-alloc-cache.h" |
15028
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
15 #include "mailbox-tree.h" |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5032
diff
changeset
|
16 #include "mailbox-list-private.h" |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
17 #include "mail-storage-private.h" |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
18 #include "mail-storage-settings.h" |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5468
diff
changeset
|
19 #include "mail-namespace.h" |
6899
69babcc2fb80
Simplify search arguments immediately when calling mailbox_search_init().
Timo Sirainen <tss@iki.fi>
parents:
6771
diff
changeset
|
20 #include "mail-search.h" |
11144
c6db5769942f
lib-storage: Rewrote search query building code to be more modular.
Timo Sirainen <tss@iki.fi>
parents:
11106
diff
changeset
|
21 #include "mail-search-register.h" |
7647
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7643
diff
changeset
|
22 #include "mailbox-search-result-private.h" |
13219
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
23 #include "mailbox-guid-cache.h" |
0 | 24 |
1138
340dea0150bf
Added client_workarounds setting, with currently one workaround for OE6.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
25 #include <stdlib.h> |
0 | 26 #include <ctype.h> |
27 | |
10723
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
28 #define MAILBOX_DELETE_RETRY_SECS (60*5) |
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
29 |
11268
0a35407e6ff4
Mail search register getting API change to fix a doveadm crash bug.
Timo Sirainen <tss@iki.fi>
parents:
11146
diff
changeset
|
30 extern struct mail_search_register *mail_search_register_imap; |
0a35407e6ff4
Mail search register getting API change to fix a doveadm crash bug.
Timo Sirainen <tss@iki.fi>
parents:
11146
diff
changeset
|
31 extern struct mail_search_register *mail_search_register_human; |
0a35407e6ff4
Mail search register getting API change to fix a doveadm crash bug.
Timo Sirainen <tss@iki.fi>
parents:
11146
diff
changeset
|
32 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
33 struct mail_storage_module_register mail_storage_module_register = { 0 }; |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
34 struct mail_module_register mail_module_register = { 0 }; |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
35 |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
36 struct mail_storage_mail_index_module mail_storage_mail_index_module = |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
37 MODULE_CONTEXT_INIT(&mail_index_module_register); |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
38 ARRAY_TYPE(mail_storage) mail_storage_classes; |
1138
340dea0150bf
Added client_workarounds setting, with currently one workaround for OE6.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
39 |
340dea0150bf
Added client_workarounds setting, with currently one workaround for OE6.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
40 void mail_storage_init(void) |
340dea0150bf
Added client_workarounds setting, with currently one workaround for OE6.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
41 { |
7245 | 42 mailbox_lists_init(); |
10412
a9eda7672869
lib-storage: Plugin hook API changed to support per-user plugins within a process.
Timo Sirainen <tss@iki.fi>
parents:
10347
diff
changeset
|
43 mail_storage_hooks_init(); |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
44 i_array_init(&mail_storage_classes, 8); |
1138
340dea0150bf
Added client_workarounds setting, with currently one workaround for OE6.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
45 } |
0 | 46 |
1351
6709d9330885
minor memory leak/cleanup fixes
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
47 void mail_storage_deinit(void) |
6709d9330885
minor memory leak/cleanup fixes
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
48 { |
11268
0a35407e6ff4
Mail search register getting API change to fix a doveadm crash bug.
Timo Sirainen <tss@iki.fi>
parents:
11146
diff
changeset
|
49 if (mail_search_register_human != NULL) |
0a35407e6ff4
Mail search register getting API change to fix a doveadm crash bug.
Timo Sirainen <tss@iki.fi>
parents:
11146
diff
changeset
|
50 mail_search_register_deinit(&mail_search_register_human); |
0a35407e6ff4
Mail search register getting API change to fix a doveadm crash bug.
Timo Sirainen <tss@iki.fi>
parents:
11146
diff
changeset
|
51 if (mail_search_register_imap != NULL) |
0a35407e6ff4
Mail search register getting API change to fix a doveadm crash bug.
Timo Sirainen <tss@iki.fi>
parents:
11146
diff
changeset
|
52 mail_search_register_deinit(&mail_search_register_imap); |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
53 if (array_is_created(&mail_storage_classes)) |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
54 array_free(&mail_storage_classes); |
10412
a9eda7672869
lib-storage: Plugin hook API changed to support per-user plugins within a process.
Timo Sirainen <tss@iki.fi>
parents:
10347
diff
changeset
|
55 mail_storage_hooks_deinit(); |
7245 | 56 mailbox_lists_deinit(); |
1351
6709d9330885
minor memory leak/cleanup fixes
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
57 } |
6709d9330885
minor memory leak/cleanup fixes
Timo Sirainen <tss@iki.fi>
parents:
1218
diff
changeset
|
58 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
59 void mail_storage_class_register(struct mail_storage *storage_class) |
0 | 60 { |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
61 i_assert(mail_storage_find_class(storage_class->name) == NULL); |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
62 |
0 | 63 /* append it after the list, so the autodetection order is correct */ |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
64 array_append(&mail_storage_classes, &storage_class, 1); |
0 | 65 } |
66 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
67 void mail_storage_class_unregister(struct mail_storage *storage_class) |
0 | 68 { |
3282 | 69 struct mail_storage *const *classes; |
70 unsigned int i, count; | |
0 | 71 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
72 classes = array_get(&mail_storage_classes, &count); |
3282 | 73 for (i = 0; i < count; i++) { |
74 if (classes[i] == storage_class) { | |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
75 array_delete(&mail_storage_classes, i, 1); |
3282 | 76 break; |
0 | 77 } |
78 } | |
79 } | |
80 | |
8173
6dd0c6755afe
Added initial support for shared mailboxes. Listing isn't supported yet.
Timo Sirainen <tss@iki.fi>
parents:
8082
diff
changeset
|
81 struct mail_storage *mail_storage_find_class(const char *name) |
3282 | 82 { |
83 struct mail_storage *const *classes; | |
84 unsigned int i, count; | |
85 | |
86 i_assert(name != NULL); | |
87 | |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
88 classes = array_get(&mail_storage_classes, &count); |
3282 | 89 for (i = 0; i < count; i++) { |
90 if (strcasecmp(classes[i]->name, name) == 0) | |
91 return classes[i]; | |
92 } | |
93 return NULL; | |
94 } | |
95 | |
3033
146897976cfa
Added mail_debug setting. Moved full_filesystem_access from global variable
Timo Sirainen <tss@iki.fi>
parents:
3016
diff
changeset
|
96 static struct mail_storage * |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
97 mail_storage_autodetect(const struct mail_namespace *ns, |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
98 struct mailbox_list_settings *set) |
0 | 99 { |
3282 | 100 struct mail_storage *const *classes; |
101 unsigned int i, count; | |
0 | 102 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
103 classes = array_get(&mail_storage_classes, &count); |
3282 | 104 for (i = 0; i < count; i++) { |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
105 if (classes[i]->v.autodetect != NULL) { |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
106 if (classes[i]->v.autodetect(ns, set)) |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
107 return classes[i]; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
108 } |
0 | 109 } |
110 return NULL; | |
111 } | |
112 | |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
113 static void |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
114 mail_storage_set_autodetection(const char **data, const char **driver) |
0 | 115 { |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
116 const char *p; |
0 | 117 |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
118 /* check if data is in driver:data format (eg. mbox:~/mail) */ |
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
119 p = *data; |
0 | 120 while (i_isalnum(*p)) p++; |
121 | |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
122 if (*p == ':' && p != *data) { |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
123 /* no autodetection if the storage driver is given. */ |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
124 *driver = t_strdup_until(*data, p); |
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
125 *data = p + 1; |
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
126 } |
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
127 } |
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
128 |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
129 static struct mail_storage * |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
130 mail_storage_get_class(struct mail_namespace *ns, const char *driver, |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
131 struct mailbox_list_settings *list_set, |
11060
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
132 enum mail_storage_flags flags, const char **error_r) |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
133 { |
11060
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
134 struct mail_storage *storage_class = NULL; |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
135 const char *home; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
136 |
13697
ad0136b56d6e
lib-storage: Added "auto" mail storage driver for forcing autodetection.
Timo Sirainen <tss@iki.fi>
parents:
13596
diff
changeset
|
137 if (driver == NULL) { |
ad0136b56d6e
lib-storage: Added "auto" mail storage driver for forcing autodetection.
Timo Sirainen <tss@iki.fi>
parents:
13596
diff
changeset
|
138 /* no mail_location, autodetect */ |
ad0136b56d6e
lib-storage: Added "auto" mail storage driver for forcing autodetection.
Timo Sirainen <tss@iki.fi>
parents:
13596
diff
changeset
|
139 } else if (strcmp(driver, "auto") == 0) { |
ad0136b56d6e
lib-storage: Added "auto" mail storage driver for forcing autodetection.
Timo Sirainen <tss@iki.fi>
parents:
13596
diff
changeset
|
140 /* explicit autodetection with "auto" driver. */ |
13709
e5fb66051028
lib-storage: Crashfix for "auto" driver in some situations.
Timo Sirainen <tss@iki.fi>
parents:
13697
diff
changeset
|
141 if (list_set->root_dir != NULL && |
e5fb66051028
lib-storage: Crashfix for "auto" driver in some situations.
Timo Sirainen <tss@iki.fi>
parents:
13697
diff
changeset
|
142 *list_set->root_dir == '\0') { |
13697
ad0136b56d6e
lib-storage: Added "auto" mail storage driver for forcing autodetection.
Timo Sirainen <tss@iki.fi>
parents:
13596
diff
changeset
|
143 /* handle the same as with driver=NULL */ |
ad0136b56d6e
lib-storage: Added "auto" mail storage driver for forcing autodetection.
Timo Sirainen <tss@iki.fi>
parents:
13596
diff
changeset
|
144 list_set->root_dir = NULL; |
ad0136b56d6e
lib-storage: Added "auto" mail storage driver for forcing autodetection.
Timo Sirainen <tss@iki.fi>
parents:
13596
diff
changeset
|
145 } |
ad0136b56d6e
lib-storage: Added "auto" mail storage driver for forcing autodetection.
Timo Sirainen <tss@iki.fi>
parents:
13596
diff
changeset
|
146 } else { |
15207
985ebfb17f35
lib-storage: Added mail_user_get_storage_class(), which auto-loads storage plugins.
Timo Sirainen <tss@iki.fi>
parents:
15166
diff
changeset
|
147 storage_class = mail_user_get_storage_class(ns->user, driver); |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
148 if (storage_class == NULL) { |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
149 *error_r = t_strdup_printf( |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
150 "Unknown mail storage driver %s", driver); |
9755
c2037505a66b
lib-storage: Don't crash if trying to use unknown storage class.
Timo Sirainen <tss@iki.fi>
parents:
9721
diff
changeset
|
151 return NULL; |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
152 } |
11060
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
153 } |
11054
373e2b3a050a
lib-storage: Don't crash if root mail directory isn't given.
Timo Sirainen <tss@iki.fi>
parents:
11010
diff
changeset
|
154 |
11060
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
155 if (list_set->root_dir == NULL || *list_set->root_dir == '\0') { |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
156 /* no root directory given. is this allowed? */ |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
157 const struct mailbox_list *list; |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
158 |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
159 list = list_set->layout == NULL ? NULL : |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
160 mailbox_list_find_class(list_set->layout); |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
161 if (storage_class == NULL && |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
162 (flags & MAIL_STORAGE_FLAG_NO_AUTODETECTION) == 0) { |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
163 /* autodetection should take care of this */ |
12626
aa131065b53d
imapc: Don't force a root directory to exist.
Timo Sirainen <tss@iki.fi>
parents:
12586
diff
changeset
|
164 } else if (storage_class != NULL && |
aa131065b53d
imapc: Don't force a root directory to exist.
Timo Sirainen <tss@iki.fi>
parents:
12586
diff
changeset
|
165 (storage_class->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) != 0) { |
aa131065b53d
imapc: Don't force a root directory to exist.
Timo Sirainen <tss@iki.fi>
parents:
12586
diff
changeset
|
166 /* root not required for this storage */ |
11060
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
167 } else if (list != NULL && |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
168 (list->props & MAILBOX_LIST_PROP_NO_ROOT) != 0) { |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
169 /* root not required for this layout */ |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
170 } else { |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
171 *error_r = "Root mail directory not given"; |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
172 return NULL; |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
173 } |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
174 } |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
175 |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
176 if (storage_class != NULL) { |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
177 storage_class->v.get_list_settings(ns, list_set); |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
178 return storage_class; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
179 } |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
180 |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
181 storage_class = mail_storage_autodetect(ns, list_set); |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
182 if (storage_class != NULL) |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
183 return storage_class; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
184 |
13710
f11ce0efa6a8
lib-storage: Improved storage creation failure error message for "auto" driver.
Timo Sirainen <tss@iki.fi>
parents:
13709
diff
changeset
|
185 (void)mail_user_get_home(ns->user, &home); |
f11ce0efa6a8
lib-storage: Improved storage creation failure error message for "auto" driver.
Timo Sirainen <tss@iki.fi>
parents:
13709
diff
changeset
|
186 if (home == NULL || *home == '\0') home = "(not set)"; |
f11ce0efa6a8
lib-storage: Improved storage creation failure error message for "auto" driver.
Timo Sirainen <tss@iki.fi>
parents:
13709
diff
changeset
|
187 |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
188 if (ns->set->location == NULL || *ns->set->location == '\0') { |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
189 *error_r = t_strdup_printf( |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
190 "Mail storage autodetection failed with home=%s", home); |
13710
f11ce0efa6a8
lib-storage: Improved storage creation failure error message for "auto" driver.
Timo Sirainen <tss@iki.fi>
parents:
13709
diff
changeset
|
191 } else if (strncmp(ns->set->location, "auto:", 5) == 0) { |
f11ce0efa6a8
lib-storage: Improved storage creation failure error message for "auto" driver.
Timo Sirainen <tss@iki.fi>
parents:
13709
diff
changeset
|
192 *error_r = t_strdup_printf( |
f11ce0efa6a8
lib-storage: Improved storage creation failure error message for "auto" driver.
Timo Sirainen <tss@iki.fi>
parents:
13709
diff
changeset
|
193 "Autodetection failed for %s (home=%s)", |
f11ce0efa6a8
lib-storage: Improved storage creation failure error message for "auto" driver.
Timo Sirainen <tss@iki.fi>
parents:
13709
diff
changeset
|
194 ns->set->location, home); |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
195 } else { |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
196 *error_r = t_strdup_printf( |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
197 "Ambiguous mail location setting, " |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
198 "don't know what to do with it: %s " |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
199 "(try prefixing it with mbox: or maildir:)", |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
200 ns->set->location); |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
201 } |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
202 return NULL; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
203 } |
12296
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
204 |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
205 static int |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
206 mail_storage_verify_root(const char *root_dir, bool autocreate, |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
207 const char **error_r) |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
208 { |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
209 struct stat st; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
210 |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
211 if (stat(root_dir, &st) == 0) { |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
212 /* exists */ |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
213 return 1; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
214 } else if (errno == EACCES) { |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
215 *error_r = mail_error_eacces_msg("stat", root_dir); |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
216 return -1; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
217 } else if (errno != ENOENT && errno != ENOTDIR) { |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
218 *error_r = t_strdup_printf("stat(%s) failed: %m", root_dir); |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
219 return -1; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
220 } else if (!autocreate) { |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
221 *error_r = t_strdup_printf( |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
222 "Root mail directory doesn't exist: %s", root_dir); |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
223 return -1; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
224 } else { |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
225 /* doesn't exist */ |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
226 return 0; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
227 } |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
228 } |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
229 |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
230 static int |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
231 mail_storage_create_root(struct mailbox_list *list, |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
232 enum mail_storage_flags flags, const char **error_r) |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
233 { |
14037
aed3379df476
lib-storage: mailbox_list_mkdir_root() API changed. Use it now for creating mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
13924
diff
changeset
|
234 const char *root_dir, *error; |
12296
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
235 bool autocreate; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
236 int ret; |
12271
0cc916fc09f9
lib-storage: Added MAIL_STORAGE_FLAG_NO_AUTOVERIFY to skip checking storage root dir existence.
Timo Sirainen <tss@iki.fi>
parents:
12264
diff
changeset
|
237 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
238 if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_MAILBOX, |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
239 &root_dir)) { |
9548
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
240 /* storage doesn't use directories (e.g. shared root) */ |
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
241 return 0; |
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
242 } |
12296
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
243 |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
244 if ((flags & MAIL_STORAGE_FLAG_NO_AUTOVERIFY) != 0) { |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
245 if (!list->mail_set->mail_debug) |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
246 return 0; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
247 |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
248 /* we don't need to verify, but since debugging is |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
249 enabled, check and log if the root doesn't exist */ |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
250 if (mail_storage_verify_root(root_dir, FALSE, &error) < 0) { |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
251 i_debug("Namespace %s: Creating storage despite: %s", |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
252 list->ns->prefix, error); |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
253 } |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
254 return 0; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
255 } |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
256 |
12296
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
257 autocreate = (flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) == 0; |
953e7c6e546b
lib-storage: Log a debug message if shared user's storage root doesn't exist with mail_debug=yes
Timo Sirainen <tss@iki.fi>
parents:
12289
diff
changeset
|
258 ret = mail_storage_verify_root(root_dir, autocreate, error_r); |
14037
aed3379df476
lib-storage: mailbox_list_mkdir_root() API changed. Use it now for creating mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
13924
diff
changeset
|
259 if (ret == 0) { |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
260 ret = mailbox_list_try_mkdir_root(list, root_dir, |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
261 MAILBOX_LIST_PATH_TYPE_MAILBOX, |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
262 error_r); |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
263 } |
14037
aed3379df476
lib-storage: mailbox_list_mkdir_root() API changed. Use it now for creating mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
13924
diff
changeset
|
264 return ret < 0 ? -1 : 0; |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
265 } |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
266 |
13468
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
267 static bool |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
268 mail_storage_match_class(struct mail_storage *storage, |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
269 const struct mail_storage *storage_class, |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
270 const struct mailbox_list_settings *set) |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
271 { |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
272 if (strcmp(storage->name, storage_class->name) != 0) |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
273 return FALSE; |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
274 |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
275 if ((storage->class_flags & MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT) != 0 && |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
276 strcmp(storage->unique_root_dir, set->root_dir) != 0) |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
277 return FALSE; |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
278 |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
279 if (strcmp(storage->name, "shared") == 0) { |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
280 /* allow multiple independent shared namespaces */ |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
281 return FALSE; |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
282 } |
13906 | 283 return TRUE; |
13468
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
284 } |
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
285 |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
286 static struct mail_storage * |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
287 mail_storage_find(struct mail_user *user, |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
288 const struct mail_storage *storage_class, |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
289 const struct mailbox_list_settings *set) |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
290 { |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
291 struct mail_storage *storage = user->storages; |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
292 |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
293 for (; storage != NULL; storage = storage->next) { |
13468
cfbca51c0ade
lib-storage: Don't try to use the same mail_storage for shared storages.
Timo Sirainen <tss@iki.fi>
parents:
13461
diff
changeset
|
294 if (mail_storage_match_class(storage, storage_class, set)) |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
295 return storage; |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
296 } |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
297 return NULL; |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
298 } |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
299 |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5468
diff
changeset
|
300 int mail_storage_create(struct mail_namespace *ns, const char *driver, |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
301 enum mail_storage_flags flags, const char **error_r) |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
302 { |
8799 | 303 struct mail_storage *storage_class, *storage = NULL; |
12785
395af848ec10
lib-storage: Allow creating a secondary mailbox_list for a namespace.
Timo Sirainen <tss@iki.fi>
parents:
12783
diff
changeset
|
304 struct mailbox_list *list; |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
305 struct mailbox_list_settings list_set; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
306 enum mailbox_list_flags list_flags = 0; |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
307 const char *data = ns->set->location; |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
308 const char *p; |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
309 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
310 if ((flags & MAIL_STORAGE_FLAG_KEEP_HEADER_MD5) == 0 && |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
311 ns->mail_set->pop3_uidl_format != NULL) { |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
312 /* if pop3_uidl_format contains %m, we want to keep the |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
313 header MD5 sums stored even if we're not running POP3 |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
314 right now. */ |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
315 p = ns->mail_set->pop3_uidl_format; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
316 while ((p = strchr(p, '%')) != NULL) { |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
317 if (p[1] == '%') |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
318 p += 2; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
319 else if (var_get_key(++p) == 'm') { |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
320 flags |= MAIL_STORAGE_FLAG_KEEP_HEADER_MD5; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
321 break; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
322 } |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
323 } |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
324 } |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
325 |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
326 memset(&list_set, 0, sizeof(list_set)); |
14057
ba48de993c8e
lib-storage: One more crashfix for recent maildir_name/mailbox_dir_name change.
Timo Sirainen <tss@iki.fi>
parents:
14037
diff
changeset
|
327 list_set.mailbox_dir_name = ""; |
ba48de993c8e
lib-storage: One more crashfix for recent maildir_name/mailbox_dir_name change.
Timo Sirainen <tss@iki.fi>
parents:
14037
diff
changeset
|
328 list_set.maildir_name = ""; |
9548
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
329 if (data == NULL) { |
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
330 /* autodetect */ |
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
331 } else if (driver != NULL && strcmp(driver, "shared") == 0) { |
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
332 /* internal shared namespace */ |
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
333 list_set.root_dir = ns->user->set->base_dir; |
ac0a9729fe3c
Fixed shared namespace initialization.
Timo Sirainen <tss@iki.fi>
parents:
9537
diff
changeset
|
334 } else { |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
335 if (driver == NULL) |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
336 mail_storage_set_autodetection(&data, &driver); |
11474 | 337 if (mailbox_list_settings_parse(ns->user, data, &list_set, |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
338 error_r) < 0) |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5468
diff
changeset
|
339 return -1; |
4869
60071a98281c
Don't call mail_storage_created hook twice.
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
340 } |
60071a98281c
Don't call mail_storage_created hook twice.
Timo Sirainen <tss@iki.fi>
parents:
4848
diff
changeset
|
341 |
11060
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
342 storage_class = mail_storage_get_class(ns, driver, &list_set, flags, |
6b1f08814e59
lib-storage: Added "none" mailbox list driver.
Timo Sirainen <tss@iki.fi>
parents:
11054
diff
changeset
|
343 error_r); |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
344 if (storage_class == NULL) |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
345 return -1; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
346 i_assert(list_set.layout != NULL); |
8786
db9811ec1f47
Added mail_user_get_temp_prefix() and mail_storage_get_temp_prefix().
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
347 |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
348 if (ns->list == NULL) { |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
349 /* first storage for namespace */ |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
350 if (mail_storage_is_mailbox_file(storage_class)) |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
351 list_flags |= MAILBOX_LIST_FLAG_MAILBOX_FILES; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
352 if (mailbox_list_create(list_set.layout, ns, &list_set, |
12785
395af848ec10
lib-storage: Allow creating a secondary mailbox_list for a namespace.
Timo Sirainen <tss@iki.fi>
parents:
12783
diff
changeset
|
353 list_flags, &list, error_r) < 0) { |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
354 *error_r = t_strdup_printf("Mailbox list driver %s: %s", |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
355 list_set.layout, *error_r); |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
356 return -1; |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
357 } |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
358 if (mail_storage_create_root(ns->list, flags, error_r) < 0) |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
359 return -1; |
6940
414c9d631a81
Replaced t_push/t_pop calls with T_FRAME*() macros.
Timo Sirainen <tss@iki.fi>
parents:
6899
diff
changeset
|
360 } |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5468
diff
changeset
|
361 |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
362 storage = mail_storage_find(ns->user, storage_class, &list_set); |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
363 if (storage != NULL) { |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
364 /* using an existing storage */ |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
365 storage->refcount++; |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
366 mail_namespace_add_storage(ns, storage); |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
367 return 0; |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
368 } |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
369 |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
370 storage = storage_class->v.alloc(); |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
371 storage->refcount = 1; |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
372 storage->storage_class = storage_class; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
373 storage->user = ns->user; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
374 storage->set = ns->mail_set; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
375 storage->flags = flags; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
376 p_array_init(&storage->module_contexts, storage->pool, 5); |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
377 |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
378 if (storage->v.create != NULL && |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
379 storage->v.create(storage, ns, error_r) < 0) { |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
380 *error_r = t_strdup_printf("%s: %s", storage->name, *error_r); |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
381 pool_unref(&storage->pool); |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
382 return -1; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
383 } |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
384 |
10412
a9eda7672869
lib-storage: Plugin hook API changed to support per-user plugins within a process.
Timo Sirainen <tss@iki.fi>
parents:
10347
diff
changeset
|
385 T_BEGIN { |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
386 hook_mail_storage_created(storage); |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
387 } T_END; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
388 |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
389 DLLIST_PREPEND(&ns->user->storages, storage); |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
390 mail_namespace_add_storage(ns, storage); |
5500
4862cb37106c
Moved namespace handling to lib-storage. Beginnings of namespace support for
Timo Sirainen <tss@iki.fi>
parents:
5468
diff
changeset
|
391 return 0; |
0 | 392 } |
393 | |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
394 void mail_storage_unref(struct mail_storage **_storage) |
0 | 395 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
396 struct mail_storage *storage = *_storage; |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
397 |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
398 i_assert(storage->refcount > 0); |
0 | 399 |
10843
e3672e7c0f9f
mdbox: Don't crash when trying to rebuild storage at deinit.
Timo Sirainen <tss@iki.fi>
parents:
10733
diff
changeset
|
400 /* set *_storage=NULL only after calling destroy() callback. |
e3672e7c0f9f
mdbox: Don't crash when trying to rebuild storage at deinit.
Timo Sirainen <tss@iki.fi>
parents:
10733
diff
changeset
|
401 for example mdbox wants to access ns->storage */ |
e3672e7c0f9f
mdbox: Don't crash when trying to rebuild storage at deinit.
Timo Sirainen <tss@iki.fi>
parents:
10733
diff
changeset
|
402 if (--storage->refcount > 0) { |
e3672e7c0f9f
mdbox: Don't crash when trying to rebuild storage at deinit.
Timo Sirainen <tss@iki.fi>
parents:
10733
diff
changeset
|
403 *_storage = NULL; |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
404 return; |
10843
e3672e7c0f9f
mdbox: Don't crash when trying to rebuild storage at deinit.
Timo Sirainen <tss@iki.fi>
parents:
10733
diff
changeset
|
405 } |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
406 |
13754
deaebb4dc98c
lib-storage: Track storage's all mailboxes to make it easier to debug if one isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
13712
diff
changeset
|
407 if (storage->mailboxes != NULL) { |
deaebb4dc98c
lib-storage: Track storage's all mailboxes to make it easier to debug if one isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
13712
diff
changeset
|
408 i_panic("Trying to deinit storage without freeing mailbox %s", |
deaebb4dc98c
lib-storage: Track storage's all mailboxes to make it easier to debug if one isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
13712
diff
changeset
|
409 storage->mailboxes->vname); |
deaebb4dc98c
lib-storage: Track storage's all mailboxes to make it easier to debug if one isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
13712
diff
changeset
|
410 } |
11106
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
411 if (storage->obj_refcount != 0) |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
412 i_panic("Trying to deinit storage before freeing its objects"); |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
413 |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
414 DLLIST_REMOVE(&storage->user->storages, storage); |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
415 |
15272
ca10d2e8d8e3
lib-storage: Moved mail attribute dict to struct mail_storage.
Timo Sirainen <tss@iki.fi>
parents:
15269
diff
changeset
|
416 storage->v.destroy(storage); |
5613 | 417 i_free(storage->error_string); |
10843
e3672e7c0f9f
mdbox: Don't crash when trying to rebuild storage at deinit.
Timo Sirainen <tss@iki.fi>
parents:
10733
diff
changeset
|
418 |
e3672e7c0f9f
mdbox: Don't crash when trying to rebuild storage at deinit.
Timo Sirainen <tss@iki.fi>
parents:
10733
diff
changeset
|
419 *_storage = NULL; |
6428
7cad076906eb
pool_unref() now takes ** pointer.
Timo Sirainen <tss@iki.fi>
parents:
6354
diff
changeset
|
420 pool_unref(&storage->pool); |
10656
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
10653
diff
changeset
|
421 |
9d3b5cbef222
Moved mail_index lookup cache from lib-storage to lib-index.
Timo Sirainen <tss@iki.fi>
parents:
10653
diff
changeset
|
422 mail_index_alloc_cache_destroy_unrefed(); |
0 | 423 } |
424 | |
11106
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
425 void mail_storage_obj_ref(struct mail_storage *storage) |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
426 { |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
427 i_assert(storage->refcount > 0); |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
428 |
13580
b7995a25c052
lib-storage: Keep mail_user referenced while storage objects exist.
Timo Sirainen <tss@iki.fi>
parents:
13509
diff
changeset
|
429 if (storage->obj_refcount++ == 0) |
b7995a25c052
lib-storage: Keep mail_user referenced while storage objects exist.
Timo Sirainen <tss@iki.fi>
parents:
13509
diff
changeset
|
430 mail_user_ref(storage->user); |
11106
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
431 } |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
432 |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
433 void mail_storage_obj_unref(struct mail_storage *storage) |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
434 { |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
435 i_assert(storage->refcount > 0); |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
436 i_assert(storage->obj_refcount > 0); |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
437 |
13580
b7995a25c052
lib-storage: Keep mail_user referenced while storage objects exist.
Timo Sirainen <tss@iki.fi>
parents:
13509
diff
changeset
|
438 if (--storage->obj_refcount == 0) { |
b7995a25c052
lib-storage: Keep mail_user referenced while storage objects exist.
Timo Sirainen <tss@iki.fi>
parents:
13509
diff
changeset
|
439 struct mail_user *user = storage->user; |
b7995a25c052
lib-storage: Keep mail_user referenced while storage objects exist.
Timo Sirainen <tss@iki.fi>
parents:
13509
diff
changeset
|
440 mail_user_unref(&user); |
b7995a25c052
lib-storage: Keep mail_user referenced while storage objects exist.
Timo Sirainen <tss@iki.fi>
parents:
13509
diff
changeset
|
441 } |
11106
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
442 } |
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
443 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
444 void mail_storage_clear_error(struct mail_storage *storage) |
0 | 445 { |
5613 | 446 i_free_and_null(storage->error_string); |
883
39e0b536e708
Storage can now specify if errors should be sent to user as BAD or NO.
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
447 |
5613 | 448 storage->error = MAIL_ERROR_NONE; |
0 | 449 } |
450 | |
5613 | 451 void mail_storage_set_error(struct mail_storage *storage, |
452 enum mail_error error, const char *string) | |
0 | 453 { |
5613 | 454 i_free(storage->error_string); |
455 storage->error_string = i_strdup(string); | |
456 storage->error = error; | |
883
39e0b536e708
Storage can now specify if errors should be sent to user as BAD or NO.
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
457 } |
39e0b536e708
Storage can now specify if errors should be sent to user as BAD or NO.
Timo Sirainen <tss@iki.fi>
parents:
765
diff
changeset
|
458 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
459 void mail_storage_set_internal_error(struct mail_storage *storage) |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
460 { |
13924
d4c506d8f534
Use t_strflocaltime() where possible.
Timo Sirainen <tss@iki.fi>
parents:
13906
diff
changeset
|
461 const char *str; |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
462 |
13924
d4c506d8f534
Use t_strflocaltime() where possible.
Timo Sirainen <tss@iki.fi>
parents:
13906
diff
changeset
|
463 str = t_strflocaltime(MAIL_ERRSTR_CRITICAL_MSG_STAMP, ioloop_time); |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
464 |
5613 | 465 i_free(storage->error_string); |
13924
d4c506d8f534
Use t_strflocaltime() where possible.
Timo Sirainen <tss@iki.fi>
parents:
13906
diff
changeset
|
466 storage->error_string = i_strdup(str); |
5613 | 467 storage->error = MAIL_ERROR_TEMP; |
13
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
468 } |
bb294faf7379
"Critical errors" aren't displayed to users anymore, ie. anything that is
Timo Sirainen <tss@iki.fi>
parents:
5
diff
changeset
|
469 |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
470 void mail_storage_set_critical(struct mail_storage *storage, |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
883
diff
changeset
|
471 const char *fmt, ...) |
0 | 472 { |
473 va_list va; | |
474 | |
13430
84bce2c8626f
lib-storage: Code cleanup to mail_storage_set_critical()
Timo Sirainen <tss@iki.fi>
parents:
13287
diff
changeset
|
475 va_start(va, fmt); |
84bce2c8626f
lib-storage: Code cleanup to mail_storage_set_critical()
Timo Sirainen <tss@iki.fi>
parents:
13287
diff
changeset
|
476 i_error("%s", t_strdup_vprintf(fmt, va)); |
84bce2c8626f
lib-storage: Code cleanup to mail_storage_set_critical()
Timo Sirainen <tss@iki.fi>
parents:
13287
diff
changeset
|
477 va_end(va); |
0 | 478 |
13430
84bce2c8626f
lib-storage: Code cleanup to mail_storage_set_critical()
Timo Sirainen <tss@iki.fi>
parents:
13287
diff
changeset
|
479 /* critical errors may contain sensitive data, so let user |
84bce2c8626f
lib-storage: Code cleanup to mail_storage_set_critical()
Timo Sirainen <tss@iki.fi>
parents:
13287
diff
changeset
|
480 see only "Internal error" with a timestamp to make it |
84bce2c8626f
lib-storage: Code cleanup to mail_storage_set_critical()
Timo Sirainen <tss@iki.fi>
parents:
13287
diff
changeset
|
481 easier to look from log files the actual error message. */ |
84bce2c8626f
lib-storage: Code cleanup to mail_storage_set_critical()
Timo Sirainen <tss@iki.fi>
parents:
13287
diff
changeset
|
482 mail_storage_set_internal_error(storage); |
0 | 483 } |
484 | |
15098
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
485 void mail_storage_copy_error(struct mail_storage *dest, |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
486 struct mail_storage *src) |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
487 { |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
488 const char *str; |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
489 enum mail_error error; |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
490 |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
491 str = mail_storage_get_last_error(src, &error); |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
492 mail_storage_set_error(dest, error, str); |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
493 } |
3b01d09f7762
lib-storage: Added mail_storage_copy_error()
Timo Sirainen <tss@iki.fi>
parents:
15041
diff
changeset
|
494 |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
495 void mail_storage_copy_list_error(struct mail_storage *storage, |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
496 struct mailbox_list *list) |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
497 { |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
498 const char *str; |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
499 enum mail_error error; |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
500 |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
501 str = mailbox_list_get_last_error(list, &error); |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
502 mail_storage_set_error(storage, error, str); |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
503 } |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
504 |
10657
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
505 void mail_storage_set_index_error(struct mailbox *box) |
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
506 { |
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
507 if (mail_index_is_deleted(box->index)) |
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
508 mailbox_set_deleted(box); |
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
509 else |
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
510 mail_storage_set_internal_error(box->storage); |
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
511 mail_index_reset_error(box->index); |
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
512 } |
e7f066508299
lib-storage: Moved struct mail_index_* from index_mailbox to mailbox.
Timo Sirainen <tss@iki.fi>
parents:
10656
diff
changeset
|
513 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
514 const struct mail_storage_settings * |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
515 mail_storage_get_settings(struct mail_storage *storage) |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
516 { |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
517 return storage->set; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
518 } |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
519 |
10670
64c8e5e792e9
lib-storage: Added mail_storage_get_user().
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
520 struct mail_user *mail_storage_get_user(struct mail_storage *storage) |
64c8e5e792e9
lib-storage: Added mail_storage_get_user().
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
521 { |
64c8e5e792e9
lib-storage: Added mail_storage_get_user().
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
522 return storage->user; |
64c8e5e792e9
lib-storage: Added mail_storage_get_user().
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
523 } |
64c8e5e792e9
lib-storage: Added mail_storage_get_user().
Timo Sirainen <tss@iki.fi>
parents:
10662
diff
changeset
|
524 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
525 void mail_storage_set_callbacks(struct mail_storage *storage, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
526 struct mail_storage_callbacks *callbacks, |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
527 void *context) |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
528 { |
9453
2a3390530f6a
struct mail_storage.callbacks is no longer a pointer.
Timo Sirainen <tss@iki.fi>
parents:
9436
diff
changeset
|
529 storage->callbacks = *callbacks; |
5462
163b48489bc6
Moved all storage destruction code to mail-storage.c and made destroy()
Timo Sirainen <tss@iki.fi>
parents:
5461
diff
changeset
|
530 storage->callback_context = context; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
531 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
532 |
9061
f3cfa467b3b3
Added mail_storage_purge() for dbox. dbox no longer calls it automatically at logout.
Timo Sirainen <tss@iki.fi>
parents:
9042
diff
changeset
|
533 int mail_storage_purge(struct mail_storage *storage) |
f3cfa467b3b3
Added mail_storage_purge() for dbox. dbox no longer calls it automatically at logout.
Timo Sirainen <tss@iki.fi>
parents:
9042
diff
changeset
|
534 { |
f3cfa467b3b3
Added mail_storage_purge() for dbox. dbox no longer calls it automatically at logout.
Timo Sirainen <tss@iki.fi>
parents:
9042
diff
changeset
|
535 return storage->v.purge == NULL ? 0 : |
f3cfa467b3b3
Added mail_storage_purge() for dbox. dbox no longer calls it automatically at logout.
Timo Sirainen <tss@iki.fi>
parents:
9042
diff
changeset
|
536 storage->v.purge(storage); |
f3cfa467b3b3
Added mail_storage_purge() for dbox. dbox no longer calls it automatically at logout.
Timo Sirainen <tss@iki.fi>
parents:
9042
diff
changeset
|
537 } |
f3cfa467b3b3
Added mail_storage_purge() for dbox. dbox no longer calls it automatically at logout.
Timo Sirainen <tss@iki.fi>
parents:
9042
diff
changeset
|
538 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
539 const char *mail_storage_get_last_error(struct mail_storage *storage, |
5613 | 540 enum mail_error *error_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
541 { |
5742
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
542 /* We get here only in error situations, so we have to return some |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
543 error. If storage->error is NONE, it means we forgot to set it at |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
544 some point.. */ |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
545 if (storage->error == MAIL_ERROR_NONE) { |
9064
d8e8a9c447af
doveadm: Implemented force-resync functionality.
Timo Sirainen <tss@iki.fi>
parents:
9061
diff
changeset
|
546 if (error_r != NULL) |
d8e8a9c447af
doveadm: Implemented force-resync functionality.
Timo Sirainen <tss@iki.fi>
parents:
9061
diff
changeset
|
547 *error_r = MAIL_ERROR_TEMP; |
5742
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
548 return storage->error_string != NULL ? storage->error_string : |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
549 "BUG: Unknown internal error"; |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
550 } |
5468
8e58322ef87e
Removed virtual mail_storage.get_last_error(). The implementation is always
Timo Sirainen <tss@iki.fi>
parents:
5465
diff
changeset
|
551 |
5742
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
552 if (storage->error_string == NULL) { |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
553 /* This shouldn't happen.. */ |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
554 storage->error_string = |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
555 i_strdup_printf("BUG: Unknown 0x%x error", |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
556 storage->error); |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
557 } |
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
558 |
9064
d8e8a9c447af
doveadm: Implemented force-resync functionality.
Timo Sirainen <tss@iki.fi>
parents:
9061
diff
changeset
|
559 if (error_r != NULL) |
d8e8a9c447af
doveadm: Implemented force-resync functionality.
Timo Sirainen <tss@iki.fi>
parents:
9061
diff
changeset
|
560 *error_r = storage->error; |
5742
7d9edc094ec7
Treat unknown errors as temporary errors.
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
561 return storage->error_string; |
0 | 562 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
563 |
12585
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
564 const char *mailbox_get_last_error(struct mailbox *box, |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
565 enum mail_error *error_r) |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
566 { |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
567 return mail_storage_get_last_error(box->storage, error_r); |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
568 } |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
569 |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
570 enum mail_error mailbox_get_last_mail_error(struct mailbox *box) |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
571 { |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
572 enum mail_error error; |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
573 |
14688
128c598d2870
Avoid using (void)s by adding ATTR_NOWARN_UNUSED_RESULT attributes and other ways.
Timo Sirainen <tss@iki.fi>
parents:
14629
diff
changeset
|
574 mail_storage_get_last_error(box->storage, &error); |
12585
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
575 return error; |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
576 } |
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
577 |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
578 bool mail_storage_is_mailbox_file(struct mail_storage *storage) |
4041
9d7420b0e1ef
Make life easier for plugins:
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3971
diff
changeset
|
579 { |
9436
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
580 return (storage->class_flags & |
4f46cee3a1d4
mail storages can now be shared between namespaces.
Timo Sirainen <tss@iki.fi>
parents:
9434
diff
changeset
|
581 MAIL_STORAGE_CLASS_FLAG_MAILBOX_IS_FILE) != 0; |
8786
db9811ec1f47
Added mail_user_get_temp_prefix() and mail_storage_get_temp_prefix().
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
582 } |
db9811ec1f47
Added mail_user_get_temp_prefix() and mail_storage_get_temp_prefix().
Timo Sirainen <tss@iki.fi>
parents:
8726
diff
changeset
|
583 |
5613 | 584 bool mail_storage_set_error_from_errno(struct mail_storage *storage) |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4646
diff
changeset
|
585 { |
5613 | 586 const char *error_string; |
587 enum mail_error error; | |
588 | |
589 if (!mail_error_from_errno(&error, &error_string)) | |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5032
diff
changeset
|
590 return FALSE; |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
591 if (storage->set->mail_debug && error != MAIL_ERROR_NOTFOUND) { |
8175
69e933c5cc26
If mail_debug=yes, log all permission (and some other) problems
Timo Sirainen <tss@iki.fi>
parents:
8173
diff
changeset
|
592 /* debugging is enabled - admin may be debugging a |
69e933c5cc26
If mail_debug=yes, log all permission (and some other) problems
Timo Sirainen <tss@iki.fi>
parents:
8173
diff
changeset
|
593 (permission) problem, so return FALSE to get the caller to |
69e933c5cc26
If mail_debug=yes, log all permission (and some other) problems
Timo Sirainen <tss@iki.fi>
parents:
8173
diff
changeset
|
594 log the full error message. */ |
69e933c5cc26
If mail_debug=yes, log all permission (and some other) problems
Timo Sirainen <tss@iki.fi>
parents:
8173
diff
changeset
|
595 return FALSE; |
69e933c5cc26
If mail_debug=yes, log all permission (and some other) problems
Timo Sirainen <tss@iki.fi>
parents:
8173
diff
changeset
|
596 } |
5613 | 597 |
598 mail_storage_set_error(storage, error, error_string); | |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5032
diff
changeset
|
599 return TRUE; |
4617
3c05b1f71ce6
mail_storage_get_mailbox_index_dir() wrapper function was missing
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
600 } |
3c05b1f71ce6
mail_storage_get_mailbox_index_dir() wrapper function was missing
Timo Sirainen <tss@iki.fi>
parents:
4596
diff
changeset
|
601 |
13794
32d1a903d42d
Implemented IMAP SPECIAL-USE extension.
Timo Sirainen <tss@iki.fi>
parents:
13793
diff
changeset
|
602 const struct mailbox_settings * |
13793
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
603 mailbox_settings_find(struct mail_user *user, const char *vname) |
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
604 { |
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
605 struct mailbox_settings *const *box_set; |
13801
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
606 struct mail_namespace *ns; |
13793
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
607 |
13801
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
608 ns = mail_namespace_find(user->namespaces, vname); |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
609 if (ns == NULL) |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
610 return NULL; |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
611 if (!array_is_created(&ns->set->mailboxes)) |
13797
272b705f0938
lib-storage: Don't crash when no there are no mailbox {} sections.
Timo Sirainen <tss@iki.fi>
parents:
13794
diff
changeset
|
612 return NULL; |
272b705f0938
lib-storage: Don't crash when no there are no mailbox {} sections.
Timo Sirainen <tss@iki.fi>
parents:
13794
diff
changeset
|
613 |
13801
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
614 if (ns->prefix_len > 0 && |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
615 strncmp(ns->prefix, vname, ns->prefix_len-1) == 0) { |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
616 if (vname[ns->prefix_len-1] == mail_namespace_get_sep(ns)) |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
617 vname += ns->prefix_len; |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
618 else if (vname[ns->prefix_len-1] == '\0') { |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
619 /* namespace prefix itself */ |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
620 vname = ""; |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
621 } |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
622 } |
867f06516121
Moved mailbox {} settings inside namespace {} and no longer require ns prefix in name.
Timo Sirainen <tss@iki.fi>
parents:
13797
diff
changeset
|
623 array_foreach(&ns->set->mailboxes, box_set) { |
13793
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
624 if (strcmp((*box_set)->name, vname) == 0) |
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
625 return *box_set; |
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
626 } |
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
627 return NULL; |
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
628 } |
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
629 |
12586
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
630 struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname, |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
631 enum mailbox_flags flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
632 { |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
633 struct mailbox_list *new_list = list; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
634 struct mail_storage *storage; |
4489
3d2be769d887
Added hook_mailbox_opened to make it easier to hook all mailbox opens.
Timo Sirainen <tss@iki.fi>
parents:
4453
diff
changeset
|
635 struct mailbox *box; |
3d2be769d887
Added hook_mailbox_opened to make it easier to hook all mailbox opens.
Timo Sirainen <tss@iki.fi>
parents:
4453
diff
changeset
|
636 |
12629
02370eda76f8
lib-storage: Mailbox virtual names are now in UTF-8 format, not IMAP mUTF-7.
Timo Sirainen <tss@iki.fi>
parents:
12626
diff
changeset
|
637 i_assert(uni_utf8_str_is_valid(vname)); |
02370eda76f8
lib-storage: Mailbox virtual names are now in UTF-8 format, not IMAP mUTF-7.
Timo Sirainen <tss@iki.fi>
parents:
12626
diff
changeset
|
638 |
13073
e8313c6b839b
lib-storage: Treat "INBOX" in INBOX/children also case-insensitively.
Timo Sirainen <tss@iki.fi>
parents:
12982
diff
changeset
|
639 if ((list->ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0 && |
e8313c6b839b
lib-storage: Treat "INBOX" in INBOX/children also case-insensitively.
Timo Sirainen <tss@iki.fi>
parents:
12982
diff
changeset
|
640 strncasecmp(vname, "INBOX", 5) == 0 && |
e8313c6b839b
lib-storage: Treat "INBOX" in INBOX/children also case-insensitively.
Timo Sirainen <tss@iki.fi>
parents:
12982
diff
changeset
|
641 strncmp(vname, "INBOX", 5) != 0) { |
12641
ad002fdc6a6c
lib-storage: Initial commit for rewritten mailbox list indexes code.
Timo Sirainen <tss@iki.fi>
parents:
12630
diff
changeset
|
642 /* make sure INBOX shows up in uppercase everywhere */ |
13073
e8313c6b839b
lib-storage: Treat "INBOX" in INBOX/children also case-insensitively.
Timo Sirainen <tss@iki.fi>
parents:
12982
diff
changeset
|
643 if (vname[5] == '\0') |
e8313c6b839b
lib-storage: Treat "INBOX" in INBOX/children also case-insensitively.
Timo Sirainen <tss@iki.fi>
parents:
12982
diff
changeset
|
644 vname = "INBOX"; |
e8313c6b839b
lib-storage: Treat "INBOX" in INBOX/children also case-insensitively.
Timo Sirainen <tss@iki.fi>
parents:
12982
diff
changeset
|
645 else if (vname[5] == mail_namespace_get_sep(list->ns)) |
e8313c6b839b
lib-storage: Treat "INBOX" in INBOX/children also case-insensitively.
Timo Sirainen <tss@iki.fi>
parents:
12982
diff
changeset
|
646 vname = t_strconcat("INBOX", vname + 5, NULL); |
12641
ad002fdc6a6c
lib-storage: Initial commit for rewritten mailbox list indexes code.
Timo Sirainen <tss@iki.fi>
parents:
12630
diff
changeset
|
647 } |
ad002fdc6a6c
lib-storage: Initial commit for rewritten mailbox list indexes code.
Timo Sirainen <tss@iki.fi>
parents:
12630
diff
changeset
|
648 |
12586
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
649 if (mailbox_list_get_storage(&new_list, vname, &storage) < 0) { |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
650 /* just use the first storage. FIXME: does this break? */ |
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
651 storage = list->ns->storage; |
5464
91b1f01b9307
mailbox_open/create: Moved the mailbox name validation and error clearing
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
652 } |
91b1f01b9307
mailbox_open/create: Moved the mailbox name validation and error clearing
Timo Sirainen <tss@iki.fi>
parents:
5462
diff
changeset
|
653 |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7175
diff
changeset
|
654 T_BEGIN { |
12586
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
655 box = storage->v.mailbox_alloc(storage, new_list, vname, flags); |
13793
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
656 box->set = mailbox_settings_find(storage->user, vname); |
10412
a9eda7672869
lib-storage: Plugin hook API changed to support per-user plugins within a process.
Timo Sirainen <tss@iki.fi>
parents:
10347
diff
changeset
|
657 hook_mailbox_allocated(box); |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
658 } T_END; |
11106
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
659 |
13754
deaebb4dc98c
lib-storage: Track storage's all mailboxes to make it easier to debug if one isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
13712
diff
changeset
|
660 DLLIST_PREPEND(&box->storage->mailboxes, box); |
11106
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
661 mail_storage_obj_ref(box->storage); |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
662 return box; |
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
663 } |
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
664 |
13219
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
665 struct mailbox *mailbox_alloc_guid(struct mailbox_list *list, |
13287
957060ca5b69
Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents:
13249
diff
changeset
|
666 const guid_128_t guid, |
13219
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
667 enum mailbox_flags flags) |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
668 { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
669 struct mailbox *box = NULL; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
670 struct mailbox_metadata metadata; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
671 enum mail_error open_error = MAIL_ERROR_TEMP; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
672 const char *vname; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
673 |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
674 if (mailbox_guid_cache_find(list, guid, &vname) < 0) { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
675 vname = NULL; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
676 } else if (vname != NULL) { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
677 box = mailbox_alloc(list, vname, flags); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
678 if (mailbox_get_metadata(box, MAILBOX_METADATA_GUID, |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
679 &metadata) < 0) { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
680 } else if (memcmp(metadata.guid, guid, |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
681 sizeof(metadata.guid)) != 0) { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
682 /* GUID mismatch, refresh cache and try again */ |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
683 mailbox_free(&box); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
684 mailbox_guid_cache_refresh(list); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
685 return mailbox_alloc_guid(list, guid, flags); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
686 } else { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
687 /* successfully opened the correct mailbox */ |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
688 return box; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
689 } |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
690 i_error("mailbox_alloc_guid(%s): " |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
691 "Couldn't verify mailbox GUID: %s", |
13287
957060ca5b69
Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents:
13249
diff
changeset
|
692 guid_128_to_string(guid), |
13219
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
693 mailbox_get_last_error(box, NULL)); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
694 vname = NULL; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
695 mailbox_free(&box); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
696 } else { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
697 vname = t_strdup_printf("(nonexistent mailbox with GUID=%s)", |
13287
957060ca5b69
Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents:
13249
diff
changeset
|
698 guid_128_to_string(guid)); |
13219
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
699 open_error = MAIL_ERROR_NOTFOUND; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
700 } |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
701 |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
702 if (vname == NULL) { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
703 vname = t_strdup_printf("(error in mailbox with GUID=%s)", |
13287
957060ca5b69
Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents:
13249
diff
changeset
|
704 guid_128_to_string(guid)); |
13219
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
705 } |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
706 box = mailbox_alloc(list, vname, flags); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
707 box->open_error = open_error; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
708 return box; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
709 } |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
710 |
15166
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
711 static bool mailbox_is_autocreated(struct mailbox *box) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
712 { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
713 if (box->inbox_user) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
714 return TRUE; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
715 return box->set != NULL && |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
716 strcmp(box->set->autocreate, MAILBOX_SET_AUTO_NO) != 0; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
717 } |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
718 |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
719 static int mailbox_autocreate(struct mailbox *box) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
720 { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
721 const char *errstr; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
722 enum mail_error error; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
723 |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
724 if (mailbox_create(box, NULL, FALSE) < 0) { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
725 errstr = mailbox_get_last_error(box, &error); |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
726 if (error != MAIL_ERROR_NOTFOUND) { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
727 mail_storage_set_critical(box->storage, |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
728 "Failed to autocreate mailbox %s: %s", |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
729 box->vname, errstr); |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
730 return -1; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
731 } |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
732 } else if (box->set != NULL && |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
733 strcmp(box->set->autocreate, |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
734 MAILBOX_SET_AUTO_SUBSCRIBE) == 0) { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
735 if (mailbox_set_subscribed(box, TRUE) < 0) { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
736 mail_storage_set_critical(box->storage, |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
737 "Failed to autosubscribe to mailbox %s: %s", |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
738 box->vname, mailbox_get_last_error(box, NULL)); |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
739 return -1; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
740 } |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
741 } |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
742 return 0; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
743 } |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
744 |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
745 static int mailbox_autocreate_and_reopen(struct mailbox *box) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
746 { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
747 int ret; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
748 |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
749 if (mailbox_autocreate(box) < 0) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
750 return -1; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
751 mailbox_close(box); |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
752 |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
753 ret = box->v.open(box); |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
754 if (ret < 0 && box->inbox_user && |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
755 !box->storage->user->inbox_open_error_logged) { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
756 box->storage->user->inbox_open_error_logged = TRUE; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
757 mail_storage_set_critical(box->storage, |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
758 "Opening INBOX failed: %s", |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
759 mailbox_get_last_error(box, NULL)); |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
760 } |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
761 return ret; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
762 } |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
763 |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
764 static bool |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
765 mailbox_name_verify_separators(const char *vname, char sep, |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
766 const char **error_r) |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
767 { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
768 unsigned int i; |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
769 bool prev_sep = FALSE; |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
770 |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
771 /* Make sure the vname is correct: non-empty, doesn't begin or end |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
772 with separator and no adjacent separators */ |
15113
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
773 for (i = 0; vname[i] != '\0'; i++) { |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
774 if (vname[i] == sep) { |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
775 if (prev_sep) { |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
776 *error_r = "Has adjacent hierarchy separators"; |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
777 return FALSE; |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
778 } |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
779 prev_sep = TRUE; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
780 } else { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
781 prev_sep = FALSE; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
782 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
783 } |
15113
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
784 if (prev_sep && i > 0) { |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
785 *error_r = "Ends with hierarchy separator"; |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
786 return FALSE; |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
787 } |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
788 return TRUE; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
789 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
790 |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
791 static int mailbox_verify_name(struct mailbox *box) |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
792 { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
793 struct mail_namespace *ns = box->list->ns; |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
794 const char *error, *vname = box->vname; |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
795 char list_sep, ns_sep; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
796 |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
797 if (box->inbox_user) { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
798 /* this is INBOX - don't bother with further checks */ |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
799 return 0; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
800 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
801 |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
802 list_sep = mailbox_list_get_hierarchy_sep(box->list); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
803 ns_sep = mail_namespace_get_sep(ns); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
804 |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
805 if (ns->prefix_len > 0) { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
806 /* vname is either "namespace/box" or "namespace" */ |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
807 i_assert(strncmp(vname, ns->prefix, ns->prefix_len-1) == 0); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
808 vname += ns->prefix_len - 1; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
809 if (vname[0] != '\0') { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
810 i_assert(vname[0] == ns->prefix[ns->prefix_len-1]); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
811 vname++; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
812 |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
813 if (vname[0] == '\0') { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
814 /* "namespace/" isn't a valid mailbox name. */ |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
815 mail_storage_set_error(box->storage, |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
816 MAIL_ERROR_PARAMS, |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
817 "Invalid mailbox name"); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
818 return -1; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
819 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
820 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
821 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
822 |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
823 if (ns_sep != list_sep && box->list->set.escape_char == '\0' && |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
824 strchr(vname, list_sep) != NULL) { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
825 mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS, t_strdup_printf( |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
826 "Character not allowed in mailbox name: '%c'", list_sep)); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
827 return -1; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
828 } |
15113
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
829 if (vname[0] == ns_sep && |
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
830 !box->storage->set->mail_full_filesystem_access) { |
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
831 mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS, |
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
832 "Invalid mailbox name: Begins with hierarchy separator"); |
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
833 return -1; |
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
834 } |
71fb4be2f666
lib-storage: Allow mailbox name to begin with separator if mail_full_filesystem_access=yes
Timo Sirainen <tss@iki.fi>
parents:
15112
diff
changeset
|
835 |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
836 if (!mailbox_name_verify_separators(vname, ns_sep, &error) || |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
837 !mailbox_list_is_valid_name(box->list, box->name, &error)) { |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
838 mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS, |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
839 t_strdup_printf("Invalid mailbox name: %s", error)); |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
840 return -1; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
841 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
842 return 0; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
843 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
844 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
845 static int mailbox_verify_existing_name(struct mailbox *box) |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
846 { |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
847 const char *path; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
848 |
15166
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
849 if (box->opened) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
850 return 0; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
851 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
852 if (mailbox_verify_name(box) < 0) |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
853 return -1; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
854 |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
855 /* Make sure box->_path is set, so mailbox_get_path() works from |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
856 now on. Note that this may also fail with some backends if the |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
857 mailbox doesn't exist. */ |
15166
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
858 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX, &path) < 0) { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
859 if (box->storage->error != MAIL_ERROR_NOTFOUND || |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
860 !mailbox_is_autocreated(box)) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
861 return -1; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
862 /* if this is an autocreated mailbox, create it now */ |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
863 if (mailbox_autocreate(box) < 0) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
864 return -1; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
865 mailbox_close(box); |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
866 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX, |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
867 &path) < 0) |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
868 return -1; |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
869 } |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
870 return 0; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
871 } |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
872 |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
873 static bool mailbox_name_has_control_chars(const char *name) |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
874 { |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
875 const char *p; |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
876 |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
877 for (p = name; *p != '\0'; p++) { |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
878 if ((unsigned char)*p < ' ') |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
879 return TRUE; |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
880 } |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
881 return FALSE; |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
882 } |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
883 |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
884 int mailbox_verify_create_name(struct mailbox *box) |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
885 { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
886 char sep = mail_namespace_get_sep(box->list->ns); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
887 |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
888 /* mailbox_alloc() already checks that vname is valid UTF8, |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
889 so we don't need to verify that. |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
890 |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
891 check vname instead of storage name, because vname is what is |
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
892 visible to users, while storage name may be a fixed length GUID. */ |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
893 if (mailbox_verify_name(box) < 0) |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
894 return -1; |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
895 if (mailbox_name_has_control_chars(box->vname)) { |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
896 mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS, |
15107
20edc46254ce
Various cleanups to checking if mailbox name is valid.
Timo Sirainen <tss@iki.fi>
parents:
15104
diff
changeset
|
897 "Control characters not allowed in new mailbox names"); |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
898 return -1; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
899 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
900 if (mailbox_list_name_is_too_large(box->vname, sep)) { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
901 mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS, |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
902 "Mailbox name too long"); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
903 return -1; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
904 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
905 return 0; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
906 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
907 |
12586
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
908 static bool have_listable_namespace_prefix(struct mail_namespace *ns, |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
909 const char *name) |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
910 { |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
911 unsigned int name_len = strlen(name); |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
912 |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
913 for (; ns != NULL; ns = ns->next) { |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
914 if ((ns->flags & (NAMESPACE_FLAG_LIST_PREFIX | |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
915 NAMESPACE_FLAG_LIST_CHILDREN)) == 0) |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
916 continue; |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
917 |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
918 if (ns->prefix_len <= name_len) |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
919 continue; |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
920 |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
921 /* if prefix has multiple hierarchies, match |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
922 any of the hierarchies */ |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
923 if (strncmp(ns->prefix, name, name_len) == 0 && |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
924 ns->prefix[name_len] == mail_namespace_get_sep(ns)) |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
925 return TRUE; |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
926 } |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
927 return FALSE; |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
928 } |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
929 |
13125
4dca25ea4a1c
lib-storage: Added auto_boxes parameter to mailbox_exists().
Timo Sirainen <tss@iki.fi>
parents:
13099
diff
changeset
|
930 int mailbox_exists(struct mailbox *box, bool auto_boxes, |
4dca25ea4a1c
lib-storage: Added auto_boxes parameter to mailbox_exists().
Timo Sirainen <tss@iki.fi>
parents:
13099
diff
changeset
|
931 enum mailbox_existence *existence_r) |
12583
4073ccc8123f
lib-storage: Replaced mailbox_list_get_name_status() with mailbox_exists().
Timo Sirainen <tss@iki.fi>
parents:
12550
diff
changeset
|
932 { |
13219
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
933 switch (box->open_error) { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
934 case 0: |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
935 break; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
936 case MAIL_ERROR_NOTFOUND: |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
937 *existence_r = MAILBOX_EXISTENCE_NONE; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
938 return 0; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
939 default: |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
940 /* unsure if this exists or not */ |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
941 return -1; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
942 } |
15166
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
943 if (mailbox_verify_name(box) < 0) { |
55ab35b0cc22
lib-storage: Do mailbox autocreation elsewhere also besides just mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
15165
diff
changeset
|
944 /* the mailbox name is invalid. we don't know if it currently |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
945 exists or not, but since it can never be accessed in any way |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
946 report it as if it didn't exist. */ |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
947 *existence_r = MAILBOX_EXISTENCE_NONE; |
13099
3a12ac2413e2
lib-storage: mailbox_exists() now returns NOSELECT for invalid mailbox names instead of error.
Timo Sirainen <tss@iki.fi>
parents:
13074
diff
changeset
|
948 return 0; |
12583
4073ccc8123f
lib-storage: Replaced mailbox_list_get_name_status() with mailbox_exists().
Timo Sirainen <tss@iki.fi>
parents:
12550
diff
changeset
|
949 } |
4073ccc8123f
lib-storage: Replaced mailbox_list_get_name_status() with mailbox_exists().
Timo Sirainen <tss@iki.fi>
parents:
12550
diff
changeset
|
950 |
13793
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
951 if (auto_boxes && box->set != NULL && mailbox_is_autocreated(box)) { |
13445
3844653d483a
lib-storage: Handle INBOX in the common mailbox_exists() code.
Timo Sirainen <tss@iki.fi>
parents:
13430
diff
changeset
|
952 *existence_r = MAILBOX_EXISTENCE_SELECT; |
3844653d483a
lib-storage: Handle INBOX in the common mailbox_exists() code.
Timo Sirainen <tss@iki.fi>
parents:
13430
diff
changeset
|
953 return 0; |
3844653d483a
lib-storage: Handle INBOX in the common mailbox_exists() code.
Timo Sirainen <tss@iki.fi>
parents:
13430
diff
changeset
|
954 } |
3844653d483a
lib-storage: Handle INBOX in the common mailbox_exists() code.
Timo Sirainen <tss@iki.fi>
parents:
13430
diff
changeset
|
955 |
14348
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
956 if (box->v.exists(box, auto_boxes, existence_r) < 0) |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
957 return -1; |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
958 |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
959 if (!box->inbox_user && *existence_r == MAILBOX_EXISTENCE_NOSELECT && |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
960 have_listable_namespace_prefix(box->storage->user->namespaces, |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
961 box->vname)) { |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
962 /* listable namespace prefix always exists. */ |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
963 *existence_r = MAILBOX_EXISTENCE_NOSELECT; |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
964 return 0; |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
965 } |
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
966 |
14550
41f2bcb43dad
lib-storage: Don't auto-drop namespaces with only INBOX shared and mail_shared_explicit_inbox=no
Timo Sirainen <tss@iki.fi>
parents:
14533
diff
changeset
|
967 /* if this is a shared namespace with only INBOX and |
41f2bcb43dad
lib-storage: Don't auto-drop namespaces with only INBOX shared and mail_shared_explicit_inbox=no
Timo Sirainen <tss@iki.fi>
parents:
14533
diff
changeset
|
968 mail_shared_explicit_inbox=no, we'll need to mark the namespace as |
41f2bcb43dad
lib-storage: Don't auto-drop namespaces with only INBOX shared and mail_shared_explicit_inbox=no
Timo Sirainen <tss@iki.fi>
parents:
14533
diff
changeset
|
969 usable here since nothing else will. */ |
41f2bcb43dad
lib-storage: Don't auto-drop namespaces with only INBOX shared and mail_shared_explicit_inbox=no
Timo Sirainen <tss@iki.fi>
parents:
14533
diff
changeset
|
970 box->list->ns->flags |= NAMESPACE_FLAG_USABLE; |
14348
55586f4a86f1
lib-storage: mailbox_exists() now returns namespace prefix as selectable if it is.
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
971 return 0; |
12583
4073ccc8123f
lib-storage: Replaced mailbox_list_get_name_status() with mailbox_exists().
Timo Sirainen <tss@iki.fi>
parents:
12550
diff
changeset
|
972 } |
4073ccc8123f
lib-storage: Replaced mailbox_list_get_name_status() with mailbox_exists().
Timo Sirainen <tss@iki.fi>
parents:
12550
diff
changeset
|
973 |
14629
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14613
diff
changeset
|
974 static int ATTR_NULL(2) |
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14613
diff
changeset
|
975 mailbox_open_full(struct mailbox *box, struct istream *input) |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
976 { |
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
977 int ret; |
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
978 |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
979 if (box->opened) |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
980 return 0; |
13219
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
981 switch (box->open_error) { |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
982 case 0: |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
983 break; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
984 case MAIL_ERROR_NOTFOUND: |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
985 mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND, |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
986 T_MAIL_ERR_MAILBOX_NOT_FOUND(box->vname)); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
987 return -1; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
988 default: |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
989 mail_storage_set_internal_error(box->storage); |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
990 box->storage->error = box->open_error; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
991 return -1; |
7098642a0374
lib-storage: Added mailbox_alloc_guid() for opening mailbox by its GUID.
Timo Sirainen <tss@iki.fi>
parents:
13207
diff
changeset
|
992 } |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
993 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
994 if (mailbox_verify_existing_name(box) < 0) |
12586
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
995 return -1; |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
996 |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
997 if (input != NULL) { |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
998 if ((box->storage->class_flags & |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
999 MAIL_STORAGE_CLASS_FLAG_OPEN_STREAMS) == 0) { |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1000 mail_storage_set_critical(box->storage, |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1001 "Storage doesn't support streamed mailboxes"); |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1002 return -1; |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1003 } |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1004 box->input = input; |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1005 box->flags |= MAILBOX_FLAG_READONLY; |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1006 i_stream_ref(box->input); |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1007 } |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1008 |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
1009 T_BEGIN { |
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
1010 ret = box->v.open(box); |
7226
e6693a0ec8e1
Renamed T_FRAME_BEGIN/END to T_BEGIN/END. Removed T_FRAME() macro and
Timo Sirainen <tss@iki.fi>
parents:
7175
diff
changeset
|
1011 } T_END; |
9125
dc220ff69fb8
When mailbox is successfully opened, mark its namespace as being usable.
Timo Sirainen <tss@iki.fi>
parents:
9064
diff
changeset
|
1012 |
10720
26b9138d561f
lib-storage: Removed INBOX auto-creating from backend code. Added bool box->inbox.
Timo Sirainen <tss@iki.fi>
parents:
10719
diff
changeset
|
1013 if (ret < 0 && box->storage->error == MAIL_ERROR_NOTFOUND && |
13793
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
1014 box->input == NULL && mailbox_is_autocreated(box)) T_BEGIN { |
ee783a878120
Moved autocreate plugin functionality into lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
13754
diff
changeset
|
1015 ret = mailbox_autocreate_and_reopen(box); |
10720
26b9138d561f
lib-storage: Removed INBOX auto-creating from backend code. Added bool box->inbox.
Timo Sirainen <tss@iki.fi>
parents:
10719
diff
changeset
|
1016 } T_END; |
26b9138d561f
lib-storage: Removed INBOX auto-creating from backend code. Added bool box->inbox.
Timo Sirainen <tss@iki.fi>
parents:
10719
diff
changeset
|
1017 |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1018 if (ret < 0) { |
10707
72a345621cd2
mailbox_open(): Don't crash if opening non-stream mailbox fails.
Timo Sirainen <tss@iki.fi>
parents:
10690
diff
changeset
|
1019 if (box->input != NULL) |
72a345621cd2
mailbox_open(): Don't crash if opening non-stream mailbox fails.
Timo Sirainen <tss@iki.fi>
parents:
10690
diff
changeset
|
1020 i_stream_unref(&box->input); |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
1021 return -1; |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1022 } |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
1023 |
9468
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
1024 box->list->ns->flags |= NAMESPACE_FLAG_USABLE; |
653183a81b6c
Mailbox opening and closing APIs changed.
Timo Sirainen <tss@iki.fi>
parents:
9455
diff
changeset
|
1025 return 0; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1026 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1027 |
14436
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1028 static bool mailbox_try_undelete(struct mailbox *box) |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1029 { |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1030 time_t mtime; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1031 |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1032 if (mail_index_get_modification_time(box->index, &mtime) < 0) |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1033 return FALSE; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1034 if (mtime + MAILBOX_DELETE_RETRY_SECS > time(NULL)) |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1035 return FALSE; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1036 |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1037 if (mailbox_mark_index_deleted(box, FALSE) < 0) |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1038 return FALSE; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1039 box->mailbox_deleted = FALSE; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1040 return TRUE; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1041 } |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1042 |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1043 int mailbox_open(struct mailbox *box) |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1044 { |
14436
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1045 if (mailbox_open_full(box, NULL) < 0) { |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1046 if (!box->mailbox_deleted) |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1047 return -1; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1048 |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1049 /* mailbox has been marked as deleted. if this deletion |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1050 started (and crashed) a long time ago, it can be confusing |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1051 to user that the mailbox can't be opened. so we'll just |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1052 undelete it and reopen. */ |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1053 if(!mailbox_try_undelete(box)) |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1054 return -1; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1055 if (mailbox_open_full(box, NULL) < 0) |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1056 return -1; |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1057 } |
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1058 return 0; |
10690
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1059 } |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1060 |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1061 int mailbox_open_stream(struct mailbox *box, struct istream *input) |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1062 { |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1063 return mailbox_open_full(box, input); |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1064 } |
b7c8221cea5b
lib-storage: Removed input parameter from mailbox_alloc(), added mailbox_open_stream()
Timo Sirainen <tss@iki.fi>
parents:
10685
diff
changeset
|
1065 |
7620 | 1066 int mailbox_enable(struct mailbox *box, enum mailbox_feature features) |
1067 { | |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1068 if (mailbox_verify_name(box) < 0) |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1069 return -1; |
7620 | 1070 return box->v.enable(box, features); |
1071 } | |
1072 | |
1073 enum mailbox_feature mailbox_get_enabled_features(struct mailbox *box) | |
1074 { | |
1075 return box->enabled_features; | |
1076 } | |
1077 | |
14859
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1078 void mail_storage_free_binary_cache(struct mail_storage *storage) |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1079 { |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1080 if (storage->binary_cache.box == NULL) |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1081 return; |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1082 |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1083 timeout_remove(&storage->binary_cache.to); |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1084 i_stream_destroy(&storage->binary_cache.input); |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1085 memset(&storage->binary_cache, 0, sizeof(storage->binary_cache)); |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1086 } |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1087 |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1088 void mailbox_close(struct mailbox *box) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1089 { |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1090 if (!box->opened) |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1091 return; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1092 |
6260
b238257f724c
If mailbox has transactions open while it's tried to be closed, die here
Timo Sirainen <tss@iki.fi>
parents:
6065
diff
changeset
|
1093 if (box->transaction_count != 0) { |
b238257f724c
If mailbox has transactions open while it's tried to be closed, die here
Timo Sirainen <tss@iki.fi>
parents:
6065
diff
changeset
|
1094 i_panic("Trying to close mailbox %s with open transactions", |
b238257f724c
If mailbox has transactions open while it's tried to be closed, die here
Timo Sirainen <tss@iki.fi>
parents:
6065
diff
changeset
|
1095 box->name); |
b238257f724c
If mailbox has transactions open while it's tried to be closed, die here
Timo Sirainen <tss@iki.fi>
parents:
6065
diff
changeset
|
1096 } |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1097 box->v.close(box); |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1098 |
14859
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1099 if (box->storage->binary_cache.box == box) |
f3ef88e19cd5
IMAP BINARY extension supports now FETCH BINARY command.
Timo Sirainen <tss@iki.fi>
parents:
14840
diff
changeset
|
1100 mail_storage_free_binary_cache(box->storage); |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1101 box->opened = FALSE; |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1102 box->mailbox_deleted = FALSE; |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1103 array_clear(&box->search_results); |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1104 } |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1105 |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1106 void mailbox_free(struct mailbox **_box) |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1107 { |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1108 struct mailbox *box = *_box; |
6260
b238257f724c
If mailbox has transactions open while it's tried to be closed, die here
Timo Sirainen <tss@iki.fi>
parents:
6065
diff
changeset
|
1109 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1110 *_box = NULL; |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1111 |
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1112 mailbox_close(box); |
10719
debbf3f39e0c
lib-storage: Use a default non-NULL mailbox.free() so plugins don't have to check for it.
Timo Sirainen <tss@iki.fi>
parents:
10718
diff
changeset
|
1113 box->v.free(box); |
13754
deaebb4dc98c
lib-storage: Track storage's all mailboxes to make it easier to debug if one isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
13712
diff
changeset
|
1114 |
deaebb4dc98c
lib-storage: Track storage's all mailboxes to make it easier to debug if one isn't closed.
Timo Sirainen <tss@iki.fi>
parents:
13712
diff
changeset
|
1115 DLLIST_REMOVE(&box->storage->mailboxes, box); |
11106
085253f549f8
lib-storage: Panic if deiniting storage before closing its mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
11060
diff
changeset
|
1116 mail_storage_obj_unref(box->storage); |
14524
3b4c336ed01b
lib-storage: Allocate MAILBOX_METADATA_CACHE_FIELDS from a new metadata mempool.
Timo Sirainen <tss@iki.fi>
parents:
14463
diff
changeset
|
1117 if (box->metadata_pool != NULL) |
3b4c336ed01b
lib-storage: Allocate MAILBOX_METADATA_CACHE_FIELDS from a new metadata mempool.
Timo Sirainen <tss@iki.fi>
parents:
14463
diff
changeset
|
1118 pool_unref(&box->metadata_pool); |
10662
8b138b29dc01
lib-storage: Split mailbox_close() and mailbox_free() functionality.
Timo Sirainen <tss@iki.fi>
parents:
10657
diff
changeset
|
1119 pool_unref(&box->pool); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1120 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1121 |
15009
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1122 bool mailbox_equals(const struct mailbox *box1, |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1123 const struct mail_namespace *ns2, const char *vname2) |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1124 { |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1125 struct mail_namespace *ns1 = mailbox_get_namespace(box1); |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1126 const char *name1; |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1127 |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1128 if (ns1 != ns2) |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1129 return FALSE; |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1130 |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1131 name1 = mailbox_get_vname(box1); |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1132 if (strcmp(name1, vname2) == 0) |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1133 return TRUE; |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1134 |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1135 return strcasecmp(name1, "INBOX") == 0 && |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1136 strcasecmp(vname2, "INBOX") == 0; |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1137 } |
e4d5c3ba305b
Moved mailbox_equals() to lib-storage.
Timo Sirainen <tss@iki.fi>
parents:
14952
diff
changeset
|
1138 |
9533
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1139 int mailbox_create(struct mailbox *box, const struct mailbox_update *update, |
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1140 bool directory) |
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1141 { |
12809
1ffeb083c993
sdbox: Fixed creating mailbox with given GUID.
Timo Sirainen <tss@iki.fi>
parents:
12734
diff
changeset
|
1142 int ret; |
12114
ba924e3ee4ae
lib-storage: Added mailbox_list_create_dir()
Timo Sirainen <tss@iki.fi>
parents:
12058
diff
changeset
|
1143 |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1144 if (mailbox_verify_create_name(box) < 0) |
9533
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1145 return -1; |
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1146 |
12809
1ffeb083c993
sdbox: Fixed creating mailbox with given GUID.
Timo Sirainen <tss@iki.fi>
parents:
12734
diff
changeset
|
1147 box->creating = TRUE; |
15041
7c6d30280cff
lib-storage API change to allow using it from C++ code
Timo Sirainen <tss@iki.fi>
parents:
15040
diff
changeset
|
1148 ret = box->v.create_box(box, update, directory); |
12809
1ffeb083c993
sdbox: Fixed creating mailbox with given GUID.
Timo Sirainen <tss@iki.fi>
parents:
12734
diff
changeset
|
1149 box->creating = FALSE; |
1ffeb083c993
sdbox: Fixed creating mailbox with given GUID.
Timo Sirainen <tss@iki.fi>
parents:
12734
diff
changeset
|
1150 return ret; |
9533
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1151 } |
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1152 |
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1153 int mailbox_update(struct mailbox *box, const struct mailbox_update *update) |
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1154 { |
12852
18d801449444
lib-storage: Moved mailbox_update() assert check from mdbox to common, plus fixed it.
Timo Sirainen <tss@iki.fi>
parents:
12822
diff
changeset
|
1155 i_assert(update->min_next_uid == 0 || |
18d801449444
lib-storage: Moved mailbox_update() assert check from mdbox to common, plus fixed it.
Timo Sirainen <tss@iki.fi>
parents:
12822
diff
changeset
|
1156 update->min_first_recent_uid == 0 || |
18d801449444
lib-storage: Moved mailbox_update() assert check from mdbox to common, plus fixed it.
Timo Sirainen <tss@iki.fi>
parents:
12822
diff
changeset
|
1157 update->min_first_recent_uid <= update->min_next_uid); |
18d801449444
lib-storage: Moved mailbox_update() assert check from mdbox to common, plus fixed it.
Timo Sirainen <tss@iki.fi>
parents:
12822
diff
changeset
|
1158 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1159 if (mailbox_verify_existing_name(box) < 0) |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1160 return -1; |
15041
7c6d30280cff
lib-storage API change to allow using it from C++ code
Timo Sirainen <tss@iki.fi>
parents:
15040
diff
changeset
|
1161 return box->v.update_box(box, update); |
9533
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1162 } |
530bbade4e3f
Added support for creating/updating mailboxes with given metadata (guid, uid validity, etc).
Timo Sirainen <tss@iki.fi>
parents:
9509
diff
changeset
|
1163 |
11487
3a0601cb9e67
Mailbox deletion: Delay marking its index deleted until ACL has had a chance to abort the deletion.
Timo Sirainen <tss@iki.fi>
parents:
11474
diff
changeset
|
1164 int mailbox_mark_index_deleted(struct mailbox *box, bool del) |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1165 { |
12264
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1166 struct mail_index_transaction *trans; |
10723
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1167 enum mail_index_transaction_flags trans_flags = 0; |
12264
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1168 enum mailbox_flags old_flag; |
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1169 int ret; |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1170 |
12040
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1171 if (box->marked_deleted && del) { |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1172 /* we already marked it deleted. this allows plugins to |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1173 "lock" the deletion earlier. */ |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1174 return 0; |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1175 } |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1176 |
12264
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1177 old_flag = box->flags & MAILBOX_FLAG_OPEN_DELETED; |
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1178 box->flags |= MAILBOX_FLAG_OPEN_DELETED; |
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1179 ret = mailbox_open(box); |
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1180 box->flags = (box->flags & ~MAILBOX_FLAG_OPEN_DELETED) | old_flag; |
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1181 if (ret < 0) |
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1182 return -1; |
a3e40c6b14fe
lib-storage: If mailbox deletion failed, we crashed while trying to write undelete record to index.
Timo Sirainen <tss@iki.fi>
parents:
12146
diff
changeset
|
1183 |
10723
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1184 trans_flags = del ? 0 : MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL; |
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1185 trans = mail_index_transaction_begin(box->view, trans_flags); |
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1186 if (del) |
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1187 mail_index_set_deleted(trans); |
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1188 else |
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1189 mail_index_set_undeleted(trans); |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1190 if (mail_index_transaction_commit(&trans) < 0) { |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1191 mail_storage_set_index_error(box); |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1192 return -1; |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1193 } |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1194 |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1195 /* sync the mailbox. this finishes the index deletion and it can |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1196 succeed only for a single session. we do it here, so the rest of |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1197 the deletion code doesn't have to worry about race conditions. */ |
12040
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1198 if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1199 return -1; |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1200 |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1201 box->marked_deleted = del; |
72b5a0af6e4e
lib-storage: Allow mailbox_mark_index_deleted() to be called multiple times within same mailbox alloc.
Timo Sirainen <tss@iki.fi>
parents:
11900
diff
changeset
|
1202 return 0; |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1203 } |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1204 |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1205 int mailbox_delete(struct mailbox *box) |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1206 { |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1207 int ret; |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1208 |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1209 if (*box->name == '\0') { |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1210 mail_storage_set_error(box->storage, MAIL_ERROR_PARAMS, |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1211 "Storage root can't be deleted"); |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1212 return -1; |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1213 } |
11740 | 1214 if (box->inbox_any) { |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1215 mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE, |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1216 "INBOX can't be deleted."); |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1217 return -1; |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1218 } |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1219 |
10678
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10676
diff
changeset
|
1220 box->deleting = TRUE; |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1221 if (mailbox_open(box) < 0) { |
12585
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
1222 if (mailbox_get_last_mail_error(box) != MAIL_ERROR_NOTFOUND) |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1223 return -1; |
14436
a109580dea25
lib-storage: If mailbox deletion crashed, undelete the mailbox when opening it.
Timo Sirainen <tss@iki.fi>
parents:
14399
diff
changeset
|
1224 /* \noselect mailbox */ |
10723
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1225 } |
eae6e4a7ee55
Mailbox deletion: If mailbox deletion seems to have crashed, allow retrying the deletion.
Timo Sirainen <tss@iki.fi>
parents:
10721
diff
changeset
|
1226 |
15041
7c6d30280cff
lib-storage API change to allow using it from C++ code
Timo Sirainen <tss@iki.fi>
parents:
15040
diff
changeset
|
1227 ret = box->v.delete_box(box); |
12058
eecc2fda78c1
lib-storage: If mailbox deletion fails, mark the index back as undeleted.
Timo Sirainen <tss@iki.fi>
parents:
12040
diff
changeset
|
1228 if (ret < 0 && box->marked_deleted) { |
eecc2fda78c1
lib-storage: If mailbox deletion fails, mark the index back as undeleted.
Timo Sirainen <tss@iki.fi>
parents:
12040
diff
changeset
|
1229 /* deletion failed. revert the mark so it can maybe be |
eecc2fda78c1
lib-storage: If mailbox deletion fails, mark the index back as undeleted.
Timo Sirainen <tss@iki.fi>
parents:
12040
diff
changeset
|
1230 tried again later. */ |
eecc2fda78c1
lib-storage: If mailbox deletion fails, mark the index back as undeleted.
Timo Sirainen <tss@iki.fi>
parents:
12040
diff
changeset
|
1231 if (mailbox_mark_index_deleted(box, FALSE) < 0) |
eecc2fda78c1
lib-storage: If mailbox deletion fails, mark the index back as undeleted.
Timo Sirainen <tss@iki.fi>
parents:
12040
diff
changeset
|
1232 return -1; |
eecc2fda78c1
lib-storage: If mailbox deletion fails, mark the index back as undeleted.
Timo Sirainen <tss@iki.fi>
parents:
12040
diff
changeset
|
1233 } |
10678
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10676
diff
changeset
|
1234 |
9740c4858a57
Mailbox deletion: Fixed race condition where a mailbox couldn't get deleted.
Timo Sirainen <tss@iki.fi>
parents:
10676
diff
changeset
|
1235 box->deleting = FALSE; |
10676
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1236 mailbox_close(box); |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1237 return ret; |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1238 } |
1fd7833c16ca
lib-storage: Mailbox deletion API changed.
Timo Sirainen <tss@iki.fi>
parents:
10670
diff
changeset
|
1239 |
14463
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1240 int mailbox_delete_empty(struct mailbox *box) |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1241 { |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1242 int ret; |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1243 |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1244 /* FIXME: should be a parameter to delete(), but since it changes API |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1245 don't do it for now */ |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1246 box->deleting_must_be_empty = TRUE; |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1247 ret = mailbox_delete(box); |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1248 box->deleting_must_be_empty = FALSE; |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1249 return ret; |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1250 } |
2d8bafd11569
lib-storage: Added mailbox_delete_empty().
Timo Sirainen <tss@iki.fi>
parents:
14436
diff
changeset
|
1251 |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1252 static bool |
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1253 mail_storages_rename_compatible(struct mail_storage *storage1, |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1254 struct mail_storage *storage2, |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1255 const char **error_r) |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1256 { |
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1257 if (storage1 == storage2) |
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1258 return TRUE; |
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1259 |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1260 if (strcmp(storage1->name, storage2->name) != 0) { |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1261 *error_r = t_strdup_printf("storage %s != %s", |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1262 storage1->name, storage2->name); |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1263 return FALSE; |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1264 } |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1265 if ((storage1->class_flags & MAIL_STORAGE_CLASS_FLAG_UNIQUE_ROOT) != 0) { |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1266 /* e.g. mdbox where all mails are in storage/ directory and |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1267 they can't be easily moved from there. */ |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1268 *error_r = t_strdup_printf("storage %s uses unique root", |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1269 storage1->name); |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1270 return FALSE; |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1271 } |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1272 return TRUE; |
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1273 } |
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1274 |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1275 static bool nullequals(const void *p1, const void *p2) |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1276 { |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1277 return (p1 == NULL && p2 == NULL) || (p1 != NULL && p2 != NULL); |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1278 } |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1279 |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1280 static bool |
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1281 mailbox_lists_rename_compatible(struct mailbox_list *list1, |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1282 struct mailbox_list *list2, |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1283 const char **error_r) |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1284 { |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1285 if (!nullequals(list1->set.alt_dir, list2->set.alt_dir)) { |
13504
19086b0d53f4
lib-storage: Improved debug logging messages.
Timo Sirainen <tss@iki.fi>
parents:
13502
diff
changeset
|
1286 *error_r = "one namespace has alt dir and another doesn't"; |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1287 return FALSE; |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1288 } |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1289 if (!nullequals(list1->set.index_dir, list2->set.index_dir)) { |
13504
19086b0d53f4
lib-storage: Improved debug logging messages.
Timo Sirainen <tss@iki.fi>
parents:
13502
diff
changeset
|
1290 *error_r = "one namespace has index dir and another doesn't"; |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1291 return FALSE; |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1292 } |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1293 if (!nullequals(list1->set.control_dir, list2->set.control_dir)) { |
13504
19086b0d53f4
lib-storage: Improved debug logging messages.
Timo Sirainen <tss@iki.fi>
parents:
13502
diff
changeset
|
1294 *error_r = "one namespace has control dir and another doesn't"; |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1295 return FALSE; |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1296 } |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1297 return TRUE; |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1298 } |
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1299 |
15038
92cc78c5dc77
lib-storage: Removed rename_children parameter from mailbox_rename()
Timo Sirainen <tss@iki.fi>
parents:
15028
diff
changeset
|
1300 int mailbox_rename(struct mailbox *src, struct mailbox *dest) |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1301 { |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1302 const char *error = NULL; |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1303 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1304 if (mailbox_verify_existing_name(src) < 0) |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1305 return -1; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1306 if (*src->name == '\0') { |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1307 mail_storage_set_error(src->storage, MAIL_ERROR_PARAMS, |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1308 "Can't rename mailbox root"); |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1309 return -1; |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1310 } |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1311 if (mailbox_verify_create_name(dest) < 0) { |
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1312 mail_storage_copy_error(dest->storage, src->storage); |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1313 return -1; |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1314 } |
13502
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1315 if (!mail_storages_rename_compatible(src->storage, |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1316 dest->storage, &error) || |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1317 !mailbox_lists_rename_compatible(src->list, |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1318 dest->list, &error)) { |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1319 if (src->storage->set->mail_debug) { |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1320 i_debug("Can't rename '%s' to '%s': %s", |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1321 src->vname, dest->vname, error); |
e57bd3e2ec27
lib-storage: If mailbox_rename() isn't possible and mail_debug=yes, log the reason why.
Timo Sirainen <tss@iki.fi>
parents:
12910
diff
changeset
|
1322 } |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1323 mail_storage_set_error(src->storage, MAIL_ERROR_NOTPOSSIBLE, |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1324 "Can't rename mailboxes across specified storages."); |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1325 return -1; |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1326 } |
12734
3c61817f30bb
lib-storage: Fixed renaming mailboxes in a non-private namespace.
Timo Sirainen <tss@iki.fi>
parents:
12674
diff
changeset
|
1327 if (src->list != dest->list && |
15012
368f3b2e3264
Renamed enum namespace_type to enum mail_namespace_type
Timo Sirainen <tss@iki.fi>
parents:
15009
diff
changeset
|
1328 (src->list->ns->type != MAIL_NAMESPACE_TYPE_PRIVATE || |
368f3b2e3264
Renamed enum namespace_type to enum mail_namespace_type
Timo Sirainen <tss@iki.fi>
parents:
15009
diff
changeset
|
1329 dest->list->ns->type != MAIL_NAMESPACE_TYPE_PRIVATE)) { |
10721
ea8f213f0e19
lib-storage: Fixes to rename error handling.
Timo Sirainen <tss@iki.fi>
parents:
10720
diff
changeset
|
1330 mail_storage_set_error(src->storage, MAIL_ERROR_NOTPOSSIBLE, |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1331 "Renaming not supported across non-private namespaces."); |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1332 return -1; |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1333 } |
15165
35b9e155f03f
lib-storage: If trying to rename mailbox over itself, fail early.
Timo Sirainen <tss@iki.fi>
parents:
15163
diff
changeset
|
1334 if (src->list == dest->list && strcmp(src->name, dest->name) == 0) { |
35b9e155f03f
lib-storage: If trying to rename mailbox over itself, fail early.
Timo Sirainen <tss@iki.fi>
parents:
15163
diff
changeset
|
1335 mail_storage_set_error(src->storage, MAIL_ERROR_EXISTS, |
35b9e155f03f
lib-storage: If trying to rename mailbox over itself, fail early.
Timo Sirainen <tss@iki.fi>
parents:
15163
diff
changeset
|
1336 "Can't rename mailbox to itself."); |
35b9e155f03f
lib-storage: If trying to rename mailbox over itself, fail early.
Timo Sirainen <tss@iki.fi>
parents:
15163
diff
changeset
|
1337 return -1; |
35b9e155f03f
lib-storage: If trying to rename mailbox over itself, fail early.
Timo Sirainen <tss@iki.fi>
parents:
15163
diff
changeset
|
1338 } |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1339 |
15041
7c6d30280cff
lib-storage API change to allow using it from C++ code
Timo Sirainen <tss@iki.fi>
parents:
15040
diff
changeset
|
1340 return src->v.rename_box(src, dest); |
10711
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1341 } |
292562f9b12c
lib-storage: Mailbox renaming API changed.
Timo Sirainen <tss@iki.fi>
parents:
10707
diff
changeset
|
1342 |
12586
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
1343 int mailbox_set_subscribed(struct mailbox *box, bool set) |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
1344 { |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1345 if (mailbox_verify_name(box) < 0) |
12586
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
1346 return -1; |
13876
bc9217cb0193
lib-storage: Added struct mailbox.set_subscribed() virtual method.
Timo Sirainen <tss@iki.fi>
parents:
13801
diff
changeset
|
1347 return box->v.set_subscribed(box, set); |
12586
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
1348 } |
a2780b694b2d
lib-storage: mailbox_alloc() now takes a virtual mailbox name and other related API changes.
Timo Sirainen <tss@iki.fi>
parents:
12585
diff
changeset
|
1349 |
15028
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1350 bool mailbox_is_subscribed(struct mailbox *box) |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1351 { |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1352 struct mailbox_node *node; |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1353 |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1354 i_assert(box->list->subscriptions != NULL); |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1355 |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1356 node = mailbox_tree_lookup(box->list->subscriptions, box->vname); |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1357 return node != NULL && (node->flags & MAILBOX_SUBSCRIBED) != 0; |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1358 } |
c00df434bfb9
lib-storage: Added mailbox_is_subscribed()
Timo Sirainen <tss@iki.fi>
parents:
15012
diff
changeset
|
1359 |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7908
diff
changeset
|
1360 struct mail_storage *mailbox_get_storage(const struct mailbox *box) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1361 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1362 return box->storage; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1363 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1364 |
9434
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
1365 struct mail_namespace * |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
1366 mailbox_get_namespace(const struct mailbox *box) |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
1367 { |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
1368 return box->list->ns; |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
1369 } |
e374a365521d
Initial commit for making mail_storage:mailbox_list to be from 1:1 to n:n.
Timo Sirainen <tss@iki.fi>
parents:
9172
diff
changeset
|
1370 |
9002
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1371 const struct mail_storage_settings *mailbox_get_settings(struct mailbox *box) |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1372 { |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1373 return box->storage->set; |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1374 } |
9d0037a997f4
Initial commit for config rewrite.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1375 |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7908
diff
changeset
|
1376 const char *mailbox_get_name(const struct mailbox *box) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1377 { |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1378 return box->name; |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1379 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1380 |
9564
279af9682cd6
lib-storage: Added mailbox_get_vname().
Timo Sirainen <tss@iki.fi>
parents:
9554
diff
changeset
|
1381 const char *mailbox_get_vname(const struct mailbox *box) |
279af9682cd6
lib-storage: Added mailbox_get_vname().
Timo Sirainen <tss@iki.fi>
parents:
9554
diff
changeset
|
1382 { |
279af9682cd6
lib-storage: Added mailbox_get_vname().
Timo Sirainen <tss@iki.fi>
parents:
9554
diff
changeset
|
1383 return box->vname; |
279af9682cd6
lib-storage: Added mailbox_get_vname().
Timo Sirainen <tss@iki.fi>
parents:
9554
diff
changeset
|
1384 } |
279af9682cd6
lib-storage: Added mailbox_get_vname().
Timo Sirainen <tss@iki.fi>
parents:
9554
diff
changeset
|
1385 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3641
diff
changeset
|
1386 bool mailbox_is_readonly(struct mailbox *box) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1387 { |
15101
78d9adf7c149
lib-storage: Added asserts to make sure mailbox_open() is called early enough.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
1388 i_assert(box->opened); |
78d9adf7c149
lib-storage: Added asserts to make sure mailbox_open() is called early enough.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
1389 |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
1390 return box->v.is_readonly(box); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1391 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1392 |
9650
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1393 bool mailbox_backends_equal(const struct mailbox *box1, |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1394 const struct mailbox *box2) |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1395 { |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1396 struct mail_namespace *ns1 = box1->list->ns, *ns2 = box2->list->ns; |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1397 |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1398 if (strcmp(box1->name, box2->name) != 0) |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1399 return FALSE; |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1400 |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1401 while (ns1->alias_for != NULL) |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1402 ns1 = ns1->alias_for; |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1403 while (ns2->alias_for != NULL) |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1404 ns2 = ns2->alias_for; |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1405 return ns1 == ns2; |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1406 } |
6b6d6e094674
Added mailbox_backends_equal().
Timo Sirainen <tss@iki.fi>
parents:
9649
diff
changeset
|
1407 |
12549
bbfa924bc4bc
lib-storage: mailbox_get_status() can now fail.
Timo Sirainen <tss@iki.fi>
parents:
12544
diff
changeset
|
1408 int mailbox_get_status(struct mailbox *box, |
bbfa924bc4bc
lib-storage: mailbox_get_status() can now fail.
Timo Sirainen <tss@iki.fi>
parents:
12544
diff
changeset
|
1409 enum mailbox_status_items items, |
bbfa924bc4bc
lib-storage: mailbox_get_status() can now fail.
Timo Sirainen <tss@iki.fi>
parents:
12544
diff
changeset
|
1410 struct mailbox_status *status_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1411 { |
13461
8eea5682ac5b
lib-storage: Make sure status/metadata structs are cleared when they're looked up.
Timo Sirainen <tss@iki.fi>
parents:
13445
diff
changeset
|
1412 memset(status_r, 0, sizeof(*status_r)); |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1413 if (mailbox_verify_existing_name(box) < 0) |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1414 return -1; |
12549
bbfa924bc4bc
lib-storage: mailbox_get_status() can now fail.
Timo Sirainen <tss@iki.fi>
parents:
12544
diff
changeset
|
1415 return box->v.get_status(box, items, status_r); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1416 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1417 |
12550
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1418 void mailbox_get_open_status(struct mailbox *box, |
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1419 enum mailbox_status_items items, |
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1420 struct mailbox_status *status_r) |
10685
3609c8a35c36
lib-storage: STATUS_GUID moved to mailbox_get_guid() that can fail.
Timo Sirainen <tss@iki.fi>
parents:
10678
diff
changeset
|
1421 { |
12550
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1422 i_assert(box->opened); |
13461
8eea5682ac5b
lib-storage: Make sure status/metadata structs are cleared when they're looked up.
Timo Sirainen <tss@iki.fi>
parents:
13445
diff
changeset
|
1423 |
8eea5682ac5b
lib-storage: Make sure status/metadata structs are cleared when they're looked up.
Timo Sirainen <tss@iki.fi>
parents:
13445
diff
changeset
|
1424 memset(status_r, 0, sizeof(*status_r)); |
12550
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1425 if (box->v.get_status(box, items, status_r) < 0) |
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1426 i_unreached(); |
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1427 } |
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1428 |
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1429 int mailbox_get_metadata(struct mailbox *box, enum mailbox_metadata_items items, |
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1430 struct mailbox_metadata *metadata_r) |
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1431 { |
13461
8eea5682ac5b
lib-storage: Make sure status/metadata structs are cleared when they're looked up.
Timo Sirainen <tss@iki.fi>
parents:
13445
diff
changeset
|
1432 memset(metadata_r, 0, sizeof(*metadata_r)); |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1433 if (mailbox_verify_existing_name(box) < 0) |
15104
3e6048697365
lib-storage: Removed mailbox list backend-specific mailbox name/pattern validation.
Timo Sirainen <tss@iki.fi>
parents:
15101
diff
changeset
|
1434 return -1; |
13461
8eea5682ac5b
lib-storage: Make sure status/metadata structs are cleared when they're looked up.
Timo Sirainen <tss@iki.fi>
parents:
13445
diff
changeset
|
1435 |
14524
3b4c336ed01b
lib-storage: Allocate MAILBOX_METADATA_CACHE_FIELDS from a new metadata mempool.
Timo Sirainen <tss@iki.fi>
parents:
14463
diff
changeset
|
1436 if (box->metadata_pool != NULL) |
3b4c336ed01b
lib-storage: Allocate MAILBOX_METADATA_CACHE_FIELDS from a new metadata mempool.
Timo Sirainen <tss@iki.fi>
parents:
14463
diff
changeset
|
1437 p_clear(box->metadata_pool); |
3b4c336ed01b
lib-storage: Allocate MAILBOX_METADATA_CACHE_FIELDS from a new metadata mempool.
Timo Sirainen <tss@iki.fi>
parents:
14463
diff
changeset
|
1438 |
12550
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1439 if (box->v.get_metadata(box, items, metadata_r) < 0) |
10733
1afcc09c2c6c
mbox: Make sure we have valid mailbox GUID when returning it.
Timo Sirainen <tss@iki.fi>
parents:
10728
diff
changeset
|
1440 return -1; |
1afcc09c2c6c
mbox: Make sure we have valid mailbox GUID when returning it.
Timo Sirainen <tss@iki.fi>
parents:
10728
diff
changeset
|
1441 |
12550
2c299c0e3bc8
lib-storage: Moved some items from mailbox_get_status() to a new mailbox_get_metadata().
Timo Sirainen <tss@iki.fi>
parents:
12549
diff
changeset
|
1442 i_assert((items & MAILBOX_METADATA_GUID) == 0 || |
13287
957060ca5b69
Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents:
13249
diff
changeset
|
1443 !guid_128_is_empty(metadata_r->guid)); |
10733
1afcc09c2c6c
mbox: Make sure we have valid mailbox GUID when returning it.
Timo Sirainen <tss@iki.fi>
parents:
10728
diff
changeset
|
1444 return 0; |
10685
3609c8a35c36
lib-storage: STATUS_GUID moved to mailbox_get_guid() that can fail.
Timo Sirainen <tss@iki.fi>
parents:
10678
diff
changeset
|
1445 } |
3609c8a35c36
lib-storage: STATUS_GUID moved to mailbox_get_guid() that can fail.
Timo Sirainen <tss@iki.fi>
parents:
10678
diff
changeset
|
1446 |
12533
67257180c7ea
lib-storage: Moved box->private_flags_mask to mailbox_get_private_flags_mask()
Timo Sirainen <tss@iki.fi>
parents:
12521
diff
changeset
|
1447 enum mail_flags mailbox_get_private_flags_mask(struct mailbox *box) |
67257180c7ea
lib-storage: Moved box->private_flags_mask to mailbox_get_private_flags_mask()
Timo Sirainen <tss@iki.fi>
parents:
12521
diff
changeset
|
1448 { |
14599
dbd42f7198eb
shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents:
14576
diff
changeset
|
1449 if (box->v.get_private_flags_mask != NULL) |
dbd42f7198eb
shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents:
14576
diff
changeset
|
1450 return box->v.get_private_flags_mask(box); |
dbd42f7198eb
shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents:
14576
diff
changeset
|
1451 else if (box->list->set.index_pvt_dir != NULL) |
dbd42f7198eb
shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents:
14576
diff
changeset
|
1452 return MAIL_SEEN; /* FIXME */ |
dbd42f7198eb
shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents:
14576
diff
changeset
|
1453 else |
12533
67257180c7ea
lib-storage: Moved box->private_flags_mask to mailbox_get_private_flags_mask()
Timo Sirainen <tss@iki.fi>
parents:
12521
diff
changeset
|
1454 return 0; |
67257180c7ea
lib-storage: Moved box->private_flags_mask to mailbox_get_private_flags_mask()
Timo Sirainen <tss@iki.fi>
parents:
12521
diff
changeset
|
1455 } |
67257180c7ea
lib-storage: Moved box->private_flags_mask to mailbox_get_private_flags_mask()
Timo Sirainen <tss@iki.fi>
parents:
12521
diff
changeset
|
1456 |
15224
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1457 int mailbox_attribute_set(struct mailbox *box, enum mail_attribute_type type, |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1458 const char *key, const char *value) |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1459 { |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1460 return box->v.attribute_set(box, type, key, value); |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1461 } |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1462 |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1463 int mailbox_attribute_unset(struct mailbox *box, enum mail_attribute_type type, |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1464 const char *key) |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1465 { |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1466 return box->v.attribute_set(box, type, key, NULL); |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1467 } |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1468 |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1469 int mailbox_attribute_get(struct mailbox *box, enum mail_attribute_type type, |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1470 const char *key, const char **value_r) |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1471 { |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1472 return box->v.attribute_get(box, type, key, value_r); |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1473 } |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1474 |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1475 struct mailbox_attribute_iter * |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1476 mailbox_attribute_iter_init(struct mailbox *box, enum mail_attribute_type type, |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1477 const char *prefix) |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1478 { |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1479 return box->v.attribute_iter_init(box, type, prefix); |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1480 } |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1481 |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1482 const char *mailbox_attribute_iter_next(struct mailbox_attribute_iter *iter) |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1483 { |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1484 return iter->box->v.attribute_iter_next(iter); |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1485 } |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1486 |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1487 int mailbox_attribute_iter_deinit(struct mailbox_attribute_iter **_iter) |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1488 { |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1489 struct mailbox_attribute_iter *iter = *_iter; |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1490 |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1491 *_iter = NULL; |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1492 return iter->box->v.attribute_iter_deinit(iter); |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1493 } |
5659c178bdeb
lib-storage: Added support to get/set/iterate mailbox attributes.
Timo Sirainen <tss@iki.fi>
parents:
15207
diff
changeset
|
1494 |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1495 struct mailbox_sync_context * |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1496 mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1497 { |
9721
51d280d34bfa
lib-storage: Use less memory from data stack.
Timo Sirainen <tss@iki.fi>
parents:
9710
diff
changeset
|
1498 struct mailbox_sync_context *ctx; |
51d280d34bfa
lib-storage: Use less memory from data stack.
Timo Sirainen <tss@iki.fi>
parents:
9710
diff
changeset
|
1499 |
8533
70b0597e2bb5
Die if trying to sync mailbox while transactions are open.
Timo Sirainen <tss@iki.fi>
parents:
8518
diff
changeset
|
1500 if (box->transaction_count != 0) { |
70b0597e2bb5
Die if trying to sync mailbox while transactions are open.
Timo Sirainen <tss@iki.fi>
parents:
8518
diff
changeset
|
1501 i_panic("Trying to sync mailbox %s with open transactions", |
70b0597e2bb5
Die if trying to sync mailbox while transactions are open.
Timo Sirainen <tss@iki.fi>
parents:
8518
diff
changeset
|
1502 box->name); |
70b0597e2bb5
Die if trying to sync mailbox while transactions are open.
Timo Sirainen <tss@iki.fi>
parents:
8518
diff
changeset
|
1503 } |
9721
51d280d34bfa
lib-storage: Use less memory from data stack.
Timo Sirainen <tss@iki.fi>
parents:
9710
diff
changeset
|
1504 T_BEGIN { |
51d280d34bfa
lib-storage: Use less memory from data stack.
Timo Sirainen <tss@iki.fi>
parents:
9710
diff
changeset
|
1505 ctx = box->v.sync_init(box, flags); |
51d280d34bfa
lib-storage: Use less memory from data stack.
Timo Sirainen <tss@iki.fi>
parents:
9710
diff
changeset
|
1506 } T_END; |
51d280d34bfa
lib-storage: Use less memory from data stack.
Timo Sirainen <tss@iki.fi>
parents:
9710
diff
changeset
|
1507 return ctx; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1508 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1509 |
6279
f52e7d1402b5
mail_index_view_sync_next() and mailbox_sync_next() returns now bool.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
1510 bool mailbox_sync_next(struct mailbox_sync_context *ctx, |
f52e7d1402b5
mail_index_view_sync_next() and mailbox_sync_next() returns now bool.
Timo Sirainen <tss@iki.fi>
parents:
6275
diff
changeset
|
1511 struct mailbox_sync_rec *sync_rec_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1512 { |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
1513 return ctx->box->v.sync_next(ctx, sync_rec_r); |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1514 } |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1515 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1516 int mailbox_sync_deinit(struct mailbox_sync_context **_ctx, |
10509
50364f04cf13
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Timo Sirainen <tss@iki.fi>
parents:
10412
diff
changeset
|
1517 struct mailbox_sync_status *status_r) |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1518 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1519 struct mailbox_sync_context *ctx = *_ctx; |
11010
f4ff6c7cdafe
lib-storage: Fix to previous change: Don't access freed memory.
Timo Sirainen <tss@iki.fi>
parents:
11009
diff
changeset
|
1520 struct mailbox *box = ctx->box; |
11009
0f0b8e1a2c55
lib-storage: If INBOX can't be opened/synced, log an error once.
Timo Sirainen <tss@iki.fi>
parents:
10843
diff
changeset
|
1521 const char *errormsg; |
0f0b8e1a2c55
lib-storage: If INBOX can't be opened/synced, log an error once.
Timo Sirainen <tss@iki.fi>
parents:
10843
diff
changeset
|
1522 enum mail_error error; |
0f0b8e1a2c55
lib-storage: If INBOX can't be opened/synced, log an error once.
Timo Sirainen <tss@iki.fi>
parents:
10843
diff
changeset
|
1523 int ret; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1524 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1525 *_ctx = NULL; |
10509
50364f04cf13
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Timo Sirainen <tss@iki.fi>
parents:
10412
diff
changeset
|
1526 |
50364f04cf13
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Timo Sirainen <tss@iki.fi>
parents:
10412
diff
changeset
|
1527 memset(status_r, 0, sizeof(*status_r)); |
11010
f4ff6c7cdafe
lib-storage: Fix to previous change: Don't access freed memory.
Timo Sirainen <tss@iki.fi>
parents:
11009
diff
changeset
|
1528 ret = box->v.sync_deinit(ctx, status_r); |
11740 | 1529 if (ret < 0 && box->inbox_user && |
11010
f4ff6c7cdafe
lib-storage: Fix to previous change: Don't access freed memory.
Timo Sirainen <tss@iki.fi>
parents:
11009
diff
changeset
|
1530 !box->storage->user->inbox_open_error_logged) { |
12585
b748c622e896
lib-storage: Added mailbox_get_last_*error() wrappers and use them.
Timo Sirainen <tss@iki.fi>
parents:
12583
diff
changeset
|
1531 errormsg = mailbox_get_last_error(box, &error); |
11009
0f0b8e1a2c55
lib-storage: If INBOX can't be opened/synced, log an error once.
Timo Sirainen <tss@iki.fi>
parents:
10843
diff
changeset
|
1532 if (error == MAIL_ERROR_NOTPOSSIBLE) { |
11010
f4ff6c7cdafe
lib-storage: Fix to previous change: Don't access freed memory.
Timo Sirainen <tss@iki.fi>
parents:
11009
diff
changeset
|
1533 box->storage->user->inbox_open_error_logged = TRUE; |
11009
0f0b8e1a2c55
lib-storage: If INBOX can't be opened/synced, log an error once.
Timo Sirainen <tss@iki.fi>
parents:
10843
diff
changeset
|
1534 i_error("Syncing INBOX failed: %s", errormsg); |
0f0b8e1a2c55
lib-storage: If INBOX can't be opened/synced, log an error once.
Timo Sirainen <tss@iki.fi>
parents:
10843
diff
changeset
|
1535 } |
0f0b8e1a2c55
lib-storage: If INBOX can't be opened/synced, log an error once.
Timo Sirainen <tss@iki.fi>
parents:
10843
diff
changeset
|
1536 } |
14556
eab6ce7a5ad6
lib-storage: Added a mailbox.synced flag, which is set when mailbox sync has succeeded.
Timo Sirainen <tss@iki.fi>
parents:
14550
diff
changeset
|
1537 if (ret == 0) |
eab6ce7a5ad6
lib-storage: Added a mailbox.synced flag, which is set when mailbox sync has succeeded.
Timo Sirainen <tss@iki.fi>
parents:
14550
diff
changeset
|
1538 box->synced = TRUE; |
11009
0f0b8e1a2c55
lib-storage: If INBOX can't be opened/synced, log an error once.
Timo Sirainen <tss@iki.fi>
parents:
10843
diff
changeset
|
1539 return ret; |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1540 } |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1541 |
10509
50364f04cf13
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Timo Sirainen <tss@iki.fi>
parents:
10412
diff
changeset
|
1542 int mailbox_sync(struct mailbox *box, enum mailbox_sync_flags flags) |
6462
60a34f26c35a
Added mailbox_sync() to easily synchronize a mailbox.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
1543 { |
60a34f26c35a
Added mailbox_sync() to easily synchronize a mailbox.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
1544 struct mailbox_sync_context *ctx; |
10509
50364f04cf13
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Timo Sirainen <tss@iki.fi>
parents:
10412
diff
changeset
|
1545 struct mailbox_sync_status status; |
6462
60a34f26c35a
Added mailbox_sync() to easily synchronize a mailbox.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
1546 |
7669
242a4fae3587
mailbox_sync(): Don't add FIX_INCONSISTENT flag if there are saved search
Timo Sirainen <tss@iki.fi>
parents:
7654
diff
changeset
|
1547 if (array_count(&box->search_results) == 0) { |
242a4fae3587
mailbox_sync(): Don't add FIX_INCONSISTENT flag if there are saved search
Timo Sirainen <tss@iki.fi>
parents:
7654
diff
changeset
|
1548 /* we don't care about mailbox's current state, so we might |
242a4fae3587
mailbox_sync(): Don't add FIX_INCONSISTENT flag if there are saved search
Timo Sirainen <tss@iki.fi>
parents:
7654
diff
changeset
|
1549 as well fix inconsistency state */ |
242a4fae3587
mailbox_sync(): Don't add FIX_INCONSISTENT flag if there are saved search
Timo Sirainen <tss@iki.fi>
parents:
7654
diff
changeset
|
1550 flags |= MAILBOX_SYNC_FLAG_FIX_INCONSISTENT; |
242a4fae3587
mailbox_sync(): Don't add FIX_INCONSISTENT flag if there are saved search
Timo Sirainen <tss@iki.fi>
parents:
7654
diff
changeset
|
1551 } |
6674
2637fb191e5e
Added MAILBOX_SYNC_FLAG_FIX_INCONSISTENT flag. mailbox_sync() uses it
Timo Sirainen <tss@iki.fi>
parents:
6592
diff
changeset
|
1552 |
6462
60a34f26c35a
Added mailbox_sync() to easily synchronize a mailbox.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
1553 ctx = mailbox_sync_init(box, flags); |
10509
50364f04cf13
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Timo Sirainen <tss@iki.fi>
parents:
10412
diff
changeset
|
1554 return mailbox_sync_deinit(&ctx, &status); |
6462
60a34f26c35a
Added mailbox_sync() to easily synchronize a mailbox.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
1555 } |
60a34f26c35a
Added mailbox_sync() to easily synchronize a mailbox.
Timo Sirainen <tss@iki.fi>
parents:
6429
diff
changeset
|
1556 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
1557 #undef mailbox_notify_changes |
14218
5e4e6c57c142
lib-storage: Removed min_timeout parameter from mailbox_notify_changes()
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
1558 void mailbox_notify_changes(struct mailbox *box, |
2322
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1559 mailbox_notify_callback_t *callback, void *context) |
aae574ed7f4c
Broke mailbox_sync() into iterator.
Timo Sirainen <tss@iki.fi>
parents:
2316
diff
changeset
|
1560 { |
15101
78d9adf7c149
lib-storage: Added asserts to make sure mailbox_open() is called early enough.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
1561 i_assert(box->opened); |
78d9adf7c149
lib-storage: Added asserts to make sure mailbox_open() is called early enough.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
1562 |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
1563 box->notify_callback = callback; |
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
1564 box->notify_context = context; |
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
1565 |
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
1566 box->v.notify_changes(box); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1567 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1568 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
1569 void mailbox_notify_changes_stop(struct mailbox *box) |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
1570 { |
15101
78d9adf7c149
lib-storage: Added asserts to make sure mailbox_open() is called early enough.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
1571 i_assert(box->opened); |
78d9adf7c149
lib-storage: Added asserts to make sure mailbox_open() is called early enough.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
1572 |
14629
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14613
diff
changeset
|
1573 box->notify_callback = NULL; |
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14613
diff
changeset
|
1574 box->notify_context = NULL; |
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14613
diff
changeset
|
1575 |
c93ca5e46a8a
Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents:
14613
diff
changeset
|
1576 box->v.notify_changes(box); |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
1577 } |
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4876
diff
changeset
|
1578 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1579 struct mail_search_context * |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1580 mailbox_search_init(struct mailbox_transaction_context *t, |
7642
077bb84e9e77
Make mail_search_args an independent structure that can be used for multiple
Timo Sirainen <tss@iki.fi>
parents:
7629
diff
changeset
|
1581 struct mail_search_args *args, |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1582 const enum mail_sort_type *sort_program, |
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1583 enum mail_fetch_field wanted_fields, |
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1584 struct mailbox_header_lookup_ctx *wanted_headers) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1585 { |
7643
803e3574f4f5
Keep mail_search_args referenced during searches.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1586 mail_search_args_ref(args); |
7908
1e69c84a1e5a
Search code cleanups and minor optimizations.
Timo Sirainen <tss@iki.fi>
parents:
7907
diff
changeset
|
1587 if (!args->simplified) |
1e69c84a1e5a
Search code cleanups and minor optimizations.
Timo Sirainen <tss@iki.fi>
parents:
7907
diff
changeset
|
1588 mail_search_args_simplify(args); |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1589 return t->box->v.search_init(t, args, sort_program, |
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1590 wanted_fields, wanted_headers); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1591 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1592 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1593 int mailbox_search_deinit(struct mail_search_context **_ctx) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1594 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1595 struct mail_search_context *ctx = *_ctx; |
7643
803e3574f4f5
Keep mail_search_args referenced during searches.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1596 struct mail_search_args *args = ctx->args; |
803e3574f4f5
Keep mail_search_args referenced during searches.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1597 int ret; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1598 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1599 *_ctx = NULL; |
7647
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7643
diff
changeset
|
1600 mailbox_search_results_initial_done(ctx); |
7643
803e3574f4f5
Keep mail_search_args referenced during searches.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1601 ret = ctx->transaction->box->v.search_deinit(ctx); |
803e3574f4f5
Keep mail_search_args referenced during searches.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1602 mail_search_args_unref(&args); |
803e3574f4f5
Keep mail_search_args referenced during searches.
Timo Sirainen <tss@iki.fi>
parents:
7642
diff
changeset
|
1603 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1604 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1605 |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1606 bool mailbox_search_next(struct mail_search_context *ctx, struct mail **mail_r) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1607 { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1608 bool tryagain; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1609 |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1610 while (!mailbox_search_next_nonblock(ctx, mail_r, &tryagain)) { |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1611 if (!tryagain) |
10347
0156d98bc822
mailbox_search_next*() API changed to return bool.
Timo Sirainen <tss@iki.fi>
parents:
9755
diff
changeset
|
1612 return FALSE; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1613 } |
10347
0156d98bc822
mailbox_search_next*() API changed to return bool.
Timo Sirainen <tss@iki.fi>
parents:
9755
diff
changeset
|
1614 return TRUE; |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1615 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1616 |
10347
0156d98bc822
mailbox_search_next*() API changed to return bool.
Timo Sirainen <tss@iki.fi>
parents:
9755
diff
changeset
|
1617 bool mailbox_search_next_nonblock(struct mail_search_context *ctx, |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1618 struct mail **mail_r, bool *tryagain_r) |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1619 { |
10347
0156d98bc822
mailbox_search_next*() API changed to return bool.
Timo Sirainen <tss@iki.fi>
parents:
9755
diff
changeset
|
1620 struct mailbox *box = ctx->transaction->box; |
7647
879208fdc7e3
Implemented CONTEXT=SEARCH extension.
Timo Sirainen <tss@iki.fi>
parents:
7643
diff
changeset
|
1621 |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1622 *mail_r = NULL; |
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1623 |
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1624 if (!box->v.search_next_nonblock(ctx, mail_r, tryagain_r)) |
10347
0156d98bc822
mailbox_search_next*() API changed to return bool.
Timo Sirainen <tss@iki.fi>
parents:
9755
diff
changeset
|
1625 return FALSE; |
0156d98bc822
mailbox_search_next*() API changed to return bool.
Timo Sirainen <tss@iki.fi>
parents:
9755
diff
changeset
|
1626 else { |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1627 mailbox_search_results_add(ctx, (*mail_r)->uid); |
10347
0156d98bc822
mailbox_search_next*() API changed to return bool.
Timo Sirainen <tss@iki.fi>
parents:
9755
diff
changeset
|
1628 return TRUE; |
0156d98bc822
mailbox_search_next*() API changed to return bool.
Timo Sirainen <tss@iki.fi>
parents:
9755
diff
changeset
|
1629 } |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1630 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1631 |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8264
diff
changeset
|
1632 bool mailbox_search_seen_lost_data(struct mail_search_context *ctx) |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8264
diff
changeset
|
1633 { |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8264
diff
changeset
|
1634 return ctx->seen_lost_data; |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8264
diff
changeset
|
1635 } |
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8264
diff
changeset
|
1636 |
7907
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1637 int mailbox_search_result_build(struct mailbox_transaction_context *t, |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1638 struct mail_search_args *args, |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1639 enum mailbox_search_result_flags flags, |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1640 struct mail_search_result **result_r) |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1641 { |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1642 struct mail_search_context *ctx; |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1643 struct mail *mail; |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1644 int ret; |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1645 |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1646 ctx = mailbox_search_init(t, args, NULL, 0, NULL); |
7907
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1647 *result_r = mailbox_search_result_save(ctx, flags); |
12870
1fbd59c48414
lib-storage: Changed mailbox_search_*() API to return pointer struct mail.
Timo Sirainen <tss@iki.fi>
parents:
12860
diff
changeset
|
1648 while (mailbox_search_next(ctx, &mail)) ; |
7907
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1649 |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1650 ret = mailbox_search_deinit(&ctx); |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1651 if (ret < 0) |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1652 mailbox_search_result_free(result_r); |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1653 return ret; |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1654 } |
021c39f58af3
Added mailbox_search_result_build().
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
1655 |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1656 struct mailbox_transaction_context * |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
1657 mailbox_transaction_begin(struct mailbox *box, |
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
1658 enum mailbox_transaction_flags flags) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1659 { |
7413
5d96b15832fc
Added transaction flags to struct mailbox_transaction_context.
Timo Sirainen <tss@iki.fi>
parents:
7358
diff
changeset
|
1660 struct mailbox_transaction_context *trans; |
5d96b15832fc
Added transaction flags to struct mailbox_transaction_context.
Timo Sirainen <tss@iki.fi>
parents:
7358
diff
changeset
|
1661 |
15101
78d9adf7c149
lib-storage: Added asserts to make sure mailbox_open() is called early enough.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
1662 i_assert(box->opened); |
78d9adf7c149
lib-storage: Added asserts to make sure mailbox_open() is called early enough.
Timo Sirainen <tss@iki.fi>
parents:
15100
diff
changeset
|
1663 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1664 box->transaction_count++; |
7413
5d96b15832fc
Added transaction flags to struct mailbox_transaction_context.
Timo Sirainen <tss@iki.fi>
parents:
7358
diff
changeset
|
1665 trans = box->v.transaction_begin(box, flags); |
5d96b15832fc
Added transaction flags to struct mailbox_transaction_context.
Timo Sirainen <tss@iki.fi>
parents:
7358
diff
changeset
|
1666 trans->flags = flags; |
5d96b15832fc
Added transaction flags to struct mailbox_transaction_context.
Timo Sirainen <tss@iki.fi>
parents:
7358
diff
changeset
|
1667 return trans; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1668 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1669 |
6512
1a3604c8ee05
mailbox_transaction_commit*() doesn't sync the mailbox anymore, so it
Timo Sirainen <tss@iki.fi>
parents:
6462
diff
changeset
|
1670 int mailbox_transaction_commit(struct mailbox_transaction_context **t) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1671 { |
9649
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1672 struct mail_transaction_commit_changes changes; |
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1673 int ret; |
5572
896845fbc4ed
Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents:
5567
diff
changeset
|
1674 |
9649
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1675 /* Store changes temporarily so that plugins overriding |
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1676 transaction_commit() can look at them. */ |
11900
25a1c1739a63
lib-storage: Don't crash in mailbox_transaction_commit() if plugin aborts transaction.
Timo Sirainen <tss@iki.fi>
parents:
11740
diff
changeset
|
1677 changes.pool = NULL; |
9649
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1678 ret = mailbox_transaction_commit_get_changes(t, &changes); |
11900
25a1c1739a63
lib-storage: Don't crash in mailbox_transaction_commit() if plugin aborts transaction.
Timo Sirainen <tss@iki.fi>
parents:
11740
diff
changeset
|
1679 if (changes.pool != NULL) |
25a1c1739a63
lib-storage: Don't crash in mailbox_transaction_commit() if plugin aborts transaction.
Timo Sirainen <tss@iki.fi>
parents:
11740
diff
changeset
|
1680 pool_unref(&changes.pool); |
9649
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1681 return ret; |
5572
896845fbc4ed
Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents:
5567
diff
changeset
|
1682 } |
896845fbc4ed
Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents:
5567
diff
changeset
|
1683 |
9649
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1684 int mailbox_transaction_commit_get_changes( |
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1685 struct mailbox_transaction_context **_t, |
47356e8dda45
mailbox_transaction_commit_get_uids() changed to _get_changes() with more generic API.
Timo Sirainen <tss@iki.fi>
parents:
9636
diff
changeset
|
1686 struct mail_transaction_commit_changes *changes_r) |
5572
896845fbc4ed
Added mailbox_transaction_commit_get_uids() which returns the UID range for
Timo Sirainen <tss@iki.fi>
parents:
5567
diff
changeset
|
1687 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1688 struct mailbox_transaction_context *t = *_t; |
10728 | 1689 int ret; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1690 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1691 t->box->transaction_count--; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1692 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1693 *_t = NULL; |
10728 | 1694 T_BEGIN { |
1695 ret = t->box->v.transaction_commit(t, changes_r); | |
1696 } T_END; | |
1697 return ret; | |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1698 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1699 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1700 void mailbox_transaction_rollback(struct mailbox_transaction_context **_t) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1701 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1702 struct mailbox_transaction_context *t = *_t; |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1703 |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1704 t->box->transaction_count--; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1705 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1706 *_t = NULL; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
1707 t->box->v.transaction_rollback(t); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1708 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1709 |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7908
diff
changeset
|
1710 unsigned int mailbox_transaction_get_count(const struct mailbox *box) |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1711 { |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1712 return box->transaction_count; |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1713 } |
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
1714 |
7913
e04513064165
CONDSTORE: STORE UNCHANGEDSINCE conflicts are now checked atomically.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
1715 void mailbox_transaction_set_max_modseq(struct mailbox_transaction_context *t, |
e04513064165
CONDSTORE: STORE UNCHANGEDSINCE conflicts are now checked atomically.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
1716 uint64_t max_modseq, |
e04513064165
CONDSTORE: STORE UNCHANGEDSINCE conflicts are now checked atomically.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
1717 ARRAY_TYPE(seq_range) *seqs) |
e04513064165
CONDSTORE: STORE UNCHANGEDSINCE conflicts are now checked atomically.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
1718 { |
12543
c7e607631eec
lib-storage: Unvirtualized some methods from struct mailbox.
Timo Sirainen <tss@iki.fi>
parents:
12540
diff
changeset
|
1719 mail_index_transaction_set_max_modseq(t->itrans, max_modseq, seqs); |
7913
e04513064165
CONDSTORE: STORE UNCHANGEDSINCE conflicts are now checked atomically.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
1720 } |
e04513064165
CONDSTORE: STORE UNCHANGEDSINCE conflicts are now checked atomically.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
1721 |
7358
ffb7e8b1c114
Added mailbox_transaction_get_mailbox()
Timo Sirainen <tss@iki.fi>
parents:
7245
diff
changeset
|
1722 struct mailbox * |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7908
diff
changeset
|
1723 mailbox_transaction_get_mailbox(const struct mailbox_transaction_context *t) |
7358
ffb7e8b1c114
Added mailbox_transaction_get_mailbox()
Timo Sirainen <tss@iki.fi>
parents:
7245
diff
changeset
|
1724 { |
ffb7e8b1c114
Added mailbox_transaction_get_mailbox()
Timo Sirainen <tss@iki.fi>
parents:
7245
diff
changeset
|
1725 return t->box; |
ffb7e8b1c114
Added mailbox_transaction_get_mailbox()
Timo Sirainen <tss@iki.fi>
parents:
7245
diff
changeset
|
1726 } |
ffb7e8b1c114
Added mailbox_transaction_get_mailbox()
Timo Sirainen <tss@iki.fi>
parents:
7245
diff
changeset
|
1727 |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1728 struct mail_save_context * |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1729 mailbox_save_alloc(struct mailbox_transaction_context *t) |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1730 { |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1731 struct mail_save_context *ctx; |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1732 |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1733 ctx = t->box->v.save_alloc(t); |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1734 ctx->data.received_date = (time_t)-1; |
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1735 ctx->data.save_date = (time_t)-1; |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1736 return ctx; |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1737 } |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1738 |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1739 void mailbox_save_set_flags(struct mail_save_context *ctx, |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1740 enum mail_flags flags, |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1741 struct mail_keywords *keywords) |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1742 { |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1743 ctx->data.flags = flags; |
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1744 ctx->data.keywords = keywords; |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1745 if (keywords != NULL) |
12537
16929d83a00c
lib-storage: Simplified mailbox_keyword*() APIs.
Timo Sirainen <tss@iki.fi>
parents:
12536
diff
changeset
|
1746 mailbox_keywords_ref(keywords); |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1747 } |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1748 |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1749 void mailbox_save_copy_flags(struct mail_save_context *ctx, struct mail *mail) |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1750 { |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1751 const char *const *keywords_list; |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1752 |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1753 keywords_list = mail_get_keywords(mail); |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1754 ctx->data.keywords = str_array_length(keywords_list) == 0 ? NULL : |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1755 mailbox_keywords_create_valid(ctx->transaction->box, |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1756 keywords_list); |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1757 ctx->data.flags = mail_get_flags(mail); |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1758 } |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1759 |
9691
b09d9350a2d9
Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents:
9650
diff
changeset
|
1760 void mailbox_save_set_min_modseq(struct mail_save_context *ctx, |
b09d9350a2d9
Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents:
9650
diff
changeset
|
1761 uint64_t min_modseq) |
b09d9350a2d9
Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents:
9650
diff
changeset
|
1762 { |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1763 ctx->data.min_modseq = min_modseq; |
9691
b09d9350a2d9
Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents:
9650
diff
changeset
|
1764 } |
b09d9350a2d9
Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents:
9650
diff
changeset
|
1765 |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1766 void mailbox_save_set_received_date(struct mail_save_context *ctx, |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1767 time_t received_date, int timezone_offset) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1768 { |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1769 ctx->data.received_date = received_date; |
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1770 ctx->data.received_tz_offset = timezone_offset; |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1771 } |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1772 |
9554
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1773 void mailbox_save_set_save_date(struct mail_save_context *ctx, |
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1774 time_t save_date) |
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1775 { |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1776 ctx->data.save_date = save_date; |
9554
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1777 } |
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1778 |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1779 void mailbox_save_set_from_envelope(struct mail_save_context *ctx, |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1780 const char *envelope) |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1781 { |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1782 i_free(ctx->data.from_envelope); |
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1783 ctx->data.from_envelope = i_strdup(envelope); |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1784 } |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1785 |
9554
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1786 void mailbox_save_set_uid(struct mail_save_context *ctx, uint32_t uid) |
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1787 { |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1788 ctx->data.uid = uid; |
9554
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1789 } |
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1790 |
8077
6d51328896d6
Added the concept of Global UIDs that are preserved across copies.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
1791 void mailbox_save_set_guid(struct mail_save_context *ctx, const char *guid) |
6d51328896d6
Added the concept of Global UIDs that are preserved across copies.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
1792 { |
6d51328896d6
Added the concept of Global UIDs that are preserved across copies.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
1793 i_assert(guid == NULL || *guid != '\0'); |
6d51328896d6
Added the concept of Global UIDs that are preserved across copies.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
1794 |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1795 i_free(ctx->data.guid); |
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1796 ctx->data.guid = i_strdup(guid); |
8077
6d51328896d6
Added the concept of Global UIDs that are preserved across copies.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
1797 } |
6d51328896d6
Added the concept of Global UIDs that are preserved across copies.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
1798 |
9554
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1799 void mailbox_save_set_pop3_uidl(struct mail_save_context *ctx, const char *uidl) |
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1800 { |
12146
ad81284d43ff
lib-storage: Added assert against empty UIDL in mailbox_save_set_pop3_uidl().
Timo Sirainen <tss@iki.fi>
parents:
12114
diff
changeset
|
1801 i_assert(*uidl != '\0'); |
12330
3959ddbc633c
lib-storage: Make sure POP3 UIDLs aren't tried to be saved with LFs.
Timo Sirainen <tss@iki.fi>
parents:
12296
diff
changeset
|
1802 i_assert(strchr(uidl, '\n') == NULL); |
12146
ad81284d43ff
lib-storage: Added assert against empty UIDL in mailbox_save_set_pop3_uidl().
Timo Sirainen <tss@iki.fi>
parents:
12114
diff
changeset
|
1803 |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1804 i_free(ctx->data.pop3_uidl); |
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1805 ctx->data.pop3_uidl = i_strdup(uidl); |
9554
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1806 } |
49f736dce881
Mailbox saving: Allow setting IMAP UID, POP3 UIDL and save date.
Timo Sirainen <tss@iki.fi>
parents:
9548
diff
changeset
|
1807 |
14399
82cd7aa65faf
lib-storage: Added mailbox_save_set_pop3_order() and implemented for Maildir.
Timo Sirainen <tss@iki.fi>
parents:
14385
diff
changeset
|
1808 void mailbox_save_set_pop3_order(struct mail_save_context *ctx, |
82cd7aa65faf
lib-storage: Added mailbox_save_set_pop3_order() and implemented for Maildir.
Timo Sirainen <tss@iki.fi>
parents:
14385
diff
changeset
|
1809 unsigned int order) |
82cd7aa65faf
lib-storage: Added mailbox_save_set_pop3_order() and implemented for Maildir.
Timo Sirainen <tss@iki.fi>
parents:
14385
diff
changeset
|
1810 { |
82cd7aa65faf
lib-storage: Added mailbox_save_set_pop3_order() and implemented for Maildir.
Timo Sirainen <tss@iki.fi>
parents:
14385
diff
changeset
|
1811 i_assert(order > 0); |
82cd7aa65faf
lib-storage: Added mailbox_save_set_pop3_order() and implemented for Maildir.
Timo Sirainen <tss@iki.fi>
parents:
14385
diff
changeset
|
1812 |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1813 ctx->data.pop3_order = order; |
14399
82cd7aa65faf
lib-storage: Added mailbox_save_set_pop3_order() and implemented for Maildir.
Timo Sirainen <tss@iki.fi>
parents:
14385
diff
changeset
|
1814 } |
82cd7aa65faf
lib-storage: Added mailbox_save_set_pop3_order() and implemented for Maildir.
Timo Sirainen <tss@iki.fi>
parents:
14385
diff
changeset
|
1815 |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1816 void mailbox_save_set_dest_mail(struct mail_save_context *ctx, |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1817 struct mail *mail) |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1818 { |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1819 ctx->dest_mail = mail; |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1820 } |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1821 |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1822 int mailbox_save_begin(struct mail_save_context **ctx, struct istream *input) |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1823 { |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1824 struct mailbox *box = (*ctx)->transaction->box; |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1825 int ret; |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1826 |
10717
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1827 if (mail_index_is_deleted(box->index)) { |
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1828 mailbox_set_deleted(box); |
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1829 return -1; |
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1830 } |
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1831 |
14533
5d9a5011c1bf
lib-storage: Don't set mail_save_context->saving=TRUE when copying via save.
Timo Sirainen <tss@iki.fi>
parents:
14524
diff
changeset
|
1832 if (!(*ctx)->copying_via_save) |
5d9a5011c1bf
lib-storage: Don't set mail_save_context->saving=TRUE when copying via save.
Timo Sirainen <tss@iki.fi>
parents:
14524
diff
changeset
|
1833 (*ctx)->saving = TRUE; |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1834 if (box->v.save_begin == NULL) { |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1835 mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE, |
6747
0cee1cccd14c
Handle missing save_init() here by returning "not supported" error.
Timo Sirainen <tss@iki.fi>
parents:
6674
diff
changeset
|
1836 "Saving messages not supported"); |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1837 ret = -1; |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1838 } else { |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1839 ret = box->v.save_begin(*ctx, input); |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1840 } |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1841 |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1842 if (ret < 0) { |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
1843 mailbox_save_cancel(ctx); |
6747
0cee1cccd14c
Handle missing save_init() here by returning "not supported" error.
Timo Sirainen <tss@iki.fi>
parents:
6674
diff
changeset
|
1844 return -1; |
0cee1cccd14c
Handle missing save_init() here by returning "not supported" error.
Timo Sirainen <tss@iki.fi>
parents:
6674
diff
changeset
|
1845 } |
4268
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4120
diff
changeset
|
1846 return 0; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1847 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1848 |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1849 int mailbox_save_continue(struct mail_save_context *ctx) |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1850 { |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
1851 return ctx->transaction->box->v.save_continue(ctx); |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1852 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1853 |
4268
7112aad504ae
Changed mailbox_save_*() API a bit: Moved the struct mail *dest_mail to
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4120
diff
changeset
|
1854 int mailbox_save_finish(struct mail_save_context **_ctx) |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1855 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1856 struct mail_save_context *ctx = *_ctx; |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1857 struct mailbox *box = ctx->transaction->box; |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1858 struct mail_keywords *keywords = ctx->data.keywords; |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1859 int ret; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1860 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1861 *_ctx = NULL; |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1862 ret = box->v.save_finish(ctx); |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1863 if (keywords != NULL) |
12537
16929d83a00c
lib-storage: Simplified mailbox_keyword*() APIs.
Timo Sirainen <tss@iki.fi>
parents:
12536
diff
changeset
|
1864 mailbox_keywords_unref(&keywords); |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1865 return ret; |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1866 } |
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1867 |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1868 void mailbox_save_cancel(struct mail_save_context **_ctx) |
2446
47e1e05cede0
Changed mail saving API to be nonblocking.
Timo Sirainen <tss@iki.fi>
parents:
2350
diff
changeset
|
1869 { |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1870 struct mail_save_context *ctx = *_ctx; |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1871 struct mail_keywords *keywords = ctx->data.keywords; |
3879
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1872 |
928229f8b3e6
deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents:
3863
diff
changeset
|
1873 *_ctx = NULL; |
3209
923ff19873d4
Major mail-storage API changes. It's now a bit cleaner and much more plugin
Timo Sirainen <tss@iki.fi>
parents:
3138
diff
changeset
|
1874 ctx->transaction->box->v.save_cancel(ctx); |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1875 if (keywords != NULL) |
12537
16929d83a00c
lib-storage: Simplified mailbox_keyword*() APIs.
Timo Sirainen <tss@iki.fi>
parents:
12536
diff
changeset
|
1876 mailbox_keywords_unref(&keywords); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1877 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1878 |
12674
048d7025c89f
lib-storage: Added mailbox_save_get_transaction().
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
1879 struct mailbox_transaction_context * |
048d7025c89f
lib-storage: Added mailbox_save_get_transaction().
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
1880 mailbox_save_get_transaction(struct mail_save_context *ctx) |
048d7025c89f
lib-storage: Added mailbox_save_get_transaction().
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
1881 { |
048d7025c89f
lib-storage: Added mailbox_save_get_transaction().
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
1882 return ctx->transaction; |
048d7025c89f
lib-storage: Added mailbox_save_get_transaction().
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
1883 } |
048d7025c89f
lib-storage: Added mailbox_save_get_transaction().
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
1884 |
8726
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1885 int mailbox_copy(struct mail_save_context **_ctx, struct mail *mail) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1886 { |
8726
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1887 struct mail_save_context *ctx = *_ctx; |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1888 struct mailbox *box = ctx->transaction->box; |
14952
b966759dd48c
lib-storage: Moved per-mail data in struct mail_save_context to separate struct.
Timo Sirainen <tss@iki.fi>
parents:
14859
diff
changeset
|
1889 struct mail_keywords *keywords = ctx->data.keywords; |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1890 int ret; |
8726
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1891 |
68db63cc32b3
Mail copying API changed to be based on save API. This allows extending it easily in future.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
1892 *_ctx = NULL; |
10717
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1893 |
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1894 if (mail_index_is_deleted(box->index)) { |
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1895 mailbox_set_deleted(box); |
14385
8897f32939b0
lib-storage: If trying to copy a message into already deleted mailbox, don't crash.
Timo Sirainen <tss@iki.fi>
parents:
14348
diff
changeset
|
1896 mailbox_save_cancel(&ctx); |
10717
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1897 return -1; |
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1898 } |
0bcb415c7a71
lib-storage: Removed some code duplication.
Timo Sirainen <tss@iki.fi>
parents:
10711
diff
changeset
|
1899 |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1900 ret = ctx->transaction->box->v.copy(ctx, mail); |
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1901 if (keywords != NULL) |
12537
16929d83a00c
lib-storage: Simplified mailbox_keyword*() APIs.
Timo Sirainen <tss@iki.fi>
parents:
12536
diff
changeset
|
1902 mailbox_keywords_unref(&keywords); |
9509
15e427021619
Added mailbox_save_copy_flags(). Use it wherever possible.
Timo Sirainen <tss@iki.fi>
parents:
9508
diff
changeset
|
1903 return ret; |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1904 } |
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1905 |
14613
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1906 int mailbox_move(struct mail_save_context **_ctx, struct mail *mail) |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1907 { |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1908 struct mail_save_context *ctx = *_ctx; |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1909 |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1910 ctx->moving = TRUE; |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1911 if (mailbox_copy(_ctx, mail) < 0) |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1912 return -1; |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1913 |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1914 mail_expunge(mail); |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1915 return 0; |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1916 } |
8d596b5adbab
lib-storage: Added mailbox_move(), which is basically copy+expunge.
Timo Sirainen <tss@iki.fi>
parents:
14599
diff
changeset
|
1917 |
13896
1e58372ee6f0
lib-storage: Added mailbox_save_using_mail()
Timo Sirainen <tss@iki.fi>
parents:
13876
diff
changeset
|
1918 int mailbox_save_using_mail(struct mail_save_context **ctx, struct mail *mail) |
1e58372ee6f0
lib-storage: Added mailbox_save_using_mail()
Timo Sirainen <tss@iki.fi>
parents:
13876
diff
changeset
|
1919 { |
1e58372ee6f0
lib-storage: Added mailbox_save_using_mail()
Timo Sirainen <tss@iki.fi>
parents:
13876
diff
changeset
|
1920 (*ctx)->saving = TRUE; |
1e58372ee6f0
lib-storage: Added mailbox_save_using_mail()
Timo Sirainen <tss@iki.fi>
parents:
13876
diff
changeset
|
1921 return mailbox_copy(ctx, mail); |
1e58372ee6f0
lib-storage: Added mailbox_save_using_mail()
Timo Sirainen <tss@iki.fi>
parents:
13876
diff
changeset
|
1922 } |
1e58372ee6f0
lib-storage: Added mailbox_save_using_mail()
Timo Sirainen <tss@iki.fi>
parents:
13876
diff
changeset
|
1923 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3641
diff
changeset
|
1924 bool mailbox_is_inconsistent(struct mailbox *box) |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1925 { |
6771
fd9effba151d
Moved mailbox_deleted to struct mailbox. Added and used
Timo Sirainen <tss@iki.fi>
parents:
6747
diff
changeset
|
1926 return box->mailbox_deleted || box->v.is_inconsistent(box); |
1915
79790750c349
importing new index code. mbox still broken.
Timo Sirainen <tss@iki.fi>
parents:
1912
diff
changeset
|
1927 } |
6771
fd9effba151d
Moved mailbox_deleted to struct mailbox. Added and used
Timo Sirainen <tss@iki.fi>
parents:
6747
diff
changeset
|
1928 |
fd9effba151d
Moved mailbox_deleted to struct mailbox. Added and used
Timo Sirainen <tss@iki.fi>
parents:
6747
diff
changeset
|
1929 void mailbox_set_deleted(struct mailbox *box) |
fd9effba151d
Moved mailbox_deleted to struct mailbox. Added and used
Timo Sirainen <tss@iki.fi>
parents:
6747
diff
changeset
|
1930 { |
fd9effba151d
Moved mailbox_deleted to struct mailbox. Added and used
Timo Sirainen <tss@iki.fi>
parents:
6747
diff
changeset
|
1931 mail_storage_set_error(box->storage, MAIL_ERROR_NOTFOUND, |
fd9effba151d
Moved mailbox_deleted to struct mailbox. Added and used
Timo Sirainen <tss@iki.fi>
parents:
6747
diff
changeset
|
1932 "Mailbox was deleted under us"); |
fd9effba151d
Moved mailbox_deleted to struct mailbox. Added and used
Timo Sirainen <tss@iki.fi>
parents:
6747
diff
changeset
|
1933 box->mailbox_deleted = TRUE; |
fd9effba151d
Moved mailbox_deleted to struct mailbox. Added and used
Timo Sirainen <tss@iki.fi>
parents:
6747
diff
changeset
|
1934 } |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1935 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1936 int mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type, |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1937 const char **path_r) |
15100
f8c1ddf55b94
lib-storage: Added mailbox_get_path_to() wrapper for mailbox_list_get_path().
Timo Sirainen <tss@iki.fi>
parents:
15098
diff
changeset
|
1938 { |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1939 int ret; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1940 |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1941 if (type == MAILBOX_LIST_PATH_TYPE_MAILBOX && box->_path != NULL) { |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1942 if (box->_path[0] == '\0') { |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1943 *path_r = NULL; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1944 return 0; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1945 } |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1946 *path_r = box->_path; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1947 return 1; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1948 } |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1949 ret = mailbox_list_get_path(box->list, box->name, type, path_r); |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1950 if (ret < 0) { |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1951 mail_storage_copy_list_error(box->storage, box->list); |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1952 return -1; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1953 } |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1954 if (type == MAILBOX_LIST_PATH_TYPE_MAILBOX && box->_path == NULL) |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1955 box->_path = ret == 0 ? "" : p_strdup(box->pool, *path_r); |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1956 return ret; |
15100
f8c1ddf55b94
lib-storage: Added mailbox_get_path_to() wrapper for mailbox_list_get_path().
Timo Sirainen <tss@iki.fi>
parents:
15098
diff
changeset
|
1957 } |
f8c1ddf55b94
lib-storage: Added mailbox_get_path_to() wrapper for mailbox_list_get_path().
Timo Sirainen <tss@iki.fi>
parents:
15098
diff
changeset
|
1958 |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1959 const char *mailbox_get_path(struct mailbox *box) |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1960 { |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1961 i_assert(box->_path != NULL); |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
1962 i_assert(box->_path[0] != '\0'); |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1963 return box->_path; |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1964 } |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1965 |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1966 static void mailbox_get_permissions_if_not_set(struct mailbox *box) |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1967 { |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1968 if (box->_perm.file_create_mode != 0) |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1969 return; |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1970 |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1971 if (box->input != NULL) { |
13243
cc7cef1f6a21
lib-storage: mailbox_list_get_permissions() now returns struct mailbox_permissions.
Timo Sirainen <tss@iki.fi>
parents:
13239
diff
changeset
|
1972 box->_perm.file_uid = geteuid(); |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1973 box->_perm.file_create_mode = 0600; |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1974 box->_perm.dir_create_mode = 0700; |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1975 box->_perm.file_create_gid = (gid_t)-1; |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1976 box->_perm.file_create_gid_origin = "defaults"; |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1977 return; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1978 } |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1979 |
13243
cc7cef1f6a21
lib-storage: mailbox_list_get_permissions() now returns struct mailbox_permissions.
Timo Sirainen <tss@iki.fi>
parents:
13239
diff
changeset
|
1980 mailbox_list_get_permissions(box->list, box->name, &box->_perm); |
cc7cef1f6a21
lib-storage: mailbox_list_get_permissions() now returns struct mailbox_permissions.
Timo Sirainen <tss@iki.fi>
parents:
13239
diff
changeset
|
1981 box->_perm.file_create_gid_origin = |
cc7cef1f6a21
lib-storage: mailbox_list_get_permissions() now returns struct mailbox_permissions.
Timo Sirainen <tss@iki.fi>
parents:
13239
diff
changeset
|
1982 p_strdup(box->pool, box->_perm.file_create_gid_origin); |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1983 } |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1984 |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1985 const struct mailbox_permissions *mailbox_get_permissions(struct mailbox *box) |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1986 { |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1987 mailbox_get_permissions_if_not_set(box); |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
1988 |
12521
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1989 if (!box->_perm.mail_index_permissions_set && box->index != NULL) { |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1990 box->_perm.mail_index_permissions_set = TRUE; |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1991 mail_index_set_permissions(box->index, |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1992 box->_perm.file_create_mode, |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1993 box->_perm.file_create_gid, |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1994 box->_perm.file_create_gid_origin); |
b22766c1aa51
lib-storage: Don't allocate index until mailbox_open()
Timo Sirainen <tss@iki.fi>
parents:
12520
diff
changeset
|
1995 } |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1996 return &box->_perm; |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1997 } |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1998 |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
1999 void mailbox_refresh_permissions(struct mailbox *box) |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2000 { |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2001 memset(&box->_perm, 0, sizeof(box->_perm)); |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2002 (void)mailbox_get_permissions(box); |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2003 } |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2004 |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2005 int mailbox_create_fd(struct mailbox *box, const char *path, int flags, |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2006 int *fd_r) |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2007 { |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2008 const struct mailbox_permissions *perm = mailbox_get_permissions(box); |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2009 mode_t old_mask; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2010 int fd; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2011 |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2012 i_assert((flags & O_CREAT) != 0); |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2013 |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2014 *fd_r = -1; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2015 |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2016 old_mask = umask(0); |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2017 fd = open(path, flags, perm->file_create_mode); |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2018 umask(old_mask); |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2019 |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2020 if (fd != -1) { |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2021 /* ok */ |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2022 } else if (errno == EEXIST) { |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2023 /* O_EXCL used, caller will handle this error */ |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2024 return 0; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2025 } else if (errno == ENOENT) { |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2026 mailbox_set_deleted(box); |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2027 return -1; |
12519
b63ff46f82ee
lib-storage: mailbox_create_fd() handles "no inferior mailboxes allowed" error now.
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
2028 } else if (errno == ENOTDIR) { |
b63ff46f82ee
lib-storage: mailbox_create_fd() handles "no inferior mailboxes allowed" error now.
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
2029 mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE, |
b63ff46f82ee
lib-storage: mailbox_create_fd() handles "no inferior mailboxes allowed" error now.
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
2030 "Mailbox doesn't allow inferior mailboxes"); |
b63ff46f82ee
lib-storage: mailbox_create_fd() handles "no inferior mailboxes allowed" error now.
Timo Sirainen <tss@iki.fi>
parents:
12330
diff
changeset
|
2031 return -1; |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2032 } else if (mail_storage_set_error_from_errno(box->storage)) { |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2033 return -1; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2034 } else { |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2035 mail_storage_set_critical(box->storage, |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2036 "open(%s, O_CREAT) failed: %m", path); |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2037 return -1; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2038 } |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2039 |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2040 if (perm->file_create_gid != (gid_t)-1) { |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2041 if (fchown(fd, (uid_t)-1, perm->file_create_gid) == 0) { |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2042 /* ok */ |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2043 } else if (errno == EPERM) { |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2044 mail_storage_set_critical(box->storage, "%s", |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2045 eperm_error_get_chgrp("fchown", path, |
12520
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2046 perm->file_create_gid, |
b26d6da05d48
lib-storage: Lazily look up mailbox path and permissions. Added functions to get them.
Timo Sirainen <tss@iki.fi>
parents:
12519
diff
changeset
|
2047 perm->file_create_gid_origin)); |
10653
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2048 } else { |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2049 mail_storage_set_critical(box->storage, |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2050 "fchown(%s) failed: %m", path); |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2051 } |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2052 } |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2053 *fd_r = fd; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2054 return 1; |
5fe70b5da1b8
lib-storage: Moved mailbox directory creation code to mailbox_list backend.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
2055 } |
11623
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
11487
diff
changeset
|
2056 |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2057 int mailbox_mkdir(struct mailbox *box, const char *path, |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2058 enum mailbox_list_path_type type) |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2059 { |
15119
981e0bc71742
lib-storage: Cleanup, use the new mailbox_*() instead of mailbox_list_*() when possible.
Timo Sirainen <tss@iki.fi>
parents:
15118
diff
changeset
|
2060 const struct mailbox_permissions *perm = mailbox_get_permissions(box); |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2061 const char *root_dir; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2062 |
15119
981e0bc71742
lib-storage: Cleanup, use the new mailbox_*() instead of mailbox_list_*() when possible.
Timo Sirainen <tss@iki.fi>
parents:
15118
diff
changeset
|
2063 if (!perm->gid_origin_is_mailbox_path) { |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2064 /* mailbox root directory doesn't exist, create it */ |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
2065 root_dir = mailbox_list_get_root_forced(box->list, type); |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2066 if (mailbox_list_mkdir_root(box->list, root_dir, type) < 0) { |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2067 mail_storage_copy_list_error(box->storage, box->list); |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2068 return -1; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2069 } |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2070 } |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2071 |
15119
981e0bc71742
lib-storage: Cleanup, use the new mailbox_*() instead of mailbox_list_*() when possible.
Timo Sirainen <tss@iki.fi>
parents:
15118
diff
changeset
|
2072 if (mkdir_parents_chgrp(path, perm->dir_create_mode, |
981e0bc71742
lib-storage: Cleanup, use the new mailbox_*() instead of mailbox_list_*() when possible.
Timo Sirainen <tss@iki.fi>
parents:
15118
diff
changeset
|
2073 perm->file_create_gid, |
981e0bc71742
lib-storage: Cleanup, use the new mailbox_*() instead of mailbox_list_*() when possible.
Timo Sirainen <tss@iki.fi>
parents:
15118
diff
changeset
|
2074 perm->file_create_gid_origin) == 0) |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2075 return 1; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2076 else if (errno == EEXIST) |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2077 return 0; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2078 else if (errno == ENOTDIR) { |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2079 mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE, |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2080 "Mailbox doesn't allow inferior mailboxes"); |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2081 return -1; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2082 } else if (mail_storage_set_error_from_errno(box->storage)) { |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2083 return -1; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2084 } else { |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2085 mail_storage_set_critical(box->storage, |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2086 "mkdir_parents(%s) failed: %m", path); |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2087 return -1; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2088 } |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2089 } |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2090 |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2091 int mailbox_create_missing_dir(struct mailbox *box, |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2092 enum mailbox_list_path_type type) |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2093 { |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2094 const char *mail_dir, *dir; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2095 struct stat st; |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
2096 int ret; |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2097 |
15163
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
2098 if ((ret = mailbox_get_path_to(box, type, &dir)) <= 0) |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
2099 return ret; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
2100 if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX, |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
2101 &mail_dir) < 0) |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
2102 return -1; |
c7a99d41e39e
lib-storage: mailbox_get_path() and friends can now return an error.
Timo Sirainen <tss@iki.fi>
parents:
15119
diff
changeset
|
2103 if (null_strcmp(dir, mail_dir) == 0) { |
15118
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2104 if ((box->list->props & MAILBOX_LIST_PROP_AUTOCREATE_DIRS) == 0) |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2105 return 0; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2106 /* the directory might not have been created yet */ |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2107 } |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2108 |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2109 /* we call this function even when the directory exists, so first do a |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2110 quick check to see if we need to mkdir anything */ |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2111 if (stat(dir, &st) == 0) |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2112 return 0; |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2113 |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2114 return mailbox_mkdir(box, dir, type); |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2115 } |
02d00843dd79
lib-storage: Cleanups to mailbox mkdir() related functions.
Timo Sirainen <tss@iki.fi>
parents:
15113
diff
changeset
|
2116 |
11623
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
11487
diff
changeset
|
2117 unsigned int mail_storage_get_lock_timeout(struct mail_storage *storage, |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
11487
diff
changeset
|
2118 unsigned int secs) |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
11487
diff
changeset
|
2119 { |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
11487
diff
changeset
|
2120 return storage->set->mail_max_lock_timeout == 0 ? secs : |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
11487
diff
changeset
|
2121 I_MIN(secs, storage->set->mail_max_lock_timeout); |
c3ee4421e86a
Added mail_max_lock_timeout setting.
Timo Sirainen <tss@iki.fi>
parents:
11487
diff
changeset
|
2122 } |
15040
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2123 |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2124 enum mail_index_open_flags |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2125 mail_storage_settings_to_index_flags(const struct mail_storage_settings *set) |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2126 { |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2127 enum mail_index_open_flags index_flags = 0; |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2128 |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2129 #ifndef MMAP_CONFLICTS_WRITE |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2130 if (set->mmap_disable) |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2131 #endif |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2132 index_flags |= MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE; |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2133 if (set->dotlock_use_excl) |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2134 index_flags |= MAIL_INDEX_OPEN_FLAG_DOTLOCK_USE_EXCL; |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2135 if (set->mail_nfs_index) |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2136 index_flags |= MAIL_INDEX_OPEN_FLAG_NFS_FLUSH; |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2137 return index_flags; |
d7dd5cdf1ba7
lib-storage: Moved mail_storage_settings_to_index_flags to mail-storage-private.h
Timo Sirainen <tss@iki.fi>
parents:
15038
diff
changeset
|
2138 } |