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: debian-mutt/commands.c
50 ===================================================================
51 --- debian-mutt.orig/commands.c 2007-04-12 19:06:45.000000000 +0200
52 +++ debian-mutt/commands.c 2007-05-16 23:09:20.000000000 +0200
53 @@ -688,6 +688,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);
61 Index: debian-mutt/flags.c
62 ===================================================================
63 --- debian-mutt.orig/flags.c 2007-05-16 23:08:46.000000000 +0200
64 +++ debian-mutt/flags.c 2007-05-16 23:43:45.000000000 +0200
65 @@ -69,7 +69,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 @@ -91,6 +97,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: debian-mutt/globals.h
99 ===================================================================
100 --- debian-mutt.orig/globals.h 2007-05-16 23:09:10.000000000 +0200
101 +++ debian-mutt/globals.h 2007-05-16 23:09:20.000000000 +0200
102 @@ -142,6 +142,7 @@ WHERE char *StChars;
106 +WHERE char *TrashPath;
107 WHERE char *Username;
109 WHERE char *XtermTitle;
110 Index: debian-mutt/imap/message.c
111 ===================================================================
112 --- debian-mutt.orig/imap/message.c 2007-05-16 23:08:46.000000000 +0200
113 +++ debian-mutt/imap/message.c 2007-05-16 23:09:20.000000000 +0200
114 @@ -816,6 +816,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 @@ -823,6 +824,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);
130 Index: debian-mutt/init.h
131 ===================================================================
132 --- debian-mutt.orig/init.h 2007-05-16 23:09:10.000000000 +0200
133 +++ debian-mutt/init.h 2007-05-16 23:09:20.000000000 +0200
134 @@ -2873,6 +2873,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 },
151 Index: debian-mutt/mutt.h
152 ===================================================================
153 --- debian-mutt.orig/mutt.h 2007-05-16 23:09:10.000000000 +0200
154 +++ debian-mutt/mutt.h 2007-05-16 23:09:20.000000000 +0200
155 @@ -206,6 +206,7 @@ enum
163 @@ -718,6 +719,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 @@ -889,6 +891,7 @@ typedef struct _context
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 */
179 Index: debian-mutt/muttlib.c
180 ===================================================================
181 --- debian-mutt.orig/muttlib.c 2007-05-16 23:08:47.000000000 +0200
182 +++ debian-mutt/muttlib.c 2007-05-16 23:09:20.000000000 +0200
183 @@ -1384,7 +1384,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)
194 Index: debian-mutt/mx.c
195 ===================================================================
196 --- debian-mutt.orig/mx.c 2007-05-16 23:09:10.000000000 +0200
197 +++ debian-mutt/mx.c 2007-05-16 23:09:20.000000000 +0200
198 @@ -838,6 +838,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 @@ -973,6 +1020,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 @@ -994,6 +1042,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 @@ -1194,6 +1250,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: debian-mutt/postpone.c
289 ===================================================================
290 --- debian-mutt.orig/postpone.c 2007-04-12 19:06:45.000000000 +0200
291 +++ debian-mutt/postpone.c 2007-05-16 23:09:20.000000000 +0200
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;
302 Index: debian-mutt/PATCHES
303 ===================================================================
304 --- debian-mutt.orig/PATCHES 2007-05-16 23:09:10.000000000 +0200
305 +++ debian-mutt/PATCHES 2007-05-16 23:09:20.000000000 +0200
307 +patch-1.5.13.cd.trash_folder.3.4
308 patch-1.5.13.nt+ab.xtitles.4
309 patch-1.5.6.dw.maildir-mtime.1
310 patch-1.5.13.cd.ifdef.2