Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib-storage/index/dbox/dbox-storage.c @ 7324:1d0de3d644e4 HEAD
LIST: Show \NoSelect status correctly.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 03 Mar 2008 06:20:36 +0200 |
parents | bbafc37e3251 |
children | 9ef06104648a |
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" |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
8 #include "unlink-directory.h" |
6960
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
9 #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
|
10 #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
|
11 #include "mail-copy.h" |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
12 #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
|
13 #include "dbox-index.h" |
4203 | 14 #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
|
15 #include "dbox-storage.h" |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 #include <stdio.h> |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #include <stdlib.h> |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #include <unistd.h> |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
20 #include <dirent.h> |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 #include <sys/stat.h> |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
23 #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
|
24 |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
25 #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
|
26 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
|
27 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
28 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
|
29 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
|
30 |
5450
7a6db5ec047d
Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents:
5448
diff
changeset
|
31 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
|
32 &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
|
33 |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
34 static int |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
35 dbox_list_delete_mailbox(struct mailbox_list *list, const char *name); |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
36 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
|
37 const char *dir, const char *fname, |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
38 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
|
39 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
|
40 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
41 static int |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
42 dbox_get_list_settings(struct mailbox_list_settings *list_set, |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
43 const char *data, enum mail_storage_flags flags, |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
44 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
|
45 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
|
46 { |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3845
diff
changeset
|
47 bool debug = (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
|
48 |
7b745fb85975
Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
49 *layout_r = "fs"; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
50 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
51 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
|
52 list_set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME; |
6804
ed4e708951de
Default maildir_name was missing.
Timo Sirainen <tss@iki.fi>
parents:
6777
diff
changeset
|
53 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
|
54 |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
55 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
|
56 /* 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
|
57 if (debug) |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 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
|
59 *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
|
60 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
61 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
62 |
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: data=%s", data); |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
65 return mailbox_list_settings_parse(data, list_set, layout_r, 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
|
66 error_r); |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
67 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
69 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
|
70 { |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
71 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
|
72 pool_t pool; |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
73 |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
74 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
|
75 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
|
76 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
|
77 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
|
78 |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
79 return &storage->storage; |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
80 } |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
81 |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
82 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
|
83 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
|
84 { |
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 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
|
89 |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
90 if (dbox_get_list_settings(&list_set, data, _storage->flags, |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
91 &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
|
92 return -1; |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
93 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
|
94 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
|
95 |
5461
08b42ced91a6
Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents:
5460
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 *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
|
100 "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
|
101 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
|
102 } 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
|
103 *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
|
104 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
|
105 } 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
|
106 *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
|
107 "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
|
108 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
|
109 } |
5460
105e0cd21036
Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents:
5459
diff
changeset
|
110 return -1; |
4859
92c0994a1fcf
Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents:
4853
diff
changeset
|
111 } |
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
|
112 } 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
|
113 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
|
114 } 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
|
115 *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
|
116 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
|
117 } 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
|
118 *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
|
119 list_set.root_dir); |
93fe72ef59f6
If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents:
7093
diff
changeset
|
120 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
121 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
122 |
6434
7b745fb85975
Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents:
6430
diff
changeset
|
123 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
|
124 return -1; |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
125 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
|
126 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
|
127 _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
|
128 _storage->list->v.delete_mailbox = dbox_list_delete_mailbox; |
6023
56879cc53cec
mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents:
5829
diff
changeset
|
129 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
130 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
|
131 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
|
132 |
6256
0c9b6ff6fb0b
Split mailbox_list_init() to _alloc() and _init(). _init() is called only
Timo Sirainen <tss@iki.fi>
parents:
6062
diff
changeset
|
133 /* 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
|
134 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
|
135 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
|
136 return 0; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
137 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
138 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
139 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
|
140 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
141 if (mkdir_parents(path, CREATE_MODE) < 0 && errno != EEXIST) { |
5613 | 142 if (!mail_storage_set_error_from_errno(storage)) { |
143 mail_storage_set_critical(storage, | |
144 "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
|
145 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
146 return -1; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
147 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
148 return 0; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
149 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
150 |
6668
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
151 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
|
152 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
|
153 { |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
154 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
|
155 |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
156 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
|
157 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
|
158 |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
159 len = strlen(storage->alt_dir); |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
160 if (strncmp(path, storage->alt_dir, len) != 0) |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
161 return t_strconcat(storage->alt_dir, path + len, NULL); |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
162 else |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
163 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
|
164 } |
4a3cc2968040
Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents:
6434
diff
changeset
|
165 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
166 static struct mailbox * |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
167 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
|
168 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
|
169 { |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
170 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
|
171 struct dbox_mailbox *mbox; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
172 struct mail_index *index; |
5618
5ea33dbddbae
Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
173 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
|
174 pool_t pool; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
175 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
176 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
|
177 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
|
178 |
5618
5ea33dbddbae
Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents:
5613
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 |
5024 | 183 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
|
184 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
|
185 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
|
186 mbox->ibox.box.pool = pool; |
5459
78eaf595359c
Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents:
5450
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 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
|
191 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
|
192 mbox->storage = storage; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
193 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
|
194 |
3813
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
195 value = getenv("DBOX_ROTATE_SIZE"); |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
196 if (value != NULL) |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
197 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
|
198 else |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
199 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
|
200 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
|
201 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
|
202 if (value != NULL) |
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
203 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
|
204 else |
18a786df5815
Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents:
3813
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 value = getenv("DBOX_ROTATE_DAYS"); |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
209 if (value != NULL) |
74289963b8a7
Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents:
3720
diff
changeset
|
210 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
|
211 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
|
212 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
|
213 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
214 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
|
215 if (value != NULL) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
216 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
|
217 else |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
218 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
|
219 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
|
220 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
221 mbox->dbox_ext_id = |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
222 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
|
223 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
|
224 sizeof(uint32_t)); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 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
|
229 |
2f9ac504ee77
When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents:
5177
diff
changeset
|
230 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
|
231 return &mbox->ibox.box; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
232 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
233 |
6960
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
234 static bool |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
235 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
|
236 { |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
237 struct stat st; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
238 |
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
|
239 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
|
240 return FALSE; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
241 |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
242 /* 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
|
243 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
|
244 /* 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
|
245 last checked it. */ |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
246 } 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
|
247 /* time to scan */ |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
248 const char *prefix = |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
249 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
|
250 |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
251 (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
|
252 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
|
253 } |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
254 return TRUE; |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
255 } |
99ad673724ad
Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents:
6940
diff
changeset
|
256 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
257 static struct mailbox * |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
258 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
|
259 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
|
260 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
261 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
|
262 const char *path; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
263 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
264 if (input != NULL) { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
265 mail_storage_set_critical(_storage, |
4029 | 266 "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
|
267 return NULL; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
268 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
269 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 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
|
274 else if (errno == ENOENT) { |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
275 if (strcmp(name, "INBOX") == 0) { |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
276 /* INBOX always exists, create it */ |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
277 if (create_dbox(_storage, path) < 0) |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
278 return NULL; |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
279 return dbox_open(storage, name, flags); |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
280 } |
186b164a9579
Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents:
6737
diff
changeset
|
281 |
5613 | 282 mail_storage_set_error(_storage, MAIL_ERROR_NOTFOUND, |
283 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
|
284 } 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
|
285 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
|
286 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
|
287 } else { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
288 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
|
289 path); |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
290 } |
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
|
291 return NULL; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
292 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
293 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
294 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
|
295 { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
296 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
297 int ret; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
298 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
299 ret = dbox_sync(mbox, TRUE); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
300 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
301 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
|
302 dbox_files_free(mbox); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
303 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
|
304 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
305 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
|
306 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
307 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 static int dbox_mailbox_create(struct mail_storage *_storage, |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6340
diff
changeset
|
309 const char *name, bool directory ATTR_UNUSED) |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 { |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
311 const char *path; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
312 struct stat st; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
313 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
314 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
|
315 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
|
316 if (stat(path, &st) == 0) { |
5613 | 317 mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE, |
318 "Mailbox already exists"); | |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 return -1; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
322 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
|
323 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
324 |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
325 static int |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
326 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
|
327 const char *name) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
328 { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
329 DIR *dir; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
330 struct dirent *d; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
331 string_t *full_path; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
332 unsigned int dir_len; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
333 bool unlinked_something = FALSE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
334 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
335 dir = opendir(path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
336 if (dir == NULL) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
337 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
|
338 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
|
339 "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
|
340 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
341 return -1; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
342 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
343 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 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
|
348 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
349 errno = 0; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
350 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
|
351 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
|
352 /* skip . and .. */ |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
353 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
|
354 continue; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
355 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
|
356 continue; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
357 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
358 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
359 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
|
360 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
|
361 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
362 /* 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
|
363 (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
|
364 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
|
365 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
|
366 unlinked_something = TRUE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
367 else if (errno != ENOENT && errno != EISDIR && errno != EPERM) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
368 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
|
369 "unlink_directory(%s) failed: %m", |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
370 str_c(full_path)); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
371 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
372 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
373 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
374 if (closedir(dir) < 0) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
375 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
|
376 path); |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
377 } |
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 if (rmdir(path) == 0) |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
380 unlinked_something = TRUE; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
381 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
|
382 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
|
383 return -1; |
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 |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
386 if (!unlinked_something) { |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
387 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
|
388 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
|
389 "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
|
390 return -1; |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
391 } |
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
392 return 0; |
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 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
|
396 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
|
397 { |
5448
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
398 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
|
399 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
|
400 const char *path, *alt_path; |
7323 | 401 bool deleted = FALSE; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
402 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
403 /* 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
409 /* 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
|
410 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
|
411 return -1; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
412 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
413 /* 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
|
414 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
|
415 MAILBOX_LIST_PATH_TYPE_MAILBOX); |
7323 | 416 if (stat(path, &st) == 0) { |
417 /* delete the mailbox first */ | |
418 if (dbox_delete_nonrecursive(list, path, name) < 0) | |
419 return -1; | |
420 | |
421 alt_path = dbox_get_alt_path(storage, path); | |
422 if (alt_path != NULL) { | |
423 if (dbox_delete_nonrecursive(list, alt_path, name) < 0) | |
424 return -1; | |
425 } | |
426 /* try to delete the directory also */ | |
427 deleted = TRUE; | |
428 path = mailbox_list_get_path(list, name, | |
429 MAILBOX_LIST_PATH_TYPE_DIR); | |
430 } else if (errno != ENOENT) { | |
431 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
|
432 return -1; |
7323 | 433 } else { |
434 /* mailbox not found - what about the directory? */ | |
435 path = mailbox_list_get_path(list, name, | |
436 MAILBOX_LIST_PATH_TYPE_DIR); | |
437 if (stat(path, &st) == 0) { | |
438 /* delete the directory */ | |
439 } else if (errno == ENOENT) { | |
440 mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND, | |
441 T_MAIL_ERR_MAILBOX_NOT_FOUND(name)); | |
442 return -1; | |
443 } else if (!mailbox_list_set_error_from_errno(list)) { | |
444 mailbox_list_set_critical(list, "stat(%s) failed: %m", | |
445 path); | |
446 return -1; | |
447 } | |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
448 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
449 |
7323 | 450 if (rmdir(path) == 0) |
451 return 0; | |
452 else if (errno == ENOTEMPTY) { | |
453 if (deleted) | |
454 return 0; | |
455 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE, | |
456 t_strdup_printf("Directory %s isn't empty, " | |
457 "can't delete it.", name)); | |
458 } else if (!mailbox_list_set_error_from_errno(list)) { | |
459 mailbox_list_set_critical(list, "rmdir() failed for %s: %m", | |
460 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
|
461 } |
7323 | 462 return -1; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
464 |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
465 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
|
466 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
467 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
|
468 const char *path; |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
469 |
5465
014236cf3dcc
Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents:
5464
diff
changeset
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 } |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
479 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
|
480 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
|
481 const char *dir, const char *fname, |
beabd433cdae
Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents:
5195
diff
changeset
|
482 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
|
483 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
|
484 { |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
485 const char *path, *maildir_path; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
486 struct stat st; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
487 int ret = 1; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
488 |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
489 /* 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
|
490 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
|
491 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
|
492 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
|
493 /* it's a file */ |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
494 *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
|
495 return 0; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
496 } |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
497 |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
498 /* need to stat() then */ |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
499 path = t_strconcat(dir, "/", fname, NULL); |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
500 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
|
501 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
|
502 /* non-directory */ |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
503 *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
|
504 ret = 0; |
6806
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
505 } 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
|
506 /* no subdirectories */ |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
507 *flags |= MAILBOX_NOCHILDREN; |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
508 } 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
|
509 /* 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
|
510 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
|
511 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
|
512 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
|
513 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
|
514 *flags |= MAILBOX_CHILDREN; |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
515 } else { |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
516 /* 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
|
517 child mailboxes. */ |
f9e24a274ede
Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents:
6804
diff
changeset
|
518 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
|
519 *flags |= MAILBOX_CHILDREN; |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
520 } |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
521 } else { |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
522 /* 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
|
523 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
|
524 *flags |= MAILBOX_NOSELECT; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
525 } |
7324
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
526 if ((*flags & MAILBOX_NOSELECT) == 0) { |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
527 /* make sure it's a selectable mailbox */ |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
528 maildir_path = t_strconcat(path, "/"DBOX_MAILDIR_NAME, NULL); |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
529 if (stat(maildir_path, &st) < 0 || !S_ISDIR(st.st_mode)) |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
530 *flags |= MAILBOX_NOSELECT; |
1d0de3d644e4
LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents:
7323
diff
changeset
|
531 } |
4808
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
532 return ret; |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
533 } |
93bc9770f938
Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
4606
diff
changeset
|
534 |
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
|
535 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
|
536 { |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
537 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
|
538 } |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
539 |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
540 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
|
541 { |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
542 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
|
543 } |
85fcdb478608
Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4395
diff
changeset
|
544 |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
545 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
|
546 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
|
547 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
|
548 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
549 { |
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
|
550 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
|
551 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
|
552 dbox_alloc, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
553 dbox_create, |
7093
f0623745bd4c
libstorage.a shouldn't reference symbols in libstorage_index.a. Changed
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
554 index_storage_destroy, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
555 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
556 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
|
557 dbox_mailbox_create |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
558 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
559 }; |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
560 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
561 struct mailbox dbox_mailbox = { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
562 MEMBER(name) NULL, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
563 MEMBER(storage) NULL, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
564 |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
565 { |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
566 index_storage_is_readonly, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
567 index_storage_allow_new_keywords, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
568 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
|
569 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
|
570 NULL, |
8341db7a1698
Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents:
6023
diff
changeset
|
571 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
572 dbox_storage_sync_init, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
573 index_mailbox_sync_next, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
574 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
|
575 NULL, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
576 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
|
577 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
|
578 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
|
579 index_transaction_rollback, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
580 index_keywords_create, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
581 index_keywords_free, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
582 index_storage_get_uids, |
6340
7b71ba1250e3
Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents:
6256
diff
changeset
|
583 dbox_mail_alloc, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
584 index_header_lookup_init, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
585 index_header_lookup_deinit, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
586 index_storage_search_init, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
587 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
|
588 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
|
589 index_storage_search_next_update_seq, |
3720
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
590 dbox_save_init, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
591 dbox_save_continue, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
592 dbox_save_finish, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
593 dbox_save_cancel, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
594 mail_storage_copy, |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
595 index_storage_is_inconsistent |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
596 } |
fd0986477809
Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
597 }; |