annotate src/lib-storage/index/dbox/dbox-storage.c @ 5613:f717fb4b31c0 HEAD

Error handling rewrite.
author Timo Sirainen <tss@iki.fi>
date Sun, 13 May 2007 20:10:48 +0300
parents 24b751bc0995
children 5ea33dbddbae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5176
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
1 /* Copyright (C) 2005-2007 Timo Sirainen */
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"
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "mkdir-parents.h"
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "unlink-directory.h"
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
8 #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
9 #include "mail-copy.h"
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "dbox-uidlist.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"
4203
4141aae720fe Fixed memory leaks
Timo Sirainen <tss@iki.fi>
parents: 4196
diff changeset
12 #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
13 #include "dbox-storage.h"
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 #include <stdio.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 #include <stdlib.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 #include <unistd.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 #include <sys/stat.h>
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #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
21
5176
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
22 /* How often to touch the uidlist lock file when using KEEP_LOCKED flag */
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
23 #define DBOX_LOCK_TOUCH_MSECS (10*1000)
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
24
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
25 #define DBOX_LIST_CONTEXT(obj) \
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
26 MODULE_CONTEXT(obj, dbox_mailbox_list_module)
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
27
4969
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
28 const struct dotlock_settings default_uidlist_dotlock_set = {
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
29 MEMBER(temp_prefix) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
30 MEMBER(lock_suffix) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
31
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
32 MEMBER(timeout) 120,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
33 MEMBER(stale_timeout) 60,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
34
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
35 MEMBER(callback) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
36 MEMBER(context) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
37
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
38 MEMBER(use_excl_lock) FALSE
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
39 };
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
40
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
41 const struct dotlock_settings default_file_dotlock_set = {
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
42 MEMBER(temp_prefix) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
43 MEMBER(lock_suffix) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
44
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
45 MEMBER(timeout) 120,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
46 MEMBER(stale_timeout) 60,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
47
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
48 MEMBER(callback) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
49 MEMBER(context) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
50
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
51 MEMBER(use_excl_lock) FALSE
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
52 };
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
53
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
54 static const struct dotlock_settings default_new_file_dotlock_set = {
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
55 MEMBER(temp_prefix) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
56 MEMBER(lock_suffix) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
57
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
58 MEMBER(timeout) 60,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
59 MEMBER(stale_timeout) 30,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
60
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
61 MEMBER(callback) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
62 MEMBER(context) NULL,
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
63
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
64 MEMBER(use_excl_lock) FALSE
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
65 };
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
66
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 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
68 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
69
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
70 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
71 &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
72
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
73 static int
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
74 dbox_list_delete_mailbox(struct mailbox_list *list, const char *name);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
75 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
76 const char *dir, const char *fname,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
77 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
78 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
79
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
80 static bool
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
81 dbox_storage_is_valid_existing_name(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
82 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
83 struct dbox_storage *storage = DBOX_LIST_CONTEXT(list);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
84 const char *p;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
85
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
86 if (!storage->list_module_ctx.super.is_valid_existing_name(list, name))
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 return FALSE;
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
88
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
89 /* Don't allow the mailbox name to end in dbox-Mails */
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
90 p = strrchr(name, '/');
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
91 if (p != NULL)
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
92 name = p + 1;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
93 return strcmp(name, DBOX_MAILDIR_NAME) != 0;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
94 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
95
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
96 static bool
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
97 dbox_storage_is_valid_create_name(struct mailbox_list *list, const char *name)
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
98 {
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
99 struct dbox_storage *storage = DBOX_LIST_CONTEXT(list);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
100 const char *const *tmp;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
101 bool ret = TRUE;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
102
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
103 if (!storage->list_module_ctx.super.is_valid_create_name(list, name))
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
104 return FALSE;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
105
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
106 /* Don't allow creating mailboxes under dbox-Mails */
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
107 t_push();
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
108 for (tmp = t_strsplit(name, "/"); *tmp != NULL; tmp++) {
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
109 if (strcmp(*tmp, DBOX_MAILDIR_NAME) == 0) {
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
110 ret = FALSE;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
111 break;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
112 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
113 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
114 t_pop();
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
115 return ret;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
118 static int
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
119 dbox_get_list_settings(struct mailbox_list_settings *list_set,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
120 const char *data, enum mail_storage_flags flags)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 {
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
122 bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
123 const char *p;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 size_t len;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
126 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
127 list_set->subscription_fname = DBOX_SUBSCRIPTION_FILE_NAME;
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
128 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
129
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130 if (data == NULL || *data == '\0') {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 /* 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
132 if (debug)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 i_info("dbox: mailbox location not given");
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
134 return -1;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 /* <root dir> [:INDEX=<dir>] */
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 if (debug)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 i_info("dbox: data=%s", data);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140 p = strchr(data, ':');
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 if (p == NULL)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
142 list_set->root_dir = data;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 else {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
144 list_set->root_dir = t_strdup_until(data, p);
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 do {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 p++;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 if (strncmp(p, "INDEX=", 6) == 0)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
149 list_set->index_dir = t_strcut(p+6, ':');
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150 p = strchr(p, ':');
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 } while (p != NULL);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 /* strip trailing '/' */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
155 len = strlen(list_set->root_dir);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
156 if (list_set->root_dir[len-1] == '/')
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
157 list_set->root_dir = t_strndup(list_set->root_dir, len-1);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
159 if (list_set->index_dir != NULL &&
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
160 strcmp(list_set->index_dir, "MEMORY") == 0)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
161 list_set->index_dir = "";
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
162 return 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
163 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
165 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
166 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
167 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
168 pool_t pool;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
169
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
170 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
171 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
172 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
173 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
174
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
175 return &storage->storage;
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
176 }
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
177
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
178 static int dbox_create(struct mail_storage *_storage, const char *data)
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
179 {
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
180 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
181 struct mailbox_list_settings list_set;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
182 struct mailbox_list *list;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
183 const char *error;
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
184 struct stat st;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
186 if (dbox_get_list_settings(&list_set, data, _storage->flags) < 0)
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
187 return -1;
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
188 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
189 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
190
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
191 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
192 if (stat(list_set.root_dir, &st) < 0) {
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
193 if (errno != ENOENT) {
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
194 i_error("stat(%s) failed: %m",
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
195 list_set.root_dir);
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
196 }
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
197 return -1;
4859
92c0994a1fcf Added MAIL_STORAGE_FLAG_NO_AUTOCREATE flag which silently fails storage
Timo Sirainen <tss@iki.fi>
parents: 4853
diff changeset
198 }
5499
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
199 } else {
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
200 if (mkdir_parents(list_set.root_dir, CREATE_MODE) < 0 &&
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
201 errno != EEXIST) {
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
202 i_error("mkdir_parents(%s) failed: %m",
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
203 list_set.root_dir);
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
204 return -1;
e1e19a0db57d Minor optimization. If we just checked that the directory existed, don't
Timo Sirainen <tss@iki.fi>
parents: 5468
diff changeset
205 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207
5539
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5499
diff changeset
208 if (mailbox_list_init(_storage->ns, "fs", &list_set,
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
209 mail_storage_get_list_flags(_storage->flags),
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
210 &list, &error) < 0) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
211 i_error("dbox fs: %s", error);
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
212 return -1;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
213 }
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
214 _storage->list = list;
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
215 storage->list_module_ctx.super = list->v;
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
216 list->v.is_valid_existing_name = dbox_storage_is_valid_existing_name;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
217 list->v.is_valid_create_name = dbox_storage_is_valid_create_name;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
218 list->v.iter_is_mailbox = dbox_list_iter_is_mailbox;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
219 list->v.delete_mailbox = dbox_list_delete_mailbox;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
220
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
221 MODULE_CONTEXT_SET_FULL(list, 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
222 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
223
4969
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
224 storage->uidlist_dotlock_set = default_uidlist_dotlock_set;
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
225 storage->file_dotlock_set = default_file_dotlock_set;
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
226 storage->new_file_dotlock_set = default_new_file_dotlock_set;
5461
08b42ced91a6 Removed mail_storage_create_with_data(). mail_storage_create() with
Timo Sirainen <tss@iki.fi>
parents: 5460
diff changeset
227 if ((_storage->flags & MAIL_STORAGE_FLAG_DOTLOCK_USE_EXCL) != 0) {
4969
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
228 storage->uidlist_dotlock_set.use_excl_lock = TRUE;
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
229 storage->file_dotlock_set.use_excl_lock = TRUE;
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
230 storage->new_file_dotlock_set.use_excl_lock = TRUE;
5c18ac362f65 More dotlock_use_excl uses.
Timo Sirainen <tss@iki.fi>
parents: 4949
diff changeset
231 }
5460
105e0cd21036 Added virtual mail_storage.alloc() function and changed create() to work
Timo Sirainen <tss@iki.fi>
parents: 5459
diff changeset
232 return 0;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
233 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
234
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
235 static bool dbox_autodetect(const char *data, enum mail_storage_flags flags)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
236 {
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
237 bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
238 struct stat st;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
239 const char *path;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
240
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
241 data = t_strcut(data, ':');
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
242
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
243 path = t_strconcat(data, "/INBOX/"DBOX_MAILDIR_NAME, NULL);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
244 if (stat(path, &st) < 0) {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
245 if (debug)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246 i_info("dbox autodetect: stat(%s) failed: %m", path);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247 return FALSE;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250 if (!S_ISDIR(st.st_mode)) {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
251 if (debug)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
252 i_info("dbox autodetect: %s not a directory", path);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
253 return FALSE;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
254 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
255 return TRUE;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
256 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
257
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
258 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
259 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
260 if (mkdir_parents(path, CREATE_MODE) < 0 && errno != EEXIST) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
261 if (!mail_storage_set_error_from_errno(storage)) {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
262 mail_storage_set_critical(storage,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
263 "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
264 }
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267 return 0;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
269
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
270 static int create_index_dir(struct mail_storage *storage, const char *name)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
271 {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
272 const char *root_dir, *index_dir;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
273
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
274 root_dir = 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
275 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
276 index_dir = 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
277 MAILBOX_LIST_PATH_TYPE_INDEX);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
278 if (strcmp(index_dir, root_dir) == 0)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279 return 0;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
280
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
281 if (mkdir_parents(index_dir, CREATE_MODE) < 0 && errno != EEXIST) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
282 mail_storage_set_critical(storage, "mkdir(%s) failed: %m",
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
283 index_dir);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
284 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
285 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287 return 0;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
288 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289
5195
840d177c468f cleanup
Timo Sirainen <tss@iki.fi>
parents: 5179
diff changeset
290 static void dbox_lock_touch_timeout(struct dbox_mailbox *mbox)
5176
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
291 {
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
292 (void)dbox_uidlist_lock_touch(mbox->uidlist);
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
293 }
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
294
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 static struct mailbox *
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 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
297 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
298 {
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
299 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
300 struct dbox_mailbox *mbox;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301 struct mail_index *index;
3813
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
302 const char *path, *index_dir, *value;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303 pool_t pool;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
305 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
306 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
307 index_dir = 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
308 MAILBOX_LIST_PATH_TYPE_INDEX);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
310 if (create_dbox(_storage, path) < 0)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311 return NULL;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
312 if (create_index_dir(_storage, name) < 0)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
313 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
314
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
315 index = index_storage_alloc(index_dir, path, DBOX_INDEX_PREFIX);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316
5024
a8a274b4c87c Use larger default pool sizes
Timo Sirainen <tss@iki.fi>
parents: 4999
diff changeset
317 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
318 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
319 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
320 mbox->ibox.box.pool = pool;
5459
78eaf595359c Removed struct index_storage abstraction. It's pointless.
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
321 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
322 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
323 mbox->ibox.index = index;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
324
3813
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
325 value = getenv("DBOX_ROTATE_SIZE");
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
326 if (value != NULL)
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
327 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
328 else
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
329 mbox->rotate_size = DBOX_DEFAULT_ROTATE_SIZE;
3845
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
330 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
331 if (value != NULL)
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
332 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
333 else
18a786df5815 Added dbox_rotate_min_size and fixed rotation checks.
Timo Sirainen <tss@iki.fi>
parents: 3813
diff changeset
334 mbox->rotate_min_size = DBOX_DEFAULT_ROTATE_MIN_SIZE;
3813
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
335 value = getenv("DBOX_ROTATE_DAYS");
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
336 if (value != NULL)
74289963b8a7 Added dbox_rotate_size and dbox_rotate_days settings.
Timo Sirainen <tss@iki.fi>
parents: 3720
diff changeset
337 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
338 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
339 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
340
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
341 mbox->storage = storage;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342 mbox->path = p_strdup(pool, path);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343 mbox->dbox_file_ext_idx =
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 mail_index_ext_register(index, "dbox-seq", 0,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 sizeof(uint32_t), sizeof(uint32_t));
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346 mbox->dbox_offset_ext_idx =
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347 mail_index_ext_register(index, "dbox-off", 0,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
348 sizeof(uint64_t), sizeof(uint64_t));
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 mbox->uidlist = dbox_uidlist_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
351 if ((flags & MAILBOX_OPEN_KEEP_LOCKED) != 0) {
4494
e3157540a801 Make pop3_lock_session work with dbox.
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
352 if (dbox_uidlist_lock(mbox->uidlist) < 0) {
e3157540a801 Make pop3_lock_session work with dbox.
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
353 struct mailbox *box = &mbox->ibox.box;
e3157540a801 Make pop3_lock_session work with dbox.
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
354
e3157540a801 Make pop3_lock_session work with dbox.
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
355 mailbox_close(&box);
e3157540a801 Make pop3_lock_session work with dbox.
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
356 return NULL;
e3157540a801 Make pop3_lock_session work with dbox.
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
357 }
5176
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
358 mbox->keep_lock_to = timeout_add(DBOX_LOCK_TOUCH_MSECS,
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
359 dbox_lock_touch_timeout,
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
360 mbox);
4494
e3157540a801 Make pop3_lock_session work with dbox.
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
361 }
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
362
2f9ac504ee77 When using KEEP_LOCK, the mbox/uidlist file must be locked before index file
Timo Sirainen <tss@iki.fi>
parents: 5177
diff changeset
363 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
364 return &mbox->ibox.box;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
365 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
366
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
367 static struct mailbox *
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368 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
369 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
370 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 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
372 const char *path;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373 struct stat st;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375 if (input != NULL) {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 mail_storage_set_critical(_storage,
4029
9bdd186d7b7d s/Maildir/dbox/
Timo Sirainen <tss@iki.fi>
parents: 4028
diff changeset
377 "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
378 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381 if (strcmp(name, "INBOX") == 0)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 return dbox_open(storage, "INBOX", flags);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
384 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
385 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
386 if (stat(path, &st) == 0) {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 return dbox_open(storage, name, flags);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 } else if (errno == ENOENT) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
389 mail_storage_set_error(_storage, MAIL_ERROR_NOTFOUND,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
390 T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
391 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392 } else {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393 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
394 path);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395 return NULL;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
398
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 static int dbox_mailbox_create(struct mail_storage *_storage,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 const char *name,
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
401 bool directory __attr_unused__)
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402 {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
403 const char *path;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 struct stat st;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
405
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
406 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
407 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
408 if (stat(path, &st) == 0) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
409 mail_storage_set_error(_storage, MAIL_ERROR_NOTPOSSIBLE,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
410 "Mailbox already exists");
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
414 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
415 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
417 static int
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
418 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
419 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
420 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
421 struct stat st;
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
422 const char *path, *mail_path;
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
424 /* make sure the indexes are closed before trying to delete the
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
425 directory that contains them */
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
426 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
427
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
428 /* 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
429 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
430 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
432 path = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_DIR);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
433 mail_path = mailbox_list_get_path(list, name,
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
434 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
435
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 if (stat(mail_path, &st) < 0 && ENOTFOUND(errno)) {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437 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
438 /* doesn't exist at all */
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
439 mailbox_list_set_error(list, MAIL_ERROR_NOTFOUND,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
440 T_MAIL_ERR_MAILBOX_NOT_FOUND(name));
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
441 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444 /* exists as a \NoSelect mailbox */
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445 if (rmdir(path) == 0)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446 return 0;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448 if (errno == ENOTEMPTY) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
449 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
450 t_strdup_printf("Directory %s isn't empty, "
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
451 "can't delete it.", name));
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 } else {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
453 mailbox_list_set_critical(list,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454 "rmdir() failed for %s: %m", path);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459
4296
e4650b4f4e5a Close index files before trying to unlink the index directory
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4276
diff changeset
460
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
461 if (unlink_directory(mail_path, TRUE) < 0) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5562
diff changeset
462 if (!mailbox_list_set_error_from_errno(list)) {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
463 mailbox_list_set_critical(list,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464 "unlink_directory() failed for %s: %m",
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 mail_path);
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467 return -1;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469 /* try also removing the root directory. it can fail if the deleted
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470 mailbox had submailboxes. do it as long as we can. */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
471 while (rmdir(path) == 0 || errno == ENOENT) {
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472 const char *p = strrchr(name, '/');
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474 if (p == NULL)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 break;
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 name = t_strdup_until(name, p);
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
478 path = mailbox_list_get_path(list, name,
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
479 MAILBOX_LIST_PATH_TYPE_DIR);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 return 0;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
483
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
484 static int dbox_storage_close(struct mailbox *box)
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485 {
4203
4141aae720fe Fixed memory leaks
Timo Sirainen <tss@iki.fi>
parents: 4196
diff changeset
486 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box;
4141aae720fe Fixed memory leaks
Timo Sirainen <tss@iki.fi>
parents: 4196
diff changeset
487
5177
53719357e0e4 If KEEP_LOCK is set and we timeout, don't crash.
Timo Sirainen <tss@iki.fi>
parents: 5176
diff changeset
488 if (mbox->keep_lock_to != NULL) {
4494
e3157540a801 Make pop3_lock_session work with dbox.
Timo Sirainen <tss@iki.fi>
parents: 4453
diff changeset
489 dbox_uidlist_unlock(mbox->uidlist);
5176
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
490 timeout_remove(&mbox->keep_lock_to);
5177
53719357e0e4 If KEEP_LOCK is set and we timeout, don't crash.
Timo Sirainen <tss@iki.fi>
parents: 5176
diff changeset
491 }
5176
db7b28a3ffbd If pop3_lock_session=yes, update maildir/dbox uidlist lock file every 10
Timo Sirainen <tss@iki.fi>
parents: 5084
diff changeset
492
4203
4141aae720fe Fixed memory leaks
Timo Sirainen <tss@iki.fi>
parents: 4196
diff changeset
493 dbox_uidlist_deinit(mbox->uidlist);
4141aae720fe Fixed memory leaks
Timo Sirainen <tss@iki.fi>
parents: 4196
diff changeset
494 if (mbox->file != NULL)
4141aae720fe Fixed memory leaks
Timo Sirainen <tss@iki.fi>
parents: 4196
diff changeset
495 dbox_file_close(mbox->file);
5466
8141168f86e1 cleaned up mailbox closing code
Timo Sirainen <tss@iki.fi>
parents: 5465
diff changeset
496 return index_storage_mailbox_close(box);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
497 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
498
5465
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
499 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
500 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
501 struct dbox_mailbox *mbox = (struct dbox_mailbox *)box;
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502
5465
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
503 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
504 index_mailbox_check_remove_all(&mbox->ibox);
5465
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
505 else
014236cf3dcc Moved notify settings to struct mailbox. Removed the parameters from
Timo Sirainen <tss@iki.fi>
parents: 5464
diff changeset
506 index_mailbox_check_add(&mbox->ibox, mbox->path);
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
507 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
508
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
509 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
510 const char *dir, const char *fname,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
511 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
512 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
513 {
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
514 const char *mail_path;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
515 struct stat st;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
516 int ret = 1;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
517
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
518 if (strcmp(fname, DBOX_MAILDIR_NAME) == 0) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
519 *flags = MAILBOX_NOSELECT;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
520 return 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
521 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
522
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
523 /* 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
524 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
525 type != MAILBOX_LIST_FILE_TYPE_SYMLINK &&
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
526 type != MAILBOX_LIST_FILE_TYPE_UNKNOWN &&
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
527 (ctx->flags & MAILBOX_LIST_ITER_FAST_FLAGS) != 0) {
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
528 /* it's a file */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
529 *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
530 return 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
531 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
532
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
533 /* need to stat() then */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
534 t_push();
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
535 mail_path = t_strconcat(dir, "/", fname, "/"DBOX_MAILDIR_NAME, NULL);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
536
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
537 if (stat(mail_path, &st) == 0) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
538 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
539 /* non-directory */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
540 *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
541 ret = 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
542 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
543 } else {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
544 /* non-selectable, but may contain subdirs */
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
545 if (errno != ENOTDIR)
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5195
diff changeset
546 *flags |= MAILBOX_CHILDREN;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
547 *flags |= MAILBOX_NOSELECT;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
548 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
549 t_pop();
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
550
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
551 return ret;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
552 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents: 4606
diff changeset
553
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
554 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
555 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
556 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
557 }
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
558
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
559 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
560 {
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
561 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
562 }
85fcdb478608 Beginnings of joining mail-storage API more closely to mail-index, so that
Timo Sirainen <timo.sirainen@movial.fi>
parents: 4395
diff changeset
563
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
564 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
565 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
566 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
567
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
568 {
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
569 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
570 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
571 dbox_alloc,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
572 dbox_create,
5462
163b48489bc6 Moved all storage destruction code to mail-storage.c and made destroy()
Timo Sirainen <tss@iki.fi>
parents: 5461
diff changeset
573 NULL,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
574 dbox_autodetect,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
575 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
576 dbox_mailbox_create
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
577 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
578 };
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
579
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
580 struct mailbox dbox_mailbox = {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581 MEMBER(name) NULL,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
582 MEMBER(storage) NULL,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
583
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
584 {
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
585 index_storage_is_readonly,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
586 index_storage_allow_new_keywords,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
587 dbox_storage_close,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
588 index_storage_get_status,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
589 dbox_storage_sync_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
590 index_mailbox_sync_next,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
591 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
592 NULL,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
593 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
594 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
595 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
596 index_transaction_rollback,
3720
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
597 index_keywords_create,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
598 index_keywords_free,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
599 index_storage_get_uids,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
600 index_mail_alloc,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
601 index_header_lookup_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
602 index_header_lookup_deinit,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
603 index_storage_search_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
604 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
605 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
606 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
607 dbox_save_init,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
608 dbox_save_continue,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
609 dbox_save_finish,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
610 dbox_save_cancel,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
611 mail_storage_copy,
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
612 index_storage_is_inconsistent
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
613 }
fd0986477809 Initial implementation of Dovecot's own high performance file format, named
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
614 };