showparents = 1;
if (!home_namespace) showparents = 1;
int imap_init_browse (char *path, struct browser_state *state){  CONNECTION *conn;  IMAP_DATA *idata;  char buf[LONG_STRING];  char nsbuf[LONG_STRING];  char mbox[LONG_STRING];  char list_cmd[5];  char seq[16];  IMAP_NAMESPACE_INFO nsi[16];  int home_namespace = 0;  int n;  int i;  int nsup;  char ctmp;  int nns;  char *cur_folder;  short showparents = 0;  int noselect;  int noinferiors;  IMAP_MBOX mx;  if (imap_parse_path (path, &mx))  {    mutt_error ("%s is an invalid IMAP path", path);    return -1;  }  strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST", sizeof (list_cmd));  conn = mutt_socket_select_connection (&mx, 0);  idata = CONN_DATA;  if (!idata || (idata->state == IMAP_DISCONNECTED))  {    if (!idata)    {      /* The current connection is a new connection */      idata = safe_calloc (1, sizeof (IMAP_DATA));      conn->data = idata;      idata->conn = conn;    }    if (imap_open_connection (idata, conn))      return (-1);  }  if (mx.mbox[0] == '\0')  {    home_namespace = 1;    mbox[0] = 0;		/* Do not replace "" with "INBOX" here */    mx.mbox = ImapHomeNamespace;    nns = 0;    if (mutt_bit_isset(idata->capabilities,NAMESPACE))    {      if (get_namespace (idata, nsbuf, sizeof (nsbuf), 			 nsi, sizeof (nsi),  &nns) != 0)	return (-1);      if (verify_namespace (conn, nsi, nns) != 0)	return (-1);    }    if (!mx.mbox)		/* Any explicitly set imap_home_namespace wins */    {       for (i = 0; i < nns; i++)	if (nsi[i].listable &&	    (nsi[i].type == IMAP_NS_PERSONAL || nsi[i].type == IMAP_NS_SHARED))	{	  mx.mbox = nsi->prefix;	  nsi->home_namespace = 1;	  break;	}    }  }  mutt_message _("Contacted server, getting folder list...");  if (mx.mbox && mx.mbox[0] != '\0')  {    imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));    n = mutt_strlen (mbox);    dprint (3, (debugfile, "imap_init_browse: mbox: %s\n", mbox));    /* if our target exists, has inferiors and isn't selectable, enter it if we     * aren't already going to */    if (mbox[n-1] != idata->delim)    {      imap_make_sequence (seq, sizeof (seq));      snprintf (buf, sizeof (buf), "%s %s \"\" \"%s\"\r\n", seq, list_cmd,        mbox);      mutt_socket_write (conn, buf);      do       {        if (imap_parse_list_response(conn, buf, sizeof(buf), &cur_folder,    	    &noselect, &noinferiors, &(idata->delim)) != 0)          return -1;        if (cur_folder)        {          imap_unquote_string (cur_folder);          if (noselect && !noinferiors && cur_folder[0] &&            (n = strlen (mbox)) < LONG_STRING-1)          {            mbox[n++] = idata->delim;            mbox[n] = '\0';          }        }      }      while ((mutt_strncmp (buf, seq, SEQLEN) != 0));    }    /* if we're descending a folder, mark it as current in browser_state */    if (mbox[n-1] == idata->delim)    {      showparents = 1;      imap_qualify_path (buf, sizeof (buf), &mx, mbox, NULL);      state->folder = safe_strdup (buf);      n--;    }    /* Find superiors to list     * Note: UW-IMAP servers return folder + delimiter when asked to list     *  folder + delimiter. Cyrus servers don't. So we ask for folder,     *  and tack on delimiter ourselves. */    for (n--; n >= 0 && mbox[n] != idata->delim ; n--);    if (n > 0)			/* "aaaa/bbbb/" -> "aaaa" */    {      ctmp = mbox[n];      mbox[n] = '\0';      /* List it to see if it can be selected */      dprint (2, (debugfile, "imap_init_browse: listing possible parent %s\n", mbox));      imap_make_sequence (seq, sizeof (seq));      snprintf (buf, sizeof (buf), "%s %s \"\" \"%s\"\r\n", seq,         list_cmd, mbox);      /* add this entry as a superior, if we aren't tab-completing */      if (showparents && add_list_result (conn, seq, buf, state, 1))          return -1;      /* if our target isn't a folder, we are in our superior */      if (!state->folder)      {        /* store folder with delimiter */        mbox[n++] = ctmp;        ctmp = mbox[n];        mbox[n] = '\0';        imap_qualify_path (buf, sizeof (buf), &mx, mbox, NULL);        state->folder = safe_strdup (buf);      }      mbox[n] = ctmp;    }     /* "/bbbb/" -> add  "/", "aaaa/" -> add "" */    else    {      char relpath[2];      /* folder may be "/" */      snprintf (relpath, sizeof (relpath), "%c" , n < 0 ? '\0' : idata->delim);      if (showparents)        imap_add_folder (idata->delim, relpath, 1, 0, state, 1);       if (!state->folder)      {        imap_qualify_path (buf, sizeof (buf), &mx, relpath, NULL);        state->folder = safe_strdup (buf);      }    }  }  /* no namespace, no folder: set folder to host only */  if (!state->folder)  {    imap_qualify_path (buf, sizeof (buf), &mx, NULL, NULL);    state->folder = safe_strdup (buf);  }  if (home_namespace && mbox[0] != '\0')  {    /* Listing the home namespace, so INBOX should be included. Home      * namespace is not "", so we have to list it explicitly. We ask the      * server to see if it has descendants. */    imap_make_sequence (seq, sizeof (seq));    snprintf (buf, sizeof (buf), "%s LIST \"\" \"INBOX\"\r\n", seq);    if (add_list_result (conn, seq, buf, state, 0))      return -1;  }  nsup = state->entrylen;  imap_make_sequence (seq, sizeof (seq));  snprintf (buf, sizeof (buf), "%s %s \"\" \"%s%%\"\r\n", seq,     list_cmd, mbox);  if (add_list_result (conn, seq, buf, state, 0))    return -1;  qsort(&(state->entry[nsup]),state->entrylen-nsup,sizeof(state->entry[0]),	(int (*)(const void*,const void*)) compare_names);  if (home_namespace)  {				/* List additional namespaces */    for (i = 0; i < nns; i++)      if (nsi[i].listable && !nsi[i].home_namespace)	imap_add_folder(nsi[i].delim, nsi[i].prefix, nsi[i].noselect,          nsi[i].noinferiors, state, 0);  }  mutt_clear_error ();  return 0;}