int port; IMAP_NAMESPACE_INFO nsi[16];
char ctmp;
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 *prune_path = NULL;  char host[SHORT_STRING];  char list_cmd[5];  char seq[16];  char *ipath = NULL;  int n;  int i;  int nsup;  int port;  IMAP_NAMESPACE_INFO nsi[16];  int nns;  int home_namespace = 0;  char *cur_folder;  short showparents = 0;  int noselect;  int noinferiors;  if (imap_parse_path (path, host, sizeof (host), &port, &ipath))    return (-1);  strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST", sizeof (list_cmd));  conn = mutt_socket_select_connection (host, port, 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 (ipath[0] == '\0')  {    home_namespace = 1;    mbox[0] = 0;		/* Do not replace "" with "INBOX" here */    ipath = 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 (!ipath)		/* 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))	{	  ipath = nsi->prefix;	  nsi->home_namespace = 1;	  break;	}    }  }  mutt_message _("Contacted server, getting folder list...");  if (ipath && ipath[0] != '\0')  {    imap_fix_path (idata, ipath, 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;      state->folder = safe_strdup (mbox);      n--;    }    /* Find superiors to list, handling trailing delimiter */    for (n--; n >= 0 && mbox[n] != idata->delim ; n--);    if (n > 0)			/* "aaaa/bbbb/" -> add "aaaa" */    {      mbox[n] = '\0';      /* List it to see if it can be selected */      dprint (2, (debugfile, "imap_init_browse: listing %s\n", mbox));      imap_make_sequence (seq, sizeof (seq));      snprintf (buf, sizeof (buf), "%s %s \"\" \"%s\"\r\n", seq,         list_cmd, mbox);      /* mark this entry as a superior, if we aren't tab-completing */      if (showparents && add_list_result (conn, seq, buf, host, port, state, 1))          return -1;      if (!state->folder)      {        state->folder = safe_malloc (n+2);        strfcpy (state->folder, mbox, n+1);        state->folder[n] = idata->delim;        state->folder[n+1] = '\0';      }      mbox[n] = idata->delim;    }     /* "/bbbb/" -> add  "/", "aaaa/" -> add "" */    else if (showparents)    {      snprintf (buf, sizeof (buf), "%c" , n<0 ? '\0' :idata->delim);      add_folder (idata->delim, buf, host, port, 1, 0, state, 1);     }  }  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, host, port, state, 0) != 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 we are viewing a folder's contents, prune the folder */  if (mbox[strlen (mbox) - 1] == idata->delim)    prune_path = mbox;  if (add_list_result(conn, seq, buf, host, port, state, 0) != 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)	add_folder(nsi[i].delim, nsi[i].prefix, host, port, 		   nsi[i].noselect, nsi[i].noinferiors, state, 0);  }  mutt_clear_error ();  return 0;}