aboutsummaryrefslogtreecommitdiffstats
path: root/trash.patch
blob: d609d184d9075d5fc9ad64f687597e5dfa2dba5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
diff -pruN -x'*.orig' mutt-1.5.20/OPS mutt-1.5.20-trash/OPS
--- mutt-1.5.20/OPS	2009-05-13 01:01:13.000000000 -0400
+++ mutt-1.5.20-trash/OPS	2009-07-23 09:44:40.000000000 -0400
@@ -141,6 +141,7 @@ OP_PREV_ENTRY "move to the previous entr
 OP_PREV_LINE "scroll up one line"
 OP_PREV_PAGE "move to the previous page"
 OP_PRINT "print the current entry"
+OP_PURGE_MESSAGE "really delete the current entry, bypassing the trash folder"
 OP_QUERY "query external program for addresses"
 OP_QUERY_APPEND "append new query results to current results"
 OP_QUIT "save changes to mailbox and quit"
diff -pruN -x'*.orig' mutt-1.5.20/PATCHES mutt-1.5.20-trash/PATCHES
--- mutt-1.5.20/PATCHES	2008-11-11 14:55:46.000000000 -0500
+++ mutt-1.5.20-trash/PATCHES	2009-07-23 09:53:20.000000000 -0400
@@ -0,0 +1 @@
+patch-1.5.20.bk.trash_folder-purge_message.1
diff -pruN -x'*.orig' mutt-1.5.20/commands.c mutt-1.5.20-trash/commands.c
--- mutt-1.5.20/commands.c	2009-06-12 19:38:52.000000000 -0400
+++ mutt-1.5.20-trash/commands.c	2009-07-23 09:44:40.000000000 -0400
@@ -716,6 +716,7 @@ int _mutt_save_message (HEADER *h, CONTE
     if (option (OPTDELETEUNTAG))
       mutt_set_flag (Context, h, M_TAG, 0);
   }
+  mutt_set_flag (Context, h, M_APPENDED, 1);
   
   return 0;
 }
diff -pruN -x'*.orig' mutt-1.5.20/curs_main.c mutt-1.5.20-trash/curs_main.c
--- mutt-1.5.20/curs_main.c	2009-06-13 22:48:36.000000000 -0400
+++ mutt-1.5.20-trash/curs_main.c	2009-07-23 09:44:40.000000000 -0400
@@ -1803,6 +1803,7 @@ int mutt_index_menu (void)
 	MAYBE_REDRAW (menu->redraw);
 	break;
 
+      case OP_PURGE_MESSAGE:
       case OP_DELETE:
 
 	CHECK_MSGCOUNT;
