Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/dbox/dbox-storage.c @ 8375:4aafdbe62680 HEAD
shared mailboxes: Cleanups, fixes and optimizations.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 01 Nov 2008 16:05:19 +0200 |
parents | 9d7c0ff9c2a0 |
children | 155700456194 |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
6961
diff
changeset
|
1 /* Copyright (c) 2007-2008 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 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 #define CREATE_MODE 0770 /* umask() should limit it more */ |
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 { |
8137
b2a258213ee0
Created mail_user_[try_]home_expand(). Used them for expanding mail directories.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
53 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
|
54 |
7b745fb85975
Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
55 *layout_r = "fs"; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
56 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
57 memset(list_set, 0, sizeof(*list_set)); |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
58 list_set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME; |
6804
ed4e708951de
Default maildir_name was missing.
Timo Sirainen <tss@iki.fi>
parents:
6777
diff
changeset
|
59 list_set->maildir_name = DBOX_MAILDIR_NAME; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
60 |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
61 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
|
62 /* 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
|
63 if (debug) |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
64 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
|
65 *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
|
66 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
67 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
69 if (debug) |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
70 i_info("dbox: data=%s", data); |
8137
b2a258213ee0
Created mail_user_[try_]home_expand(). Used them for expanding mail directories.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
71 return mailbox_list_settings_parse(data, list_set, storage->ns, |
b2a258213ee0
Created mail_user_[try_]home_expand(). Used them for expanding mail directories.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
72 layout_r, alt_dir_r, error_r); |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
73 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
74 |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
75 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
|
76 { |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
77 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
|
78 pool_t pool; |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
79 |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 storage->storage.pool = pool; |
8319
8553bb4c53ad
Fixed shared mailboxes to work with plugins.
Timo Sirainen <tss@iki.fi>
parents:
8137
diff
changeset
|
84 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
|
85 |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
86 return &storage->storage; |
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 |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
89 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
|
90 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
|
91 { |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
92 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
|
93 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
|
94 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
|
95 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
|
96 |
8137
b2a258213ee0
Created mail_user_[try_]home_expand(). Used them for expanding mail directories.
Timo Sirainen <tss@iki.fi>
parents:
8075
diff
changeset
|
97 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
|
98 &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
|
99 return -1; |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
100 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
|
101 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
|
102 |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
103 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
|
104 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
|
105 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
|
106 *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
|
107 "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
|
108 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
|
109 } 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
|
110 *error_r = mail_storage_eacces_msg("stat", |
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
|
111 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
|
112 } 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
|
113 *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
|
114 "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
|
115 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
|
116 } |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
117 return -1; |
4859
92c0994a1fcf
Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents:
4853
diff
changeset
|
118 } |
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 } 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
|
120 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
|
121 } else if (errno == EACCES) { |
8375
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
122 if (_storage->ns->type != NAMESPACE_SHARED) { |
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
123 *error_r = mail_storage_eacces_msg("mkdir", |
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
124 list_set.root_dir); |
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
125 return -1; |
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
126 } |
4aafdbe62680
shared mailboxes: Cleanups, fixes and optimizations.
Timo Sirainen <tss@iki.fi>
parents:
8374
diff
changeset
|
127 /* 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
|
128 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
|
129 } 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
|
130 *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
|
131 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
|
132 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
133 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
134 |
6434
7b745fb85975
Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
135 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
|
136 return -1; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
137 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
|
138 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
|
139 _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
|
140 _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
|
141 _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
|
142 _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
|
143 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
144 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
|
145 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
|
146 |
6256
0c9b6ff6fb0b
Split mailbox_list_init() to _alloc() and _init(). _init() is called only
Timo Sirainen <tss@iki.fi>
parents:
6062
diff
changeset
|
147 /* 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
|
148 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
|
149 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
|
150 return 0; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
151 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
152 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
153 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
|
154 { |
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
|
155 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
|
156 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
|
157 |
ab1c170b1559
Use permissions based on mail root directory when creating new files/dirs under it.
Timo Sirainen <tss@iki.fi>
parents:
8011
diff
changeset
|
158 mailbox_list_get_dir_permissions(storage->list, &mode, &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
|
159 if (mkdir_parents_chown(path, mode, (uid_t)-1, gid) < 0 && |
ab1c170b1559
Use permissions based on mail root directory when creating new files/dirs under it.
Timo Sirainen <tss@iki.fi>
parents:
8011
diff
changeset
|
160 errno != EEXIST) { |
5613 | 161 if (!mail_storage_set_error_from_errno(storage)) { |
162 mail_storage_set_critical(storage, | |
163 "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
|
164 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
165 return -1; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 return 0; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
168 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
169 |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
170 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
|
171 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
|
172 { |
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
|
173 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
|
174 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
|
175 |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
176 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
|
177 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
|
178 |
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
|
179 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
|
180 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
|
181 |
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
182 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
|
183 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
|
184 /* 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
|
185 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
|
186 } |
9ef06104648a
MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents:
7324
diff
changeset
|
187 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
|
188 } |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
189 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
190 static struct mailbox * |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
191 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
|
192 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
|
193 { |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
194 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
|
195 struct dbox_mailbox *mbox; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
196 struct mail_index *index; |
5618
5ea33dbddbae
Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
197 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
|
198 pool_t pool; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
199 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
200 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
|
201 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
|
202 |
5618
5ea33dbddbae
Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
203 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
|
204 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
|
205 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
|
206 |
5024 | 207 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
|
208 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
|
209 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
|
210 mbox->ibox.box.pool = pool; |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 mbox->storage = storage; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
217 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
|
218 |
3813
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
219 value = getenv("DBOX_ROTATE_SIZE"); |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
220 if (value != NULL) |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
221 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
|
222 else |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
223 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
|
224 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
|
225 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
|
226 if (value != NULL) |
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
227 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
|
228 else |
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 value = getenv("DBOX_ROTATE_DAYS"); |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
233 if (value != NULL) |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
234 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
|
235 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
|
236 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
|
237 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
238 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
|
239 if (value != NULL) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
240 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
|
241 else |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
242 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
|
243 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
|
244 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
245 mbox->dbox_ext_id = |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
246 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
|
247 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
|
248 sizeof(uint32_t)); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 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
|
253 |
2f9ac504ee77
When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents:
5177
diff
changeset
|
254 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
|
255 return &mbox->ibox.box; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
256 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 |
6960
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
258 static bool |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
259 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
|
260 { |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
261 struct stat st; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
262 |
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
|
263 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
|
264 return FALSE; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
265 |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
266 /* 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
|
267 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
|
268 /* 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
|
269 last checked it. */ |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
270 } 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
|
271 /* time to scan */ |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
272 const char *prefix = |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
273 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
|
274 |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
275 (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
|
276 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
|
277 } |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
278 return TRUE; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
279 } |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
280 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
281 static struct mailbox * |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
282 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
|
283 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
|
284 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
285 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
|
286 const char *path; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
287 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 if (input != NULL) { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
289 mail_storage_set_critical(_storage, |
4029 | 290 "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
|
291 return NULL; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 (_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
|
301 /* INBOX always exists, create it */ |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
302 if (create_dbox(_storage, path) < 0) |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
303 return NULL; |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
304 return dbox_open(storage, name, flags); |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
305 } |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
306 |
5613 | 307 mail_storage_set_error(_storage, MAIL_ERROR_NOTFOUND, |
308 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
|
309 } 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
|
310 mail_storage_set_critical(_storage, "%s", |
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
|
311 mail_storage_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
|
312 } else { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 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
|
314 path); |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
315 } |
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
|
316 return NULL; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
319 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
|
320 { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
321 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
|
322 int ret = 0; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
323 |
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
|
324 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
|
325 /* 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
|
326 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
|
327 } |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
328 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
329 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
|
330 dbox_files_free(mbox); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
331 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
|
332 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
333 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
|
334 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
335 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 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
|
337 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
|
338 { |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
339 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
|
340 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
|
341 struct stat st; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
343 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
|
344 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
|
345 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
|
346 if (stat(path, &st) == 0) { |
5613 | 347 mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE, |
348 "Mailbox already exists"); | |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
349 return -1; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
350 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
351 |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
352 /* 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
|
353 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
|
354 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
|
355 it. */ |
7585
326ca0ed8983
dbox: Support creating non-selectable mailboxes ("directories").
Timo Sirainen <tss@iki.fi>
parents:
7533
diff
changeset
|
356 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
|
357 if (alt_path != NULL && stat(alt_path, &st) == 0) { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
358 mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
359 "Mailbox already exists"); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
360 return -1; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
361 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
362 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
363 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
|
364 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
365 |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
366 static int |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
367 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
|
368 const char *name) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
369 { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
370 DIR *dir; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
371 struct dirent *d; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
372 string_t *full_path; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
373 unsigned int dir_len; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
374 bool unlinked_something = FALSE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
375 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
376 dir = opendir(path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
377 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
|
378 if (errno == ENOENT) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
379 return 0; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
380 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
|
381 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
|
382 "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
|
383 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
384 return -1; |
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 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
387 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
|
388 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
|
389 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
|
390 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
|
391 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
392 errno = 0; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
393 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
|
394 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
|
395 /* skip . and .. */ |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
396 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
|
397 continue; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
398 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
|
399 continue; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
400 } |
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 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
|
403 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
|
404 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
405 /* 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
|
406 (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
|
407 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
|
408 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
|
409 unlinked_something = TRUE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
410 else if (errno != ENOENT && errno != EISDIR && errno != EPERM) { |
7403 | 411 mailbox_list_set_critical(list, "unlink(%s) failed: %m", |
412 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
|
413 } |
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 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
416 if (closedir(dir) < 0) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
417 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
|
418 path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
419 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
420 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
421 if (rmdir(path) == 0) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
422 unlinked_something = TRUE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
423 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
|
424 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
|
425 return -1; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
426 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
427 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
428 if (!unlinked_something) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
429 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE, |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
430 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
|
431 "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
|
432 return -1; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
433 } |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
434 return 1; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
435 } |
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 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
|
438 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
|
439 { |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
440 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
|
441 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
|
442 const char *path, *alt_path; |
7323 | 443 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
|
444 int ret; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
445 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
446 /* 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
|
447 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
|
448 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
|
449 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
|
450 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
|
451 |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
452 /* 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
|
453 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
|
454 return -1; |
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 /* 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
|
457 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
|
458 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
|
459 if ((ret = dbox_delete_nonrecursive(list, path, name)) > 0) { |
7323 | 460 /* delete the mailbox first */ |
461 alt_path = dbox_get_alt_path(storage, path); | |
462 if (alt_path != NULL) { | |
463 if (dbox_delete_nonrecursive(list, alt_path, name) < 0) | |
464 return -1; | |
465 } | |
466 /* try to delete the directory also */ | |
467 deleted = TRUE; | |
468 path = mailbox_list_get_path(list, name, | |
469 MAILBOX_LIST_PATH_TYPE_DIR); | |
470 } else if (errno != ENOENT) { | |
471 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
|
472 return -1; |
7323 | 473 } else { |
474 /* mailbox not found - what about the directory? */ | |
475 path = mailbox_list_get_path(list, name, | |
476 MAILBOX_LIST_PATH_TYPE_DIR); | |
477 if (stat(path, &st) == 0) { | |
478 /* delete the directory */ | |
479 } else if (errno == ENOENT) { | |
480 mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, | |
481 T_MAIL_ERR_MAILBOX_NOT_FOUND(name)); | |
482 return -1; | |
483 } else if (!mailbox_list_set_error_from_errno(list)) { | |
484 mailbox_list_set_critical(list, "stat(%s) failed: %m", | |
485 path); | |
486 return -1; | |
487 } | |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
488 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
489 |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
490 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
|
491 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
|
492 (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
|
493 |
7323 | 494 if (rmdir(path) == 0) |
495 return 0; | |
496 else if (errno == ENOTEMPTY) { | |
497 if (deleted) | |
498 return 0; | |
499 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE, | |
500 t_strdup_printf("Directory %s isn't empty, " | |
501 "can't delete it.", name)); | |
502 } else if (!mailbox_list_set_error_from_errno(list)) { | |
503 mailbox_list_set_critical(list, "rmdir() failed for %s: %m", | |
504 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
|
505 } |
7323 | 506 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
507 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
508 |
7355
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
509 static bool |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
510 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
|
511 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
|
512 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
|
513 { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
514 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
|
515 const char *path; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
516 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
517 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
|
518 return FALSE; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
519 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
520 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
|
521 *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
|
522 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
|
523 return FALSE; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
524 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
525 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
|
526 *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
|
527 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
|
528 return TRUE; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
529 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
530 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
531 static int |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
532 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
|
533 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
|
534 { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
535 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
|
536 struct stat st; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
537 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
538 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
|
539 &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
|
540 return 0; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
541 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
542 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
|
543 /* 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
|
544 safest to just report error. */ |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
545 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE, |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
546 "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
|
547 return -1; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
548 } 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
|
549 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
|
550 alt_newpath); |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
551 return -1; |
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 return 0; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
554 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
555 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
556 static int |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
557 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
|
558 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
|
559 { |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
560 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
|
561 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
|
562 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
563 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
|
564 newname) < 0) |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
565 return -1; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
566 |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
567 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
|
568 &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
|
569 return 0; |
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 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
|
572 /* ok */ |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
573 } 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
|
574 /* 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
|
575 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
|
576 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 return 0; |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
579 } |
5193f5c6ab5d
dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents:
7331
diff
changeset
|
580 |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
581 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
|
582 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
583 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box; |
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
|
584 const char *path; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
585 |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
586 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
|
587 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
|
588 else { |
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
|
589 path = t_strdup_printf("%s/"DBOX_INDEX_PREFIX".log", |
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
|
590 mbox->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
|
591 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
|
592 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
593 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
594 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
595 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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 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
|
601 { |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
602 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
|
603 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
|
604 int ret = 1; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
605 |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
606 /* 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
|
607 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
|
608 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
|
609 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
|
610 /* it's a file */ |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
611 *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
|
612 return 0; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
613 } |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
614 |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
615 /* need to stat() then */ |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
616 path = t_strconcat(dir, "/", fname, NULL); |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
617 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
|
618 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
|
619 /* non-directory */ |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
620 *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
|
621 ret = 0; |
6806
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
622 } 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
|
623 /* no subdirectories */ |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
624 *flags |= MAILBOX_NOCHILDREN; |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
625 } 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
|
626 /* 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
|
627 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
|
628 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
|
629 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
|
630 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
|
631 *flags |= MAILBOX_CHILDREN; |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
632 } else { |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
633 /* 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
|
634 child mailboxes. */ |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
635 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
|
636 *flags |= MAILBOX_CHILDREN; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
637 } |
7533
7690cdabb3f8
dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents:
7495
diff
changeset
|
638 } 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
|
639 /* 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
|
640 *flags |= MAILBOX_NONEXISTENT; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
641 } else { |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
642 /* 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
|
643 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
|
644 *flags |= MAILBOX_NOSELECT; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
645 } |
7533
7690cdabb3f8
dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents:
7495
diff
changeset
|
646 if ((*flags & (MAILBOX_NOSELECT | MAILBOX_NONEXISTENT)) == 0) { |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
647 /* make sure it's a selectable mailbox */ |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
648 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
|
649 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
|
650 *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
|
651 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
|
652 /* 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
|
653 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
|
654 *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
|
655 else |
5a6aa66e2ccd
dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents:
7829
diff
changeset
|
656 *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
|
657 } |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
658 } |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
659 return ret; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
660 } |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
661 |
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
|
662 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
|
663 { |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
664 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
|
665 } |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
666 |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
667 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
|
668 { |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
669 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
|
670 } |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
671 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
672 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
|
673 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
|
674 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
|
675 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
676 { |
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
|
677 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
|
678 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
|
679 dbox_alloc, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
680 dbox_create, |
7093
f0623745bd4c
libstorage.a shouldn't reference symbols in libstorage_index.a. Changed
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
681 index_storage_destroy, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
682 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
683 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
|
684 dbox_mailbox_create |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
685 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
686 }; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
687 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
688 struct mailbox dbox_mailbox = { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
689 MEMBER(name) NULL, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
690 MEMBER(storage) NULL, |
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 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
693 index_storage_is_readonly, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
694 index_storage_allow_new_keywords, |
7620 | 695 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
|
696 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
|
697 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
|
698 NULL, |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6023
diff
changeset
|
699 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
700 dbox_storage_sync_init, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
701 index_mailbox_sync_next, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
702 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
|
703 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
704 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
|
705 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
|
706 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
|
707 index_transaction_rollback, |
7913
e04513064165
CONDSTORE: STORE UNCHANGEDSINCE conflicts are now checked atomically.
Timo Sirainen <tss@iki.fi>
parents:
7830
diff
changeset
|
708 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
|
709 index_keywords_create, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
710 index_keywords_free, |
8042
0e7a9547be83
Added mailbox_keyword_is_valid().
Timo Sirainen <tss@iki.fi>
parents:
8037
diff
changeset
|
711 index_keyword_is_valid, |
7653
f8e902acfbae
Renamed mailbox_get_uids() to mailbox_get_seq_range().
Timo Sirainen <tss@iki.fi>
parents:
7629
diff
changeset
|
712 index_storage_get_seq_range, |
7654 | 713 index_storage_get_uid_range, |
7629 | 714 index_storage_get_expunged_uids, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
715 dbox_mail_alloc, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
716 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
|
717 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
|
718 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
|
719 index_storage_search_init, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
720 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
|
721 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
|
722 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
|
723 dbox_save_alloc, |
8a068f879cd1
mailbox_save_init() API was split to multiple functions.
Timo Sirainen <tss@iki.fi>
parents:
8042
diff
changeset
|
724 dbox_save_begin, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
725 dbox_save_continue, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
726 dbox_save_finish, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
727 dbox_save_cancel, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
728 mail_storage_copy, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
729 index_storage_is_inconsistent |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
730 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
731 }; |