conn = mutt_socket_find (&mx, 0); idata = CONN_DATA;
conn = mutt_socket_find (&(mx.account), 0); idata = (IMAP_DATA*) conn->data;
int imap_mailbox_check (char *path, int new){  CONNECTION *conn;  IMAP_DATA *idata;  char buf[LONG_STRING];  char mbox[LONG_STRING];  char mbox_unquoted[LONG_STRING];  char *s;  int msgcount = 0;  IMAP_MBOX mx;    if (imap_parse_path (path, &mx))    return -1;  conn = mutt_socket_find (&mx, 0);  idata = CONN_DATA;  if (!idata || (idata->state == IMAP_DISCONNECTED))  {    /* If passive is selected, then we don't open connections to check     * for new mail */    if (option (OPTIMAPPASSIVE))      return -1;    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;  }  imap_fix_path (idata, mx.mbox, buf, sizeof (buf));  /* Update the path, if it fits */  if (strlen (buf) < strlen (mx.mbox))      strcpy (mx.mbox, buf);  imap_munge_mbox_name (mbox, sizeof(mbox), buf);  strfcpy (mbox_unquoted, buf, sizeof (mbox_unquoted));  /* The draft IMAP implementor's guide warns againts using the STATUS   * command on a mailbox that you have selected    */  if (mutt_strcmp (mbox_unquoted, idata->selected_mailbox) == 0      || (mutt_strcasecmp (mbox_unquoted, "INBOX") == 0	  && mutt_strcasecmp (mbox_unquoted, idata->selected_mailbox) == 0))  {    strfcpy (buf, "NOOP", sizeof (buf));  }  else if (mutt_bit_isset(idata->capabilities,IMAP4REV1) ||	   mutt_bit_isset(idata->capabilities,STATUS))  {				    snprintf (buf, sizeof (buf), "STATUS %s (%s)", mbox,      new ? "RECENT" : "MESSAGES");  }  else  {    /* Server does not support STATUS, and this is not the current mailbox.     * There is no lightweight way to check recent arrivals */      return -1;  }  imap_cmd_start (idata, buf);  do   {    if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)      return -1;    if (buf[0] == '*')     {      s = imap_next_word (buf);      if (mutt_strncasecmp ("STATUS", s, 6) == 0)      {	s = imap_next_word (s);	if (mutt_strncmp (mbox_unquoted, s, mutt_strlen (mbox_unquoted)) == 0)	{	  s = imap_next_word (s);	  s = imap_next_word (s);	  if (isdigit (*s))	  {	    if (*s != '0')	    {	      dprint (1, (debugfile, "Mail in %s\n", path));	      msgcount = atoi(s);	    }	  }	}      }      else      {	if (conn->data && 	    imap_handle_untagged (idata, buf) != 0)	  return -1;      }    }  }  while ((mutt_strncmp (buf, idata->seq, SEQLEN) != 0));  imap_cmd_finish (idata);  return msgcount;}