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