Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Mon, 4 Apr 2005 15:40:12 +0000 (15:40 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Mon, 4 Apr 2005 15:40:12 +0000 (15:40 +0000)
merge in latest mutt changes

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@248 e385b8ad-14ed-0310-8656-cc95a2468c6d

ChangeLog
imap/imap.c
imap/imap_private.h
imap/message.c

index 819f1bb..2956048 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2005-04-03 00:14:51  Daniel Jacobowitz  <dan@debian.org>  (brendan)
+
+       * imap/imap.c, imap/imap_private.h, imap/message.c: Synchronise
+       message flags before moving messages.
+
 2005-03-31 04:55:09  Thomas Glanzmann  <sithglan@stud.uni-erlangen.de>  (brendan)
 
        * mh.c: Another hcache cygwin portability fix.
 2005-03-31 04:55:09  Thomas Glanzmann  <sithglan@stud.uni-erlangen.de>  (brendan)
 
        * mh.c: Another hcache cygwin portability fix.
 2005-01-29 19:15:07  Thomas Glanzmann  <sithglan@stud.uni-erlangen.de>  (roessler)
                                  
      * hcache.c: - make hcache.c conform to mutt codingstyle
 2005-01-29 19:15:07  Thomas Glanzmann  <sithglan@stud.uni-erlangen.de>  (roessler)
                                  
      * hcache.c: - make hcache.c conform to mutt codingstyle
-     - use $Id: ChangeLog,v 3.419 2005/03/31 04:56:39 brendan Exp $ CVS keyword instead of %K% BitKeeper keyword
+     - use $Id: ChangeLog,v 3.420 2005/04/03 00:15:36 brendan Exp $ CVS keyword instead of %K% BitKeeper keyword
                                  
 2005-01-29 19:15:07  Thomas Glanzmann  <sithglan@stud.uni-erlangen.de>  (roessler)
 
                                  
 2005-01-29 19:15:07  Thomas Glanzmann  <sithglan@stud.uni-erlangen.de>  (roessler)
 
index 6ada64f..9047114 100644 (file)
@@ -2,7 +2,7 @@
  * Copyright notice from original mutt:
  * Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
  * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
  * Copyright notice from original mutt:
  * Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
  * Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
- * Copyright (C) 1999-2003 Brendan Cully <brendan@kublai.com>
+ * Copyright (C) 1999-2005 Brendan Cully <brendan@kublai.com>
  *
  * This file is part of mutt-ng, see http://www.muttng.org/.
  * It's licensed under the GNU General Public License,
  *
  * This file is part of mutt-ng, see http://www.muttng.org/.
  * It's licensed under the GNU General Public License,
@@ -884,6 +884,76 @@ int imap_make_msg_set (IMAP_DATA * idata, BUFFER * buf, int flag, int changed)
   return count;
 }
 
   return count;
 }
 
+/* Update the IMAP server to reflect the flags a single message.  */
+
+int imap_sync_message (IMAP_DATA *idata, HEADER *hdr, BUFFER *cmd,
+                      int *err_continue)
+{
+  char flags[LONG_STRING];
+  char uid[11];
+
+  hdr->changed = 0;
+
+  snprintf (uid, sizeof (uid), "%u", HEADER_DATA(hdr)->uid);
+  cmd->dptr = cmd->data;
+  mutt_buffer_addstr (cmd, "UID STORE ");
+  mutt_buffer_addstr (cmd, uid);
+
+  flags[0] = '\0';
+      
+  imap_set_flag (idata, IMAP_ACL_SEEN, hdr->read, "\\Seen ",
+                flags, sizeof (flags));
+  imap_set_flag (idata, IMAP_ACL_WRITE, hdr->flagged,
+                "\\Flagged ", flags, sizeof (flags));
+  imap_set_flag (idata, IMAP_ACL_WRITE, hdr->replied,
+                "\\Answered ", flags, sizeof (flags));
+  imap_set_flag (idata, IMAP_ACL_DELETE, hdr->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, hdr, 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 */
+  hdr->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 && (*err_continue != M_YES))
+  {
+    *err_continue = imap_continue ("imap_sync_message: STORE failed",
+                                  idata->cmd.buf);
+    if (*err_continue != M_YES)
+      return -1;
+  }
+
+  hdr->active = 1;
+  idata->ctx->changed--;
+
+  return 0;
+}
+
 /* update the IMAP server to reflect message changes done within mutt.
  * Arguments
  *   ctx: the current context
 /* update the IMAP server to reflect message changes done within mutt.
  * Arguments
  *   ctx: the current context
@@ -895,8 +965,6 @@ int imap_sync_mailbox (CONTEXT * ctx, int expunge, int *index_hint)
   IMAP_DATA *idata;
   CONTEXT *appendctx = NULL;
   BUFFER cmd;
   IMAP_DATA *idata;
   CONTEXT *appendctx = NULL;
   BUFFER cmd;
-  char flags[LONG_STRING];
-  char uid[11];
   int deleted;
   int n;
   int err_continue = M_NO;      /* continue on error? */
   int deleted;
   int n;
   int err_continue = M_NO;      /* continue on error? */
