summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-05-23 11:33:49 +0300
committerSergey Poznyakoff <gray@gnu.org>2021-05-23 11:33:49 +0300
commitb2ba2052a94f658284875d03e54ea1ac83c29d1c (patch)
tree9853d8ba9210eb863916a121a3f4ad8bce9315b9
parent3f74f2ada1d077751b3b73bbc828c1918dde9ebf (diff)
downloadmailutils-b2ba2052a94f658284875d03e54ea1ac83c29d1c.tar.gz
mailutils-b2ba2052a94f658284875d03e54ea1ac83c29d1c.tar.bz2
Fix the previous commit: take into account "" mailbox names.
* libproto/imap/folder.c (_mu_imap_folder_separator): Use empty mailbox name to get the hierarchy delimiter. * libproto/imap/genlist.c: Take into account eventual hierarchy delimiter queries.
-rw-r--r--libproto/imap/folder.c2
-rw-r--r--libproto/imap/genlist.c29
2 files changed, 28 insertions, 3 deletions
diff --git a/libproto/imap/folder.c b/libproto/imap/folder.c
index efed97f4d..d99b5bc65 100644
--- a/libproto/imap/folder.c
+++ b/libproto/imap/folder.c
@@ -276,7 +276,7 @@ _mu_imap_folder_separator (mu_folder_t folder, int *sep)
if (mu_url_sget_path (folder->url, &path) || strcmp (path, "INBOX") == 0)
path = "";
- rc = mu_imap_list_new (imap, path, "%", &list);
+ rc = mu_imap_list_new (imap, path, "", &list);
if (rc)
return rc;
if (mu_list_head (list, (void**)&resp))
diff --git a/libproto/imap/genlist.c b/libproto/imap/genlist.c
index f55c79333..cff337b6f 100644
--- a/libproto/imap/genlist.c
+++ b/libproto/imap/genlist.c
@@ -78,7 +78,8 @@ list_untagged_handler (mu_imap_t imap, mu_list_t resp, void *data)
_mu_imap_list_nth_element_is_string (resp, 0, clos->command))
{
struct mu_list_response *rp;
-
+ char const *name;
+
rp = calloc (1, sizeof (*rp));
if (!rp)
{
@@ -95,7 +96,31 @@ list_untagged_handler (mu_imap_t imap, mu_list_t resp, void *data)
elt = _mu_imap_list_at (resp, 3);
if (!(elt && elt->type == imap_eltype_string))
return;
- rp->name = strdup (elt->v.string + imap->prefix_len);
+
+ name = elt->v.string;
+ /*
+ * Skip first imap->prefix_len characters of the returned name. This
+ * is the length of the path part in the folder URL. Note, however,
+ * that there is a case when an IMAP server can return a name shorter
+ * than that: namely, when given an empty mailbox (wref) name. As per
+ * RFC 3501:
+ *
+ * An empty ("" string) mailbox name argument is a special request to
+ * return the hierarchy delimiter and the root name of the name given
+ * in the reference.
+ *
+ * The following conditional takes this into account. It is based on
+ * a reasonable assumption that the root name is always shorter than
+ * the reference name.
+ *
+ * FIXME: Perhaps it would be safer to compare with the pathname prefix
+ * instead. To do so, mu_imap_t should include the prefix (or a pointer
+ * to mu_folder_t).
+ */
+ if (strlen (name) > imap->prefix_len)
+ name += imap->prefix_len;
+
+ rp->name = strdup (name);
if (!rp->name)
{
free (rp);

Return to:

Send suggestions and report system problems to the System administrator.