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

Re: trash patch, Mutt 1.5.13



* Jason Helfman <jhelfman@xxxxxxxxxxxxxx> [2006-10-06 07:19 -0700]:
> The trash patch mentioned earlier sounds like something I would like to
> try out, but the latest version is 1.5.5.1 for the patch.
> 
> Does anyone have or know of a resource that has more up-to-date patches?
> 
> The patch is failing when trying to patch my installed version (1.5.13).

I use the attached version with 1.5.12. It applies to 1.5.13 and the
result compiles, but I haven't tested it yet.

Nicolas

-- 
http://www.rachinsky.de/nicolas
diff -r -u ../mutt-1.5.11.orig/commands.c ./commands.c
--- ../mutt-1.5.11.orig/commands.c      Sun Sep 25 10:41:37 2005
+++ ./commands.c        Sun Sep 25 10:48:14 2005
@@ -690,6 +690,7 @@
     if (option (OPTDELETEUNTAG))
       mutt_set_flag (Context, h, M_TAG, 0);
   }
+  mutt_set_flag (Context, h, M_APPENDED, 1);
   
   return 0;
 }
diff -r -u ../mutt-1.5.11.orig/flags.c ./flags.c
--- ../mutt-1.5.11.orig/flags.c Sun Sep 25 10:41:37 2005
+++ ./flags.c   Sun Sep 25 10:42:20 2005
@@ -69,7 +69,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) 
@@ -88,6 +94,17 @@
         */
        if (ctx->magic == M_MAILDIR && upd_ctx && h->trash)
          ctx->changed = 1;
+      }
+      break;
+
+    case M_APPENDED:
+      if (bf)
+      {
+       if (!h->appended)
+       {
+         h->appended = 1;
+         if (upd_ctx) ctx->appended++;
+       }
       }
       break;
 
diff -r -u ../mutt-1.5.11.orig/globals.h ./globals.h
--- ../mutt-1.5.11.orig/globals.h       Sun Sep 25 10:41:37 2005
+++ ./globals.h Sun Sep 25 10:42:20 2005
@@ -130,6 +130,7 @@
 WHERE char *Status;
 WHERE char *Tempdir;
 WHERE char *Tochars;
+WHERE char *TrashPath;
 WHERE char *Username;
 WHERE char *Visual;
 
diff -r -u ../mutt-1.5.11.orig/imap/message.c ./imap/message.c
--- ../mutt-1.5.11.orig/imap/message.c  Sun Sep 25 10:41:37 2005
+++ ./imap/message.c    Sun Sep 25 10:42:20 2005
@@ -766,6 +766,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);
         }
@@ -773,6 +774,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 -r -u ../mutt-1.5.11.orig/init.h ./init.h
--- ../mutt-1.5.11.orig/init.h  Sun Sep 25 10:41:37 2005
+++ ./init.h    Sun Sep 25 10:42:20 2005
@@ -2814,6 +2814,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 -r -u ../mutt-1.5.11.orig/mutt.h ./mutt.h
--- ../mutt-1.5.11.orig/mutt.h  Sun Sep 25 10:41:37 2005
+++ ./mutt.h    Sun Sep 25 10:42:20 2005
@@ -203,6 +203,7 @@
   M_DELETE,
   M_UNDELETE,
   M_DELETED,
+  M_APPENDED,
   M_FLAG,
   M_TAG,
   M_UNTAG,
@@ -708,6 +709,7 @@
   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 deleted : 1;
   unsigned int changed : 1;
   unsigned int attach_del : 1;                 /* has an attachment marked for 
deletion */
@@ -838,6 +840,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 -r -u ../mutt-1.5.11.orig/muttlib.c ./muttlib.c
--- ../mutt-1.5.11.orig/muttlib.c       Sun Sep 25 10:41:37 2005
+++ ./muttlib.c Sun Sep 25 10:45:07 2005
@@ -1292,7 +1292,9 @@
 
   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 -r -u ../mutt-1.5.11.orig/mx.c ./mx.c
--- ../mutt-1.5.11.orig/mx.c    Sun Sep 25 10:41:37 2005
+++ ./mx.c      Sun Sep 25 10:42:20 2005
@@ -850,6 +850,53 @@
   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
+           && 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)
 {
@@ -989,6 +1036,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
          {
@@ -1010,6 +1058,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)
@@ -1209,6 +1265,12 @@
    * mx_update_tables, so ctx->deleted is 0 when it comes back */
   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)
diff -r -u ../mutt-1.5.11.orig/postpone.c ./postpone.c
--- ../mutt-1.5.11.orig/postpone.c      Sun Sep 25 10:41:37 2005
+++ ./postpone.c        Sun Sep 25 10:42:20 2005
@@ -279,6 +279,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;
 
diff -pruN mutt-1.5.5.1-orig/PATCHES mutt-1.5.5.1-trash/PATCHES
--- PATCHES     Tue Apr 15 15:18:34 2003
+++ PATCHES     Tue Nov 11 02:43:35 2003
@@ -1,0 +1 @@
+patch-1.5.11.cd-nr.trash_folder.3.4