2 This is the trash folder patch by Cedric Duval <cedricduval@free.fr>.
4 With this patch, if the trash variable is set to a path (unset by default), the
5 deleted mails will be moved to a trash folder instead of being irremediably
6 purged when syncing the mailbox.
8 For instance, set trash="~/Mail/trash" will cause every deleted mail to go to
11 Note that the append to the trash folder doesn't occur until the resync is
12 done. This allows you to change your mind and undo deletes, and thus the moves
13 to the trash folder are unnecessary.
17 * You might also want to have a look at the purge message feature below
18 which is related to this patch.
19 * IMAP is now supported. To retain the previous behavior, add this to your
21 folder-hook ^imap:// 'unset trash'
25 Every once in a while, someone asks what are the advantages of this patch over
26 a macro based solution. Here's an attempt to answer this question:
28 * The folder history doesn't clutter up with unwanted trash entries.
29 * Delayed move to the trash allows to change one's mind.
30 * No need to treat the case of "normal folders" and trash folders
31 separately with folder-hooks, and to create two sets of macros (one for
32 the index, one for the pager).
33 * Works not only with delete-message, but also with every deletion
34 functions like delete-pattern, delete-thread or delete-subthread.
36 To sum up, it's more integrated and transparent to the user.
38 * Patch last synced with upstream:
40 - File: http://cedricduval.free.fr/mutt/patches/download/patch-1.5.5.1.cd.trash_folder.3.4
44 - structure of _mutt_save_message changed (commands.c)
45 - context of option (OPTCONFIRMAPPEND) changed (muttlib.c)
46 - Fixed indentation of "appended" in mutt.h.
49 Index: trash/commands.c
50 ===================================================================
51 --- trash.orig/commands.c 2006-12-12 14:15:02.000000000 +0100
52 +++ trash/commands.c 2007-02-15 19:34:10.324888040 +0100
53 @@ -690,6 +690,7 @@ int _mutt_save_message (HEADER *h, CONTE
54 if (option (OPTDELETEUNTAG))
55 mutt_set_flag (Context, h, M_TAG, 0);
57 + mutt_set_flag (Context, h, M_APPENDED, 1);
62 ===================================================================
63 --- trash.orig/flags.c 2006-12-12 14:15:02.000000000 +0100
64 +++ trash/flags.c 2007-02-15 19:34:10.325887888 +0100
65 @@ -66,7 +66,13 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
69 - if (upd_ctx) ctx->deleted--;
76 + h->appended = 0; /* when undeleting, also reset the appended flag */
78 /* see my comment above */
79 if (ctx->magic == M_IMAP)
80 @@ -88,6 +94,17 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
90 + if (upd_ctx) ctx->appended++;
97 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
98 Index: trash/globals.h
99 ===================================================================
100 --- trash.orig/globals.h 2007-01-04 15:23:49.000000000 +0100
101 +++ trash/globals.h 2007-02-15 19:34:10.325887888 +0100
102 @@ -135,6 +135,7 @@ WHERE char *StChars;
106 +WHERE char *TrashPath;
107 WHERE char *Username;
110 Index: trash/imap/message.c
111 ===================================================================
112 --- trash.orig/imap/message.c 2007-02-14 15:32:38.000000000 +0100
113 +++ trash/imap/message.c 2007-02-15 19:34:10.325887888 +0100
114 @@ -817,6 +817,7 @@ int imap_copy_messages (CONTEXT* ctx, HE
115 if (ctx->hdrs[n]->tagged)
117 mutt_set_flag (ctx, ctx->hdrs[n], M_DELETE, 1);
118 + mutt_set_flag (ctx, ctx->hdrs[n], M_APPENDED, 1);
119 if (option (OPTDELETEUNTAG))
120 mutt_set_flag (ctx, ctx->hdrs[n], M_TAG, 0);
122 @@ -824,6 +825,7 @@ int imap_copy_messages (CONTEXT* ctx, HE
125 mutt_set_flag (ctx, h, M_DELETE, 1);
126 + mutt_set_flag (ctx, h, M_APPENDED, 1);
127 if (option (OPTDELETEUNTAG))
128 mutt_set_flag (ctx, h, M_TAG, 0);
131 ===================================================================
132 --- trash.orig/init.h 2006-12-12 14:15:03.000000000 +0100
133 +++ trash/init.h 2007-02-15 19:34:10.326887736 +0100
134 @@ -2808,6 +2808,16 @@ struct option_t MuttVars[] = {
135 ** by \fIyou\fP. The sixth character is used to indicate when a mail
136 ** was sent to a mailing-list you subscribe to (default: L).
138 + { "trash", DT_PATH, R_NONE, UL &TrashPath, 0 },
141 + ** If set, this variable specifies the path of the trash folder where the
142 + ** mails marked for deletion will be moved, instead of being irremediably
145 + ** NOTE: When you delete a message in the trash folder, it is really
146 + ** deleted, so that you have a way to clean the trash.
149 { "tunnel", DT_STR, R_NONE, UL &Tunnel, UL 0 },
152 ===================================================================
153 --- trash.orig/mutt.h 2007-01-04 15:23:49.000000000 +0100
154 +++ trash/mutt.h 2007-02-15 19:34:10.327887584 +0100
155 @@ -200,6 +200,7 @@ enum
163 @@ -703,6 +704,7 @@ typedef struct header
164 unsigned int mime : 1; /* has a MIME-Version header? */
165 unsigned int flagged : 1; /* marked important? */
166 unsigned int tagged : 1;
167 + unsigned int appended : 1; /* has been saved */
168 unsigned int deleted : 1;
169 unsigned int changed : 1;
170 unsigned int attach_del : 1; /* has an attachment marked for deletion */
171 @@ -873,6 +875,7 @@ typedef struct
172 int new; /* how many new messages? */
173 int unread; /* how many unread messages? */
174 int deleted; /* how many deleted messages */
175 + int appended; /* how many saved messages? */
176 int flagged; /* how many flagged messages */
177 int msgnotreadyet; /* which msg "new" in pager, -1 if none */
178 #if defined USE_POP || defined USE_IMAP
179 Index: trash/muttlib.c
180 ===================================================================
181 --- trash.orig/muttlib.c 2007-01-04 15:23:50.000000000 +0100
182 +++ trash/muttlib.c 2007-02-15 19:34:10.327887584 +0100
183 @@ -1265,7 +1265,9 @@ int mutt_save_confirm (const char *s, st
185 if (magic > 0 && !mx_access (s, W_OK))
187 - if (option (OPTCONFIRMAPPEND))
188 + if (option (OPTCONFIRMAPPEND) &&
189 + (!TrashPath || (mutt_strcmp (s, TrashPath) != 0)))
190 + /* if we're appending to the trash, there's no point in asking */
192 snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
193 if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
195 ===================================================================
196 --- trash.orig/mx.c 2006-12-12 14:15:03.000000000 +0100
197 +++ trash/mx.c 2007-02-15 19:34:10.328887432 +0100
198 @@ -822,6 +822,53 @@ static int sync_mailbox (CONTEXT *ctx, i
202 +/* move deleted mails to the trash folder */
203 +static int trash_append (CONTEXT *ctx)
205 + CONTEXT *ctx_trash;
207 + struct stat st, stc;
209 + if (!TrashPath || !ctx->deleted ||
210 + (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
213 + for (;i < ctx->msgcount && (!ctx->hdrs[i]->deleted ||
214 + ctx->hdrs[i]->appended); i++);
215 + if (i == ctx->msgcount)
216 + return 0; /* nothing to be done */
218 + if (mutt_save_confirm (TrashPath, &st) != 0)
220 + mutt_error _("message(s) not deleted");
224 + if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino
225 + && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev)
226 + return 0; /* we are in the trash folder: simple sync */
228 + if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL)
230 + for (i = 0 ; i < ctx->msgcount ; i++)
231 + if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended
232 + && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
234 + mx_close_mailbox (ctx_trash, NULL);
238 + mx_close_mailbox (ctx_trash, NULL);
242 + mutt_error _("Can't open trash folder");
249 /* save changes and close mailbox */
250 int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
252 @@ -957,6 +1004,7 @@ int mx_close_mailbox (CONTEXT *ctx, int
253 if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0)
255 mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1);
256 + mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1);
260 @@ -978,6 +1026,14 @@ int mx_close_mailbox (CONTEXT *ctx, int
264 + /* copy mails to the trash before expunging */
265 + if (purge && ctx->deleted)
266 + if (trash_append (ctx) != 0)
273 /* allow IMAP to preserve the deleted flag across sessions */
274 if (ctx->magic == M_IMAP)
275 @@ -1173,6 +1229,12 @@ int mx_sync_mailbox (CONTEXT *ctx, int *
276 msgcount = ctx->msgcount;
277 deleted = ctx->deleted;
279 + if (purge && ctx->deleted)
281 + if (trash_append (ctx) == -1)
286 if (ctx->magic == M_IMAP)
287 rc = imap_sync_mailbox (ctx, purge, index_hint);
288 Index: trash/postpone.c
289 ===================================================================
290 --- trash.orig/postpone.c 2006-12-12 14:15:03.000000000 +0100
291 +++ trash/postpone.c 2007-02-15 19:34:10.328887432 +0100
292 @@ -279,6 +279,9 @@ int mutt_get_postponed (CONTEXT *ctx, HE
293 /* finished with this message, so delete it. */
294 mutt_set_flag (PostContext, h, M_DELETE, 1);
296 + /* and consider it saved, so that it won't be moved to the trash folder */
297 + mutt_set_flag (PostContext, h, M_APPENDED, 1);
299 /* update the count for the status display */
300 PostCount = PostContext->msgcount - PostContext->deleted;
303 ===================================================================
304 --- trash/PATCHES.orig 2007-02-15 19:35:06.277381968 +0100
305 +++ trash/PATCHES 2007-02-15 19:35:06.277381968 +0100
307 +patch-1.5.13.cd.trash_folder.3.4