On 2007-04-12 16:42:19 -0700, William Yardley wrote: > Oops! I don't know how those ended up missing, but thanks for noticing; > I've corrected my own install.
BTW, the patch no longer applies since last night. I'm now using the attached one (not tested). -- Vincent Lefèvre <[EMAIL PROTECTED]> - Web: <http://www.vinc17.org/> 100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/> Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
diff -Naurd mutt-hg/PATCHES mutt-new/PATCHES --- mutt-hg/PATCHES 2007-03-06 19:39:44.000000000 +0000 +++ mutt-new/PATCHES 2007-04-13 07:30:02.000000000 +0000 @@ -0,0 +1 @@ +patch-1.5.15hg.cd.trash_folder.vl.1 diff -Naurd mutt-hg/commands.c mutt-new/commands.c --- mutt-hg/commands.c 2007-03-21 02:35:44.000000000 +0000 +++ mutt-new/commands.c 2007-04-13 07:29:32.000000000 +0000 @@ -688,6 +688,7 @@ if (option (OPTDELETEUNTAG)) mutt_set_flag (Context, h, M_TAG, 0); } + mutt_set_flag (Context, h, M_APPENDED, 1); return 0; } diff -Naurd mutt-hg/flags.c mutt-new/flags.c --- mutt-hg/flags.c 2007-04-13 07:26:12.000000000 +0000 +++ mutt-new/flags.c 2007-04-13 07:33:47.000000000 +0000 @@ -69,7 +69,13 @@ { h->deleted = 0; update = 1; - if (upd_ctx) ctx->deleted--; + if (upd_ctx) + { + ctx->deleted--; + if (h->appended) + ctx->appended--; + } + h->appended = 0; /* when undeleting, also reset the appended flag */ #ifdef USE_IMAP /* see my comment above */ if (ctx->magic == M_IMAP) @@ -91,6 +97,17 @@ } break; + case M_APPENDED: + if (bf) + { + if (!h->appended) + { + h->appended = 1; + if (upd_ctx) ctx->appended++; + } + } + break; + case M_NEW: if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN)) diff -Naurd mutt-hg/globals.h mutt-new/globals.h --- mutt-hg/globals.h 2007-04-12 23:03:47.000000000 +0000 +++ mutt-new/globals.h 2007-04-13 07:29:32.000000000 +0000 @@ -142,6 +142,7 @@ WHERE char *Status; WHERE char *Tempdir; WHERE char *Tochars; +WHERE char *TrashPath; WHERE char *Username; WHERE char *Visual; diff -Naurd mutt-hg/imap/message.c mutt-new/imap/message.c --- mutt-hg/imap/message.c 2007-04-12 23:03:48.000000000 +0000 +++ mutt-new/imap/message.c 2007-04-13 07:29:32.000000000 +0000 @@ -816,6 +816,7 @@ if (ctx->hdrs[n]->tagged) { mutt_set_flag (ctx, ctx->hdrs[n], M_DELETE, 1); + mutt_set_flag (ctx, ctx->hdrs[n], M_APPENDED, 1); if (option (OPTDELETEUNTAG)) mutt_set_flag (ctx, ctx->hdrs[n], M_TAG, 0); } @@ -823,6 +824,7 @@ else { mutt_set_flag (ctx, h, M_DELETE, 1); + mutt_set_flag (ctx, h, M_APPENDED, 1); if (option (OPTDELETEUNTAG)) mutt_set_flag (ctx, h, M_TAG, 0); } diff -Naurd mutt-hg/init.h mutt-new/init.h --- mutt-hg/init.h 2007-04-12 23:03:48.000000000 +0000 +++ mutt-new/init.h 2007-04-13 07:29:32.000000000 +0000 @@ -2862,6 +2862,16 @@ ** by \fIyou\fP. The sixth character is used to indicate when a mail ** was sent to a mailing-list you subscribe to (default: L). */ + { "trash", DT_PATH, R_NONE, UL &TrashPath, 0 }, + /* + ** .pp + ** If set, this variable specifies the path of the trash folder where the + ** mails marked for deletion will be moved, instead of being irremediably + ** purged. + ** .pp + ** NOTE: When you delete a message in the trash folder, it is really + ** deleted, so that you have a way to clean the trash. + */ #ifdef USE_SOCKET { "tunnel", DT_STR, R_NONE, UL &Tunnel, UL 0 }, /* diff -Naurd mutt-hg/mutt.h mutt-new/mutt.h --- mutt-hg/mutt.h 2007-04-12 23:03:48.000000000 +0000 +++ mutt-new/mutt.h 2007-04-13 07:29:32.000000000 +0000 @@ -201,6 +201,7 @@ M_DELETE, M_UNDELETE, M_DELETED, + M_APPENDED, M_FLAG, M_TAG, M_UNTAG, @@ -711,6 +712,7 @@ unsigned int mime : 1; /* has a MIME-Version header? */ unsigned int flagged : 1; /* marked important? */ unsigned int tagged : 1; + unsigned int appended : 1; /* has been saved */ unsigned int deleted : 1; unsigned int changed : 1; unsigned int attach_del : 1; /* has an attachment marked for deletion */ @@ -882,6 +884,7 @@ int new; /* how many new messages? */ int unread; /* how many unread messages? */ int deleted; /* how many deleted messages */ + int appended; /* how many saved messages? */ int flagged; /* how many flagged messages */ int msgnotreadyet; /* which msg "new" in pager, -1 if none */ diff -Naurd mutt-hg/muttlib.c mutt-new/muttlib.c --- mutt-hg/muttlib.c 2007-04-08 01:13:34.000000000 +0000 +++ mutt-new/muttlib.c 2007-04-13 07:29:32.000000000 +0000 @@ -1382,7 +1382,9 @@ if (magic > 0 && !mx_access (s, W_OK)) { - if (option (OPTCONFIRMAPPEND)) + if (option (OPTCONFIRMAPPEND) && + (!TrashPath || (mutt_strcmp (s, TrashPath) != 0))) + /* if we're appending to the trash, there's no point in asking */ { snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s); if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO) diff -Naurd mutt-hg/mx.c mutt-new/mx.c --- mutt-hg/mx.c 2007-04-04 00:39:30.000000000 +0000 +++ mutt-new/mx.c 2007-04-13 07:29:32.000000000 +0000 @@ -808,6 +808,53 @@ return rc; } +/* move deleted mails to the trash folder */ +static int trash_append (CONTEXT *ctx) +{ + CONTEXT *ctx_trash; + int i = 0; + struct stat st, stc; + + if (!TrashPath || !ctx->deleted || + (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH))) + return 0; + + for (;i < ctx->msgcount && (!ctx->hdrs[i]->deleted || + ctx->hdrs[i]->appended); i++); + if (i == ctx->msgcount) + return 0; /* nothing to be done */ + + if (mutt_save_confirm (TrashPath, &st) != 0) + { + mutt_error _("message(s) not deleted"); + return -1; + } + + if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino + && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev) + return 0; /* we are in the trash folder: simple sync */ + + if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL) + { + for (i = 0 ; i < ctx->msgcount ; i++) + if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended + && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) + { + mx_close_mailbox (ctx_trash, NULL); + return -1; + } + + mx_close_mailbox (ctx_trash, NULL); + } + else + { + mutt_error _("Can't open trash folder"); + return -1; + } + + return 0; +} + /* save changes and close mailbox */ int mx_close_mailbox (CONTEXT *ctx, int *index_hint) { @@ -943,6 +990,7 @@ if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0) { mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1); + mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1); } else { @@ -964,6 +1012,14 @@ return 0; } + /* copy mails to the trash before expunging */ + if (purge && ctx->deleted) + if (trash_append (ctx) != 0) + { + ctx->closing = 0; + return -1; + } + #ifdef USE_IMAP /* allow IMAP to preserve the deleted flag across sessions */ if (ctx->magic == M_IMAP) @@ -1159,6 +1215,12 @@ msgcount = ctx->msgcount; deleted = ctx->deleted; + if (purge && ctx->deleted) + { + if (trash_append (ctx) == -1) + return -1; + } + #ifdef USE_IMAP if (ctx->magic == M_IMAP) rc = imap_sync_mailbox (ctx, purge, index_hint); diff -Naurd mutt-hg/postpone.c mutt-new/postpone.c --- mutt-hg/postpone.c 2007-03-21 02:35:44.000000000 +0000 +++ mutt-new/postpone.c 2007-04-13 07:29:32.000000000 +0000 @@ -279,6 +279,9 @@ /* finished with this message, so delete it. */ mutt_set_flag (PostContext, h, M_DELETE, 1); + /* and consider it saved, so that it won't be moved to the trash folder */ + mutt_set_flag (PostContext, h, M_APPENDED, 1); + /* update the count for the status display */ PostCount = PostContext->msgcount - PostContext->deleted;