Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/dbox/dbox-storage.c @ 9658:8ba4253adc9b HEAD tip
*-login: SSL connections didn't get closed when the client got destroyed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 May 2014 16:41:29 +0300 |
parents | 99caf87fb3ce |
children |
rev | line source |
---|---|
9532
00cd9aacd03c
Updated copyright notices to include year 2010.
Timo Sirainen <tss@iki.fi>
parents:
9466
diff
changeset
|
1 /* Copyright (c) 2007-2010 Dovecot authors, see the included COPYING file */ |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "lib.h" |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
4 #include "array.h" |
5176
db7b28a3ffbd
If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents:
5084
diff
changeset
|
5 #include "ioloop.h" |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
6 #include "str.h" |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
7 #include "mkdir-parents.h" |
6960
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
8 #include "unlink-old-files.h" |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
9 #include "index-mail.h" |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "mail-copy.h" |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 #include "dbox-sync.h" |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
12 #include "dbox-index.h" |
4203 | 13 #include "dbox-file.h" |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
14 #include "dbox-storage.h" |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
15 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #include <stdio.h> |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #include <stdlib.h> |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #include <unistd.h> |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
19 #include <dirent.h> |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 #include <sys/stat.h> |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 |
9541
99caf87fb3ce
mbox, dbox, cydir: Create mail directory with 0700 permission, not 0770.
Timo Sirainen <tss@iki.fi>
parents:
9532
diff
changeset
|
22 #define CREATE_MODE 0700 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
24 #define DBOX_LIST_CONTEXT(obj) \ |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
25 MODULE_CONTEXT(obj, dbox_mailbox_list_module) |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
26 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
27 extern struct mail_storage dbox_storage; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 extern struct mailbox dbox_mailbox; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
29 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
30 static MODULE_CONTEXT_DEFINE_INIT(dbox_mailbox_list_module, |
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
31 &mailbox_list_module_register); |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
32 |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
33 static int |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
34 dbox_list_delete_mailbox(struct mailbox_list *list, const char *name); |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
35 static int |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
36 dbox_list_rename_mailbox(struct mailbox_list *list, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
37 const char *oldname, const char *newname); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
38 static int |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
39 dbox_list_rename_mailbox_pre(struct mailbox_list *list, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
40 const char *oldname, const char *newname); |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
41 static int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx, |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
42 const char *dir, const char *fname, |
7495
7f7003bcf422
Added mailbox_name parameter to mailbox_list.iter_is_mailbox().
Timo Sirainen <tss@iki.fi>
parents:
7458
diff
changeset
|
43 const char *mailbox_name, |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
44 enum mailbox_list_file_type type, |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
45 enum mailbox_info_flags *flags); |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
46 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
47 static int |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
48 dbox_get_list_settings(struct mailbox_list_settings *list_set, |
8137
b2a258213ee0
Created mail_user_[try_]home_expand(). Used them for expanding mail directories.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
49 const char *data, struct mail_storage *storage, |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
50 const char **layout_r, const char **alt_dir_r, |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
51 const char **error_r) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
52 { |
8817
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
53 const char *subs_fname = DBOX_SUBSCRIPTION_FILE_NAME; |
8137
b2a258213ee0
Created mail_user_[try_]home_expand(). Used them for expanding mail directories.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
54 bool debug = (storage->flags & MAIL_STORAGE_FLAG_DEBUG) != 0; |
6434
7b745fb85975
Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
55 |
7b745fb85975
Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
56 *layout_r = "fs"; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
58 memset(list_set, 0, sizeof(*list_set)); |
8817
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
59 list_set->subscription_fname = subs_fname; |
6804
ed4e708951de
Default maildir_name was missing.
Timo Sirainen <tss@iki.fi>
parents:
6777
diff
changeset
|
60 list_set->maildir_name = DBOX_MAILDIR_NAME; |
8817
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
61 list_set->mailbox_dir_name = DBOX_MAILBOX_DIR_NAME; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
63 if (data == NULL || *data == '\0' || *data == ':') { |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 /* we won't do any guessing for this format. */ |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
65 if (debug) |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
66 i_info("dbox: mailbox location not given"); |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
67 *error_r = "Root mail directory not given"; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
68 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
71 if (debug) |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
72 i_info("dbox: data=%s", data); |
8817
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
73 if (mailbox_list_settings_parse(data, list_set, storage->ns, |
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
74 layout_r, alt_dir_r, error_r) < 0) |
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
75 return -1; |
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
76 |
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
77 if (*list_set->mailbox_dir_name == '\0' && |
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
78 list_set->subscription_fname == subs_fname) |
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
79 list_set->subscription_fname = DBOX_OLD_SUBSCRIPTION_FILE_NAME; |
d8c071203322
dbox: Changed the default mailbox dir name, subscriptions and uidvalidity filenames.
Timo Sirainen <tss@iki.fi>
parents:
8767
diff
changeset
|
80 return 0; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
81 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
82 |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
83 static struct mail_storage *dbox_alloc(void) |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
84 { |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
85 struct dbox_storage *storage; |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
86 pool_t pool; |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
87 |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
88 pool = pool_alloconly_create("dbox storage", 512+256); |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
89 storage = p_new(pool, struct dbox_storage, 1); |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
90 storage->storage = dbox_storage; |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
91 storage->storage.pool = pool; |
8319
8553bb4c53ad
Fixed shared mailboxes to work with plugins.
Timo Sirainen <tss@iki.fi>
parents:
8137
diff
changeset
|
92 storage->storage.storage_class = &dbox_storage; |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
93 |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
94 return &storage->storage; |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
95 } |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
96 |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
97 static int dbox_create(struct mail_storage *_storage, const char *data, |
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
98 const char **error_r) |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
99 { |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
100 struct dbox_storage *storage = (struct dbox_storage *)_storage; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
101 struct mailbox_list_settings list_set; |
4859
92c0994a1fcf
Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents:
4853
diff
changeset
|
102 struct stat st; |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
103 const char *layout, *alt_dir; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
104 |
8137
b2a258213ee0
Created mail_user_[try_]home_expand(). Used them for expanding mail directories.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
105 if (dbox_get_list_settings(&list_set, data, _storage, |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
106 &layout, &alt_dir, error_r) < 0) |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
107 return -1; |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
108 list_set.mail_storage_flags = &_storage->flags; |
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
109 list_set.lock_method = &_storage->lock_method; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
110 |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
111 if ((_storage->flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) { |
4859
92c0994a1fcf
Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents:
4853
diff
changeset
|
112 if (stat(list_set.root_dir, &st) < 0) { |
7175
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
113 if (errno == ENOENT) { |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
114 *error_r = t_strdup_printf( |
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
115 "Root mail directory doesn't exist: %s", |
4859
92c0994a1fcf
Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents:
4853
diff
changeset
|
116 list_set.root_dir); |
7175
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
117 } else if (errno == EACCES) { |
8518
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
8495
diff
changeset
|
118 *error_r = mail_error_eacces_msg("stat", |
7175
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
119 list_set.root_dir); |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
120 } else { |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
121 *error_r = t_strdup_printf( |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
122 "stat(%s) failed: %m", |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
123 list_set.root_dir); |
4859
92c0994a1fcf
Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents:
4853
diff
changeset
|
124 } |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
125 return -1; |
4859
92c0994a1fcf
Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents:
4853
diff
changeset
|
126 } |
7175
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
127 } else if (mkdir_parents(list_set.root_dir, |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
128 CREATE_MODE) == 0 || errno == EEXIST) { |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
129 } else if (errno == EACCES) { |
8375
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
130 if (_storage->ns->type != NAMESPACE_SHARED) { |
8642
dd53d40a2f09
Permission denied error handling can now suggest missing +w permissions.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
131 *error_r = mail_error_create_eacces_msg("mkdir", |
dd53d40a2f09
Permission denied error handling can now suggest missing +w permissions.
Timo Sirainen <tss@iki.fi>
parents:
8590
diff
changeset
|
132 list_set.root_dir); |
8375
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
133 return -1; |
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
134 } |
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
135 /* can't create a new user, but we don't want to fail |
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
136 the storage creation. */ |
5499
e1e19a0db57d
Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents:
5468
diff
changeset
|
137 } else { |
7175
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
138 *error_r = t_strdup_printf("mkdir(%s) failed: %m", |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
139 list_set.root_dir); |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
140 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
142 |
6434
7b745fb85975
Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
143 if (mailbox_list_alloc(layout, &_storage->list, error_r) < 0) |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
144 return -1; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
145 storage->list_module_ctx.super = _storage->list->v; |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
146 storage->alt_dir = p_strdup(_storage->pool, alt_dir); |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
147 _storage->list->v.iter_is_mailbox = dbox_list_iter_is_mailbox; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
148 _storage->list->v.delete_mailbox = dbox_list_delete_mailbox; |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
149 _storage->list->v.rename_mailbox = dbox_list_rename_mailbox; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
150 _storage->list->v.rename_mailbox_pre = dbox_list_rename_mailbox_pre; |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
151 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
152 MODULE_CONTEXT_SET_FULL(_storage->list, dbox_mailbox_list_module, |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
153 storage, &storage->list_module_ctx); |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
154 |
6256
0c9b6ff6fb0b
Split mailbox_list_init() to _alloc() and _init(). _init() is called only
Timo Sirainen <tss@iki.fi>
parents:
6062
diff
changeset
|
155 /* finish list init after we've overridden vfuncs */ |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
156 mailbox_list_init(_storage->list, _storage->ns, &list_set, |
6256
0c9b6ff6fb0b
Split mailbox_list_init() to _alloc() and _init(). _init() is called only
Timo Sirainen <tss@iki.fi>
parents:
6062
diff
changeset
|
157 mail_storage_get_list_flags(_storage->flags)); |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
158 return 0; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
159 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
160 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
161 static int create_dbox(struct mail_storage *storage, const char *path) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
162 { |
9168
2bbf175bb6d3
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
8854
diff
changeset
|
163 const char *origin; |
8037
ab1c170b1559
Use permissions based on mail root directory when creating new files/dirs under it.
Timo Sirainen <tss@iki.fi>
parents:
8011
diff
changeset
|
164 mode_t mode; |
ab1c170b1559
Use permissions based on mail root directory when creating new files/dirs under it.
Timo Sirainen <tss@iki.fi>
parents:
8011
diff
changeset
|
165 gid_t gid; |
ab1c170b1559
Use permissions based on mail root directory when creating new files/dirs under it.
Timo Sirainen <tss@iki.fi>
parents:
8011
diff
changeset
|
166 |
9168
2bbf175bb6d3
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
8854
diff
changeset
|
167 mailbox_list_get_dir_permissions(storage->list, NULL, |
2bbf175bb6d3
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
8854
diff
changeset
|
168 &mode, &gid, &origin); |
2bbf175bb6d3
Whenever file's group changing fails, show the group origin in the error message.
Timo Sirainen <tss@iki.fi>
parents:
8854
diff
changeset
|
169 if (mkdir_parents_chgrp(path, mode, gid, origin) < 0 && |
8037
ab1c170b1559
Use permissions based on mail root directory when creating new files/dirs under it.
Timo Sirainen <tss@iki.fi>
parents:
8011
diff
changeset
|
170 errno != EEXIST) { |
5613 | 171 if (!mail_storage_set_error_from_errno(storage)) { |
172 mail_storage_set_critical(storage, | |
173 "mkdir(%s) failed: %m", path); | |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
174 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 return -1; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
176 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
177 return 0; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
178 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
179 |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
180 static const char * |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
181 dbox_get_alt_path(struct dbox_storage *storage, const char *path) |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
182 { |
7331
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
183 const char *root; |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
184 unsigned int len; |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
185 |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
186 if (storage->alt_dir == NULL) |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
187 return NULL; |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
188 |
7331
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
189 root = mailbox_list_get_path(storage->storage.list, NULL, |
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
190 MAILBOX_LIST_PATH_TYPE_DIR); |
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
191 |
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
192 len = strlen(root); |
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
193 if (strncmp(path, root, len) != 0 && path[len] == '/') { |
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
194 /* can't determine the alt path - shouldn't happen */ |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
195 return NULL; |
7331
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
196 } |
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
197 return t_strconcat(storage->alt_dir, path + len, NULL); |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
198 } |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
199 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
200 static struct mailbox * |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
201 dbox_open(struct dbox_storage *storage, const char *name, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
202 enum mailbox_open_flags flags) |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
203 { |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
204 struct mail_storage *_storage = &storage->storage; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
205 struct dbox_mailbox *mbox; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
206 struct mail_index *index; |
5618
5ea33dbddbae
Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
207 const char *path, *value; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
208 pool_t pool; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
209 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
210 path = mailbox_list_get_path(_storage->list, name, |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
211 MAILBOX_LIST_PATH_TYPE_MAILBOX); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
212 |
5618
5ea33dbddbae
Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
213 index = index_storage_alloc(_storage, name, flags, DBOX_INDEX_PREFIX); |
6737
977f224e57a6
Cydir and dbox needs to fsync appends and expunges in indexes, because they
Timo Sirainen <tss@iki.fi>
parents:
6668
diff
changeset
|
214 mail_index_set_fsync_types(index, MAIL_INDEX_SYNC_TYPE_APPEND | |
977f224e57a6
Cydir and dbox needs to fsync appends and expunges in indexes, because they
Timo Sirainen <tss@iki.fi>
parents:
6668
diff
changeset
|
215 MAIL_INDEX_SYNC_TYPE_EXPUNGE); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
216 |
5024 | 217 pool = pool_alloconly_create("dbox mailbox", 1024+512); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
218 mbox = p_new(pool, struct dbox_mailbox, 1); |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
219 mbox->ibox.box = dbox_mailbox; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
220 mbox->ibox.box.pool = pool; |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
221 mbox->ibox.storage = &storage->storage; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
222 mbox->ibox.mail_vfuncs = &dbox_mail_vfuncs; |
5179
2f9ac504ee77
When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents:
5177
diff
changeset
|
223 mbox->ibox.index = index; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
224 mbox->path = p_strdup(pool, path); |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
225 mbox->alt_path = p_strdup(pool, dbox_get_alt_path(storage, path)); |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
226 mbox->storage = storage; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
227 mbox->last_interactive_change = ioloop_time; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
228 |
3813
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
229 value = getenv("DBOX_ROTATE_SIZE"); |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
230 if (value != NULL) |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
231 mbox->rotate_size = (uoff_t)strtoul(value, NULL, 10) * 1024; |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
232 else |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
233 mbox->rotate_size = DBOX_DEFAULT_ROTATE_SIZE; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
234 mbox->rotate_size = 0; /* FIXME: currently anything else doesn't work */ |
3845
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
235 value = getenv("DBOX_ROTATE_MIN_SIZE"); |
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
236 if (value != NULL) |
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
237 mbox->rotate_min_size = (uoff_t)strtoul(value, NULL, 10) * 1024; |
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
238 else |
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
239 mbox->rotate_min_size = DBOX_DEFAULT_ROTATE_MIN_SIZE; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
240 if (mbox->rotate_min_size > mbox->rotate_size) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
241 mbox->rotate_min_size = mbox->rotate_size; |
3813
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
242 value = getenv("DBOX_ROTATE_DAYS"); |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
243 if (value != NULL) |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
244 mbox->rotate_days = (unsigned int)strtoul(value, NULL, 10); |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
245 else |
4177
4eaaef28cc38
dbox settings in config file didn't work, and the defaults were also a bit
Timo Sirainen <tss@iki.fi>
parents:
4172
diff
changeset
|
246 mbox->rotate_days = DBOX_DEFAULT_ROTATE_DAYS; |
3813
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
247 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
248 value = getenv("DBOX_MAX_OPEN_FILES"); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
249 if (value != NULL) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
250 mbox->max_open_files = (unsigned int)strtoul(value, NULL, 10); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
251 else |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
252 mbox->max_open_files = DBOX_DEFAULT_MAX_OPEN_FILES; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
253 i_array_init(&mbox->open_files, I_MIN(mbox->max_open_files, 128)); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
254 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
255 mbox->dbox_ext_id = |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
256 mail_index_ext_register(index, "dbox", 0, |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
257 sizeof(struct dbox_mail_index_record), |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
258 sizeof(uint32_t)); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
259 mbox->dbox_hdr_ext_id = |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
260 mail_index_ext_register(index, "dbox-hdr", |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
261 sizeof(struct dbox_index_header), 0, 0); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
262 mbox->dbox_index = dbox_index_init(mbox); |
5179
2f9ac504ee77
When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents:
5177
diff
changeset
|
263 |
2f9ac504ee77
When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents:
5177
diff
changeset
|
264 index_storage_mailbox_init(&mbox->ibox, name, flags, FALSE); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 return &mbox->ibox.box; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
266 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
267 |
6960
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
268 static bool |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
269 dbox_cleanup_if_exists(struct mail_storage *storage, const char *path) |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
270 { |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
271 struct stat st; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
272 |
7175
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
273 if (stat(path, &st) < 0) |
6960
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
274 return FALSE; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
275 |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
276 /* check once in a while if there are temp files to clean up */ |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
277 if (st.st_atime > st.st_ctime + DBOX_TMP_DELETE_SECS) { |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
278 /* there haven't been any changes to this directory since we |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
279 last checked it. */ |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
280 } else if (st.st_atime < ioloop_time - DBOX_TMP_SCAN_SECS) { |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
281 /* time to scan */ |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
282 const char *prefix = |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
283 mailbox_list_get_global_temp_prefix(storage->list); |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
284 |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
285 (void)unlink_old_files(path, prefix, |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
286 ioloop_time - DBOX_TMP_DELETE_SECS); |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
287 } |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
288 return TRUE; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
289 } |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
290 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
291 static struct mailbox * |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 dbox_mailbox_open(struct mail_storage *_storage, const char *name, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 struct istream *input, enum mailbox_open_flags flags) |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
294 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
295 struct dbox_storage *storage = (struct dbox_storage *)_storage; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
296 const char *path; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
297 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
298 if (input != NULL) { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
299 mail_storage_set_critical(_storage, |
4029 | 300 "dbox doesn't support streamed mailboxes"); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
301 return NULL; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
302 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
303 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
304 path = mailbox_list_get_path(_storage->list, name, |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
305 MAILBOX_LIST_PATH_TYPE_MAILBOX); |
6960
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
306 if (dbox_cleanup_if_exists(_storage, path)) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 return dbox_open(storage, name, flags); |
6777
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
308 else if (errno == ENOENT) { |
8374
9d7c0ff9c2a0
dbox/mbox: Don't auto-create INBOX if storage isn't in the INBOX namespace.
Timo Sirainen <tss@iki.fi>
parents:
8319
diff
changeset
|
309 if (strcmp(name, "INBOX") == 0 && |
9d7c0ff9c2a0
dbox/mbox: Don't auto-create INBOX if storage isn't in the INBOX namespace.
Timo Sirainen <tss@iki.fi>
parents:
8319
diff
changeset
|
310 (_storage->ns->flags & NAMESPACE_FLAG_INBOX) != 0) { |
6777
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
311 /* INBOX always exists, create it */ |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
312 if (create_dbox(_storage, path) < 0) |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
313 return NULL; |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
314 return dbox_open(storage, name, flags); |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
315 } |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
316 |
5613 | 317 mail_storage_set_error(_storage, MAIL_ERROR_NOTFOUND, |
318 T_MAIL_ERR_MAILBOX_NOT_FOUND(name)); | |
7175
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
319 } else if (errno == EACCES) { |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
320 mail_storage_set_critical(_storage, "%s", |
8518
1e42b631f037
Improved "Permission denied" error handling. It'll now show also the uid/gid name.
Timo Sirainen <tss@iki.fi>
parents:
8495
diff
changeset
|
321 mail_error_eacces_msg("stat", path)); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 } else { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 mail_storage_set_critical(_storage, "stat(%s) failed: %m", |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 path); |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
325 } |
7175
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
326 return NULL; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
327 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
328 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
329 static int dbox_storage_mailbox_close(struct mailbox *box) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
330 { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
331 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box; |
7495
7f7003bcf422
Added mailbox_name parameter to mailbox_list.iter_is_mailbox().
Timo Sirainen <tss@iki.fi>
parents:
7458
diff
changeset
|
332 int ret = 0; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
333 |
7458
43674a726a92
If mailbox hasn't been opened when closing it, don't crash when trying to
Timo Sirainen <tss@iki.fi>
parents:
7403
diff
changeset
|
334 if (box->opened) { |
43674a726a92
If mailbox hasn't been opened when closing it, don't crash when trying to
Timo Sirainen <tss@iki.fi>
parents:
7403
diff
changeset
|
335 /* see if we want to flush dirty flags */ |
43674a726a92
If mailbox hasn't been opened when closing it, don't crash when trying to
Timo Sirainen <tss@iki.fi>
parents:
7403
diff
changeset
|
336 ret = dbox_sync(mbox, TRUE); |
43674a726a92
If mailbox hasn't been opened when closing it, don't crash when trying to
Timo Sirainen <tss@iki.fi>
parents:
7403
diff
changeset
|
337 } |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
338 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
339 dbox_index_deinit(&mbox->dbox_index); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
340 dbox_files_free(mbox); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
341 array_free(&mbox->open_files); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
342 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
343 return index_storage_mailbox_close(box) < 0 ? -1 : ret; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
344 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
345 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
346 static int dbox_mailbox_create(struct mail_storage *_storage, |
7585
326ca0ed8983
dbox: Support creating non-selectable mailboxes ("directories").
Timo Sirainen <tss@iki.fi>
parents:
7533
diff
changeset
|
347 const char *name, bool directory) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
348 { |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
349 struct dbox_storage *storage = (struct dbox_storage *)_storage; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
350 const char *path, *alt_path; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 struct stat st; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
352 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
353 path = mailbox_list_get_path(_storage->list, name, |
7585
326ca0ed8983
dbox: Support creating non-selectable mailboxes ("directories").
Timo Sirainen <tss@iki.fi>
parents:
7533
diff
changeset
|
354 directory ? MAILBOX_LIST_PATH_TYPE_DIR : |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
355 MAILBOX_LIST_PATH_TYPE_MAILBOX); |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
356 if (stat(path, &st) == 0) { |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8399
diff
changeset
|
357 mail_storage_set_error(_storage, MAIL_ERROR_EXISTS, |
5613 | 358 "Mailbox already exists"); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 return -1; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
361 |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
362 /* make sure the alt path doesn't exist yet. it shouldn't (except with |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
363 race conditions with RENAME/DELETE), but if something crashed and |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
364 left it lying around we don't want to start overwriting files in |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
365 it. */ |
7585
326ca0ed8983
dbox: Support creating non-selectable mailboxes ("directories").
Timo Sirainen <tss@iki.fi>
parents:
7533
diff
changeset
|
366 alt_path = directory ? NULL : dbox_get_alt_path(storage, path); |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
367 if (alt_path != NULL && stat(alt_path, &st) == 0) { |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8399
diff
changeset
|
368 mail_storage_set_error(_storage, MAIL_ERROR_EXISTS, |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
369 "Mailbox already exists"); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
370 return -1; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
371 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
372 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
373 return create_dbox(_storage, path); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
374 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
376 static int |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
377 dbox_delete_nonrecursive(struct mailbox_list *list, const char *path, |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
378 const char *name) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
379 { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
380 DIR *dir; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
381 struct dirent *d; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
382 string_t *full_path; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
383 unsigned int dir_len; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
384 bool unlinked_something = FALSE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
385 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
386 dir = opendir(path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
387 if (dir == NULL) { |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
388 if (errno == ENOENT) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
389 return 0; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
390 if (!mailbox_list_set_error_from_errno(list)) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
391 mailbox_list_set_critical(list, |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
392 "opendir(%s) failed: %m", path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
393 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
394 return -1; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
395 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
396 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
397 full_path = t_str_new(256); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
398 str_append(full_path, path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
399 str_append_c(full_path, '/'); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
400 dir_len = str_len(full_path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
401 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
402 errno = 0; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
403 while ((d = readdir(dir)) != NULL) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
404 if (d->d_name[0] == '.') { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
405 /* skip . and .. */ |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
406 if (d->d_name[1] == '\0') |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
407 continue; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
408 if (d->d_name[1] == '.' && d->d_name[2] == '\0') |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
409 continue; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
410 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
411 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
412 str_truncate(full_path, dir_len); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
413 str_append(full_path, d->d_name); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
414 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
415 /* trying to unlink() a directory gives either EPERM or EISDIR |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
416 (non-POSIX). it doesn't really work anywhere in practise, |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
417 so don't bother stat()ing the file first */ |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
418 if (unlink(str_c(full_path)) == 0) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
419 unlinked_something = TRUE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
420 else if (errno != ENOENT && errno != EISDIR && errno != EPERM) { |
7403 | 421 mailbox_list_set_critical(list, "unlink(%s) failed: %m", |
422 str_c(full_path)); | |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
423 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
424 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
425 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
426 if (closedir(dir) < 0) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
427 mailbox_list_set_critical(list, "closedir(%s) failed: %m", |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
428 path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
429 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
430 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
431 if (rmdir(path) == 0) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
432 unlinked_something = TRUE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
433 else if (errno != ENOENT && errno != ENOTEMPTY) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
434 mailbox_list_set_critical(list, "rmdir(%s) failed: %m", path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
435 return -1; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
436 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
437 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
438 if (!unlinked_something) { |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8399
diff
changeset
|
439 mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
440 t_strdup_printf("Directory %s isn't empty, " |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
441 "can't delete it.", name)); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
442 return -1; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
443 } |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
444 return 1; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
445 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
446 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
447 static int |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
448 dbox_list_delete_mailbox(struct mailbox_list *list, const char *name) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 { |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
450 struct dbox_storage *storage = DBOX_LIST_CONTEXT(list); |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
451 struct stat st; |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
452 const char *path, *alt_path; |
7323 | 453 bool deleted = FALSE; |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
454 int ret; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
455 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
456 /* Make sure the indexes are closed before trying to delete the |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
457 directory that contains them. It can still fail with some NFS |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
458 implementations if indexes are opened by another session, but |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
459 that can't really be helped. */ |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
460 index_storage_destroy_unrefed(); |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
461 |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
462 /* delete the index and control directories */ |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
463 if (storage->list_module_ctx.super.delete_mailbox(list, name) < 0) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 return -1; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
465 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
466 /* check if the mailbox actually exists */ |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
467 path = mailbox_list_get_path(list, name, |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
468 MAILBOX_LIST_PATH_TYPE_MAILBOX); |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
469 if ((ret = dbox_delete_nonrecursive(list, path, name)) > 0) { |
7323 | 470 /* delete the mailbox first */ |
471 alt_path = dbox_get_alt_path(storage, path); | |
472 if (alt_path != NULL) { | |
473 if (dbox_delete_nonrecursive(list, alt_path, name) < 0) | |
474 return -1; | |
475 } | |
8399
155700456194
Fixed dbox to work with Maildir++ layout.
Timo Sirainen <tss@iki.fi>
parents:
8375
diff
changeset
|
476 if (*list->set.maildir_name == '\0') { |
155700456194
Fixed dbox to work with Maildir++ layout.
Timo Sirainen <tss@iki.fi>
parents:
8375
diff
changeset
|
477 /* everything was in the one directory that was |
155700456194
Fixed dbox to work with Maildir++ layout.
Timo Sirainen <tss@iki.fi>
parents:
8375
diff
changeset
|
478 already deleted succesfully. */ |
155700456194
Fixed dbox to work with Maildir++ layout.
Timo Sirainen <tss@iki.fi>
parents:
8375
diff
changeset
|
479 return 0; |
155700456194
Fixed dbox to work with Maildir++ layout.
Timo Sirainen <tss@iki.fi>
parents:
8375
diff
changeset
|
480 } |
7323 | 481 /* try to delete the directory also */ |
482 deleted = TRUE; | |
483 path = mailbox_list_get_path(list, name, | |
484 MAILBOX_LIST_PATH_TYPE_DIR); | |
485 } else if (errno != ENOENT) { | |
486 mailbox_list_set_critical(list, "stat(%s) failed: %m", path); | |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
487 return -1; |
7323 | 488 } else { |
489 /* mailbox not found - what about the directory? */ | |
490 path = mailbox_list_get_path(list, name, | |
491 MAILBOX_LIST_PATH_TYPE_DIR); | |
492 if (stat(path, &st) == 0) { | |
493 /* delete the directory */ | |
494 } else if (errno == ENOENT) { | |
495 mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, | |
496 T_MAIL_ERR_MAILBOX_NOT_FOUND(name)); | |
497 return -1; | |
498 } else if (!mailbox_list_set_error_from_errno(list)) { | |
499 mailbox_list_set_critical(list, "stat(%s) failed: %m", | |
500 path); | |
501 return -1; | |
502 } | |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
503 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
505 alt_path = dbox_get_alt_path(storage, path); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
506 if (alt_path != NULL) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
507 (void)rmdir(alt_path); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
508 |
7323 | 509 if (rmdir(path) == 0) |
510 return 0; | |
511 else if (errno == ENOTEMPTY) { | |
512 if (deleted) | |
513 return 0; | |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8399
diff
changeset
|
514 mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, |
7323 | 515 t_strdup_printf("Directory %s isn't empty, " |
516 "can't delete it.", name)); | |
517 } else if (!mailbox_list_set_error_from_errno(list)) { | |
518 mailbox_list_set_critical(list, "rmdir() failed for %s: %m", | |
519 path); | |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
520 } |
7323 | 521 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
522 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
523 |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
524 static bool |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
525 dbox_list_rename_get_alt_paths(struct mailbox_list *list, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
526 const char *oldname, const char *newname, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
527 const char **oldpath_r, const char **newpath_r) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
528 { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
529 struct dbox_storage *storage = DBOX_LIST_CONTEXT(list); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
530 const char *path; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
531 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
532 if (storage->alt_dir == NULL) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
533 return FALSE; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
534 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
535 path = mailbox_list_get_path(list, oldname, MAILBOX_LIST_PATH_TYPE_DIR); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
536 *oldpath_r = dbox_get_alt_path(storage, path); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
537 if (*oldpath_r == NULL) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
538 return FALSE; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
539 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
540 path = mailbox_list_get_path(list, newname, MAILBOX_LIST_PATH_TYPE_DIR); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
541 *newpath_r = dbox_get_alt_path(storage, path); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
542 i_assert(*newpath_r != NULL); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
543 return TRUE; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
544 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
545 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
546 static int |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
547 dbox_list_rename_mailbox_pre(struct mailbox_list *list, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
548 const char *oldname, const char *newname) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
549 { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
550 const char *alt_oldpath, *alt_newpath; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
551 struct stat st; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
552 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
553 if (!dbox_list_rename_get_alt_paths(list, oldname, newname, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
554 &alt_oldpath, &alt_newpath)) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
555 return 0; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
556 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
557 if (stat(alt_newpath, &st) == 0) { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
558 /* race condition or a directory left there lying around? |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
559 safest to just report error. */ |
8411
abd0ef855a33
Implemented imap-response-codes draft.
Timo Sirainen <tss@iki.fi>
parents:
8399
diff
changeset
|
560 mailbox_list_set_error(list, MAIL_ERROR_EXISTS, |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
561 "Target mailbox already exists"); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
562 return -1; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
563 } else if (errno != ENOENT) { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
564 mailbox_list_set_critical(list, "stat(%s) failed: %m", |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
565 alt_newpath); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
566 return -1; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
567 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
568 return 0; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
569 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
570 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
571 static int |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
572 dbox_list_rename_mailbox(struct mailbox_list *list, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
573 const char *oldname, const char *newname) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
574 { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
575 struct dbox_storage *storage = DBOX_LIST_CONTEXT(list); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
576 const char *alt_oldpath, *alt_newpath; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
577 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
578 if (storage->list_module_ctx.super.rename_mailbox(list, oldname, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
579 newname) < 0) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
580 return -1; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
581 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
582 if (!dbox_list_rename_get_alt_paths(list, oldname, newname, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
583 &alt_oldpath, &alt_newpath)) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
584 return 0; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
585 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
586 if (rename(alt_oldpath, alt_newpath) == 0) { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
587 /* ok */ |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
588 } else if (errno != ENOENT) { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
589 /* renaming is done already, so just log the error */ |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
590 mailbox_list_set_critical(list, "rename(%s, %s) failed: %m", |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
591 alt_oldpath, alt_newpath); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
592 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
593 return 0; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
594 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
595 |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
596 static void dbox_notify_changes(struct mailbox *box) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
597 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
598 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box; |
9466
68af994e7f3c
dbox notify: Look for dbox index files from index dir, not mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
9168
diff
changeset
|
599 const char *dir, *path; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
600 |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
601 if (box->notify_callback == NULL) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
602 index_mailbox_check_remove_all(&mbox->ibox); |
6961
16f761cdc910
All changes end up to dovecot.index.log with dbox, so watch only it instead
Timo Sirainen <tss@iki.fi>
parents:
6960
diff
changeset
|
603 else { |
9466
68af994e7f3c
dbox notify: Look for dbox index files from index dir, not mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
9168
diff
changeset
|
604 dir = mailbox_list_get_path(box->storage->list, box->name, |
68af994e7f3c
dbox notify: Look for dbox index files from index dir, not mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
9168
diff
changeset
|
605 MAILBOX_LIST_PATH_TYPE_INDEX); |
68af994e7f3c
dbox notify: Look for dbox index files from index dir, not mail root dir.
Timo Sirainen <tss@iki.fi>
parents:
9168
diff
changeset
|
606 path = t_strdup_printf("%s/"DBOX_INDEX_PREFIX".log", dir); |
6961
16f761cdc910
All changes end up to dovecot.index.log with dbox, so watch only it instead
Timo Sirainen <tss@iki.fi>
parents:
6960
diff
changeset
|
607 index_mailbox_check_add(&mbox->ibox, path); |
16f761cdc910
All changes end up to dovecot.index.log with dbox, so watch only it instead
Timo Sirainen <tss@iki.fi>
parents:
6960
diff
changeset
|
608 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
609 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
610 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
611 static int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6340
diff
changeset
|
612 ATTR_UNUSED, |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
613 const char *dir, const char *fname, |
7495
7f7003bcf422
Added mailbox_name parameter to mailbox_list.iter_is_mailbox().
Timo Sirainen <tss@iki.fi>
parents:
7458
diff
changeset
|
614 const char *mailbox_name ATTR_UNUSED, |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
615 enum mailbox_list_file_type type, |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
616 enum mailbox_info_flags *flags) |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
617 { |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
618 const char *path, *maildir_path; |
7829
1550dc4f24a5
dbox: Set MAILBOX_CHILDREN flag for \NoSelect mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
619 struct stat st, st2; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
620 int ret = 1; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
621 |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
622 /* try to avoid stat() with these checks */ |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
623 if (type != MAILBOX_LIST_FILE_TYPE_DIR && |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
624 type != MAILBOX_LIST_FILE_TYPE_SYMLINK && |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
625 type != MAILBOX_LIST_FILE_TYPE_UNKNOWN) { |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
626 /* it's a file */ |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
627 *flags |= MAILBOX_NOSELECT | MAILBOX_NOINFERIORS; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
628 return 0; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
629 } |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
630 |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
631 /* need to stat() then */ |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
632 path = t_strconcat(dir, "/", fname, NULL); |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
633 if (stat(path, &st) == 0) { |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
634 if (!S_ISDIR(st.st_mode)) { |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
635 /* non-directory */ |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
636 *flags |= MAILBOX_NOSELECT | MAILBOX_NOINFERIORS; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
637 ret = 0; |
6806
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
638 } else if (st.st_nlink == 2) { |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
639 /* no subdirectories */ |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
640 *flags |= MAILBOX_NOCHILDREN; |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
641 } else if (*ctx->list->set.maildir_name != '\0') { |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
642 /* default configuration: we have one directory |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
643 containing the mailboxes. if there are 3 links, |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
644 either this is a selectable mailbox without children |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
645 or non-selectable mailbox with children */ |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
646 if (st.st_nlink > 3) |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
647 *flags |= MAILBOX_CHILDREN; |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
648 } else { |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
649 /* non-default configuration: all subdirectories are |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
650 child mailboxes. */ |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
651 if (st.st_nlink > 2) |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
652 *flags |= MAILBOX_CHILDREN; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
653 } |
7533
7690cdabb3f8
dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents:
7495
diff
changeset
|
654 } else if (errno == ENOENT) { |
7690cdabb3f8
dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents:
7495
diff
changeset
|
655 /* doesn't exist - probably a non-existing subscribed mailbox */ |
7690cdabb3f8
dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents:
7495
diff
changeset
|
656 *flags |= MAILBOX_NONEXISTENT; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
657 } else { |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
658 /* non-selectable. probably either access denied, or symlink |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
659 destination not found. don't bother logging errors. */ |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
660 *flags |= MAILBOX_NOSELECT; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
661 } |
7533
7690cdabb3f8
dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents:
7495
diff
changeset
|
662 if ((*flags & (MAILBOX_NOSELECT | MAILBOX_NONEXISTENT)) == 0) { |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
663 /* make sure it's a selectable mailbox */ |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
664 maildir_path = t_strconcat(path, "/"DBOX_MAILDIR_NAME, NULL); |
7830
5a6aa66e2ccd
dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7829
diff
changeset
|
665 if (stat(maildir_path, &st2) < 0 || !S_ISDIR(st2.st_mode)) |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
666 *flags |= MAILBOX_NOSELECT; |
7830
5a6aa66e2ccd
dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7829
diff
changeset
|
667 if (st.st_nlink == 3 && *ctx->list->set.maildir_name != '\0') { |
5a6aa66e2ccd
dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7829
diff
changeset
|
668 /* now we know what link count 3 means. */ |
5a6aa66e2ccd
dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7829
diff
changeset
|
669 if ((*flags & MAILBOX_NOSELECT) != 0) |
7829
1550dc4f24a5
dbox: Set MAILBOX_CHILDREN flag for \NoSelect mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
670 *flags |= MAILBOX_CHILDREN; |
7830
5a6aa66e2ccd
dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7829
diff
changeset
|
671 else |
5a6aa66e2ccd
dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7829
diff
changeset
|
672 *flags |= MAILBOX_NOCHILDREN; |
7829
1550dc4f24a5
dbox: Set MAILBOX_CHILDREN flag for \NoSelect mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7798
diff
changeset
|
673 } |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
674 } |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
675 return ret; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
676 } |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
677 |
4453
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
678 static void dbox_class_init(void) |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
679 { |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
680 dbox_transaction_class_init(); |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
681 } |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
682 |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
683 static void dbox_class_deinit(void) |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
684 { |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
685 dbox_transaction_class_deinit(); |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
686 } |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
687 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
688 struct mail_storage dbox_storage = { |
4453
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
689 MEMBER(name) DBOX_STORAGE_NAME, |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
690 MEMBER(mailbox_is_file) FALSE, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
691 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
692 { |
4453
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
693 dbox_class_init, |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
694 dbox_class_deinit, |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
695 dbox_alloc, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
696 dbox_create, |
7093
f0623745bd4c
libstorage.a shouldn't reference symbols in libstorage_index.a. Changed
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
697 index_storage_destroy, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
698 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
699 dbox_mailbox_open, |
5468
8e58322ef87e
Removed virtual mail_storage.get_last_error(). The implementation is always
Timo Sirainen <tss@iki.fi>
parents:
5466
diff
changeset
|
700 dbox_mailbox_create |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
701 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
702 }; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
703 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
704 struct mailbox dbox_mailbox = { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
705 MEMBER(name) NULL, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
706 MEMBER(storage) NULL, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
707 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
708 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
709 index_storage_is_readonly, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
710 index_storage_allow_new_keywords, |
7620 | 711 index_storage_mailbox_enable, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
712 dbox_storage_mailbox_close, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
713 index_storage_get_status, |
6062
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6023
diff
changeset
|
714 NULL, |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6023
diff
changeset
|
715 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
716 dbox_storage_sync_init, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
717 index_mailbox_sync_next, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
718 index_mailbox_sync_deinit, |
5562
24b751bc0995
Added sync_notify() callback to struct mail_storage. It's now called for
Timo Sirainen <tss@iki.fi>
parents:
5539
diff
changeset
|
719 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
720 dbox_notify_changes, |
4453
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
721 index_transaction_begin, |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
722 index_transaction_commit, |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
723 index_transaction_rollback, |
7913
e04513064165
CONDSTORE: STORE UNCHANGEDSINCE conflicts are now checked atomically.
Timo Sirainen <tss@iki.fi>
parents:
7830
diff
changeset
|
724 index_transaction_set_max_modseq, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
725 index_keywords_create, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
726 index_keywords_free, |
8042
0e7a9547be83
Added mailbox_keyword_is_valid().
Timo Sirainen <tss@iki.fi>
parents:
8037
diff
changeset
|
727 index_keyword_is_valid, |
7653
f8e902acfbae
Renamed mailbox_get_uids() to mailbox_get_seq_range().
Timo Sirainen <tss@iki.fi>
parents:
7629
diff
changeset
|
728 index_storage_get_seq_range, |
7654 | 729 index_storage_get_uid_range, |
7629 | 730 index_storage_get_expunged_uids, |
8484
db78eab2ba5d
Initial support for getting full text search working nicely with virtual mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8411
diff
changeset
|
731 NULL, |
8495
ffb37c392166
Finished making full text search indexes work fast with virtual mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8484
diff
changeset
|
732 NULL, |
ffb37c392166
Finished making full text search indexes work fast with virtual mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
8484
diff
changeset
|
733 NULL, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
734 dbox_mail_alloc, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
735 index_header_lookup_init, |
8011
2d902d1f8bea
struct mailbox_header_lookup_ctx can now be referenced/unreferenced so it
Timo Sirainen <tss@iki.fi>
parents:
7913
diff
changeset
|
736 index_header_lookup_ref, |
2d902d1f8bea
struct mailbox_header_lookup_ctx can now be referenced/unreferenced so it
Timo Sirainen <tss@iki.fi>
parents:
7913
diff
changeset
|
737 index_header_lookup_unref, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
738 index_storage_search_init, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
739 index_storage_search_deinit, |
4939
ff2272c228cc
Dovecot is now able to execute multiple commands at the same time.
Timo Sirainen <tss@iki.fi>
parents:
4894
diff
changeset
|
740 index_storage_search_next_nonblock, |
4196
6ac0d63b297f
Optimized searching a bit for cases where we can restrict search range by
Timo Sirainen <tss@iki.fi>
parents:
4177
diff
changeset
|
741 index_storage_search_next_update_seq, |
8075
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
742 dbox_save_alloc, |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
743 dbox_save_begin, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
744 dbox_save_continue, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
745 dbox_save_finish, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
746 dbox_save_cancel, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
747 mail_storage_copy, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
748 index_storage_is_inconsistent |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
749 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
750 }; |