Ticket #20412: patch-1.5.20.bk.trash_folder-purge_message.1

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