From: Thomas Roessler Date: Mon, 21 May 2001 08:42:06 +0000 (+0000) Subject: Attachment deletion for IMAP folders. By Brendan Cully. X-Git-Tag: mutt-1-3-19-rel~49 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c8123af1dd2806aec1ecb556ec21595e11f6a31;p=mutt Attachment deletion for IMAP folders. By Brendan Cully. --- diff --git a/commands.c b/commands.c index 3c0679f9..995b6627 100644 --- a/commands.c +++ b/commands.c @@ -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; diff --git a/imap/imap.c b/imap/imap.c index 0be0040c..ee5d7039 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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 */ diff --git a/imap/message.c b/imap/message.c index a1fe061a..1110bdb7 100644 --- a/imap/message.c +++ b/imap/message.c @@ -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 786887f0..9dec7b34 100644 --- 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); diff --git a/protos.h b/protos.h index 0923589c..3e0e4e1c 100644 --- 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 *);