On Wed, Apr 11, 2007 at 08:33:59PM -0400, Mike Hunter wrote: > On Apr 11 at 17:03, Mun Johl wrote: > > On Mon, Apr 09, 2007 at 06:39 PM PDT, Vincent Lefevre wrote: > > > On 2007-04-09 16:04:23 -0700, William Yardley wrote: > > > > Anyway, anyone else think this would be a good addition? > > > > > > Yes, I'd like it (since I use it).
> > Ditto. > Me me me me me! I have a version of the patch (attached) which should apply to current CVS. w
diff -u mutt-1.5.12/PATCHES mutt-1.5.12.patched/PATCHES --- mutt-1.5.12/PATCHES 2006-07-14 11:12:47.000000000 -0700 +++ mutt-1.5.12.patched/PATCHES 2006-08-07 23:17:35.000000000 -0700 @@ -0,0 +1 @@ +patch-1.5.5.1.cd.trash_folder.3.4 diff -u mutt-1.5.12/commands.c mutt-1.5.12.patched/commands.c --- mutt-1.5.12/commands.c 2006-06-08 04:50:16.000000000 -0700 +++ mutt-1.5.12.patched/commands.c 2006-08-07 23:17:34.000000000 -0700 @@ -689,6 +689,8 @@ if (option (OPTDELETEUNTAG)) mutt_set_flag (Context, h, M_TAG, 0); } + + mutt_set_flag (Context, h, M_APPENDED, 1); return 0; } Common subdirectories: mutt-1.5.12/contrib and mutt-1.5.12.patched/contrib Common subdirectories: mutt-1.5.12/doc and mutt-1.5.12.patched/doc diff -u mutt-1.5.12/flags.c mutt-1.5.12.patched/flags.c --- mutt-1.5.12/flags.c 2005-10-31 02:03:00.000000000 -0800 +++ mutt-1.5.12.patched/flags.c 2006-08-07 23:17:34.000000000 -0700 @@ -70,7 +70,13 @@ else if (h->deleted) { h->deleted = 0; - 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) @@ -92,6 +98,17 @@ } break; + case M_APPENDED: + if (bf) + { + if (!h->appended) + { + h->appended = 1; + if (upd_ctx) ctx->appended++; + } + } + break; + case M_NEW: #ifdef USE_IMAP Only in mutt-1.5.12.patched/: flags.c.orig diff -u mutt-1.5.12/globals.h mutt-1.5.12.patched/globals.h --- mutt-1.5.12/globals.h 2006-07-05 01:40:05.000000000 -0700 +++ mutt-1.5.12.patched/globals.h 2006-08-07 23:17:34.000000000 -0700 @@ -135,6 +135,7 @@ WHERE char *Status; WHERE char *Tempdir; WHERE char *Tochars; +WHERE char *TrashPath; WHERE char *Username; WHERE char *Visual; Only in mutt-1.5.12.patched/: globals.h.orig Common subdirectories: mutt-1.5.12/imap and mutt-1.5.12.patched/imap diff -u mutt-1.5.12/init.h mutt-1.5.12.patched/init.h --- mutt-1.5.12/init.h 2006-07-05 01:40:05.000000000 -0700 +++ mutt-1.5.12.patched/init.h 2006-08-07 23:17:34.000000000 -0700 @@ -2795,6 +2795,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 }, /* Only in mutt-1.5.12.patched/: init.h.orig Common subdirectories: mutt-1.5.12/intl and mutt-1.5.12.patched/intl Common subdirectories: mutt-1.5.12/m4 and mutt-1.5.12.patched/m4 diff -u mutt-1.5.12/mutt.h mutt-1.5.12.patched/mutt.h --- mutt-1.5.12/mutt.h 2006-06-08 04:49:07.000000000 -0700 +++ mutt-1.5.12.patched/mutt.h 2006-08-07 23:17:34.000000000 -0700 @@ -198,6 +198,7 @@ M_DELETE, M_UNDELETE, M_DELETED, + M_APPENDED, M_FLAG, M_TAG, M_UNTAG, @@ -700,6 +701,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 */ @@ -854,6 +856,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 */ #if defined USE_POP || defined USE_IMAP Only in mutt-1.5.12.patched/: mutt.h.orig diff -u mutt-1.5.12/muttlib.c mutt-1.5.12.patched/muttlib.c --- mutt-1.5.12/muttlib.c 2006-06-08 04:51:03.000000000 -0700 +++ mutt-1.5.12.patched/muttlib.c 2006-08-07 23:19:02.000000000 -0700 @@ -1265,7 +1265,10 @@ 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) Only in mutt-1.5.12.patched/: muttlib.c.orig diff -u mutt-1.5.12/mx.c mutt-1.5.12.patched/mx.c --- mutt-1.5.12/mx.c 2006-05-18 11:44:29.000000000 -0700 +++ mutt-1.5.12.patched/mx.c 2006-08-07 23:17:34.000000000 -0700 @@ -819,6 +819,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) { @@ -954,6 +1001,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 { @@ -975,6 +1023,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) @@ -1170,6 +1226,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); Only in mutt-1.5.12.patched/: mx.c.orig Common subdirectories: mutt-1.5.12/po and mutt-1.5.12.patched/po diff -u mutt-1.5.12/postpone.c mutt-1.5.12.patched/postpone.c --- mutt-1.5.12/postpone.c 2006-04-20 09:46:35.000000000 -0700 +++ mutt-1.5.12.patched/postpone.c 2006-08-07 23:17:35.000000000 -0700 @@ -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; Only in mutt-1.5.12.patched/: postpone.c.orig