1 diff --git a/PATCHES b/PATCHES
2 index e69de29..6a47dd7 100644
6 +patch-1.5.16hg.cd.trash_folder.vl.1
7 diff --git a/commands.c b/commands.c
8 index 2fdcb7f..998f2fd 100644
11 @@ -688,6 +688,7 @@ int _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode, int dec
12 if (option (OPTDELETEUNTAG))
13 mutt_set_flag (Context, h, M_TAG, 0);
15 + mutt_set_flag (Context, h, M_APPENDED, 1);
19 diff --git a/flags.c b/flags.c
20 index 732eb01..6cda898 100644
23 @@ -69,7 +69,13 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
27 - if (upd_ctx) ctx->deleted--;
34 + h->appended = 0; /* when undeleting, also reset the appended flag */
36 /* see my comment above */
37 if (ctx->magic == M_IMAP)
38 @@ -91,6 +97,17 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
48 + if (upd_ctx) ctx->appended++;
55 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
56 diff --git a/globals.h b/globals.h
57 index 15c0d14..9699a4d 100644
60 @@ -142,6 +142,7 @@ WHERE char *StChars;
64 +WHERE char *TrashPath;
68 diff --git a/imap/message.c b/imap/message.c
69 index 77cef6e..aa21819 100644
72 @@ -816,6 +816,7 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete)
73 if (ctx->hdrs[n]->tagged)
75 mutt_set_flag (ctx, ctx->hdrs[n], M_DELETE, 1);
76 + mutt_set_flag (ctx, ctx->hdrs[n], M_APPENDED, 1);
77 if (option (OPTDELETEUNTAG))
78 mutt_set_flag (ctx, ctx->hdrs[n], M_TAG, 0);
80 @@ -823,6 +824,7 @@ int imap_copy_messages (CONTEXT* ctx, HEADER* h, char* dest, int delete)
83 mutt_set_flag (ctx, h, M_DELETE, 1);
84 + mutt_set_flag (ctx, h, M_APPENDED, 1);
85 if (option (OPTDELETEUNTAG))
86 mutt_set_flag (ctx, h, M_TAG, 0);
88 diff --git a/init.h b/init.h
89 index 2674bef..5f8100f 100644
92 @@ -2863,6 +2863,16 @@ struct option_t MuttVars[] = {
93 ** by \fIyou\fP. The sixth character is used to indicate when a mail
94 ** was sent to a mailing-list you subscribe to (default: L).
96 + { "trash", DT_PATH, R_NONE, UL &TrashPath, 0 },
99 + ** If set, this variable specifies the path of the trash folder where the
100 + ** mails marked for deletion will be moved, instead of being irremediably
103 + ** NOTE: When you delete a message in the trash folder, it is really
104 + ** deleted, so that you have a way to clean the trash.
107 { "tunnel", DT_STR, R_NONE, UL &Tunnel, UL 0 },
109 diff --git a/mutt.h b/mutt.h
110 index 5930e14..9c07161 100644
113 @@ -201,6 +201,7 @@ enum
121 @@ -711,6 +712,7 @@ typedef struct header
122 unsigned int mime : 1; /* has a MIME-Version header? */
123 unsigned int flagged : 1; /* marked important? */
124 unsigned int tagged : 1;
125 + unsigned int appended : 1; /* has been saved */
126 unsigned int deleted : 1;
127 unsigned int changed : 1;
128 unsigned int attach_del : 1; /* has an attachment marked for deletion */
129 @@ -882,6 +884,7 @@ typedef struct _context
130 int new; /* how many new messages? */
131 int unread; /* how many unread messages? */
132 int deleted; /* how many deleted messages */
133 + int appended; /* how many saved messages? */
134 int flagged; /* how many flagged messages */
135 int msgnotreadyet; /* which msg "new" in pager, -1 if none */
137 diff --git a/muttlib.c b/muttlib.c
138 index 497b5f8..7860376 100644
141 @@ -1384,7 +1384,9 @@ int mutt_save_confirm (const char *s, struct stat *st)
143 if (magic > 0 && !mx_access (s, W_OK))
145 - if (option (OPTCONFIRMAPPEND))
146 + if (option (OPTCONFIRMAPPEND) &&
147 + (!TrashPath || (mutt_strcmp (s, TrashPath) != 0)))
148 + /* if we're appending to the trash, there's no point in asking */
150 snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
151 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
152 diff --git a/mx.c b/mx.c
153 index afa6843..fe1fd1d 100644
156 @@ -808,6 +808,53 @@ static int sync_mailbox (CONTEXT *ctx, int *index_hint)
160 +/* move deleted mails to the trash folder */
161 +static int trash_append (CONTEXT *ctx)
163 + CONTEXT *ctx_trash;
165 + struct stat st, stc;
167 + if (!TrashPath || !ctx->deleted ||
168 + (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
171 + for (;i < ctx->msgcount && (!ctx->hdrs[i]->deleted ||
172 + ctx->hdrs[i]->appended); i++);
173 + if (i == ctx->msgcount)
174 + return 0; /* nothing to be done */
176 + if (mutt_save_confirm (TrashPath, &st) != 0)
178 + mutt_error _("message(s) not deleted");
182 + if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino
183 + && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev)
184 + return 0; /* we are in the trash folder: simple sync */
186 + if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL)
188 + for (i = 0 ; i < ctx->msgcount ; i++)
189 + if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended
190 + && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
192 + mx_close_mailbox (ctx_trash, NULL);
196 + mx_close_mailbox (ctx_trash, NULL);
200 + mutt_error _("Can't open trash folder");
207 /* save changes and close mailbox */
208 int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
210 @@ -943,6 +990,7 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
211 if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0)
213 mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1);
214 + mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1);
218 @@ -964,6 +1012,14 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
222 + /* copy mails to the trash before expunging */
223 + if (purge && ctx->deleted)
224 + if (trash_append (ctx) != 0)
231 /* allow IMAP to preserve the deleted flag across sessions */
232 if (ctx->magic == M_IMAP)
233 @@ -1159,6 +1215,12 @@ int mx_sync_mailbox (CONTEXT *ctx, int *index_hint)
234 msgcount = ctx->msgcount;
235 deleted = ctx->deleted;
237 + if (purge && ctx->deleted)
239 + if (trash_append (ctx) == -1)
244 if (ctx->magic == M_IMAP)
245 rc = imap_sync_mailbox (ctx, purge, index_hint);
246 diff --git a/postpone.c b/postpone.c
247 index bcb8607..c367247 100644
250 @@ -279,6 +279,9 @@ int mutt_get_postponed (CONTEXT *ctx, HEADER *hdr, HEADER **cur, char *fcc, size
251 /* finished with this message, so delete it. */
252 mutt_set_flag (PostContext, h, M_DELETE, 1);
254 + /* and consider it saved, so that it won't be moved to the trash folder */
255 + mutt_set_flag (PostContext, h, M_APPENDED, 1);
257 /* update the count for the status display */
258 PostCount = PostContext->msgcount - PostContext->deleted;