imap: fix LIST "" "mbox"
* imap4d/list.c (imap4d_list): Move the longest directory prefix to the reference. * imap4d/tests/list.at: New testcase. * libmu_sieve/tests.c: Fix bug introduced by previous commit
Showing
3 changed files
with
21 additions
and
36 deletions
... | @@ -170,17 +170,14 @@ imap4d_list (struct imap4d_session *session, | ... | @@ -170,17 +170,14 @@ imap4d_list (struct imap4d_session *session, |
170 | mu_folder_t folder; | 170 | mu_folder_t folder; |
171 | char *cwd; | 171 | char *cwd; |
172 | struct refinfo refinfo; | 172 | struct refinfo refinfo; |
173 | size_t seglen; | 173 | size_t i; |
174 | 174 | ||
175 | switch (*wcard) | 175 | switch (*wcard) |
176 | { | 176 | { |
177 | /* Absolute Path in wcard, dump the old ref. */ | 177 | /* Absolute Path in wcard, dump the old ref. */ |
178 | case '/': | 178 | case '/': |
179 | { | 179 | ref = mu_strdup ("/"); |
180 | ref = calloc (2, 1); | ||
181 | ref[0] = *wcard; | ||
182 | wcard++; | 180 | wcard++; |
183 | } | ||
184 | break; | 181 | break; |
185 | 182 | ||
186 | /* Absolute Path, but take care of things like ~guest/Mail, | 183 | /* Absolute Path, but take care of things like ~guest/Mail, |
... | @@ -207,23 +204,22 @@ imap4d_list (struct imap4d_session *session, | ... | @@ -207,23 +204,22 @@ imap4d_list (struct imap4d_session *session, |
207 | ref = mu_strdup (ref); | 204 | ref = mu_strdup (ref); |
208 | } | 205 | } |
209 | 206 | ||
210 | /* Move any directory not containing a wildcard into the reference | 207 | /* Find the longest directory prefix */ |
211 | So (ref = ~guest, wcard = Mail/folder1/%.vf) --> | 208 | i = strcspn (wcard, "%*"); |
212 | (ref = ~guest/Mail/folder1, wcard = %.vf). */ | 209 | while (i > 0 && wcard[i - 1] != '/') |
213 | seglen = strcspn (wcard, "%*"); | 210 | i--; |
214 | 211 | /* Append it to the reference */ | |
215 | if (seglen) | 212 | if (i) |
216 | { | 213 | { |
217 | size_t reflen = strlen (ref); | 214 | size_t reflen = strlen (ref); |
218 | int addslash = (reflen > 0 && ref[reflen-1] != '/'); | 215 | int addslash = (reflen > 0 && ref[reflen-1] != '/'); |
219 | size_t len = seglen + reflen + addslash + 1; | 216 | size_t len = i + reflen + addslash; |
220 | 217 | ||
221 | ref = realloc (ref, len); | 218 | ref = mu_realloc (ref, len); |
222 | if (addslash) | 219 | if (addslash) |
223 | ref[reflen++] = '/'; | 220 | ref[reflen++] = '/'; |
224 | memcpy (ref + reflen, wcard, seglen); | 221 | memcpy (ref + reflen, wcard, i - 1); /* omit the trailing / */ |
225 | ref[reflen + seglen] = 0; | 222 | ref[len-1] = 0; |
226 | wcard += seglen; | ||
227 | } | 223 | } |
228 | 224 | ||
229 | /* Allocates. */ | 225 | /* Allocates. */ |
... | @@ -235,20 +231,6 @@ imap4d_list (struct imap4d_session *session, | ... | @@ -235,20 +231,6 @@ imap4d_list (struct imap4d_session *session, |
235 | "The requested item could not be found."); | 231 | "The requested item could not be found."); |
236 | } | 232 | } |
237 | 233 | ||
238 | /* FIXME */ | ||
239 | if (wcard[0] == 0) | ||
240 | { | ||
241 | char *p = strrchr (ref, '/'); | ||
242 | if (p && p[1]) | ||
243 | { | ||
244 | *p++ = 0; | ||
245 | wcard = p; | ||
246 | |||
247 | p = strrchr (cwd, '/'); | ||
248 | *p = 0; | ||
249 | } | ||
250 | } | ||
251 | |||
252 | status = mu_folder_create (&folder, cwd); | 234 | status = mu_folder_create (&folder, cwd); |
253 | if (status) | 235 | if (status) |
254 | { | 236 | { | ... | ... |
... | @@ -135,6 +135,12 @@ LIST_CHECK([empty reference + INBOX],[list07], | ... | @@ -135,6 +135,12 @@ LIST_CHECK([empty reference + INBOX],[list07], |
135 | * LIST (\NoInferiors) NIL INBOX | 135 | * LIST (\NoInferiors) NIL INBOX |
136 | ]) | 136 | ]) |
137 | 137 | ||
138 | LIST_CHECK([empty reference + mailbox],[list08], | ||
139 | ["" "search.mbox"], | ||
140 | [dnl | ||
141 | * LIST (\NoInferiors) "/" search.mbox | ||
142 | ]) | ||
143 | |||
138 | dnl ---------------------------------------------------------------------- | 144 | dnl ---------------------------------------------------------------------- |
139 | 145 | ||
140 | m4_popdef([IMAP4D_HOMEDIR]) | 146 | m4_popdef([IMAP4D_HOMEDIR]) | ... | ... |
... | @@ -71,13 +71,10 @@ retrieve_address (void *item, void *data, size_t idx, char **pval) | ... | @@ -71,13 +71,10 @@ retrieve_address (void *item, void *data, size_t idx, char **pval) |
71 | return MU_ERR_NOENT; | 71 | return MU_ERR_NOENT; |
72 | rc = mu_address_create (&ap->addr, val); | 72 | rc = mu_address_create (&ap->addr, val); |
73 | free (val); | 73 | free (val); |
74 | switch (rc) | 74 | if (rc) |
75 | { | 75 | { |
76 | case MU_ERR_EMPTY_ADDRESS: | 76 | if (rc == MU_ERR_EMPTY_ADDRESS) |
77 | case MU_ERR_NOENT: | 77 | rc = MU_ERR_NOENT; |
78 | return MU_ERR_NOENT; | ||
79 | |||
80 | default: | ||
81 | return rc; | 78 | return rc; |
82 | } | 79 | } |
83 | } | 80 | } | ... | ... |
-
Please register or sign in to post a comment