diff -Naur mutt-1.6.0/OPS mutt-1.6.0-trash/OPS --- mutt-1.6.0/OPS 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/OPS 2016-04-26 13:07:58.000000000 -0400 @@ -142,6 +142,7 @@ OP_PREV_LINE "scroll up one line" OP_PREV_PAGE "move to the previous page" OP_PRINT "print the current entry" +OP_PURGE_MESSAGE "really delete the current entry, bypassing the trash folder" OP_QUERY "query external program for addresses" OP_QUERY_APPEND "append new query results to current results" OP_QUIT "save changes to mailbox and quit" diff -Naur mutt-1.6.0/PATCHES mutt-1.6.0-trash/PATCHES --- mutt-1.6.0/PATCHES 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/PATCHES 2016-04-28 13:03:38.000000000 -0400 @@ -0,0 +1 @@ +patch-1.6.0.bk.trash_folder-purge_message.1 diff -Naur mutt-1.6.0/commands.c mutt-1.6.0-trash/commands.c --- mutt-1.6.0/commands.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/commands.c 2016-04-26 13:07:58.000000000 -0400 @@ -720,6 +720,7 @@ if (option (OPTDELETEUNTAG)) mutt_set_flag (Context, h, M_TAG, 0); } + mutt_set_flag (Context, h, M_APPENDED, 1); return 0; } diff -Naur mutt-1.6.0/curs_main.c mutt-1.6.0-trash/curs_main.c --- mutt-1.6.0/curs_main.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/curs_main.c 2016-04-26 13:07:58.000000000 -0400 @@ -1919,6 +1919,7 @@ MAYBE_REDRAW (menu->redraw); break; + case OP_PURGE_MESSAGE: case OP_DELETE: CHECK_MSGCOUNT; @@ -1930,6 +1931,7 @@ if (tag) { mutt_tag_set_flag (M_DELETE, 1); + mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1); if (option (OPTDELETEUNTAG)) mutt_tag_set_flag (M_TAG, 0); menu->redraw = REDRAW_INDEX; @@ -1937,6 +1939,8 @@ else { mutt_set_flag (Context, CURHDR, M_DELETE, 1); + mutt_set_flag (Context, CURHDR, M_PURGED, + (op != OP_PURGE_MESSAGE) ? 0 : 1); if (option (OPTDELETEUNTAG)) mutt_set_flag (Context, CURHDR, M_TAG, 0); if (option (OPTRESOLVE)) @@ -2242,11 +2246,13 @@ if (tag) { mutt_tag_set_flag (M_DELETE, 0); + mutt_tag_set_flag (M_PURGED, 0); menu->redraw = REDRAW_INDEX; } else { mutt_set_flag (Context, CURHDR, M_DELETE, 0); + mutt_set_flag (Context, CURHDR, M_PURGED, 0); if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) { menu->current++; @@ -2268,9 +2274,11 @@ CHECK_ACL(M_ACL_DELETE, _("Cannot undelete message(s)")); rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0, - op == OP_UNDELETE_THREAD ? 0 : 1); + op == OP_UNDELETE_THREAD ? 0 : 1) + + mutt_thread_set_flag (CURHDR, M_PURGED, 0, + op == OP_UNDELETE_THREAD ? 0 : 1); - if (rc != -1) + if (rc > -1) { if (option (OPTRESOLVE)) { diff -Naur mutt-1.6.0/flags.c mutt-1.6.0-trash/flags.c --- mutt-1.6.0/flags.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/flags.c 2016-04-26 13:07:58.000000000 -0400 @@ -65,7 +65,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) @@ -87,6 +93,27 @@ } break; + case M_APPENDED: + if (bf) + { + if (!h->appended) + { + h->appended = 1; + if (upd_ctx) ctx->appended++; + } + } + break; + + case M_PURGED: + if (bf) + { + if (!h->purged) + h->purged = 1; + } + else if (h->purged) + h->purged = 0; + break; + case M_NEW: if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN)) diff -Naur mutt-1.6.0/functions.h mutt-1.6.0-trash/functions.h --- mutt-1.6.0/functions.h 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/functions.h 2016-04-26 13:07:58.000000000 -0400 @@ -121,6 +121,7 @@ { "toggle-write", OP_TOGGLE_WRITE, "%" }, { "next-thread", OP_MAIN_NEXT_THREAD, "\016" }, { "next-subthread", OP_MAIN_NEXT_SUBTHREAD, "\033n" }, + { "purge-message", OP_PURGE_MESSAGE, NULL }, { "query", OP_QUERY, "Q" }, { "quit", OP_QUIT, "q" }, { "reply", OP_REPLY, "r" }, @@ -213,6 +214,7 @@ { "print-message", OP_PRINT, "p" }, { "previous-thread", OP_MAIN_PREV_THREAD, "\020" }, { "previous-subthread",OP_MAIN_PREV_SUBTHREAD, "\033p" }, + { "purge-message", OP_PURGE_MESSAGE, NULL }, { "quit", OP_QUIT, "Q" }, { "exit", OP_EXIT, "q" }, { "reply", OP_REPLY, "r" }, diff -Naur mutt-1.6.0/globals.h mutt-1.6.0-trash/globals.h --- mutt-1.6.0/globals.h 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/globals.h 2016-04-26 13:09:03.000000000 -0400 @@ -141,6 +141,7 @@ WHERE char *Status; WHERE char *Tempdir; WHERE char *Tochars; +WHERE char *TrashPath; WHERE char *TSStatusFormat; WHERE char *TSIconFormat; WHERE short TSSupported; diff -Naur mutt-1.6.0/imap/message.c mutt-1.6.0-trash/imap/message.c --- mutt-1.6.0/imap/message.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/imap/message.c 2016-04-26 13:13:41.000000000 -0400 @@ -886,6 +886,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); } @@ -893,6 +894,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 -Naur mutt-1.6.0/init.h mutt-1.6.0-trash/init.h --- mutt-1.6.0/init.h 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/init.h 2016-04-26 13:08:07.000000000 -0400 @@ -3419,6 +3419,16 @@ ** provided that ``$$ts_enabled'' has been set. This string is identical in ** formatting to the one used by ``$$status_format''. */ + { "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 -Naur mutt-1.6.0/mutt.h mutt-1.6.0-trash/mutt.h --- mutt-1.6.0/mutt.h 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/mutt.h 2016-04-26 13:08:07.000000000 -0400 @@ -182,6 +182,8 @@ M_DELETE, M_UNDELETE, M_DELETED, + M_APPENDED, + M_PURGED, M_FLAG, M_TAG, M_UNTAG, @@ -719,6 +721,8 @@ 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 purged : 1; /* bypassing the trash folder */ unsigned int deleted : 1; unsigned int changed : 1; unsigned int attach_del : 1; /* has an attachment marked for deletion */ @@ -891,6 +895,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 -Naur mutt-1.6.0/muttlib.c mutt-1.6.0-trash/muttlib.c --- mutt-1.6.0/muttlib.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/muttlib.c 2016-04-26 13:08:07.000000000 -0400 @@ -1511,7 +1511,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 -Naur mutt-1.6.0/mx.c mutt-1.6.0-trash/mx.c --- mutt-1.6.0/mx.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/mx.c 2016-04-26 13:08:07.000000000 -0400 @@ -776,6 +776,54 @@ 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 + && !ctx->hdrs[i]->purged + && 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) { @@ -912,6 +960,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 { @@ -936,6 +985,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) @@ -1140,6 +1197,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 -Naur mutt-1.6.0/pager.c mutt-1.6.0-trash/pager.c --- mutt-1.6.0/pager.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/pager.c 2016-04-26 13:10:24.000000000 -0400 @@ -2351,6 +2351,7 @@ MAYBE_REDRAW (redraw); break; + case OP_PURGE_MESSAGE: case OP_DELETE: CHECK_MODE(IsHeader (extra)); CHECK_READONLY; @@ -2358,6 +2359,8 @@ CHECK_ACL(M_ACL_DELETE, _("Cannot delete message")); mutt_set_flag (Context, extra->hdr, M_DELETE, 1); + mutt_set_flag (Context, extra->hdr, M_PURGED, + ch != OP_PURGE_MESSAGE ? 0 : 1); if (option (OPTDELETEUNTAG)) mutt_set_flag (Context, extra->hdr, M_TAG, 0); redraw = REDRAW_STATUS | REDRAW_INDEX; @@ -2688,6 +2691,7 @@ CHECK_ACL(M_ACL_DELETE, _("Cannot undelete message")); mutt_set_flag (Context, extra->hdr, M_DELETE, 0); + mutt_set_flag (Context, extra->hdr, M_PURGED, 0); redraw = REDRAW_STATUS | REDRAW_INDEX; if (option (OPTRESOLVE)) { @@ -2704,9 +2708,11 @@ CHECK_ACL(M_ACL_DELETE, _("Cannot undelete message(s)")); r = mutt_thread_set_flag (extra->hdr, M_DELETE, 0, + ch == OP_UNDELETE_THREAD ? 0 : 1) + + mutt_thread_set_flag (extra->hdr, M_PURGED, 0, ch == OP_UNDELETE_THREAD ? 0 : 1); - if (r != -1) + if (r > -1) { if (option (OPTRESOLVE)) { diff -Naur mutt-1.6.0/pattern.c mutt-1.6.0-trash/pattern.c --- mutt-1.6.0/pattern.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/pattern.c 2016-04-26 13:08:07.000000000 -0400 @@ -1367,8 +1367,10 @@ { switch (op) { - case M_DELETE: case M_UNDELETE: + mutt_set_flag (Context, Context->hdrs[Context->v2r[i]], M_PURGED, + 0); + case M_DELETE: mutt_set_flag (Context, Context->hdrs[Context->v2r[i]], M_DELETE, (op == M_DELETE)); break; diff -Naur mutt-1.6.0/postpone.c mutt-1.6.0-trash/postpone.c --- mutt-1.6.0/postpone.c 2016-04-02 14:12:22.000000000 -0400 +++ mutt-1.6.0-trash/postpone.c 2016-04-26 13:08:07.000000000 -0400 @@ -277,6 +277,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;