if (mutt_bit_isset (CTX_DATA->rights, IMAP_ACL_WRITE)) imap_add_keywords (flags, ctx->hdrs[n], CTX_DATA->flags);
if (mutt_bit_isset (idata->rights, IMAP_ACL_WRITE)) imap_add_keywords (flags, ctx->hdrs[n], idata->flags);
int imap_sync_mailbox (CONTEXT* ctx, int expunge, int *index_hint){  char buf[HUGE_STRING];  char flags[LONG_STRING];  char tmp[LONG_STRING];  int deleted;  int n;  int err_continue = M_NO;	/* continue on error? */  int rc;  if (CTX_DATA->state != IMAP_SELECTED)  {    dprint (2, (debugfile, "imap_sync_mailbox: no mailbox selected\n"));    return -1;  }  imap_allow_reopen (ctx);	/* This function is only called when the calling code				 * expects the context to be changed.				 */  if ((rc = imap_check_mailbox (ctx, index_hint)) != 0)    return rc;  /* if we are expunging anyway, we can do deleted messages very quickly... */  if (expunge && mutt_bit_isset (CTX_DATA->rights, IMAP_ACL_DELETE))  {    deleted = imap_make_msg_set (buf, sizeof (buf), ctx, M_DELETE, 1);    /* if we have a message set, then let's delete */    if (deleted)    {      mutt_message (_("Marking %d messages deleted..."), deleted);      snprintf (tmp, sizeof (tmp), "STORE %s +FLAGS.SILENT (\\Deleted)", buf);      if (imap_exec (buf, sizeof (buf), CTX_DATA, tmp, 0) != 0)        /* continue, let regular store try before giving up */        dprint(2, (debugfile, "imap_sync_mailbox: fast delete failed\n"));      else        /* mark these messages as unchanged so second pass ignores them */        for (n = 0; n < ctx->msgcount; n++)          if (ctx->hdrs[n]->deleted && ctx->hdrs[n]->changed)            ctx->hdrs[n]->changed = 0;    }  }  /* save status changes */  for (n = 0; n < ctx->msgcount; n++)  {    if (ctx->hdrs[n]->changed)    {      mutt_message (_("Saving message status flags... [%d/%d]"), n+1, ctx->msgcount);            flags[0] = '\0';            imap_set_flag (ctx, IMAP_ACL_SEEN, ctx->hdrs[n]->read, "\\Seen ",        flags);      imap_set_flag (ctx, IMAP_ACL_WRITE, ctx->hdrs[n]->flagged, "\\Flagged ",        flags);      imap_set_flag (ctx, IMAP_ACL_WRITE, ctx->hdrs[n]->replied,        "\\Answered ", flags);      imap_set_flag (ctx, IMAP_ACL_DELETE, ctx->hdrs[n]->deleted, "\\Deleted ",        flags);      /* now make sure we don't lose custom tags */      if (mutt_bit_isset (CTX_DATA->rights, IMAP_ACL_WRITE))        imap_add_keywords (flags, ctx->hdrs[n], CTX_DATA->flags);            mutt_remove_trailing_ws (flags);            /* UW-IMAP is OK with null flags, Cyrus isn't. The only solution is to       * explicitly revoke all system flags (if we have permission) */      if (!*flags)      {        imap_set_flag (ctx, IMAP_ACL_SEEN, 1, "\\Seen ", flags);        imap_set_flag (ctx, IMAP_ACL_WRITE, 1, "\\Flagged ", flags);        imap_set_flag (ctx, IMAP_ACL_WRITE, 1, "\\Answered ", flags);        imap_set_flag (ctx, IMAP_ACL_DELETE, 1, "\\Deleted ", flags);        mutt_remove_trailing_ws (flags);        snprintf (buf, sizeof (buf), "STORE %d -FLAGS.SILENT (%s)",          ctx->hdrs[n]->index + 1, flags);      }      else        snprintf (buf, sizeof (buf), "STORE %d FLAGS.SILENT (%s)",          ctx->hdrs[n]->index + 1, flags);      /* after all this it's still possible to have no flags, if you       * have no ACL rights */      if (*flags && (imap_exec (buf, sizeof (buf), CTX_DATA, buf, 0) != 0) &&        (err_continue != M_YES))      {        err_continue = imap_continue ("imap_sync_mailbox: STORE failed", buf);        if (err_continue != M_YES)          return -1;      }      ctx->hdrs[n]->changed = 0;    }  }  ctx->changed = 0;  if (expunge == 1)  {    /* expunge is implicit if closing */    if (ctx->closing)    {      mutt_message _("Closing mailbox...");      if (imap_exec (buf, sizeof (buf), CTX_DATA, "CLOSE", 0) != 0)      {        imap_error ("imap_sync_mailbox: CLOSE failed", buf);        return -1;      }      /* state is set in imap_fastclose_mailbox */    }    else if (mutt_bit_isset(CTX_DATA->rights, IMAP_ACL_DELETE))    {      mutt_message _("Expunging messages from server...");      CTX_DATA->status = IMAP_EXPUNGE;      if (imap_exec (buf, sizeof (buf), CTX_DATA, "EXPUNGE", 0) != 0)      {        imap_error ("imap_sync_mailbox: EXPUNGE failed", buf);        return -1;      }      CTX_DATA->status = 0;    }  }  for (n = 0; n < IMAP_CACHE_LEN; n++)  {    if (CTX_DATA->cache[n].path)    {      unlink (CTX_DATA->cache[n].path);      safe_free ((void **) &CTX_DATA->cache[n].path);    }  }  return 0;}