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

Re: mbox-hook: broken or useless?



Thomas Glanzmann,

>> My preferred configuration is this:  Mails sent on behalf of
>> mailing lists are directed to their own folders using an external
>> mechanism (such as procmail or sieve), and they are never moved out
>> of it, even after they are read.  Mail meant for me is sent to a
>> single Inbox-folder, regardless of who sent it or which of my email
>> addresses it was sent to.  That way, after I have read the email,
>> I can move it to an appropriate read mail folder for archiving.
>> I want this last step to go automatically when I quit mutt, and
>> I assume this is a very common desire, hence there should be a
>> way to make mutt do it.
> 
> no. Expect for coding it. That is what I wanted, too, when I switched
> from pine to mutt:
> 
> http://groups-beta.google.com/group/comp.mail.mutt/browse_thread/thread/dec6555eb5edcfb0/4e046008652e9dc7?q=author:Thomas+author:Glanzmann+move+mutt&rnum=1#4e046008652e9dc7
> 
> This was long time ago. And currently I am hot unhappy enough with the
> save-hook shit to code around it. However, if you have something that
> works, let me know. [...]

OK, it's been a while, but I finally decided to write a patch
that should make mutt work the way I like.  To make it simpler, I
decided to drop the move-hook idea, and simply alter the behavior of
save-hook instead.  Now, in addition to its old semantics, save-hook
will also be called on mailbox close.  I.e., if there is a matching
save-hook rule, the default mbox destination is overridden by the
save-hook destination.

The patch is included below.  If you, or anyone else, can spot
any obvious problems with this, please let me know -- I really
don't want to loose any mail over this. :-)

--- mutt-1.5.10/hook.c.orig     2005-02-03 19:47:52.000000000 +0100
+++ mutt-1.5.10/hook.c  2005-08-26 20:36:14.000000000 +0200
@@ -351,7 +351,7 @@
   current_hook_type = 0;
 }
 
-static int
+int
 mutt_addr_hook (char *path, size_t pathlen, int type, CONTEXT *ctx, HEADER 
*hdr)
 {
   HOOK *hook;
--- mutt-1.5.10/mx.c.orig       2005-08-02 09:08:01.000000000 +0200
+++ mutt-1.5.10/mx.c    2005-08-26 20:55:11.000000000 +0200
@@ -819,6 +819,8 @@
   return rc;
 }
 
+int mutt_addr_hook (char *path, size_t pathlen, int type, CONTEXT *ctx, HEADER 
*hdr);
+
 /* save changes and close mailbox */
 int mx_close_mailbox (CONTEXT *ctx, int *index_hint)
 {
@@ -944,14 +946,17 @@
     else /* use regular append-copy mode */
 #endif
     {
-      if (mx_open_mailbox (mbox, M_APPEND, &f) == NULL)
-      {
-       ctx->closing = 0;
-       return -1;
-      }
+      char save_hook_mbox[_POSIX_PATH_MAX];
 
       for (i = 0; i < ctx->msgcount; i++)
       {
+        if (mutt_addr_hook (save_hook_mbox, sizeof (save_hook_mbox), 
M_SAVEHOOK, ctx, ctx->hdrs[i]) == 0)
+          strfcpy (mbox, save_hook_mbox, sizeof (mbox));
+        if (mx_open_mailbox (mbox, M_APPEND, &f) == NULL)
+        {
+          ctx->closing = 0;
+          return -1;
+        }
        if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted
             && !(ctx->hdrs[i]->flagged && option (OPTKEEPFLAGGED)))
         {
@@ -966,9 +971,8 @@
            return -1;
          }
        }
+        mx_close_mailbox (&f, NULL);
       }
-    
-      mx_close_mailbox (&f, NULL);
     }
     
   }

-- 
 Haakon