@@ -951,16 +1019,10 @@ int imap_sync_mailbox (CONTEXT * ctx, int expunge, int *index_hint)
   /* save status changes */
   for (n = 0; n < ctx->msgcount; n++) {
     if (ctx->hdrs[n]->active && ctx->hdrs[n]->changed) {
   /* save status changes */
   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);
 
 
       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 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 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. */
@@ -979,61 +1041,11 @@ int imap_sync_mailbox (CONTEXT * ctx, int expunge, int *index_hint)
         else
           _mutt_save_message (ctx->hdrs[n], appendctx, 1, 0, 0);
       }
         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;
-        }
-      }
 
 
-      ctx->hdrs[n]->active = 1;
+      if (imap_sync_message (idata, ctx->hdrs[n], &cmd, &err_continue) < 0) {
+        rc = -1;
+        goto out;
+      }
     }
   }
   ctx->changed = 0;
     }
   }
   ctx->changed = 0;
index 6ac9d58..b2494cc 100644 (file)
@@ -191,6 +191,7 @@ int imap_read_literal (FILE * fp, IMAP_DATA * idata, long bytes);
 void imap_expunge_mailbox (IMAP_DATA * idata);
 int imap_reconnect (CONTEXT * ctx);
 void imap_logout (IMAP_DATA * idata);
 void imap_expunge_mailbox (IMAP_DATA * idata);
 int imap_reconnect (CONTEXT * ctx);
 void imap_logout (IMAP_DATA * idata);
+int imap_sync_message (IMAP_DATA*, HEADER*, BUFFER*, int*);
 
 /* auth.c */
 int imap_authenticate (IMAP_DATA * idata);
 
 /* auth.c */
 int imap_authenticate (IMAP_DATA * idata);
index 08a9d3f..19cbe9f 100644 (file)
@@ -621,13 +621,14 @@ fail:
 int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete)
 {
   IMAP_DATA *idata;
 int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete)
 {
   IMAP_DATA *idata;
-  BUFFER cmd;
+  BUFFER cmd, sync_cmd;
   char uid[11];
   char mbox[LONG_STRING];
   char mmbox[LONG_STRING];
   int rc;
   int n;
   IMAP_MBOX mx;
   char uid[11];
   char mbox[LONG_STRING];
   char mmbox[LONG_STRING];
   int rc;
   int n;
   IMAP_MBOX mx;
+  int err_continue = M_NO;
 
   idata = (IMAP_DATA *) ctx->data;
 
 
   idata = (IMAP_DATA *) ctx->data;
 
@@ -652,6 +653,7 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete)
 
   imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));
 
 
   imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));
 
+  memset (&sync_cmd, 0, sizeof (sync_cmd));
   memset (&cmd, 0, sizeof (cmd));
   mutt_buffer_addstr (&cmd, "UID COPY ");
 
   memset (&cmd, 0, sizeof (cmd));
   mutt_buffer_addstr (&cmd, "UID COPY ");
 
@@ -667,6 +669,17 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete)
                  "imap_copy_messages: Message contains attachments to be deleted\n"));
         return 1;
       }
                  "imap_copy_messages: Message contains attachments to be deleted\n"));
         return 1;
       }
+
+      if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->active &&
+         ctx->hdrs[n]->changed)
+      {
+       rc = imap_sync_message (idata, ctx->hdrs[n], &sync_cmd, &err_continue);
+       if (rc < 0)
+       {
+         dprint (1, (debugfile, "imap_copy_messages: could not sync\n"));
+         goto fail;
+       }
+      }
     }
 
     rc = imap_make_msg_set (idata, &cmd, M_TAG, 0);
     }
 
     rc = imap_make_msg_set (idata, &cmd, M_TAG, 0);
@@ -680,6 +693,16 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete)
     mutt_message (_("Copying message %d to %s..."), h->index + 1, mbox);
     snprintf (uid, sizeof (uid), "%u", HEADER_DATA (h)->uid);
     mutt_buffer_addstr (&cmd, uid);
     mutt_message (_("Copying message %d to %s..."), h->index + 1, mbox);
     snprintf (uid, sizeof (uid), "%u", HEADER_DATA (h)->uid);
     mutt_buffer_addstr (&cmd, uid);
+
+    if (h->active && h->changed)
+    {
+      rc = imap_sync_message (idata, h, &sync_cmd, &err_continue);
+      if (rc < 0)
+      {
+       dprint (1, (debugfile, "imap_copy_messages: could not sync\n"));
+       goto fail;
+      }
+    }
   }
 
   /* let's get it on */
   }
 
   /* let's get it on */
@@ -734,12 +757,16 @@ int imap_copy_messages (CONTEXT * ctx, HEADER * h, char *dest, int delete)
 
   if (cmd.data)
     FREE (&cmd.data);
 
   if (cmd.data)
     FREE (&cmd.data);
+  if (sync_cmd.data)
+    FREE (&sync_cmd.data);
   FREE (&mx.mbox);
   return 0;
 
 fail:
   if (cmd.data)
     FREE (&cmd.data);
   FREE (&mx.mbox);
   return 0;
 
 fail:
   if (cmd.data)
     FREE (&cmd.data);
+  if (sync_cmd.data)
+    FREE (&sync_cmd.data);
   FREE (&mx.mbox);
   return -1;
 }
   FREE (&mx.mbox);
   return -1;
 }