@@ -1813,6 +1814,7 @@ int mutt_index_menu (void)
 	if (tag)
 	{
 	  mutt_tag_set_flag (M_DELETE, 1);
+	  mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
 	  if (option (OPTDELETEUNTAG))
 	    mutt_tag_set_flag (M_TAG, 0);
 	  menu->redraw = REDRAW_INDEX;
@@ -1820,6 +1822,8 @@ int mutt_index_menu (void)
 	else
 	{
 	  mutt_set_flag (Context, CURHDR, M_DELETE, 1);
+	  mutt_set_flag (Context, CURHDR, M_PURGED,
+			 (op != OP_PURGE_MESSAGE) ? 0 : 1);
 	  if (option (OPTDELETEUNTAG))
 	    mutt_set_flag (Context, CURHDR, M_TAG, 0);
 	  if (option (OPTRESOLVE))
@@ -2116,11 +2120,13 @@ int mutt_index_menu (void)
 	if (tag)
 	{
 	  mutt_tag_set_flag (M_DELETE, 0);
+	  mutt_tag_set_flag (M_PURGED, 0);
 	  menu->redraw = REDRAW_INDEX;
 	}
 	else
 	{
 	  mutt_set_flag (Context, CURHDR, M_DELETE, 0);
+	  mutt_set_flag (Context, CURHDR, M_PURGED, 0);
 	  if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
 	  {
 	    menu->current++;
@@ -2141,9 +2147,11 @@ int mutt_index_menu (void)
 	CHECK_ACL(M_ACL_DELETE, _("undelete message(s)"));
 
 	rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
-				   op == OP_UNDELETE_THREAD ? 0 : 1);
+				   op == OP_UNDELETE_THREAD ? 0 : 1)
+	  + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
+				  op == OP_UNDELETE_THREAD ? 0 : 1);
 
-	if (rc != -1)
+	if (rc > -1)
 	{
 	  if (option (OPTRESOLVE))
 	  {
diff -pruN -x'*.orig' mutt-1.5.20/flags.c mutt-1.5.20-trash/flags.c
--- mutt-1.5.20/flags.c	2008-12-16 22:50:09.000000000 -0500
+++ mutt-1.5.20-trash/flags.c	2009-07-23 09:44:40.000000000 -0400
@@ -65,7 +65,13 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
       {
 	h->deleted = 0;
         update = 1;
-	if (upd_ctx) ctx->deleted--;
+        if (upd_ctx)
+        {
+          ctx->deleted--;
+          if (h->appended)
+            ctx->appended--;
+        }
+        h->appended = 0; /* when undeleting, also reset the appended flag */
 #ifdef USE_IMAP
         /* see my comment above */
 	if (ctx->magic == M_IMAP) 
@@ -87,6 +93,27 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
       }
       break;
 
+    case M_APPENDED:
+      if (bf)
+      {
+       if (!h->appended)
+       {
+         h->appended = 1;
+         if (upd_ctx) ctx->appended++;
+       }
+      }
+      break;
+
+    case M_PURGED:
+      if (bf)
+      {
+	if (!h->purged)
+	  h->purged = 1;
+      }
+      else if (h->purged)
+	h->purged = 0;
+      break;
+
     case M_NEW:
 
       if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
diff -pruN -x'*.orig' mutt-1.5.20/functions.h mutt-1.5.20-trash/functions.h
--- mutt-1.5.20/functions.h	2009-04-30 01:36:17.000000000 -0400
+++ mutt-1.5.20-trash/functions.h	2009-07-23 09:44:40.000000000 -0400
@@ -120,6 +120,7 @@ struct binding_t OpMain[] = { /* map: in
   { "toggle-write",		OP_TOGGLE_WRITE,		"%" },
   { "next-thread",		OP_MAIN_NEXT_THREAD,		"\016" },
   { "next-subthread",		OP_MAIN_NEXT_SUBTHREAD,		"\033n" },
+  { "purge-message",		OP_PURGE_MESSAGE,		NULL },
   { "query",			OP_QUERY,			"Q" },
   { "quit",			OP_QUIT,			"q" },
   { "reply",			OP_REPLY,			"r" },
@@ -209,6 +210,7 @@ struct binding_t OpPager[] = { /* map: p
   { "print-message",	OP_PRINT,			"p" },
   { "previous-thread",	OP_MAIN_PREV_THREAD,		"\020" },
   { "previous-subthread",OP_MAIN_PREV_SUBTHREAD,	"\033p" },
+  { "purge-message",	OP_PURGE_MESSAGE,		NULL },
   { "quit",		OP_QUIT,			"Q" },
   { "exit",		OP_EXIT,			"q" },
   { "reply",		OP_REPLY,			"r" },
diff -pruN -x'*.orig' mutt-1.5.20/globals.h mutt-1.5.20-trash/globals.h
--- mutt-1.5.20/globals.h	2009-06-03 16:48:31.000000000 -0400
+++ mutt-1.5.20-trash/globals.h	2009-07-23 09:44:40.000000000 -0400
@@ -139,6 +139,7 @@ WHERE char *StChars;
 WHERE char *Status;
 WHERE char *Tempdir;
 WHERE char *Tochars;
+WHERE char *TrashPath;
 WHERE char *Username;
 WHERE char *Visual;
 
diff -pruN -x'*.orig' mutt-1.5.20/imap/message.c mutt-1.5.20-trash/imap/message.c
--- mutt-1.5.20/imap/message.c	2009-06-07 13:52:57.000000000 -0400
+++ mutt-1.5.20-trash/imap/message.c	2009-07-23 09:44:40.000000000 -0400
@@ -867,6 +867,7 @@ int imap_copy_messages (CONTEXT* ctx, HE
         if (ctx->hdrs[n]->tagged)
         {
           mutt_set_flag (ctx, ctx->hdrs[n], M_DELETE, 1);
+         mutt_set_flag (ctx, ctx->hdrs[n], M_APPENDED, 1);
           if (option (OPTDELETEUNTAG))
             mutt_set_flag (ctx, ctx->hdrs[n], M_TAG, 0);
         }
@@ -874,6 +875,7 @@ int imap_copy_messages (CONTEXT* ctx, HE
     else
     {
       mutt_set_flag (ctx, h, M_DELETE, 1);
+      mutt_set_flag (ctx, h, M_APPENDED, 1);
       if (option (OPTDELETEUNTAG))
         mutt_set_flag (ctx, h, M_TAG, 0);
     }
diff -pruN -x'*.orig' mutt-1.5.20/init.h mutt-1.5.20-trash/init.h
--- mutt-1.5.20/init.h	2009-06-13 17:35:21.000000000 -0400
+++ mutt-1.5.20-trash/init.h	2009-07-23 09:44:40.000000000 -0400
@@ -3180,6 +3180,16 @@ struct option_t MuttVars[] = {
   ** by \fIyou\fP.  The sixth character is used to indicate when a mail
   ** was sent to a mailing-list you subscribe to.
   */
+  { "trash",           DT_PATH, R_NONE, UL &TrashPath, 0 },
+  /*
+  ** .pp
+  ** If set, this variable specifies the path of the trash folder where the
+  ** mails marked for deletion will be moved, instead of being irremediably
+  ** purged.
+  ** .pp
+  ** NOTE: When you delete a message in the trash folder, it is really
+  ** deleted, so that you have a way to clean the trash.
+  */
 #ifdef USE_SOCKET
   { "tunnel",            DT_STR, R_NONE, UL &Tunnel, UL 0 },
   /*
diff -pruN -x'*.orig' mutt-1.5.20/mutt.h mutt-1.5.20-trash/mutt.h
--- mutt-1.5.20/mutt.h	2009-06-12 18:15:42.000000000 -0400
+++ mutt-1.5.20-trash/mutt.h	2009-07-23 09:44:40.000000000 -0400
@@ -187,6 +187,8 @@ enum
   M_DELETE,
   M_UNDELETE,
   M_DELETED,
+  M_APPENDED,
+  M_PURGED,
   M_FLAG,
   M_TAG,
   M_UNTAG,
@@ -701,6 +703,8 @@ typedef struct header
   unsigned int mime : 1;    		/* has a MIME-Version header? */
   unsigned int flagged : 1; 		/* marked important? */
   unsigned int tagged : 1;
+  unsigned int appended : 1; /* has been saved */
+  unsigned int purged : 1;   /* bypassing the trash folder */
   unsigned int deleted : 1;
   unsigned int changed : 1;
   unsigned int attach_del : 1; 		/* has an attachment marked for deletion */
@@ -873,6 +877,7 @@ typedef struct _context
   int new;			/* how many new messages? */
   int unread;			/* how many unread messages? */
   int deleted;			/* how many deleted messages */
+  int appended;                 /* how many saved messages? */
   int flagged;			/* how many flagged messages */
   int msgnotreadyet;		/* which msg "new" in pager, -1 if none */
 
diff -pruN -x'*.orig' mutt-1.5.20/muttlib.c mutt-1.5.20-trash/muttlib.c
--- mutt-1.5.20/muttlib.c	2009-05-18 20:11:35.000000000 -0400
+++ mutt-1.5.20-trash/muttlib.c	2009-07-23 09:44:40.000000000 -0400
@@ -1460,7 +1460,9 @@ int mutt_save_confirm (const char *s, st
 
   if (magic > 0 && !mx_access (s, W_OK))
   {
-    if (option (OPTCONFIRMAPPEND))
+    if (option (OPTCONFIRMAPPEND) &&
+       (!TrashPath || (mutt_strcmp (s, TrashPath) != 0)))
+      /* if we're appending to the trash, there's no point in asking */
     {
       snprintf (tmp, sizeof (tmp), _("Append messages to %s?"), s);
       if ((rc = mutt_yesorno (tmp, M_YES)) == M_NO)
diff -pruN -x'*.orig' mutt-1.5.20/mx.c mutt-1.5.20-trash/mx.c
--- mutt-1.5.20/mx.c	2009-06-11 00:29:41.000000000 -0400
+++ mutt-1.5.20-trash/mx.c	2009-07-23 09:44:40.000000000 -0400
@@ -773,6 +773,54 @@ static int sync_mailbox (CONTEXT *ctx, i
   return rc;
 }
 
+/* move deleted mails to the trash folder */
+static int trash_append (CONTEXT *ctx)
+{
+    CONTEXT *ctx_trash;
+    int i = 0;
+    struct stat st, stc;
+
+    if (!TrashPath || !ctx->deleted ||
+       (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
+      return 0;
+
+    for (;i < ctx->msgcount && (!ctx->hdrs[i]->deleted ||
+                               ctx->hdrs[i]->appended); i++);
+    if (i == ctx->msgcount)
+      return 0; /* nothing to be done */
+
+    if (mutt_save_confirm (TrashPath, &st) != 0)
+    {
+      mutt_error _("message(s) not deleted");
+      return -1;
+    }
+
+    if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino
+       && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev)
+      return 0;  /* we are in the trash folder: simple sync */
+
+    if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL)
+    {
+      for (i = 0 ; i < ctx->msgcount ; i++)
+       if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended
+           && !ctx->hdrs[i]->purged
+           && mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
+         {
+           mx_close_mailbox (ctx_trash, NULL);
+           return -1;
+         }
+
+      mx_close_mailbox (ctx_trash, NULL);
+    }
+    else
+    {
+      mutt_error _("Can't open trash folder");
+      return -1;
+    }
+
+    return 0;
+}
+
 /* save changes and close mailbox */
 int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
 {
@@ -909,6 +957,7 @@ int mx_close_mailbox (CONTEXT *ctx, int 
 	  if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0)
 	  {
 	    mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1);
+            mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1);
 	  }
 	  else
 	  {
@@ -931,6 +980,14 @@ int mx_close_mailbox (CONTEXT *ctx, int 
     return 0;
   }
   
+  /* copy mails to the trash before expunging */
+  if (purge && ctx->deleted)
+    if (trash_append (ctx) != 0)
+    {
+      ctx->closing = 0;
+      return -1;
+    }
+
 #ifdef USE_IMAP
   /* allow IMAP to preserve the deleted flag across sessions */
   if (ctx->magic == M_IMAP)
@@ -1130,6 +1187,12 @@ int mx_sync_mailbox (CONTEXT *ctx, int *
   msgcount = ctx->msgcount;
   deleted = ctx->deleted;
 
+  if (purge && ctx->deleted)
+  {
+    if (trash_append (ctx) == -1)
+      return -1;
+  } 
+
 #ifdef USE_IMAP
   if (ctx->magic == M_IMAP)
     rc = imap_sync_mailbox (ctx, purge, index_hint);
diff -pruN -x'*.orig' mutt-1.5.20/pager.c mutt-1.5.20-trash/pager.c
--- mutt-1.5.20/pager.c	2009-06-03 16:48:31.000000000 -0400
+++ mutt-1.5.20-trash/pager.c	2009-07-23 09:44:40.000000000 -0400
@@ -2309,12 +2309,15 @@ search_next:
 	MAYBE_REDRAW (redraw);
 	break;
 
+      case OP_PURGE_MESSAGE:
       case OP_DELETE:
 	CHECK_MODE(IsHeader (extra));
 	CHECK_READONLY;
 	CHECK_ACL(M_ACL_DELETE, _("delete message"));
 
 	mutt_set_flag (Context, extra->hdr, M_DELETE, 1);
+	mutt_set_flag (Context, extra->hdr, M_PURGED,
+		       ch != OP_PURGE_MESSAGE ? 0 : 1);
         if (option (OPTDELETEUNTAG))
 	  mutt_set_flag (Context, extra->hdr, M_TAG, 0);
 	redraw = REDRAW_STATUS | REDRAW_INDEX;
@@ -2641,6 +2644,7 @@ search_next:
 	CHECK_ACL(M_ACL_DELETE, _("undelete message"));
 
 	mutt_set_flag (Context, extra->hdr, M_DELETE, 0);
+	mutt_set_flag (Context, extra->hdr, M_PURGED, 0);
 	redraw = REDRAW_STATUS | REDRAW_INDEX;
 	if (option (OPTRESOLVE))
 	{
@@ -2656,9 +2660,11 @@ search_next:
 	CHECK_ACL(M_ACL_DELETE, _("undelete message(s)"));
 
 	r = mutt_thread_set_flag (extra->hdr, M_DELETE, 0,
+				  ch == OP_UNDELETE_THREAD ? 0 : 1)
+	  + mutt_thread_set_flag (extra->hdr, M_PURGED, 0,
 				  ch == OP_UNDELETE_THREAD ? 0 : 1);
 
-	if (r != -1)
+	if (r > -1)
 	{
 	  if (option (OPTRESOLVE))
 	  {
diff -pruN -x'*.orig' mutt-1.5.20/pattern.c mutt-1.5.20-trash/pattern.c
--- mutt-1.5.20/pattern.c	2009-06-03 16:48:31.000000000 -0400
+++ mutt-1.5.20-trash/pattern.c	2009-07-23 09:44:40.000000000 -0400
@@ -1347,8 +1347,10 @@ int mutt_pattern_func (int op, char *pro
       {
 	switch (op)
 	{
-	  case M_DELETE:
 	  case M_UNDELETE:
+	    mutt_set_flag (Context, Context->hdrs[Context->v2r[i]], M_PURGED,
+			   0);
+	  case M_DELETE:
 	    mutt_set_flag (Context, Context->hdrs[Context->v2r[i]], M_DELETE, 
 			  (op == M_DELETE));
 	    break;
diff -pruN -x'*.orig' mutt-1.5.20/postpone.c mutt-1.5.20-trash/postpone.c
--- mutt-1.5.20/postpone.c	2009-06-13 17:28:37.000000000 -0400
+++ mutt-1.5.20-trash/postpone.c	2009-07-23 09:44:40.000000000 -0400
@@ -276,6 +276,9 @@ int mutt_get_postponed (CONTEXT *ctx, HE
   /* finished with this message, so delete it. */
   mutt_set_flag (PostContext, h, M_DELETE, 1);
 
+  /* and consider it saved, so that it won't be moved to the trash folder */
+  mutt_set_flag (PostContext, h, M_APPENDED, 1);
+
   /* update the count for the status display */
   PostCount = PostContext->msgcount - PostContext->deleted;