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: mutt/commands.c
50 ===================================================================
51 --- mutt.orig/commands.c 2009-06-25 12:35:37.000000000 +0200
52 +++ mutt/commands.c 2009-06-25 12:35:48.000000000 +0200
54 if (option (OPTDELETEUNTAG))
55 mutt_set_flag (Context, h, M_TAG, 0);
57 + mutt_set_flag (Context, h, M_APPENDED, 1);
62 ===================================================================
63 --- mutt.orig/flags.c 2009-06-25 12:35:37.000000000 +0200
64 +++ mutt/flags.c 2009-06-25 12:35:48.000000000 +0200
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)
90 + if (upd_ctx) ctx->appended++;
97 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
99 ===================================================================
100 --- mutt.orig/globals.h 2009-06-25 12:35:44.000000000 +0200
101 +++ mutt/globals.h 2009-06-25 12:35:48.000000000 +0200
106 +WHERE char *TrashPath;
107 WHERE char *Username;
109 WHERE char *XtermTitle;
110 Index: mutt/imap/message.c
111 ===================================================================
112 --- mutt.orig/imap/message.c 2009-06-25 12:35:37.000000000 +0200
113 +++ mutt/imap/message.c 2009-06-25 12:35:48.000000000 +0200
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);
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 --- mutt.orig/init.h 2009-06-25 12:35:44.000000000 +0200
133 +++ mutt/init.h 2009-06-25 12:35:48.000000000 +0200
134 @@ -3180,6 +3180,16 @@
135 ** by \fIyou\fP. The sixth character is used to indicate when a mail
136 ** was sent to a mailing-list you subscribe to.
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 --- mutt.orig/mutt.h 2009-06-25 12:35:44.000000000 +0200
154 +++ mutt/mutt.h 2009-06-25 12:35:48.000000000 +0200
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 */
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: mutt/muttlib.c
180 ===================================================================
181 --- mutt.orig/muttlib.c 2009-06-25 12:35:37.000000000 +0200
182 +++ mutt/muttlib.c 2009-06-25 12:35:48.000000000 +0200
183 @@ -1460,7 +1460,9 @@
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 --- mutt.orig/mx.c 2009-06-25 12:35:37.000000000 +0200
197 +++ mutt/mx.c 2009-06-25 12:35:48.000000000 +0200
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)
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);
264 + /* copy mails to the trash before expunging */
265 + if (purge && ctx->deleted && mutt_strcmp(ctx->path, TrashPath))
266 + if (trash_append (ctx) != 0)
273 /* allow IMAP to preserve the deleted flag across sessions */
274 if (ctx->magic == M_IMAP)
275 @@ -1130,6 +1186,12 @@
276 msgcount = ctx->msgcount;
277 deleted = ctx->deleted;
279 + if (purge && ctx->deleted && mutt_strcmp(ctx->path, TrashPath))
281 + if (trash_append (ctx) == -1)
286 if (ctx->magic == M_IMAP)
287 rc = imap_sync_mailbox (ctx, purge, index_hint);
288 Index: mutt/postpone.c
289 ===================================================================
290 --- mutt.orig/postpone.c 2009-06-25 12:35:37.000000000 +0200
291 +++ mutt/postpone.c 2009-06-25 12:35:48.000000000 +0200
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;