File patch-1.5.5.1.cd.trash_folder.3.4 of Package mutt
Index: mutt-1.5.21/commands.c
===================================================================
--- mutt-1.5.21.orig/commands.c
+++ mutt-1.5.21/commands.c
@@ -716,8 +716,9 @@ int _mutt_save_message (HEADER *h, CONTE
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);
return 0;
}
Index: mutt-1.5.21/flags.c
===================================================================
--- mutt-1.5.21.orig/flags.c
+++ mutt-1.5.21/flags.c
@@ -66,9 +66,15 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
else if (h->deleted)
{
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)
{
@@ -88,8 +94,19 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
ctx->changed = 1;
}
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))
return;
Index: mutt-1.5.21/globals.h
===================================================================
--- mutt-1.5.21.orig/globals.h
+++ mutt-1.5.21/globals.h
@@ -140,8 +140,9 @@ WHERE char *SslCACertFile INITVAL (NULL)
WHERE char *StChars;
WHERE char *Status;
WHERE char *Tempdir;
WHERE char *Tochars;
+WHERE char *TrashPath;
WHERE char *Username;
WHERE char *Visual;
WHERE char *XtermTitle;
WHERE char *XtermIcon;
Index: mutt-1.5.21/imap/message.c
===================================================================
--- mutt-1.5.21.orig/imap/message.c
+++ mutt-1.5.21/imap/message.c
@@ -894,15 +894,17 @@ int imap_copy_messages (CONTEXT* ctx, HE
{
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);
}
}
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);
}
}
Index: mutt-1.5.21/init.h
===================================================================
--- mutt-1.5.21.orig/init.h
+++ mutt-1.5.21/init.h
@@ -2172,8 +2172,18 @@ struct option_t MuttVars[] = {
** in the mailbox specified by this variable.
** .pp
** 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.
+ ** .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
{ "preconnect", DT_STR, R_NONE, UL &Preconnect, UL 0},
/*
** .pp
Index: mutt-1.5.21/mutt.h
===================================================================
--- mutt-1.5.21.orig/mutt.h
+++ mutt-1.5.21/mutt.h
@@ -191,8 +191,9 @@ enum
M_UNREAD,
M_DELETE,
M_UNDELETE,
M_DELETED,
+ M_APPENDED,
M_FLAG,
M_TAG,
M_UNTAG,
M_LIMIT,
@@ -721,8 +722,9 @@ 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 */
unsigned int old : 1;
@@ -894,8 +896,9 @@ typedef struct _context
int tagged; /* how many messages are tagged? */
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 */
#ifdef USE_COMPRESSED
Index: mutt-1.5.21/muttlib.c
===================================================================
--- mutt-1.5.21.orig/muttlib.c
+++ mutt-1.5.21/muttlib.c
@@ -1565,9 +1565,11 @@ int mutt_save_confirm (const char *s, st
#endif
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)
ret = 1;
Index: mutt-1.5.21/mx.c
===================================================================
--- mutt-1.5.21.orig/mx.c
+++ mutt-1.5.21/mx.c
@@ -823,8 +823,55 @@ 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 = 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)
{
int i, move_messages = 0, purge = 1, read_msgs = 0;
@@ -963,8 +1010,9 @@ int mx_close_mailbox (CONTEXT *ctx, int
{
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
{
mx_close_mailbox (&f, NULL);
@@ -987,8 +1035,16 @@ int mx_close_mailbox (CONTEXT *ctx, int
mx_fastclose_mailbox (ctx);
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)
{
@@ -1189,8 +1245,14 @@ int mx_sync_mailbox (CONTEXT *ctx, int *
* mx_update_tables, so ctx->deleted is 0 when it comes back */
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);
else
Index: mutt-1.5.21/postpone.c
===================================================================
--- mutt-1.5.21.orig/postpone.c
+++ mutt-1.5.21/postpone.c
@@ -276,8 +276,11 @@ 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;
/* avoid the "purge deleted messages" prompt */
Index: mutt-1.5.21/PATCHES
===================================================================
--- mutt-1.5.21.orig/PATCHES
+++ mutt-1.5.21/PATCHES
@@ -1,5 +1,6 @@
patch-1.5.3.vk.pgp_verbose_mime
+patch-1.5.5.1.cd.trash_folder.3.4
patch-1.5.9.aw.listreply.1
patch-1.5.21.sidebar.20120829.txt
patch-1.5.19.rr.compressed.1
patch-1.5.5.1.nt.xtitles.3.ab.1