annotate src/lib-storage/index/dbox/dbox-storage.c @ 7830:5a6aa66e2ccd HEAD

dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
author Timo Sirainen <tss@iki.fi>
date Thu, 12 Jun 2008 02:08:16 +0300
parents 1550dc4f24a5
children e04513064165
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7086
7ed926ed7aa4 Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents: 6961
diff changeset
1 /* Copyright (c) 2007-2008 Dovecot authors, see the included COPYING file */
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
4 #include "array.h"
5176
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
5 #include "ioloop.h"
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
6 #include "str.h"
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "mkdir-parents.h"
6960
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
8 #include "unlink-old-files.h"
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
9 #include "index-mail.h"
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "mail-copy.h"
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "dbox-sync.h"
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
12 #include "dbox-index.h"
4203
4141aae720fe Fixed memory leaks
Timo Sirainen <tss@iki.fi>
parents: 4196
diff changeset
13 #include "dbox-file.h"
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 #include "dbox-storage.h"
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #include <stdio.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <stdlib.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include <unistd.h>
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
19 #include <dirent.h>
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #include <sys/stat.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 #define CREATE_MODE 0770 /* umask() should limit it more */
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
24 #define DBOX_LIST_CONTEXT(obj) \
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
25 MODULE_CONTEXT(obj, dbox_mailbox_list_module)
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
26
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 extern struct mail_storage dbox_storage;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28 extern struct mailbox dbox_mailbox;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
30 static MODULE_CONTEXT_DEFINE_INIT(dbox_mailbox_list_module,
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
31 &mailbox_list_module_register);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
32
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
33 static int
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
34 dbox_list_delete_mailbox(struct mailbox_list *list, const char *name);
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
35 static int
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
36 dbox_list_rename_mailbox(struct mailbox_list *list,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
37 const char *oldname, const char *newname);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
38 static int
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
39 dbox_list_rename_mailbox_pre(struct mailbox_list *list,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
40 const char *oldname, const char *newname);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
41 static int dbox_list_iter_is_mailbox(struct mailbox_list_iterate_context *ctx,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
42 const char *dir, const char *fname,
7495
7f7003bcf422 Added mailbox_name parameter to mailbox_list.iter_is_mailbox().
Timo Sirainen <tss@iki.fi>
parents: 7458
diff changeset
43 const char *mailbox_name,
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
44 enum mailbox_list_file_type type,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
45 enum mailbox_info_flags *flags);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
46
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
47 static int
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
48 dbox_get_list_settings(struct mailbox_list_settings *list_set,
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
49 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
50 const char **layout_r, const char **alt_dir_r,
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
51 const char **error_r)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 {
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
53 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
54
7b745fb85975 Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents: 6430
diff changeset
55 *layout_r = "fs";
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
57 memset(list_set, 0, sizeof(*list_set));
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
58 list_set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
6804
ed4e708951de Default maildir_name was missing.
Timo Sirainen <tss@iki.fi>
parents: 6777
diff changeset
59 list_set->maildir_name = DBOX_MAILDIR_NAME;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
61 if (data == NULL || *data == '\0' || *data == ':') {
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 /* we won't do any guessing for this format. */
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 if (debug)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 i_info("dbox: mailbox location not given");
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
65 *error_r = "Root mail directory not given";
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
66 return -1;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 if (debug)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 i_info("dbox: data=%s", data);
6668
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
71 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
72 error_r);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
73 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
75 static struct mail_storage *dbox_alloc(void)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
76 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
77 struct dbox_storage *storage;
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
78 pool_t pool;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
79
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
80 pool = pool_alloconly_create("dbox storage", 512+256);
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
81 storage = p_new(pool, struct dbox_storage, 1);
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
82 storage->storage = dbox_storage;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
83 storage->storage.pool = pool;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
84
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
85 return &storage->storage;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
86 }
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
87
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
88 static int dbox_create(struct mail_storage *_storage, const char *data,
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
89 const char **error_r)
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
90 {
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
91 struct dbox_storage *storage = (struct dbox_storage *)_storage;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
92 struct mailbox_list_settings list_set;
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
93 struct stat st;
6668
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
94 const char *layout, *alt_dir;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
96 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
97 &layout, &alt_dir, error_r) < 0)
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
98 return -1;
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
99 list_set.mail_storage_flags = &_storage->flags;
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
100 list_set.lock_method = &_storage->lock_method;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
101
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
102 if ((_storage->flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) != 0) {
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
103 if (stat(list_set.root_dir, &st) < 0) {
7175
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
104 if (errno == ENOENT) {
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
105 *error_r = t_strdup_printf(
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
106 "Root mail directory doesn't exist: %s",
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
107 list_set.root_dir);
7175
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
108 } else if (errno == EACCES) {
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
109 *error_r = mail_storage_eacces_msg("stat",
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
110 list_set.root_dir);
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
111 } else {
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
112 *error_r = t_strdup_printf(
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
113 "stat(%s) failed: %m",
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
114 list_set.root_dir);
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
115 }
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
116 return -1;
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
117 }
7175
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
118 } else if (mkdir_parents(list_set.root_dir,
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
119 CREATE_MODE) == 0 || errno == EEXIST) {
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
120 } else if (errno == EACCES) {
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
121 *error_r = mail_storage_eacces_msg("mkdir", list_set.root_dir);
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
122 return -1;
5499
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
123 } else {
7175
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
124 *error_r = t_strdup_printf("mkdir(%s) failed: %m",
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
125 list_set.root_dir);
93fe72ef59f6 If mail storage or mailbox can't be accessed because of EACCES, log an error
Timo Sirainen <tss@iki.fi>
parents: 7093
diff changeset
126 return -1;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128
6434
7b745fb85975 Moved mail_location data parsing to a common function. It supports now also
Timo Sirainen <tss@iki.fi>
parents: 6430
diff changeset
129 if (mailbox_list_alloc(layout, &_storage->list, error_r) < 0)
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
130 return -1;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
131 storage->list_module_ctx.super = _storage->list->v;
6668
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
132 storage->alt_dir = p_strdup(_storage->pool, alt_dir);
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
133 _storage->list->v.iter_is_mailbox = dbox_list_iter_is_mailbox;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
134 _storage->list->v.delete_mailbox = dbox_list_delete_mailbox;
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
135 _storage->list->v.rename_mailbox = dbox_list_rename_mailbox;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
136 _storage->list->v.rename_mailbox_pre = dbox_list_rename_mailbox_pre;
6023
56879cc53cec mail_storage.create() now returns error message string. Also fixed handling
Timo Sirainen <tss@iki.fi>
parents: 5829
diff changeset
137
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
138 MODULE_CONTEXT_SET_FULL(_storage->list, dbox_mailbox_list_module,
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
139 storage, &storage->list_module_ctx);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
140
6256
0c9b6ff6fb0b Split mailbox_list_init() to _alloc() and _init(). _init() is called only
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
141 /* finish list init after we've overridden vfuncs */
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
142 mailbox_list_init(_storage->list, _storage->ns, &list_set,
6256
0c9b6ff6fb0b Split mailbox_list_init() to _alloc() and _init(). _init() is called only
Timo Sirainen <tss@iki.fi>
parents: 6062
diff changeset
143 mail_storage_get_list_flags(_storage->flags));
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
144 return 0;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
147 static int create_dbox(struct mail_storage *storage, const char *path)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 if (mkdir_parents(path, CREATE_MODE) < 0 && errno != EEXIST) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
150 if (!mail_storage_set_error_from_errno(storage)) {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
151 mail_storage_set_critical(storage,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
152 "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
153 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 return 0;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158
6668
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
159 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
160 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
161 {
7331
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
162 const char *root;
6668
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
163 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
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 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
166 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
167
7331
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
168 root = mailbox_list_get_path(storage->storage.list, NULL,
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
169 MAILBOX_LIST_PATH_TYPE_DIR);
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
170
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
171 len = strlen(root);
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
172 if (strncmp(path, root, len) != 0 && path[len] == '/') {
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
173 /* can't determine the alt path - shouldn't happen */
6668
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
174 return NULL;
7331
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
175 }
9ef06104648a MAIL_INDEX_MAIL_FLAG_BACKEND specifies if file should be in alt dir or
Timo Sirainen <tss@iki.fi>
parents: 7324
diff changeset
176 return t_strconcat(storage->alt_dir, path + len, NULL);
6668
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
177 }
4a3cc2968040 Support for looking up dbox files from an alternative directory if they're
Timo Sirainen <tss@iki.fi>
parents: 6434
diff changeset
178
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 static struct mailbox *
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 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
181 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
182 {
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
183 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
184 struct dbox_mailbox *mbox;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 struct mail_index *index;
5618
5ea33dbddbae Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
186 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
187 pool_t pool;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
189 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
190 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
191
5618
5ea33dbddbae Moved index directory creation code to index_storage_alloc().
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
192 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
193 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
194 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
195
5024
a8a274b4c87c Use larger default pool sizes
Timo Sirainen <tss@iki.fi>
parents: 4999
diff changeset
196 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
197 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
198 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
199 mbox->ibox.box.pool = pool;
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
200 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
201 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
202 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
203 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
204 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
205 mbox->storage = storage;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
206 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
207
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_SIZE");
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_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
211 else
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
212 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
213 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
214 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
215 if (value != NULL)
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
216 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
217 else
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
218 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
219 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
220 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
221 value = getenv("DBOX_ROTATE_DAYS");
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
222 if (value != NULL)
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
223 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
224 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
225 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
226
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
227 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
228 if (value != NULL)
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
229 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
230 else
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
231 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
232 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
233
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
234 mbox->dbox_ext_id =
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
235 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
236 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
237 sizeof(uint32_t));
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
238 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
239 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
240 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
241 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
242
2f9ac504ee77 When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents: 5177
diff changeset
243 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
244 return &mbox->ibox.box;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246
6960
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
247 static bool
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
248 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
249 {
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
250 struct stat st;
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
251
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
252 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
253 return FALSE;
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
254
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
255 /* 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
256 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
257 /* 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
258 last checked it. */
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
259 } 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
260 /* time to scan */
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
261 const char *prefix =
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
262 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
263
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
264 (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
265 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
266 }
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
267 return TRUE;
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
268 }
99ad673724ad Scan dbox directories every 8 days and delete stale temp files.
Timo Sirainen <tss@iki.fi>
parents: 6940
diff changeset
269
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
270 static struct mailbox *
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 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
272 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
273 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
274 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
275 const char *path;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 if (input != NULL) {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278 mail_storage_set_critical(_storage,
4029
9bdd186d7b7d s/Maildir/dbox/
Timo Sirainen <tss@iki.fi>
parents: 4028
diff changeset
279 "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
280 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
283 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
284 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
285 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
286 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
287 else if (errno == ENOENT) {
186b164a9579 Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents: 6737
diff changeset
288 if (strcmp(name, "INBOX") == 0) {
186b164a9579 Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents: 6737
diff changeset
289 /* INBOX always exists, create it */
186b164a9579 Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents: 6737
diff changeset
290 if (create_dbox(_storage, path) < 0)
186b164a9579 Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents: 6737
diff changeset
291 return NULL;
186b164a9579 Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents: 6737
diff changeset
292 return dbox_open(storage, name, flags);
186b164a9579 Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents: 6737
diff changeset
293 }
186b164a9579 Delay creating directories until we really need them.
Timo Sirainen <tss@iki.fi>
parents: 6737
diff changeset
294
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
295 mail_storage_set_error(_storage, MAIL_ERROR_NOTFOUND,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
296 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
297 } 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
298 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
299 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
300 } else {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301 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
302 path);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303 }
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
304 return NULL;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
307 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
308 {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
309 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box;
7495
7f7003bcf422 Added mailbox_name parameter to mailbox_list.iter_is_mailbox().
Timo Sirainen <tss@iki.fi>
parents: 7458
diff changeset
310 int ret = 0;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
311
7458
43674a726a92 If mailbox hasn't been opened when closing it, don't crash when trying to
Timo Sirainen <tss@iki.fi>
parents: 7403
diff changeset
312 if (box->opened) {
43674a726a92 If mailbox hasn't been opened when closing it, don't crash when trying to
Timo Sirainen <tss@iki.fi>
parents: 7403
diff changeset
313 /* see if we want to flush dirty flags */
43674a726a92 If mailbox hasn't been opened when closing it, don't crash when trying to
Timo Sirainen <tss@iki.fi>
parents: 7403
diff changeset
314 ret = dbox_sync(mbox, TRUE);
43674a726a92 If mailbox hasn't been opened when closing it, don't crash when trying to
Timo Sirainen <tss@iki.fi>
parents: 7403
diff changeset
315 }
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
316
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
317 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
318 dbox_files_free(mbox);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
319 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
320
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
321 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
322 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
323
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324 static int dbox_mailbox_create(struct mail_storage *_storage,
7585
326ca0ed8983 dbox: Support creating non-selectable mailboxes ("directories").
Timo Sirainen <tss@iki.fi>
parents: 7533
diff changeset
325 const char *name, bool directory)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
326 {
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
327 struct dbox_storage *storage = (struct dbox_storage *)_storage;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
328 const char *path, *alt_path;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
329 struct stat st;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
330
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
331 path = mailbox_list_get_path(_storage->list, name,
7585
326ca0ed8983 dbox: Support creating non-selectable mailboxes ("directories").
Timo Sirainen <tss@iki.fi>
parents: 7533
diff changeset
332 directory ? MAILBOX_LIST_PATH_TYPE_DIR :
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
333 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
334 if (stat(path, &st) == 0) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
335 mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
336 "Mailbox already exists");
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
337 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
338 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
339
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
340 /* make sure the alt path doesn't exist yet. it shouldn't (except with
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
341 race conditions with RENAME/DELETE), but if something crashed and
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
342 left it lying around we don't want to start overwriting files in
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
343 it. */
7585
326ca0ed8983 dbox: Support creating non-selectable mailboxes ("directories").
Timo Sirainen <tss@iki.fi>
parents: 7533
diff changeset
344 alt_path = directory ? NULL : dbox_get_alt_path(storage, path);
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
345 if (alt_path != NULL && stat(alt_path, &st) == 0) {
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
346 mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
347 "Mailbox already exists");
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
348 return -1;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
349 }
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
350
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
351 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
352 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
354 static int
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
355 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
356 const char *name)
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 DIR *dir;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
359 struct dirent *d;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
360 string_t *full_path;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
361 unsigned int dir_len;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
362 bool unlinked_something = FALSE;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
363
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
364 dir = opendir(path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
365 if (dir == NULL) {
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
366 if (errno == ENOENT)
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
367 return 0;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
368 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
369 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
370 "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
371 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
372 return -1;
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
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
375 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
376 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
377 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
378 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
379
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
380 errno = 0;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
381 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
382 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
383 /* skip . and .. */
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
384 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
385 continue;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
386 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
387 continue;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
388 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
389
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
390 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
391 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
392
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
393 /* 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
394 (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
395 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
396 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
397 unlinked_something = TRUE;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
398 else if (errno != ENOENT && errno != EISDIR && errno != EPERM) {
7403
da3b83d7928f Error message fixes
Timo Sirainen <tss@iki.fi>
parents: 7355
diff changeset
399 mailbox_list_set_critical(list, "unlink(%s) failed: %m",
da3b83d7928f Error message fixes
Timo Sirainen <tss@iki.fi>
parents: 7355
diff changeset
400 str_c(full_path));
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
401 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
402 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
403
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
404 if (closedir(dir) < 0) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
405 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
406 path);
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
407 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
408
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
409 if (rmdir(path) == 0)
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
410 unlinked_something = TRUE;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
411 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
412 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
413 return -1;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
414 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
415
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
416 if (!unlinked_something) {
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
417 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
418 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
419 "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
420 return -1;
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
421 }
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
422 return 1;
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
423 }
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
424
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
425 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
426 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
427 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
428 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
429 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
430 const char *path, *alt_path;
7323
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
431 bool deleted = FALSE;
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
432 int ret;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
434 /* 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
435 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
436 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
437 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
438 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
439
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
440 /* 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
441 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
442 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
444 /* 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
445 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
446 MAILBOX_LIST_PATH_TYPE_MAILBOX);
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
447 if ((ret = dbox_delete_nonrecursive(list, path, name)) > 0) {
7323
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
448 /* delete the mailbox first */
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
449 alt_path = dbox_get_alt_path(storage, path);
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
450 if (alt_path != NULL) {
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
451 if (dbox_delete_nonrecursive(list, alt_path, name) < 0)
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
452 return -1;
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
453 }
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
454 /* try to delete the directory also */
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
455 deleted = TRUE;
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
456 path = mailbox_list_get_path(list, name,
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
457 MAILBOX_LIST_PATH_TYPE_DIR);
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
458 } else if (errno != ENOENT) {
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
459 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
460 return -1;
7323
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
461 } else {
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
462 /* mailbox not found - what about the directory? */
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
463 path = mailbox_list_get_path(list, name,
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
464 MAILBOX_LIST_PATH_TYPE_DIR);
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
465 if (stat(path, &st) == 0) {
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
466 /* delete the directory */
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
467 } else if (errno == ENOENT) {
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
468 mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
469 T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
470 return -1;
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
471 } else if (!mailbox_list_set_error_from_errno(list)) {
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
472 mailbox_list_set_critical(list, "stat(%s) failed: %m",
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
473 path);
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
474 return -1;
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
475 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
478 alt_path = dbox_get_alt_path(storage, path);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
479 if (alt_path != NULL)
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
480 (void)rmdir(alt_path);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
481
7323
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
482 if (rmdir(path) == 0)
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
483 return 0;
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
484 else if (errno == ENOTEMPTY) {
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
485 if (deleted)
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
486 return 0;
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
487 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
488 t_strdup_printf("Directory %s isn't empty, "
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
489 "can't delete it.", name));
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
490 } else if (!mailbox_list_set_error_from_errno(list)) {
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
491 mailbox_list_set_critical(list, "rmdir() failed for %s: %m",
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
492 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
493 }
7323
bbafc37e3251 Mailbox deletion fixes.
Timo Sirainen <tss@iki.fi>
parents: 7175
diff changeset
494 return -1;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
495 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
496
7355
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
497 static bool
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
498 dbox_list_rename_get_alt_paths(struct mailbox_list *list,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
499 const char *oldname, const char *newname,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
500 const char **oldpath_r, const char **newpath_r)
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
501 {
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
502 struct dbox_storage *storage = DBOX_LIST_CONTEXT(list);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
503 const char *path;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
504
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
505 if (storage->alt_dir == NULL)
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
506 return FALSE;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
507
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
508 path = mailbox_list_get_path(list, oldname, MAILBOX_LIST_PATH_TYPE_DIR);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
509 *oldpath_r = dbox_get_alt_path(storage, path);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
510 if (*oldpath_r == NULL)
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
511 return FALSE;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
512
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
513 path = mailbox_list_get_path(list, newname, MAILBOX_LIST_PATH_TYPE_DIR);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
514 *newpath_r = dbox_get_alt_path(storage, path);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
515 i_assert(*newpath_r != NULL);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
516 return TRUE;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
517 }
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
518
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
519 static int
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
520 dbox_list_rename_mailbox_pre(struct mailbox_list *list,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
521 const char *oldname, const char *newname)
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
522 {
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
523 const char *alt_oldpath, *alt_newpath;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
524 struct stat st;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
525
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
526 if (!dbox_list_rename_get_alt_paths(list, oldname, newname,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
527 &alt_oldpath, &alt_newpath))
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
528 return 0;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
529
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
530 if (stat(alt_newpath, &st) == 0) {
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
531 /* race condition or a directory left there lying around?
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
532 safest to just report error. */
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
533 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
534 "Target mailbox already exists");
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
535 return -1;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
536 } else if (errno != ENOENT) {
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
537 mailbox_list_set_critical(list, "stat(%s) failed: %m",
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
538 alt_newpath);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
539 return -1;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
540 }
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
541 return 0;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
542 }
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
543
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
544 static int
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
545 dbox_list_rename_mailbox(struct mailbox_list *list,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
546 const char *oldname, const char *newname)
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
547 {
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
548 struct dbox_storage *storage = DBOX_LIST_CONTEXT(list);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
549 const char *alt_oldpath, *alt_newpath;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
550
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
551 if (storage->list_module_ctx.super.rename_mailbox(list, oldname,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
552 newname) < 0)
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
553 return -1;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
554
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
555 if (!dbox_list_rename_get_alt_paths(list, oldname, newname,
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
556 &alt_oldpath, &alt_newpath))
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
557 return 0;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
558
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
559 if (rename(alt_oldpath, alt_newpath) == 0) {
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
560 /* ok */
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
561 } else if (errno != ENOENT) {
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
562 /* renaming is done already, so just log the error */
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
563 mailbox_list_set_critical(list, "rename(%s, %s) failed: %m",
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
564 alt_oldpath, alt_newpath);
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
565 }
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
566 return 0;
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
567 }
5193f5c6ab5d dbox: Fixes to creating, deleting and renaming mailboxes when using alt
Timo Sirainen <tss@iki.fi>
parents: 7331
diff changeset
568
5465
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
569 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
570 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
571 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
572 const char *path;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
573
5465
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
574 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
575 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
576 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
577 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
578 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
579 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
580 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
582
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
583 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
584 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
585 const char *dir, const char *fname,
7495
7f7003bcf422 Added mailbox_name parameter to mailbox_list.iter_is_mailbox().
Timo Sirainen <tss@iki.fi>
parents: 7458
diff changeset
586 const char *mailbox_name ATTR_UNUSED,
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
587 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
588 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
589 {
7324
1d0de3d644e4 LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents: 7323
diff changeset
590 const char *path, *maildir_path;
7829
1550dc4f24a5 dbox: Set MAILBOX_CHILDREN flag for \NoSelect mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7798
diff changeset
591 struct stat st, st2;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
592 int ret = 1;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
593
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
594 /* 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
595 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
596 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
597 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
598 /* it's a file */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
599 *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
600 return 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
601 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
602
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
603 /* need to stat() then */
7324
1d0de3d644e4 LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents: 7323
diff changeset
604 path = t_strconcat(dir, "/", fname, NULL);
1d0de3d644e4 LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents: 7323
diff changeset
605 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
606 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
607 /* non-directory */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
608 *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
609 ret = 0;
6806
f9e24a274ede Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents: 6804
diff changeset
610 } 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
611 /* no subdirectories */
f9e24a274ede Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents: 6804
diff changeset
612 *flags |= MAILBOX_NOCHILDREN;
f9e24a274ede Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents: 6804
diff changeset
613 } 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
614 /* 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
615 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
616 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
617 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
618 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
619 *flags |= MAILBOX_CHILDREN;
f9e24a274ede Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents: 6804
diff changeset
620 } else {
f9e24a274ede Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents: 6804
diff changeset
621 /* 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
622 child mailboxes. */
f9e24a274ede Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents: 6804
diff changeset
623 if (st.st_nlink > 2)
f9e24a274ede Return children state based on directory links count if possible.
Timo Sirainen <tss@iki.fi>
parents: 6804
diff changeset
624 *flags |= MAILBOX_CHILDREN;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
625 }
7533
7690cdabb3f8 dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents: 7495
diff changeset
626 } else if (errno == ENOENT) {
7690cdabb3f8 dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents: 7495
diff changeset
627 /* doesn't exist - probably a non-existing subscribed mailbox */
7690cdabb3f8 dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents: 7495
diff changeset
628 *flags |= MAILBOX_NONEXISTENT;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
629 } else {
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
630 /* 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
631 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
632 *flags |= MAILBOX_NOSELECT;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
633 }
7533
7690cdabb3f8 dbox & cydir: If mailbox doesn't exist, return it as \nonexistent instead of
Timo Sirainen <tss@iki.fi>
parents: 7495
diff changeset
634 if ((*flags & (MAILBOX_NOSELECT | MAILBOX_NONEXISTENT)) == 0) {
7324
1d0de3d644e4 LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents: 7323
diff changeset
635 /* make sure it's a selectable mailbox */
1d0de3d644e4 LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents: 7323
diff changeset
636 maildir_path = t_strconcat(path, "/"DBOX_MAILDIR_NAME, NULL);
7830
5a6aa66e2ccd dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7829
diff changeset
637 if (stat(maildir_path, &st2) < 0 || !S_ISDIR(st2.st_mode))
7324
1d0de3d644e4 LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents: 7323
diff changeset
638 *flags |= MAILBOX_NOSELECT;
7830
5a6aa66e2ccd dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7829
diff changeset
639 if (st.st_nlink == 3 && *ctx->list->set.maildir_name != '\0') {
5a6aa66e2ccd dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7829
diff changeset
640 /* now we know what link count 3 means. */
5a6aa66e2ccd dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7829
diff changeset
641 if ((*flags & MAILBOX_NOSELECT) != 0)
7829
1550dc4f24a5 dbox: Set MAILBOX_CHILDREN flag for \NoSelect mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7798
diff changeset
642 *flags |= MAILBOX_CHILDREN;
7830
5a6aa66e2ccd dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7829
diff changeset
643 else
5a6aa66e2ccd dbox: Set MAILBOX_NOCHILDREN flag for selectable mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7829
diff changeset
644 *flags |= MAILBOX_NOCHILDREN;
7829
1550dc4f24a5 dbox: Set MAILBOX_CHILDREN flag for \NoSelect mailboxes if we know it.
Timo Sirainen <tss@iki.fi>
parents: 7798
diff changeset
645 }
7324
1d0de3d644e4 LIST: Show \NoSelect status correctly.
Timo Sirainen <tss@iki.fi>
parents: 7323
diff changeset
646 }
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
647 return ret;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
648 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
649
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
650 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
651 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
652 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
653 }
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
654
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
655 static void dbox_class_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
656 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
657 dbox_transaction_class_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
658 }
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
659
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
660 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
661 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
662 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
663
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
664 {
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
665 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
666 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
667 dbox_alloc,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
668 dbox_create,
7093
f0623745bd4c libstorage.a shouldn't reference symbols in libstorage_index.a. Changed
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
669 index_storage_destroy,
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
670 NULL,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
671 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
672 dbox_mailbox_create
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
673 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
674 };
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
675
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
676 struct mailbox dbox_mailbox = {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
677 MEMBER(name) NULL,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
678 MEMBER(storage) NULL,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
679
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
680 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
681 index_storage_is_readonly,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
682 index_storage_allow_new_keywords,
7620
4b8c1c164d8f Initial CONDSTORE support.
Timo Sirainen <tss@iki.fi>
parents: 7403
diff changeset
683 index_storage_mailbox_enable,
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
684 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
685 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
686 NULL,
8341db7a1698 Moved mailbox list index sync stamp checking and updating to
Timo Sirainen <tss@iki.fi>
parents: 6023
diff changeset
687 NULL,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
688 dbox_storage_sync_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
689 index_mailbox_sync_next,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
690 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
691 NULL,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
692 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
693 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
694 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
695 index_transaction_rollback,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
696 index_keywords_create,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
697 index_keywords_free,
7653
f8e902acfbae Renamed mailbox_get_uids() to mailbox_get_seq_range().
Timo Sirainen <tss@iki.fi>
parents: 7629
diff changeset
698 index_storage_get_seq_range,
7654
1004a3555a03 Added mailbox_get_uid_range().
Timo Sirainen <tss@iki.fi>
parents: 7653
diff changeset
699 index_storage_get_uid_range,
7629
bad3a811a148 Added QRESYNC support.
Timo Sirainen <tss@iki.fi>
parents: 7620
diff changeset
700 index_storage_get_expunged_uids,
6340
7b71ba1250e3 Initial commit for dbox redesign/rewrite. Currently supports only one
Timo Sirainen <tss@iki.fi>
parents: 6256
diff changeset
701 dbox_mail_alloc,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
702 index_header_lookup_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
703 index_header_lookup_deinit,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
704 index_storage_search_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
705 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
706 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
707 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
708 dbox_save_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
709 dbox_save_continue,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
710 dbox_save_finish,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
711 dbox_save_cancel,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
712 mail_storage_copy,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
713 index_storage_is_inconsistent
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
714 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
715 };