- for (n = 0; n < ctx->msgcount; n++)
- {
- if (ctx->hdrs[n]->active && ctx->hdrs[n]->changed)
- {
- ctx->hdrs[n]->changed = 0;
-
- mutt_message (_("Saving message status flags... [%d/%d]"), n+1,
- ctx->msgcount);
-
- snprintf (uid, sizeof (uid), "%u", HEADER_DATA(ctx->hdrs[n])->uid);
- cmd.dptr = cmd.data;
- mutt_buffer_addstr (&cmd, "UID STORE ");
- mutt_buffer_addstr (&cmd, uid);
-
- /* if attachments have been deleted we delete the message and reupload
- * it. This works better if we're expunging, of course. */
- if (ctx->hdrs[n]->attach_del)
- {
- dprint (3, (debugfile, "imap_sync_mailbox: Attachments to be deleted, falling back to _mutt_save_message\n"));
- if (!appendctx)
- appendctx = mx_open_mailbox (ctx->path, M_APPEND | M_QUIET, NULL);
- if (!appendctx)
- {
- dprint (1, (debugfile, "imap_sync_mailbox: Error opening mailbox in append mode\n"));
- }
- else
- _mutt_save_message (ctx->hdrs[n], appendctx, 1, 0, 0);
- }
- flags[0] = '\0';
-
- imap_set_flag (idata, IMAP_ACL_SEEN, ctx->hdrs[n]->read, "\\Seen ",
- flags, sizeof (flags));
- imap_set_flag (idata, IMAP_ACL_WRITE, ctx->hdrs[n]->flagged,
- "\\Flagged ", flags, sizeof (flags));
- imap_set_flag (idata, IMAP_ACL_WRITE, ctx->hdrs[n]->replied,
- "\\Answered ", flags, sizeof (flags));
- imap_set_flag (idata, IMAP_ACL_DELETE, ctx->hdrs[n]->deleted,
- "\\Deleted ", flags, sizeof (flags));
-
- /* now make sure we don't lose custom tags */
- if (mutt_bit_isset (idata->rights, IMAP_ACL_WRITE))
- imap_add_keywords (flags, ctx->hdrs[n], idata->flags, sizeof (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 (idata, IMAP_ACL_SEEN, 1, "\\Seen ", flags, sizeof (flags));
- imap_set_flag (idata, IMAP_ACL_WRITE, 1, "\\Flagged ", flags, sizeof (flags));
- imap_set_flag (idata, IMAP_ACL_WRITE, 1, "\\Answered ", flags, sizeof (flags));
- imap_set_flag (idata, IMAP_ACL_DELETE, 1, "\\Deleted ", flags, sizeof (flags));
-
- mutt_remove_trailing_ws (flags);
-
- mutt_buffer_addstr (&cmd, " -FLAGS.SILENT (");
- }
- else
- mutt_buffer_addstr (&cmd, " FLAGS.SILENT (");
-
- mutt_buffer_addstr (&cmd, flags);
- mutt_buffer_addstr (&cmd, ")");
-
- /* dumb hack for bad UW-IMAP 4.7 servers spurious FLAGS updates */
- ctx->hdrs[n]->active = 0;
-
- /* after all this it's still possible to have no flags, if you
- * have no ACL rights */
- if (*flags && (imap_exec (idata, cmd.data, 0) != 0) &&
- (err_continue != M_YES))
- {
- err_continue = imap_continue ("imap_sync_mailbox: STORE failed",
- idata->cmd.buf);
- if (err_continue != M_YES)
- {
- rc = -1;
- goto out;
- }
+ for (n = 0; n < ctx->msgcount; n++) {
+ if (ctx->hdrs[n]->active && ctx->hdrs[n]->changed) {
+
+ mutt_message (_("Saving message status flags... [%d/%d]"), n + 1,
+ ctx->msgcount);
+
+ /* if the message has been rethreaded or attachments have been deleted
+ * we delete the message and reupload it.
+ * This works better if we're expunging, of course. */
+ if ((ctx->hdrs[n]->env && (ctx->hdrs[n]->env->refs_changed || ctx->hdrs[n]->env->irt_changed)) ||
+ ctx->hdrs[n]->attach_del) {
+ if (!appendctx)
+ appendctx = mx_open_mailbox (ctx->path, M_APPEND | M_QUIET, NULL);
+ if (appendctx) {
+ _mutt_save_message (ctx->hdrs[n], appendctx, 1, 0, 0);
+ }