imap4d: uniformly use mailbox name and record for opening mailboxes
This avoids problems with escaping pathnames that contain characters specific for URLs * imap4d/select.c (imap4d_select0): Don't use mailbox URL. * lib/manlock.c (manlock_open_mailbox_from_record): New function. * lib/muaux.h (manlock_open_mailbox_from_record): New proto.
Showing
3 changed files
with
34 additions
and
4 deletions
... | @@ -38,6 +38,7 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname, | ... | @@ -38,6 +38,7 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname, |
38 | { | 38 | { |
39 | int status; | 39 | int status; |
40 | char *mailbox_name; | 40 | char *mailbox_name; |
41 | mu_record_t record; | ||
41 | 42 | ||
42 | /* FIXME: Check state. */ | 43 | /* FIXME: Check state. */ |
43 | 44 | ||
... | @@ -59,24 +60,25 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname, | ... | @@ -59,24 +60,25 @@ imap4d_select0 (struct imap4d_command *command, const char *mboxname, |
59 | 60 | ||
60 | if (strcmp (mboxname, "INBOX") == 0) | 61 | if (strcmp (mboxname, "INBOX") == 0) |
61 | flags |= MU_STREAM_CREAT; | 62 | flags |= MU_STREAM_CREAT; |
62 | mailbox_name = namespace_translate_name (mboxname, 1, NULL); | 63 | mailbox_name = namespace_get_name (mboxname, &record, NULL); |
63 | 64 | ||
64 | if (!mailbox_name) | 65 | if (!mailbox_name) |
65 | return io_completion_response (command, RESP_NO, "Couldn't open mailbox"); | 66 | return io_completion_response (command, RESP_NO, "Couldn't open mailbox"); |
66 | 67 | ||
67 | if (flags & MU_STREAM_WRITE) | 68 | if (flags & MU_STREAM_WRITE) |
68 | { | 69 | { |
69 | status = manlock_open_mailbox (&mbox, mailbox_name, 1, flags); | 70 | status = manlock_open_mailbox_from_record (&mbox, record, |
71 | mailbox_name, flags); | ||
70 | if (status) | 72 | if (status) |
71 | flags &= ~MU_STREAM_WRITE; | 73 | flags &= ~MU_STREAM_WRITE; |
72 | } | 74 | } |
73 | 75 | ||
74 | if (!(flags & MU_STREAM_WRITE)) | 76 | if (!(flags & MU_STREAM_WRITE)) |
75 | { | 77 | { |
76 | status = mu_mailbox_create_default (&mbox, mailbox_name); | 78 | status = mu_mailbox_create_from_record (&mbox, record, mailbox_name); |
77 | 79 | ||
78 | if (status) | 80 | if (status) |
79 | mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_create_default", | 81 | mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_create_from_record", |
80 | mailbox_name, | 82 | mailbox_name, |
81 | status); | 83 | status); |
82 | else | 84 | else | ... | ... |
... | @@ -183,6 +183,31 @@ manlock_open_mailbox (mu_mailbox_t *pmbox, const char *mailbox_name, int def, | ... | @@ -183,6 +183,31 @@ manlock_open_mailbox (mu_mailbox_t *pmbox, const char *mailbox_name, int def, |
183 | return status; | 183 | return status; |
184 | } | 184 | } |
185 | 185 | ||
186 | int | ||
187 | manlock_open_mailbox_from_record (mu_mailbox_t *pmbox, mu_record_t record, | ||
188 | const char *mailbox_name, int flags) | ||
189 | { | ||
190 | mu_mailbox_t mbox; | ||
191 | int status; | ||
192 | |||
193 | status = mu_mailbox_create_from_record (&mbox, record, mailbox_name); | ||
194 | if (status) | ||
195 | { | ||
196 | mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_create_from_record", | ||
197 | mailbox_name, | ||
198 | status); | ||
199 | return 1; | ||
200 | } | ||
201 | |||
202 | status = mailbox_open_and_lock (mbox, flags); | ||
203 | |||
204 | if (status == 0) | ||
205 | *pmbox = mbox; | ||
206 | else | ||
207 | mu_mailbox_destroy (&mbox); | ||
208 | |||
209 | return status; | ||
210 | } | ||
186 | 211 | ||
187 | struct mu_cfg_param manlock_param[] = { | 212 | struct mu_cfg_param manlock_param[] = { |
188 | { "enable", mu_c_bool, &manlock_mandatory_locking, 0, NULL, | 213 | { "enable", mu_c_bool, &manlock_mandatory_locking, 0, NULL, | ... | ... |
... | @@ -24,6 +24,9 @@ extern char *manlock_lock_dir; | ... | @@ -24,6 +24,9 @@ extern char *manlock_lock_dir; |
24 | 24 | ||
25 | int manlock_open_mailbox (mu_mailbox_t *pmbox, const char *mailbox_name, | 25 | int manlock_open_mailbox (mu_mailbox_t *pmbox, const char *mailbox_name, |
26 | int def, int flags); | 26 | int def, int flags); |
27 | int manlock_open_mailbox_from_record (mu_mailbox_t *pmbox, mu_record_t record, | ||
28 | const char *mailbox_name, int flags); | ||
29 | |||
27 | int manlock_lock (mu_mailbox_t mbox); | 30 | int manlock_lock (mu_mailbox_t mbox); |
28 | int manlock_touchlock (mu_mailbox_t mbox); | 31 | int manlock_touchlock (mu_mailbox_t mbox); |
29 | int manlock_unlock (mu_mailbox_t mbox); | 32 | int manlock_unlock (mu_mailbox_t mbox); | ... | ... |
-
Please register or sign in to post a comment