]> granicus.if.org Git - mutt/commitdiff
Attachment deletion for IMAP folders. By Brendan Cully.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 21 May 2001 08:42:06 +0000 (08:42 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 21 May 2001 08:42:06 +0000 (08:42 +0000)
commands.c
imap/imap.c
imap/message.c
mx.c
protos.h

index 3c0679f9d4ca9e50803426224c7ffee5e6635b58..995b662760f6adacb0bd2d1090d07a36deefbbe6 100644 (file)
@@ -591,7 +591,7 @@ static void set_copy_flags (HEADER *hdr, int decode, int decrypt, int *cmflags,
   }
 }
 
-static void _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode, int decrypt)
+void _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode, int decrypt)
 {
   int cmflags, chflags;
   
index 0be0040cdd06f3677c5421d3580e93b14b54a440..ee5d7039fe808e36348d0e08c657747c154f6971 100644 (file)
@@ -872,6 +872,7 @@ int imap_make_msg_set (IMAP_DATA* idata, char* buf, size_t buflen, int flag,
 int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
 {
   IMAP_DATA* idata;
+  CONTEXT* appendctx = NULL;
   char buf[HUGE_STRING];
   char flags[LONG_STRING];
   char tmp[LONG_STRING];
@@ -929,8 +930,17 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
   {
     if (ctx->hdrs[n]->changed)
     {
-      mutt_message (_("Saving message status flags... [%d/%d]"), n+1, ctx->msgcount);
-      
+      mutt_message (_("Saving message status flags... [%d/%d]"), n+1,
+        ctx->msgcount);
+
+      /* 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"));
+       appendctx = mx_open_mailbox (ctx->path, M_APPEND | M_QUIET, NULL);
+       _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 ",
@@ -974,7 +984,10 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
         err_continue = imap_continue ("imap_sync_mailbox: STORE failed",
           idata->cmd.buf);
         if (err_continue != M_YES)
-          return -1;
+       {
+         rc = -1;
+         goto out;
+       }
       }
 
       ctx->hdrs[n]->changed = 0;
@@ -990,11 +1003,19 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
     if (imap_exec (idata, "EXPUNGE", 0) != 0)
     {
       imap_error ("imap_sync_mailbox: EXPUNGE failed", idata->cmd.buf);
-      return -1;
+      rc = -1;
+      goto out;
     }
   }
 
-  return 0;
+  rc = 0;
+ out:
+  if (appendctx)
+  {
+    mx_fastclose_mailbox (appendctx);
+    FREE (&appendctx);
+  }
+  return rc;
 }
 
 /* imap_close_mailbox: issue close command if neccessary, reset IMAP_DATA */
index a1fe061a820bf3df13c5e8265722e6341094e6da..1110bdb7561ffc022c5c58758644e2dbde7003a6 100644 (file)
@@ -553,23 +553,41 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete)
 
   if (imap_parse_path (dest, &mx))
   {
-    dprint (1, (debugfile, "imap_copy_message: bad destination %s\n", dest));
+    dprint (1, (debugfile, "imap_copy_messages: bad destination %s\n", dest));
     return -1;
   }
 
   /* check that the save-to folder is in the same account */
   if (!mutt_account_match (&(CTX_DATA->conn->account), &(mx.account)))
   {
-    dprint (3, (debugfile, "imap_copy_message: %s not same server as %s\n",
+    dprint (3, (debugfile, "imap_copy_messages: %s not same server as %s\n",
       dest, ctx->path));
     return 1;
   }
 
+  if (h && h->attach_del)
+  {
+    dprint (3, (debugfile, "imap_copy_messages: Message contains attachments to be deleted\n"));
+    return 1;
+  }
+  
   imap_fix_path (idata, mx.mbox, cmd, sizeof (cmd));
 
   /* Null HEADER* means copy tagged messages */
   if (!h)
   {
+    /* if any messages have attachments to delete, fall through to FETCH
+     * and APPEND. TODO: Copy what we can with COPY, fall through for the
+     * remainder. */
+    for (n = 0; n < ctx->msgcount; n++)
+    {
+      if (ctx->hdrs[n]->tagged && ctx->hdrs[n]->attach_del)
+      {
+       dprint (3, (debugfile, "imap_copy_messages: Message contains attachments to be deleted\n"));
+       return 1;
+      }
+    }
+    
     rc = imap_make_msg_set (idata, buf, sizeof (buf), M_TAG, 0);
     if (!rc)
     {
diff --git a/mx.c b/mx.c
index 786887f070a0dee5ebf062102468e55fba23798e..9dec7b340a2bf321d39da4b3d35d81cea5f82942 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -638,7 +638,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
     {
       mx_fastclose_mailbox (ctx);
       if (!pctx)
-       safe_free ((void **) &ctx);
+       FREE (&ctx);
       return NULL;
     }
     return ctx;
@@ -723,7 +723,7 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx)
   {
     mx_fastclose_mailbox (ctx);
     if (!pctx)
-      safe_free ((void **) &ctx);
+      FREE (&ctx);
   }
 
   unset_option (OPTFORCEREFRESH);
index 0923589c8965c70f45def9e96455a3044ed5eed2..3e0e4e1c310fb8ea5ac97de77139a117e46caa69 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -295,8 +295,8 @@ int mutt_parse_mono (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_parse_unmono (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_parse_push (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_parse_rc_line (/* const */ char *, BUFFER *, BUFFER *);
-int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, char *line, char *p, short user_hdrs, short weed,
-                           short do_2047, LIST **lastp);
+int mutt_parse_rfc822_line (ENVELOPE *e, HEADER *hdr, char *line, char *p,
+  short user_hdrs, short weed, short do_2047, LIST **lastp);
 int mutt_parse_score (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_parse_unscore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
 int mutt_parse_unhook (BUFFER *, BUFFER *, unsigned long, BUFFER *);
@@ -305,6 +305,7 @@ int mutt_pipe_attachment (FILE *, BODY *, const char *, char *);
 int mutt_print_attachment (FILE *, BODY *);
 int mutt_query_complete (char *, size_t);
 int mutt_save_attachment (FILE *, BODY *, char *, int, HEADER *);
+void _mutt_save_message (HEADER *, CONTEXT *, int, int, int);
 int mutt_save_message (HEADER *, int, int, int, int *);
 int mutt_search_command (int, int);
 int mutt_compose_menu (HEADER *, char *, size_t, HEADER *);