diff -pruN mutt-1.3.17.orig/commands.c mutt-1.3.17/commands.c --- mutt-1.3.17.orig/commands.c Tue Feb 13 15:40:41 2001 +++ mutt-1.3.17/commands.c Thu Jul 26 00:17:58 2001 @@ -600,11 +600,15 @@ static void _mutt_save_message (HEADER * if (decode || decrypt) mutt_parse_mime_message (Context, h); - if (mutt_append_message (ctx, Context, h, cmflags, chflags) == 0 && delete) + if (mutt_append_message (ctx, Context, h, cmflags, chflags) == 0) { - mutt_set_flag (Context, h, M_DELETE, 1); - if (option (OPTDELETEUNTAG)) - mutt_set_flag (Context, h, M_TAG, 0); + if (delete) + { + mutt_set_flag (Context, h, M_DELETE, 1); + if (option (OPTDELETEUNTAG)) + mutt_set_flag (Context, h, M_TAG, 0); + } + mutt_set_flag (Context, h, M_APPENDED, 1); } } diff -pruN mutt-1.3.17.orig/flags.c mutt-1.3.17/flags.c --- mutt-1.3.17.orig/flags.c Thu Dec 21 10:19:23 2000 +++ mutt-1.3.17/flags.c Thu Jul 26 00:17:59 2001 @@ -87,6 +87,17 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE } break; + case M_APPENDED: + if (bf) + { + if (!h->appended) + { + h->appended = 1; + if (upd_ctx) ctx->appended++; + } + } + break; + case M_NEW: if (bf) { diff -pruN mutt-1.3.17.orig/globals.h mutt-1.3.17/globals.h --- mutt-1.3.17.orig/globals.h Thu Feb 15 17:37:04 2001 +++ mutt-1.3.17/globals.h Thu Jul 26 00:17:59 2001 @@ -99,6 +99,7 @@ WHERE char *StChars; WHERE char *Status; WHERE char *Tempdir; WHERE char *Tochars; +WHERE char *TrashPath; WHERE char *Username; WHERE char *Visual; diff -pruN mutt-1.3.17.orig/init.h mutt-1.3.17/init.h --- mutt-1.3.17.orig/init.h Mon Mar 5 21:51:23 2001 +++ mutt-1.3.17/init.h Thu Jul 26 00:17:59 2001 @@ -1506,6 +1506,13 @@ struct option_t MuttVars[] = { ** in the folder specified by this variable. Also see the ``$$postpone'' ** variable. */ + { "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. + */ #ifdef USE_SOCKET { "preconnect", DT_STR, R_NONE, UL &Preconnect, UL 0}, /* diff -pruN mutt-1.3.17.orig/mutt.h mutt-1.3.17/mutt.h --- mutt-1.3.17.orig/mutt.h Sun Mar 4 11:51:48 2001 +++ mutt-1.3.17/mutt.h Thu Jul 26 00:17:59 2001 @@ -179,6 +179,7 @@ enum M_DELETE, M_UNDELETE, M_DELETED, + M_APPENDED, M_FLAG, M_TAG, M_UNTAG, @@ -595,6 +596,7 @@ typedef struct header 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 */ @@ -704,6 +706,7 @@ typedef struct 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 */ #if defined USE_POP || defined USE_IMAP diff -pruN mutt-1.3.17.orig/mx.c mutt-1.3.17/mx.c --- mutt-1.3.17.orig/mx.c Mon Feb 19 12:05:01 2001 +++ mutt-1.3.17/mx.c Thu Jul 26 00:17:59 2001 @@ -814,6 +814,47 @@ static int sync_mailbox (CONTEXT *ctx, i return rc; } +/* move deleted mails to the trash folder */ +static int trash_append (CONTEXT *ctx) +{ + CONTEXT *ctx_trash; + int i; + struct stat st, stc; + + if (!TrashPath || !ctx->deleted) + return 0; + + if (!mutt_save_confirm (TrashPath, &st)) + { + 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) { @@ -990,11 +1031,19 @@ int mx_close_mailbox (CONTEXT *ctx, int if (ctx->changed || ctx->deleted) { - if ((check = sync_mailbox (ctx, index_hint)) != 0) + int trsh = 0; + + if ((!ctx->deleted || (trsh = trash_append (ctx)) == 0) + && (check = sync_mailbox (ctx, index_hint)) != 0) { ctx->closing = 0; return check; } + if (trsh != 0) + { + ctx->closing = 0; + return -1; + } } } @@ -1163,8 +1212,12 @@ int mx_sync_mailbox (CONTEXT *ctx, int * if (ctx->magic == M_IMAP) rc = imap_sync_mailbox (ctx, purge, index_hint); else -#endif +#endif /* enter this block unconditionally if IMAP is not used */ + { + if (trash_append (ctx) == -1) + return -1; rc = sync_mailbox (ctx, index_hint); + } if (rc == 0) { #ifdef USE_IMAP diff -pruN mutt-1.3.17.orig/postpone.c mutt-1.3.17/postpone.c --- mutt-1.3.17.orig/postpone.c Mon Feb 12 17:59:17 2001 +++ mutt-1.3.17/postpone.c Thu Jul 26 00:17:59 2001 @@ -270,6 +270,9 @@ int mutt_get_postponed (CONTEXT *ctx, HE /* 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;