]> git.pld-linux.org Git - packages/mutt.git/blobdiff - mutt-cd.trash_folder.patch
- patch with new `keep_to' option to better handle corporate world
[packages/mutt.git] / mutt-cd.trash_folder.patch
index 4c1861abf866be9b1cf49fd9e65a5bae166901fd..632541cf9ae54e3d1caed5c748149962f8972c28 100644 (file)
@@ -1,28 +1,80 @@
-diff -pruN2 mutt-1.3.27.orig/commands.c mutt-1.3.27/commands.c
---- mutt-1.3.27.orig/commands.c        Mon Dec  3 11:17:57 2001
-+++ mutt-1.3.27/commands.c     Wed Jan 23 22:33:11 2002
-@@ -616,9 +616,13 @@ void _mutt_save_message (HEADER *h, CONT
-     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);
+# vim:ft=diff:
+This is the trash folder patch by Cedric Duval <cedricduval@free.fr>.
+
+With this patch, if the trash variable is set to a path (unset by default), the
+deleted mails will be moved to a trash folder instead of being irremediably
+purged when syncing the mailbox.
+
+For instance, set trash="~/Mail/trash" will cause every deleted mail to go to
+this folder.
+
+Note that the append to the trash folder doesn't occur until the resync is
+done. This allows you to change your mind and undo deletes, and thus the moves
+to the trash folder are unnecessary.
+
+Notes
+
+    * You might also want to have a look at the purge message feature below
+      which is related to this patch.
+    * IMAP is now supported. To retain the previous behavior, add this to your
+      muttrc:
+      folder-hook ^imap:// 'unset trash'
+
+FAQ
+
+Every once in a while, someone asks what are the advantages of this patch over
+a macro based solution. Here's an attempt to answer this question:
+
+    * The folder history doesn't clutter up with unwanted trash entries.
+    * Delayed move to the trash allows to change one's mind.
+    * No need to treat the case of "normal folders" and trash folders
+      separately with folder-hooks, and to create two sets of macros (one for
+      the index, one for the pager).
+    * Works not only with delete-message, but also with every deletion
+      functions like delete-pattern, delete-thread or delete-subthread.
+
+To sum up, it's more integrated and transparent to the user.
+
+* Patch last synced with upstream:
+  - Date: 2007-02-15
+  - File: http://cedricduval.free.fr/mutt/patches/download/patch-1.5.5.1.cd.trash_folder.3.4
+
+* Changes made:
+  - Updated to 1.5.13:
+    - structure of _mutt_save_message changed (commands.c)
+    - context of option (OPTCONFIRMAPPEND) changed (muttlib.c)
+  - Fixed indentation of "appended" in mutt.h.
+
+== END PATCH
+--- a/commands.c
++++ b/commands.c
+@@ -717,6 +717,7 @@
+     if (option (OPTDELETEUNTAG))
+       mutt_set_flag (Context, h, M_TAG, 0);
    }
++  mutt_set_flag (Context, h, M_APPENDED, 1);
+   
+   return 0;
  }
-diff -pruN2 mutt-1.3.27.orig/flags.c mutt-1.3.27/flags.c
---- mutt-1.3.27.orig/flags.c   Tue Jan 15 22:12:59 2002
-+++ mutt-1.3.27/flags.c        Wed Jan 23 22:33:11 2002
-@@ -76,4 +76,15 @@ void _mutt_set_flag (CONTEXT *ctx, HEADE
+--- a/flags.c
++++ b/flags.c
+@@ -65,7 +65,13 @@
+       {
+       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,17 @@
+       }
        break;
  
 +    case M_APPENDED:
@@ -37,21 +89,41 @@ diff -pruN2 mutt-1.3.27.orig/flags.c mutt-1.3.27/flags.c
 +      break;
 +
      case M_NEW:
-       if (bf)
-diff -pruN2 mutt-1.3.27.orig/globals.h mutt-1.3.27/globals.h
---- mutt-1.3.27.orig/globals.h Thu Jan  3 21:56:46 2002
-+++ mutt-1.3.27/globals.h      Wed Jan 23 22:33:11 2002
-@@ -110,4 +110,5 @@ WHERE char *Status;
+       if (!mutt_bit_isset(ctx->rights,M_ACL_SEEN))
+--- a/globals.h
++++ b/globals.h
+@@ -139,6 +139,7 @@
+ WHERE char *Status;
  WHERE char *Tempdir;
  WHERE char *Tochars;
 +WHERE char *TrashPath;
  WHERE char *Username;
  WHERE char *Visual;
-diff -pruN2 mutt-1.3.27.orig/init.h mutt-1.3.27/init.h
---- mutt-1.3.27.orig/init.h    Mon Dec 10 11:09:03 2001
-+++ mutt-1.3.27/init.h Wed Jan 23 22:33:11 2002
-@@ -2236,4 +2236,11 @@ struct option_t MuttVars[] = {
-   ** was sent to a mailing-list you subscribe to (default: L).
+ WHERE char *XtermTitle;
+--- a/imap/message.c
++++ b/imap/message.c
+@@ -876,6 +876,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);
+         }
+@@ -883,6 +884,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);
+     }
+--- a/init.h
++++ b/init.h
+@@ -3195,6 +3195,16 @@
+   ** 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 },
 +  /*
@@ -59,47 +131,75 @@ diff -pruN2 mutt-1.3.27.orig/init.h mutt-1.3.27/init.h
 +  ** 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 -pruN2 mutt-1.3.27.orig/mutt.h mutt-1.3.27/mutt.h
---- mutt-1.3.27.orig/mutt.h    Tue Jan 15 22:00:32 2002
-+++ mutt-1.3.27/mutt.h Wed Jan 23 22:33:11 2002
-@@ -185,4 +185,5 @@ enum
+   /*
+--- a/mutt.h
++++ b/mutt.h
+@@ -187,6 +187,7 @@
+   M_DELETE,
    M_UNDELETE,
    M_DELETED,
 +  M_APPENDED,
    M_FLAG,
    M_TAG,
-@@ -618,4 +619,5 @@ typedef struct header
+   M_UNTAG,
+@@ -707,6 +708,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 appended : 1;          /* has been saved */
    unsigned int deleted : 1;
    unsigned int changed : 1;
-@@ -740,4 +742,5 @@ typedef struct
+   unsigned int attach_del : 1;                /* has an attachment marked for deletion */
+@@ -879,6 +881,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 */
-diff -pruN2 mutt-1.3.27.orig/mx.c mutt-1.3.27/mx.c
---- mutt-1.3.27.orig/mx.c      Tue Jan 15 22:09:53 2002
-+++ mutt-1.3.27/mx.c   Wed Jan 23 22:33:11 2002
-@@ -816,4 +816,45 @@ static int sync_mailbox (CONTEXT *ctx, i
+--- a/muttlib.c
++++ b/muttlib.c
+@@ -1515,7 +1515,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)
+--- a/mx.c
++++ b/mx.c
+@@ -776,6 +776,53 @@
+   return rc;
  }
  
 +/* move deleted mails to the trash folder */
 +static int trash_append (CONTEXT *ctx)
 +{
 +    CONTEXT *ctx_trash;
-+    int i;
++    int i = 0;
 +    struct stat st, stc;
 +
-+    if (!TrashPath || !ctx->deleted)
++    if (!TrashPath || !ctx->deleted ||
++      (ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH)))
 +      return 0;
 +
-+    if (!mutt_save_confirm (TrashPath, &st))
++    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;
@@ -132,41 +232,47 @@ diff -pruN2 mutt-1.3.27.orig/mx.c mutt-1.3.27/mx.c
 +
  /* save changes and close mailbox */
  int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
-@@ -999,9 +1040,17 @@ int mx_close_mailbox (CONTEXT *ctx, int 
-     if (ctx->changed || ctx->deleted)
-     {
--      if ((check = sync_mailbox (ctx, index_hint)) != 0)
-+      int trsh = 0;
-+
-+      if ((!ctx->deleted || (trsh = trash_append (ctx)) == 0)
-+      && (check = sync_mailbox (ctx, index_hint)) != 0)
-       {
-       ctx->closing = 0;
-       return check;
-       }
-+      if (trsh != 0)
-+      {
-+      ctx->closing = 0;
-+      return -1;
-+      }
-     }
+ {
+@@ -912,6 +959,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
+         {
+@@ -936,6 +984,14 @@
+     return 0;
    }
-@@ -1174,6 +1223,10 @@ int mx_sync_mailbox (CONTEXT *ctx, int *
-     rc = imap_sync_mailbox (ctx, purge, index_hint);
-   else
--#endif
-+#endif /* enter this block unconditionally if IMAP is not used */
+   
++  /* copy mails to the trash before expunging */
++  if (purge && ctx->deleted && mutt_strcmp(ctx->path, TrashPath))
++    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)
+@@ -1133,6 +1189,12 @@
+   msgcount = ctx->msgcount;
+   deleted = ctx->deleted;
++  if (purge && ctx->deleted && mutt_strcmp(ctx->path, TrashPath))
 +  {
 +    if (trash_append (ctx) == -1)
 +      return -1;
-     rc = sync_mailbox (ctx, index_hint);
 +  }
-   if (rc == 0)
-   {
-diff -pruN2 mutt-1.3.27.orig/postpone.c mutt-1.3.27/postpone.c
---- mutt-1.3.27.orig/postpone.c        Mon Dec  3 11:17:57 2001
-+++ mutt-1.3.27/postpone.c     Wed Jan 23 22:33:11 2002
-@@ -271,4 +271,7 @@ int mutt_get_postponed (CONTEXT *ctx, HE
++
+ #ifdef USE_IMAP
+   if (ctx->magic == M_IMAP)
+     rc = imap_sync_mailbox (ctx, purge, index_hint);
+--- a/postpone.c
++++ b/postpone.c
+@@ -277,6 +277,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 */
@@ -174,8 +280,4 @@ diff -pruN2 mutt-1.3.27.orig/postpone.c mutt-1.3.27/postpone.c
 +
    /* update the count for the status display */
    PostCount = PostContext->msgcount - PostContext->deleted;
-diff -pruN mutt-1.3.27.orig/PATCHES mutt-1.3.27/PATCHES
---- mutt-1.3.27.orig/PATCHES    Mon Nov 26 20:16:52 2001
-+++ mutt-1.3.27/PATCHES Thu Dec  6 16:27:55 2001
-@@ -1,0 +1 @@
-+patch-1.3.27.cd.trash_folder.1
This page took 0.054213 seconds and 4 git commands to generate.