Sort = oldsort;
int imap_make_msg_set (char* buf, size_t buflen, CONTEXT* ctx, int flag,  int changed){  HEADER** hdrs;	/* sorted local copy */  int count = 0;	/* number of messages in message set */  int match = 0;	/* whether current message matches flag condition */  int setstart = 0;	/* start of current message range */  char* tmp;  int n;  /* sanity-check */  if (!buf || buflen < 2)    return 0;  *buf = '\0';  /* make copy of header pointers to sort in natural order */  hdrs = safe_calloc (ctx->msgcount, sizeof (HEADER*));  memcpy (hdrs, ctx->hdrs, ctx->msgcount * sizeof (HEADER*));  qsort ((void*) hdrs, ctx->msgcount, sizeof (HEADER*),    mutt_get_sort_func (SORT_ORDER));  tmp = safe_malloc (buflen);  for (n = 0; n < ctx->msgcount; n++)  {    match = 0;    switch (flag)    {      case M_DELETE:        if (hdrs[n]->deleted)          match = 1;        break;      case M_TAG:        if (hdrs[n]->tagged)          match = 1;        break;    }    if (match && (!changed || hdrs[n]->changed))    {      count++;      if (setstart == 0)      {        setstart = n+1;        if (!buf[0])          snprintf (buf, buflen, "%u", n+1);        else        {          strncpy (tmp, buf, buflen);          snprintf (buf, buflen, "%s,%u", tmp, n+1);        }      }      /* tie up if the last message also matches */      else if (n == ctx->msgcount-1)      {        strncpy (tmp, buf, buflen);        snprintf (buf, buflen, "%s:%u", tmp, n+1);      }    }    else if (setstart)    {      if (n > setstart)      {        strncpy (tmp, buf, buflen);        snprintf (buf, buflen, "%s:%u", tmp, n);      }      setstart = 0;    }  }  safe_free ((void**) &tmp);  safe_free ((void**) &hdrs);  return count;}