updated on Sun Jan 22 16:00:49 UTC 2012
[aur-mirror.git] / mutt-trash / trash.diff
blobc75c348f6d2be6e8af7a3f9b8397a679abcd3577
1 diff --git a/PATCHES b/PATCHES
2 index e69de29..6a47dd7 100644
3 --- a/PATCHES
4 +++ b/PATCHES
5 @@ -0,0 +1 @@
6 +patch-1.5.16hg.cd.trash_folder.vl.1
7 diff --git a/commands.c b/commands.c
8 index 2fdcb7f..998f2fd 100644
9 --- a/commands.c
10 +++ b/commands.c
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);
17 return 0;
19 diff --git a/flags.c b/flags.c
20 index 732eb01..6cda898 100644
21 --- a/flags.c
22 +++ b/flags.c
23 @@ -69,7 +69,13 @@ void _mutt_set_flag (CONTEXT *ctx, HEADER *h, int flag, int bf, int upd_ctx)
25 h->deleted = 0;
26 update = 1;
27 - if (upd_ctx) ctx->deleted--;
28 + if (upd_ctx)
29 + {
30 + ctx->deleted--;
31 + if (h->appended)
32 + ctx->appended--;
33 + }
34 + h->appended = 0; /* when undeleting, also reset the appended flag */
35 #ifdef USE_IMAP
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)
40 break;
42 + case M_APPENDED:
43 + if (bf)
44 + {
45 + if (!h->appended)
46 + {
47 + h->appended = 1;
48 + if (upd_ctx) ctx->appended++;
49 + }
50 + }
51 + break;
53 case M_NEW:
55 if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
56 diff --git a/globals.h b/globals.h
57 index 15c0d14..9699a4d 100644
58 --- a/globals.h
59 +++ b/globals.h
60 @@ -142,6 +142,7 @@ WHERE char *StChars;
61 WHERE char *Status;
62 WHERE char *Tempdir;
63 WHERE char *Tochars;
64 +WHERE char *TrashPath;
65 WHERE char *Username;
66 WHERE char *Visual;
68 diff --git a/imap/message.c b/imap/message.c
69 index 77cef6e..aa21819 100644
70 --- a/imap/message.c
71 +++ b/imap/message.c
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)
81 else
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
90 --- a/init.h
91 +++ b/init.h
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 },
97 + /*
98 + ** .pp
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
101 + ** purged.
102 + ** .pp
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.
105 + */
106 #ifdef USE_SOCKET
107 { "tunnel", DT_STR, R_NONE, UL &Tunnel, UL 0 },
109 diff --git a/mutt.h b/mutt.h
110 index 5930e14..9c07161 100644
111 --- a/mutt.h
112 +++ b/mutt.h
113 @@ -201,6 +201,7 @@ enum
114 M_DELETE,
115 M_UNDELETE,
116 M_DELETED,
117 + M_APPENDED,
118 M_FLAG,
119 M_TAG,
120 M_UNTAG,
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
139 --- a/muttlib.c
140 +++ b/muttlib.c
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
154 --- a/mx.c
155 +++ b/mx.c
156 @@ -808,6 +808,53 @@ static int sync_mailbox (CONTEXT *ctx, int *index_hint)
157 return rc;
160 +/* move deleted mails to the trash folder */
161 +static int trash_append (CONTEXT *ctx)
163 + CONTEXT *ctx_trash;
164 + int i = 0;
165 + struct stat st, stc;
167 + if (!TrashPath || !ctx->deleted ||
168 + (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
169 + return 0;
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");
179 + return -1;
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);
193 + return -1;
196 + mx_close_mailbox (ctx_trash, NULL);
198 + else
200 + mutt_error _("Can't open trash folder");
201 + return -1;
204 + return 0;
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);
216 else
218 @@ -964,6 +1012,14 @@ int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
219 return 0;
222 + /* copy mails to the trash before expunging */
223 + if (purge && ctx->deleted)
224 + if (trash_append (ctx) != 0)
226 + ctx->closing = 0;
227 + return -1;
230 #ifdef USE_IMAP
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)
240 + return -1;
241 + }
243 #ifdef USE_IMAP
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
248 --- a/postpone.c
249 +++ b/postpone.c
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;