char *pn = pc;
char* pn;   pc += 8; SKIPWS (pc); pn = pc;
int imap_reopen_mailbox (CONTEXT *ctx, int *index_hint){  HEADER **old_hdrs;  int old_msgcount;  char buf[LONG_STRING];  char bufout[LONG_STRING];  char seq[8];  char *pc = NULL;  int count = 0;  int msg_mod = 0;  int n;  int i, j;  int index_hint_set;  ctx->quiet = 1;  if (Sort != SORT_ORDER)  {    short old_sort;    old_sort = Sort;    Sort = SORT_ORDER;    mutt_sort_headers (ctx, 1);    Sort = old_sort;  }  old_hdrs = NULL;  old_msgcount = 0;  /* simulate a close */  hash_destroy (&ctx->id_hash, NULL);  hash_destroy (&ctx->subj_hash, NULL);  safe_free ((void **) &ctx->v2r);  if (ctx->readonly)  {    for (i = 0; i < ctx->msgcount; i++)      mutt_free_header (&(ctx->hdrs[i])); /* nothing to do! */    safe_free ((void **) &ctx->hdrs);  }  else  {    /* save the old headers */    old_msgcount = ctx->msgcount;    old_hdrs = ctx->hdrs;    ctx->hdrs = NULL;  }  ctx->hdrmax = 0;      /* force allocation of new headers */  ctx->msgcount = 0;  ctx->vcount = 0;  ctx->tagged = 0;  ctx->deleted = 0;  ctx->new = 0;  ctx->unread = 0;  ctx->flagged = 0;  ctx->changed = 0;  ctx->id_hash = hash_create (1031);  ctx->subj_hash = hash_create (1031);  mutt_message (_("Reopening mailbox... %s"), CTX_DATA->selected_mailbox);  imap_quote_string (buf, sizeof (buf), CTX_DATA->selected_mailbox);  imap_make_sequence (seq, sizeof (seq));  snprintf (bufout, sizeof (bufout), "%s %s %s\r\n", seq,    ctx->readonly ? "EXAMINE" : "SELECT", buf);  mutt_socket_write (CTX_DATA->conn, bufout);  do  {    if (mutt_socket_read_line_d (buf, sizeof (buf), CTX_DATA->conn) < 0)      break;    if (buf[0] == '*')    {      pc = buf + 2;      if (isdigit (*pc))      {	char *pn = pc;	while (*pc && isdigit (*pc))	  pc++;	*pc++ = 0;	n = atoi (pn);	SKIPWS (pc);	if (mutt_strncasecmp ("EXISTS", pc, 6) == 0)	  count = n;      }      else if (imap_handle_untagged (CTX_DATA, buf) != 0)	return (-1);    }  }  while (mutt_strncmp (seq, buf, mutt_strlen (seq)) != 0);  /* check for READ-ONLY notification */  if (!strncmp (imap_get_qualifier (buf), "[READ-ONLY]", 11))  {    dprint (2, (debugfile, "Mailbox is read-only.\n"));    ctx->readonly = 1;  }  if (!imap_code (buf))  {    char *s;    s = imap_next_word (buf); /* skip seq */    s = imap_next_word (s); /* Skip response */    CTX_DATA->state = IMAP_AUTHENTICATED;    mutt_error (s);    sleep (1);    return (-1);  }  ctx->hdrmax = count;  ctx->hdrs = safe_malloc (count * sizeof (HEADER *));  ctx->v2r = safe_malloc (count * sizeof (int));  ctx->msgcount = 0;  count = imap_read_headers (ctx, 0, count - 1) + 1;  index_hint_set = (index_hint == NULL);  if (!ctx->readonly)  {    for (i = 0; i < ctx->msgcount; i++)    {      int found = 0;      /* some messages have been deleted, and new  messages have been       * appended at the end; the heuristic is that old messages have then       * "advanced" towards the beginning of the folder, so we begin the       * search at index "i"       */      for (j = i; j < old_msgcount; j++)      {	if (old_hdrs[j] == NULL)	  continue;	if (mbox_strict_cmp_headers (ctx->hdrs[i], old_hdrs[j]))	{	  found = 1;	  break;	}      }      if (!found)      {	for (j = 0; j < i && j < old_msgcount; j++)	{	  if (old_hdrs[j] == NULL)	    continue;	  if (mbox_strict_cmp_headers (ctx->hdrs[i], old_hdrs[j]))	  {	    found = 1;	    break;	  }	}      }      if (found)      {	/* this is best done here */	if (!index_hint_set && *index_hint == j)	  *index_hint = i;	if (old_hdrs[j]->changed)	{	  /* Only update the flags if the old header was changed;	   * otherwise, the header may have been modified	   * externally, and we don't want to lose _those_ changes 	   */	  	  mutt_set_flag (ctx, ctx->hdrs[i], M_FLAG, old_hdrs[j]->flagged);	  mutt_set_flag (ctx, ctx->hdrs[i], M_REPLIED, old_hdrs[j]->replied);	  mutt_set_flag (ctx, ctx->hdrs[i], M_OLD, old_hdrs[j]->old);	  mutt_set_flag (ctx, ctx->hdrs[i], M_READ, old_hdrs[j]->read);	}	mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, old_hdrs[j]->deleted);	mutt_set_flag (ctx, ctx->hdrs[i], M_TAG, old_hdrs[j]->tagged);	/* we don't need this header any more */	mutt_free_header (&(old_hdrs[j]));      }    }    /* free the remaining old headers */    for (j = 0; j < old_msgcount; j++)    {      if (old_hdrs[j])      {	mutt_free_header (&(old_hdrs[j]));	msg_mod = 1;      }    }    safe_free ((void **) &old_hdrs);  }  ctx->quiet = 0;  return 0;}