<<< Date Index >>>     <<< Thread Index >>>

Updated trash_folder patch for 1.5.4+CVS



Hello,

a recent change in mutt's CVS version broke Cédric Duval's trash_folder
patch. The problem is:

RCS file: /home/roessler/cvs/mutt/muttlib.c,v
retrieving revision 3.16
retrieving revision 3.17
diff -u -r3.16 -r3.17
--- muttlib.c   24 Jul 2003 18:40:50 -0000      3.16
+++ muttlib.c   4 Oct 2003 20:34:59 -0000       3.17
@@ -1133,11 +1155,12 @@
   return (f);
 }
 
-/* returns 1 if OK to proceed, 0 to abort */
+/* returns 0 if OK to proceed, -1 to abort, 1 to retry */
 int mutt_save_confirm (const char *s, struct stat *st)
 {
   char tmp[_POSIX_PATH_MAX];
-  int ret = 1;
+  int ret = 0;
+  int rc;
   int magic = 0;
 
   magic = mx_get_magic (s);


The fix is simple:

diff -ur mutt-orig-patch/mx.c mutt-patch-fixed/mx.c
--- mutt-orig-patch/mx.c        2003-10-28 14:44:46.000000000 +0100
+++ mutt-patch-fixed/mx.c       2003-10-28 14:56:38.000000000 +0100
@@ -831,7 +831,7 @@
     if (i == ctx->msgcount)
       return 0; /* nothing to be done */
 
-    if (!mutt_save_confirm (TrashPath, &st))
+    if (mutt_save_confirm (TrashPath, &st) != 0)
     {
       mutt_error _("message(s) not deleted");
       return -1;


I'll attach a complete patch (including the purge_messge patch).

Christoph
-- 
Christoph Berg <cb@xxxxxxxxxxxxxxxx>, http://www.df7cb.de/
Wohnheim D, 2405, Universität des Saarlandes, 0681/9657944
diff -ur ../MUTT/mutt/OPS mutt-patch-fixed/OPS
--- ../MUTT/mutt/OPS    2003-07-04 19:07:22.000000000 +0200
+++ mutt-patch-fixed/OPS        2003-10-28 14:44:46.000000000 +0100
@@ -138,6 +138,7 @@
 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 -ur ../MUTT/mutt/PATCHES mutt-patch-fixed/PATCHES
--- ../MUTT/mutt/PATCHES        2002-12-09 18:44:54.000000000 +0100
+++ mutt-patch-fixed/PATCHES    2003-10-28 14:44:46.000000000 +0100
@@ -0,0 +1,2 @@
+patch-1.5.4.cd.trash_folder.3.3
+patch-1.5.4.cd.purge_message.3.3
diff -ur ../MUTT/mutt/commands.c mutt-patch-fixed/commands.c
--- ../MUTT/mutt/commands.c     2003-10-04 22:34:59.000000000 +0200
+++ mutt-patch-fixed/commands.c 2003-10-28 14:44:46.000000000 +0100
@@ -663,11 +663,15 @@
   if (decode || decrypt)
     mutt_parse_mime_message (Context, h);
 
-  if (mutt_append_message (ctx, Context, h, cmflags, chflags) == 0 && delete)
+  if (mutt_append_message (ctx, Context, h, cmflags, chflags) == 0)
   {
-    mutt_set_flag (Context, h, M_DELETE, 1);
-    if (option (OPTDELETEUNTAG))
-      mutt_set_flag (Context, h, M_TAG, 0);
+    if (delete)
+    {
+      mutt_set_flag (Context, h, M_DELETE, 1);
+      if (option (OPTDELETEUNTAG))
+       mutt_set_flag (Context, h, M_TAG, 0);
+    }
+    mutt_set_flag (Context, h, M_APPENDED, 1);
   }
 }
 
diff -ur ../MUTT/mutt/curs_main.c mutt-patch-fixed/curs_main.c
--- ../MUTT/mutt/curs_main.c    2003-09-03 19:09:09.000000000 +0200
+++ mutt-patch-fixed/curs_main.c        2003-10-28 14:44:46.000000000 +0100
@@ -1701,6 +1701,7 @@
        MAYBE_REDRAW (menu->redraw);
        break;
 
+      case OP_PURGE_MESSAGE:
       case OP_DELETE:
 
        CHECK_MSGCOUNT;
@@ -1714,6 +1715,7 @@
        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;
@@ -1721,6 +1723,8 @@
        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))
@@ -2001,11 +2005,13 @@
        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++;
@@ -2029,9 +2035,11 @@
 #endif
 
        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 -ur ../MUTT/mutt/flags.c mutt-patch-fixed/flags.c
--- ../MUTT/mutt/flags.c        2003-01-31 00:48:36.000000000 +0100
+++ mutt-patch-fixed/flags.c    2003-10-28 14:44:46.000000000 +0100
@@ -65,7 +65,13 @@
       else if (h->deleted)
       {
        h->deleted = 0;
-       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 @@
       }
       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:
 
 #ifdef USE_IMAP
