annotate src/lib-storage/mailbox-list.c @ 5839:978722ad6184 HEAD

s/mask/pattern/ for mailbox listing.
author Timo Sirainen <tss@iki.fi>
date Fri, 29 Jun 2007 19:41:22 +0300
parents ec09ad1d017f
children 272796cfee66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
1 /* Copyright (C) 2006-2007 Timo Sirainen */
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "lib.h"
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "array.h"
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "ioloop.h"
5318
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
6 #include "mkdir-parents.h"
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
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:
diff changeset
8 #include "mailbox-list-private.h"
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include <time.h>
5550
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
11 #include <unistd.h>
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12 #include <dirent.h>
5550
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
13 #include <sys/stat.h>
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 /* 20 * (200+1) < 4096 which is the standard PATH_MAX. Having these settings
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 prevents malicious user from creating eg. "a/a/a/.../a" mailbox name and
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 then start renaming them to larger names from end to beginning, which
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 eventually would start causing the failures when trying to use too
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 long mailbox names. */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 #define MAILBOX_MAX_HIERARCHY_LEVELS 20
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 #define MAILBOX_MAX_HIERARCHY_NAME_LENGTH 200
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 /* Message to show to users when critical error occurs */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 #define CRITICAL_MSG \
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 "Internal error occurred. Refer to server log for more information."
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 #define CRITICAL_MSG_STAMP CRITICAL_MSG " [%Y-%m-%d %H:%M:%S]"
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27
5450
7a6db5ec047d Better type safety to module_contexts arrays. Already fixed some bugs.
Timo Sirainen <tss@iki.fi>
parents: 5448
diff changeset
28 struct mailbox_list_module_register mailbox_list_module_register = { 0 };
4814
Timo Sirainen <tss@iki.fi>
parents: 4808
diff changeset
29
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 void (*hook_mailbox_list_created)(struct mailbox_list *list);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 static ARRAY_DEFINE(mailbox_list_drivers, const struct mailbox_list *);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 static bool mailbox_list_driver_find(const char *name, unsigned int *idx_r)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 const struct mailbox_list *const *drivers;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 unsigned int i, count;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 drivers = array_get(&mailbox_list_drivers, &count);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 for (i = 0; i < count; i++) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 if (strcasecmp(drivers[i]->name, name) == 0) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 *idx_r = i;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 return TRUE;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 return FALSE;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 void mailbox_list_register(const struct mailbox_list *list)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 if (!array_is_created(&mailbox_list_drivers))
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 i_array_init(&mailbox_list_drivers, 4);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 else {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 unsigned int idx;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 if (mailbox_list_driver_find(list->name, &idx)) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 i_fatal("mailbox_list_register(%s): duplicate driver",
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 list->name);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62 array_append(&mailbox_list_drivers, &list, 1);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
65 void mailbox_list_unregister(const struct mailbox_list *list)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
66 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 unsigned int idx;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 if (!mailbox_list_driver_find(list->name, &idx)) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 i_fatal("mailbox_list_unregister(%s): unknown driver",
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 list->name);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 array_delete(&mailbox_list_drivers, idx, 1);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 if (array_count(&mailbox_list_drivers) == 0)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 array_free(&mailbox_list_drivers);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78
5539
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
79 int mailbox_list_init(struct mail_namespace *ns, const char *driver,
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80 const struct mailbox_list_settings *set,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
81 enum mailbox_list_flags flags,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
82 struct mailbox_list **list_r, const char **error_r)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 const struct mailbox_list *const *class_p;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 struct mailbox_list *list;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 unsigned int idx;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 if (!mailbox_list_driver_find(driver, &idx)) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 *error_r = "Unknown mailbox list driver";
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 return -1;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92
5486
61ef8b18a12c assert updates
Timo Sirainen <tss@iki.fi>
parents: 5473
diff changeset
93 i_assert(set->root_dir == NULL || *set->root_dir != '\0');
61ef8b18a12c assert updates
Timo Sirainen <tss@iki.fi>
parents: 5473
diff changeset
94 i_assert(set->subscription_fname == NULL ||
61ef8b18a12c assert updates
Timo Sirainen <tss@iki.fi>
parents: 5473
diff changeset
95 *set->subscription_fname != '\0');
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 class_p = array_idx(&mailbox_list_drivers, idx);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 list = (*class_p)->v.alloc();
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99
5539
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
100 list->ns = ns;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 list->flags = flags;
5550
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
102 list->cached_uid = (uid_t)-1;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
103 list->cached_gid = (gid_t)-1;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
104
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 /* copy settings */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106 list->set.root_dir = p_strdup(list->pool, set->root_dir);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 list->set.index_dir = set->index_dir == NULL ||
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 strcmp(set->index_dir, set->root_dir) == 0 ? NULL :
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 p_strdup(list->pool, set->index_dir);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 list->set.control_dir = set->control_dir == NULL ||
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 strcmp(set->control_dir, set->root_dir) == 0 ? NULL :
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 p_strdup(list->pool, set->control_dir);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113
5617
a0310d7b6971 Fixes for INDEX=MEMORY
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
114 if (list->set.index_dir != NULL &&
a0310d7b6971 Fixes for INDEX=MEMORY
Timo Sirainen <tss@iki.fi>
parents: 5613
diff changeset
115 *list->set.index_dir != '\0') {
5318
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
116 if (mkdir_parents(list->set.index_dir, 0700) < 0 &&
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
117 errno != EEXIST)
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
118 i_error("mkdir(%s) failed: %m", list->set.index_dir);
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
119 }
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
120 if (list->set.control_dir != NULL) {
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
121 if (mkdir_parents(list->set.control_dir, 0700) < 0 &&
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
122 errno != EEXIST)
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
123 i_error("mkdir(%s) failed: %m", list->set.control_dir);
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
124 }
3a3906587641 Create index/control dirs if they don't exist
Timo Sirainen <tss@iki.fi>
parents: 4906
diff changeset
125
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 list->set.inbox_path = p_strdup(list->pool, set->inbox_path);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 list->set.subscription_fname =
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 p_strdup(list->pool, set->subscription_fname);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 list->set.maildir_name = p_strdup(list->pool, set->maildir_name);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4814
diff changeset
131 list->set.mail_storage_flags = set->mail_storage_flags;
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
132 list->set.lock_method = set->lock_method;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4814
diff changeset
133
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134 if ((flags & MAILBOX_LIST_FLAG_DEBUG) != 0) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 i_info("%s: root=%s, index=%s, control=%s, inbox=%s",
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 driver, list->set.root_dir,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 list->set.index_dir == NULL ? "" : list->set.index_dir,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 list->set.control_dir == NULL ?
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139 "" : list->set.control_dir,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140 list->set.inbox_path == NULL ?
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 "" : list->set.inbox_path);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 array_create(&list->module_contexts, list->pool, sizeof(void *), 5);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 if (hook_mailbox_list_created != NULL)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147 hook_mailbox_list_created(list);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4814
diff changeset
149 list->set.mail_storage_flags = NULL;
4876
f1d77064884c Lock handling changes. Everything goes through file-lock API now and there's
Timo Sirainen <tss@iki.fi>
parents: 4848
diff changeset
150 list->set.lock_method = NULL;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4814
diff changeset
151
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 *list_r = list;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153 return 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 void mailbox_list_deinit(struct mailbox_list *list)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
158 i_free_and_null(list->error_string);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 list->v.deinit(list);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163 const char *mailbox_list_get_driver_name(struct mailbox_list *list)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165 return list->name;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 char mailbox_list_get_hierarchy_sep(struct mailbox_list *list)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170 return list->hierarchy_sep;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172
5539
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
173 enum mailbox_list_flags mailbox_list_get_flags(struct mailbox_list *list)
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
174 {
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
175 return list->flags;
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
176 }
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
177
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
178 struct mail_namespace *mailbox_list_get_namespace(struct mailbox_list *list)
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
179 {
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
180 return list->ns;
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
181 }
7d828d1b39ab Added mailbox_list to struct mail_namespace. Added a few functions to get
Timo Sirainen <tss@iki.fi>
parents: 5486
diff changeset
182
5839
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
183 bool mailbox_list_is_valid_pattern(struct mailbox_list *list,
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
184 const char *pattern)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 {
5839
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
186 return list->v.is_valid_pattern(list, pattern);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 bool mailbox_list_is_valid_existing_name(struct mailbox_list *list,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190 const char *name)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192 return list->v.is_valid_existing_name(list, name);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195 bool mailbox_list_is_valid_create_name(struct mailbox_list *list,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
196 const char *name)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
197 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
198 return list->v.is_valid_create_name(list, name);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 const char *mailbox_list_get_path(struct mailbox_list *list, const char *name,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
202 enum mailbox_list_path_type type)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
203 {
5470
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
204 mailbox_list_clear_error(list);
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
205
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 return list->v.get_path(list, name, type);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
208
5550
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
209 int mailbox_list_get_permissions(struct mailbox_list *list, const char *name,
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
210 mode_t *mode_r, uid_t *uid_r, gid_t *gid_r)
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
211 {
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
212 const char *path;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
213 struct stat st;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
214
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
215 mailbox_list_clear_error(list);
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
216
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
217 path = mailbox_list_get_path(list, name,
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
218 MAILBOX_LIST_PATH_TYPE_MAILBOX);
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
219 if (*path == '\0')
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
220 return -1;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
221
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
222 if (stat(path, &st) < 0) {
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
223 if (ENOTFOUND(errno))
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
224 return 0;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
225 mailbox_list_set_critical(list, "stat(%s) failed: %m", path);
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
226 return -1;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
227 }
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
228
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
229 *mode_r = st.st_mode & 0666;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
230
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
231 if (list->cached_uid == (uid_t)-1)
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
232 list->cached_uid = geteuid();
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
233 *uid_r = list->cached_uid == st.st_uid ? (uid_t)-1 : st.st_uid;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
234
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
235 if (S_ISDIR(st.st_mode) && (st.st_mode & S_ISGID) != 0) {
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
236 /* directory's GID is used automatically for new files */
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
237 *gid_r = (gid_t)-1;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
238 } else {
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
239 if (list->cached_gid == (gid_t)-1)
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
240 list->cached_gid = getegid();
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
241 *gid_r = list->cached_gid == st.st_gid ? (gid_t)-1 : st.st_gid;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
242 }
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
243 return 1;
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
244 }
3c8d3c722539 Added mailbox_list_get_permissions() and MAILBOX_LIST_ITER_RAW_LIST.
Timo Sirainen <tss@iki.fi>
parents: 5539
diff changeset
245
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246 const char *mailbox_list_get_temp_prefix(struct mailbox_list *list)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
248 return list->v.get_temp_prefix(list);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
249 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
250
5839
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
251 const char *mailbox_list_join_refpattern(struct mailbox_list *list,
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
252 const char *ref, const char *pattern)
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4814
diff changeset
253 {
5839
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
254 if (list->v.join_refpattern != NULL)
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
255 return list->v.join_refpattern(list, ref, pattern);
5470
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
256
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
257 /* the default implementation: */
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
258 if (*ref != '\0') {
5839
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
259 /* merge reference and pattern */
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
260 pattern = t_strconcat(ref, pattern, NULL);
5470
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
261 }
5839
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
262 return pattern;
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4814
diff changeset
263 }
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4814
diff changeset
264
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
265 int mailbox_list_get_mailbox_name_status(struct mailbox_list *list,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
266 const char *name,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
267 enum mailbox_name_status *status)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
268 {
5470
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
269 mailbox_list_clear_error(list);
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
270
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
271 if (!mailbox_list_is_valid_existing_name(list, name)) {
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
272 *status = MAILBOX_NAME_INVALID;
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
273 return 0;
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
274 }
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
275
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
276 return list->v.get_mailbox_name_status(list, name, status);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
277 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
278
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
279 struct mailbox_list_iterate_context *
5839
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
280 mailbox_list_iter_init(struct mailbox_list *list, const char *pattern,
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
281 enum mailbox_list_iter_flags flags)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
282 {
5473
b5404d36494f cleanup
Timo Sirainen <tss@iki.fi>
parents: 5472
diff changeset
283 mailbox_list_clear_error(list);
b5404d36494f cleanup
Timo Sirainen <tss@iki.fi>
parents: 5472
diff changeset
284
5839
978722ad6184 s/mask/pattern/ for mailbox listing.
Timo Sirainen <tss@iki.fi>
parents: 5807
diff changeset
285 return list->v.iter_init(list, pattern, flags);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287
5807
ec09ad1d017f mailbox_list_iter_next() returns now const pointer.
Timo Sirainen <tss@iki.fi>
parents: 5617
diff changeset
288 const struct mailbox_info *
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289 mailbox_list_iter_next(struct mailbox_list_iterate_context *ctx)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 return ctx->list->v.iter_next(ctx);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
293
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
294 int mailbox_list_iter_deinit(struct mailbox_list_iterate_context **_ctx)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
295 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
296 struct mailbox_list_iterate_context *ctx = *_ctx;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298 *_ctx = NULL;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 return ctx->list->v.iter_deinit(ctx);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
301 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
303 int mailbox_list_set_subscribed(struct mailbox_list *list,
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
304 const char *name, bool set)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305 {
5470
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
306 mailbox_list_clear_error(list);
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
307
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
308 return list->v.set_subscribed(list, name, set);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
311 int mailbox_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: 5318
diff changeset
312 {
5471
7df495c556ff Verify that mailbox name is valid before deleting it.
Timo Sirainen <tss@iki.fi>
parents: 5470
diff changeset
313 if (!mailbox_list_is_valid_existing_name(list, name)) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
314 mailbox_list_set_error(list, MAIL_ERROR_PARAMS,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
315 "Invalid mailbox name");
5471
7df495c556ff Verify that mailbox name is valid before deleting it.
Timo Sirainen <tss@iki.fi>
parents: 5470
diff changeset
316 return -1;
7df495c556ff Verify that mailbox name is valid before deleting it.
Timo Sirainen <tss@iki.fi>
parents: 5470
diff changeset
317 }
5472
21ccc57946b8 cleanup
Timo Sirainen <tss@iki.fi>
parents: 5471
diff changeset
318 if (strcmp(name, "INBOX") == 0) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
319 mailbox_list_set_error(list, MAIL_ERROR_NOTPOSSIBLE,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
320 "INBOX can't be deleted.");
5472
21ccc57946b8 cleanup
Timo Sirainen <tss@iki.fi>
parents: 5471
diff changeset
321 return -1;
21ccc57946b8 cleanup
Timo Sirainen <tss@iki.fi>
parents: 5471
diff changeset
322 }
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
323 return list->v.delete_mailbox(list, name);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
324 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
325
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
326 int mailbox_list_rename_mailbox(struct mailbox_list *list,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
327 const char *oldname, const char *newname)
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
328 {
5470
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
329 if (!mailbox_list_is_valid_existing_name(list, oldname) ||
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
330 !mailbox_list_is_valid_create_name(list, newname)) {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
331 mailbox_list_set_error(list, MAIL_ERROR_PARAMS,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
332 "Invalid mailbox name");
5470
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
333 return -1;
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
334 }
402796d50c3e Moved some common code to mailbox-list.c
Timo Sirainen <tss@iki.fi>
parents: 5450
diff changeset
335
5448
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
336 return list->v.rename_mailbox(list, oldname, newname);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
337 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
338
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
339 int mailbox_list_delete_index_control(struct mailbox_list *list,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
340 const char *name)
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
341 {
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
342 const char *path, *index_dir, *dir;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
343
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
344 path = mailbox_list_get_path(list, name,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
345 MAILBOX_LIST_PATH_TYPE_MAILBOX);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
346
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
347 /* delete the index directory first, so that if we crash we don't
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
348 leave indexes for deleted mailboxes lying around */
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
349 index_dir = mailbox_list_get_path(list, name,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
350 MAILBOX_LIST_PATH_TYPE_INDEX);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
351 if (*index_dir != '\0' && strcmp(index_dir, path) != 0) {
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
352 if (unlink_directory(index_dir, TRUE) < 0 && errno != ENOENT) {
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
353 mailbox_list_set_critical(list,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
354 "unlink_directory(%s) failed: %m", index_dir);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
355 return -1;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
356 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
357 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
358
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
359 /* control directory next */
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
360 dir = mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_CONTROL);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
361 if (*dir != '\0' && strcmp(dir, path) != 0 &&
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
362 strcmp(dir, index_dir) != 0) {
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
363 if (unlink_directory(dir, TRUE) < 0 && errno != ENOENT) {
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
364 mailbox_list_set_critical(list,
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
365 "unlink_directory(%s) failed: %m", dir);
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
366 return -1;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
367 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
368 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
369 return 0;
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
370 }
beabd433cdae Moved delete/rename operations to mailbox_list API. Fixed mbox/maildir to
Timo Sirainen <tss@iki.fi>
parents: 5318
diff changeset
371
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 bool mailbox_list_name_is_too_large(const char *name, char sep)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 unsigned int levels = 1, level_len = 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 for (; *name != '\0'; name++) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377 if (*name == sep) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
378 if (level_len > MAILBOX_MAX_HIERARCHY_NAME_LENGTH)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
379 return TRUE;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
380 levels++;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
381 level_len = 0;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
382 } else {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
383 level_len++;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
384 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
385 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
386
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
387 if (level_len > MAILBOX_MAX_HIERARCHY_NAME_LENGTH)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
388 return TRUE;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
389 if (levels > MAILBOX_MAX_HIERARCHY_LEVELS)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 return TRUE;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
391 return FALSE;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
394 enum mailbox_list_file_type mailbox_list_get_file_type(const struct dirent *d)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 enum mailbox_list_file_type type;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
398 #ifdef HAVE_DIRENT_D_TYPE
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 switch (d->d_type) {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 case DT_UNKNOWN:
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
401 type = MAILBOX_LIST_FILE_TYPE_UNKNOWN;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402 break;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
403 case DT_REG:
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 type = MAILBOX_LIST_FILE_TYPE_FILE;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
405 break;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
406 case DT_DIR:
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407 type = MAILBOX_LIST_FILE_TYPE_DIR;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408 break;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 case DT_LNK:
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 type = MAILBOX_LIST_FILE_TYPE_SYMLINK;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 break;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 default:
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
413 type = MAILBOX_LIST_FILE_TYPE_OTHER;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414 break;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
415 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 #else
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417 type = MAILBOX_LIST_FILE_TYPE_UNKNOWN;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
418 #endif
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
419 return type;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
420 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
421
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
422 const char *mailbox_list_get_last_error(struct mailbox_list *list,
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
423 enum mail_error *error_r)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424 {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
425 *error_r = list->error;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
427 return list->error_string != NULL ? list->error_string :
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
428 "Unknown internal list error";
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
429 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 void mailbox_list_clear_error(struct mailbox_list *list)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
433 i_free_and_null(list->error_string);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
435 list->error = MAIL_ERROR_NONE;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
438 void mailbox_list_set_error(struct mailbox_list *list,
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
439 enum mail_error error, const char *string)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
440 {
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
441 i_free(list->error_string);
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
442 list->error_string = i_strdup(string);
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
443
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
444 list->error = error;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446
4848
967de900c73a Mailbox list indexing and related changes. Currently works only with
Timo Sirainen <tss@iki.fi>
parents: 4814
diff changeset
447 void mailbox_list_set_internal_error(struct mailbox_list *list)
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 struct tm *tm;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450 char str[256];
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 tm = localtime(&ioloop_time);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
454 i_free(list->error_string);
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
455 list->error_string =
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456 strftime(str, sizeof(str), CRITICAL_MSG_STAMP, tm) > 0 ?
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457 i_strdup(str) : i_strdup(CRITICAL_MSG);
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
458 list->error = MAIL_ERROR_TEMP;
4808
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459 }
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
460
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
461 void mailbox_list_set_critical(struct mailbox_list *list, const char *fmt, ...)
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 {
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
463 va_list va;
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 va_start(va, fmt);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 i_error("%s", t_strdup_vprintf(fmt, va));
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467 va_end(va);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469 /* critical errors may contain sensitive data, so let user
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470 see only "Internal error" with a timestamp to make it
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 easier to look from log files the actual error message. */
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472 mailbox_list_set_internal_error(list);
93bc9770f938 Initial code for separation of mailbox accessing and directory layout
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 }
5613
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
474
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
475 bool mailbox_list_set_error_from_errno(struct mailbox_list *list)
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
476 {
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
477 const char *error_string;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
478 enum mail_error error;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
479
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
480 if (!mail_error_from_errno(&error, &error_string))
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
481 return FALSE;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
482
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
483 mailbox_list_set_error(list, error, error_string);
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
484 return TRUE;
f717fb4b31c0 Error handling rewrite.
Timo Sirainen <tss@iki.fi>
parents: 5550
diff changeset
485 }