Commit 4323d352 4323d352150c7af79b9f1699d2130c4cae1e4b88 by Sergey Poznyakoff

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
1 parent 9f1d5ced
......@@ -170,17 +170,14 @@ imap4d_list (struct imap4d_session *session,
mu_folder_t folder;
char *cwd;
struct refinfo refinfo;
size_t seglen;
size_t i;
switch (*wcard)
{
/* Absolute Path in wcard, dump the old ref. */
case '/':
{
ref = calloc (2, 1);
ref[0] = *wcard;
ref = mu_strdup ("/");
wcard++;
}
break;
/* Absolute Path, but take care of things like ~guest/Mail,
......@@ -207,23 +204,22 @@ imap4d_list (struct imap4d_session *session,
ref = mu_strdup (ref);
}
/* Move any directory not containing a wildcard into the reference
So (ref = ~guest, wcard = Mail/folder1/%.vf) -->
(ref = ~guest/Mail/folder1, wcard = %.vf). */
seglen = strcspn (wcard, "%*");
if (seglen)
/* Find the longest directory prefix */
i = strcspn (wcard, "%*");
while (i > 0 && wcard[i - 1] != '/')
i--;
/* Append it to the reference */
if (i)
{
size_t reflen = strlen (ref);
int addslash = (reflen > 0 && ref[reflen-1] != '/');
size_t len = seglen + reflen + addslash + 1;
size_t len = i + reflen + addslash;
ref = realloc (ref, len);
ref = mu_realloc (ref, len);
if (addslash)
ref[reflen++] = '/';
memcpy (ref + reflen, wcard, seglen);
ref[reflen + seglen] = 0;
wcard += seglen;
memcpy (ref + reflen, wcard, i - 1); /* omit the trailing / */
ref[len-1] = 0;
}
/* Allocates. */
......@@ -235,20 +231,6 @@ imap4d_list (struct imap4d_session *session,
"The requested item could not be found.");
}
/* FIXME */
if (wcard[0] == 0)
{
char *p = strrchr (ref, '/');
if (p && p[1])
{
*p++ = 0;
wcard = p;
p = strrchr (cwd, '/');
*p = 0;
}
}
status = mu_folder_create (&folder, cwd);
if (status)
{
......
......@@ -135,6 +135,12 @@ LIST_CHECK([empty reference + INBOX],[list07],
* LIST (\NoInferiors) NIL INBOX
])
LIST_CHECK([empty reference + mailbox],[list08],
["" "search.mbox"],
[dnl
* LIST (\NoInferiors) "/" search.mbox
])
dnl ----------------------------------------------------------------------
m4_popdef([IMAP4D_HOMEDIR])
......
......@@ -71,13 +71,10 @@ retrieve_address (void *item, void *data, size_t idx, char **pval)
return MU_ERR_NOENT;
rc = mu_address_create (&ap->addr, val);
free (val);
switch (rc)
if (rc)
{
case MU_ERR_EMPTY_ADDRESS:
case MU_ERR_NOENT:
return MU_ERR_NOENT;
default:
if (rc == MU_ERR_EMPTY_ADDRESS)
rc = MU_ERR_NOENT;
return rc;
}
}
......