diff -ur ../MUTT/mutt/functions.h mutt-patch-fixed/functions.h
--- ../MUTT/mutt/functions.h    2003-07-04 19:07:22.000000000 +0200
+++ mutt-patch-fixed/functions.h        2003-10-28 14:44:46.000000000 +0100
@@ -101,6 +101,7 @@
   { "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" },
@@ -185,6 +186,7 @@
   { "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 -ur ../MUTT/mutt/globals.h mutt-patch-fixed/globals.h
--- ../MUTT/mutt/globals.h      2003-07-15 13:41:32.000000000 +0200
+++ mutt-patch-fixed/globals.h  2003-10-28 14:44:46.000000000 +0100
@@ -110,6 +110,7 @@
 WHERE char *Status;
 WHERE char *Tempdir;
 WHERE char *Tochars;
+WHERE char *TrashPath;
 WHERE char *Username;
 WHERE char *Visual;
 
diff -ur ../MUTT/mutt/imap/message.c mutt-patch-fixed/imap/message.c
--- ../MUTT/mutt/imap/message.c 2003-07-24 20:40:50.000000000 +0200
+++ mutt-patch-fixed/imap/message.c     2003-10-28 14:44:46.000000000 +0100
@@ -624,6 +624,7 @@
         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);
         }
@@ -631,6 +632,7 @@
     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 -ur ../MUTT/mutt/init.h mutt-patch-fixed/init.h
--- ../MUTT/mutt/init.h 2003-09-04 17:10:09.000000000 +0200
+++ mutt-patch-fixed/init.h     2003-10-28 14:44:46.000000000 +0100
@@ -2559,6 +2559,16 @@
   ** by \fIyou\fP.  The sixth character is used to indicate when a mail
   ** was sent to a mailing-list you subscribe to (default: L).
   */
+  { "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 -ur ../MUTT/mutt/mutt.h mutt-patch-fixed/mutt.h
--- ../MUTT/mutt/mutt.h 2003-10-04 22:34:59.000000000 +0200
+++ mutt-patch-fixed/mutt.h     2003-10-28 14:44:46.000000000 +0100
@@ -197,6 +197,8 @@
   M_DELETE,
   M_UNDELETE,
   M_DELETED,
+  M_APPENDED,
+  M_PURGED,
   M_FLAG,
   M_TAG,
   M_UNTAG,
@@ -636,6 +638,8 @@
   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 */
@@ -764,6 +768,7 @@
   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 */
 #if defined USE_POP || defined USE_IMAP
diff -ur ../MUTT/mutt/muttlib.c mutt-patch-fixed/muttlib.c
--- ../MUTT/mutt/muttlib.c      2003-10-04 22:34:59.000000000 +0200
+++ mutt-patch-fixed/muttlib.c  2003-10-28 14:44:46.000000000 +0100
@@ -1181,7 +1181,9 @@
       return 1;
     }
 
-    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 -ur ../MUTT/mutt/mx.c mutt-patch-fixed/mx.c
--- ../MUTT/mutt/mx.c   2003-09-19 15:03:25.000000000 +0200
+++ mutt-patch-fixed/mx.c       2003-10-28 14:56:38.000000000 +0100
@@ -815,6 +815,54 @@
   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)
 {
@@ -954,6 +1002,7 @@
          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
          {
@@ -975,6 +1024,14 @@
     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)
@@ -1168,6 +1225,12 @@
   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 -ur ../MUTT/mutt/pager.c mutt-patch-fixed/pager.c
--- ../MUTT/mutt/pager.c        2003-10-04 22:34:59.000000000 +0200
+++ mutt-patch-fixed/pager.c    2003-10-28 14:44:46.000000000 +0100
@@ -2183,6 +2183,7 @@
        MAYBE_REDRAW (redraw);
        break;
 
+      case OP_PURGE_MESSAGE:
       case OP_DELETE:
        CHECK_MODE(IsHeader (extra));
        CHECK_READONLY;
@@ -2192,6 +2193,8 @@
 #endif
 
        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;
@@ -2520,6 +2523,7 @@
 #endif
 
        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))
        {
@@ -2538,9 +2542,11 @@
 #endif
 
        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 -ur ../MUTT/mutt/pattern.c mutt-patch-fixed/pattern.c
--- ../MUTT/mutt/pattern.c      2003-07-24 20:40:50.000000000 +0200
+++ mutt-patch-fixed/pattern.c  2003-10-28 14:44:46.000000000 +0100
@@ -1167,8 +1167,10 @@
       {
        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 -ur ../MUTT/mutt/postpone.c mutt-patch-fixed/postpone.c
--- ../MUTT/mutt/postpone.c     2003-09-03 19:22:09.000000000 +0200
+++ mutt-patch-fixed/postpone.c 2003-10-28 14:44:46.000000000 +0100
@@ -275,6 +275,9 @@
   /* 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;
 

Attachment: signature.asc
Description: Digital signature