Gregory Seidman wrote:
> Well, I sort of like it. Incidentally, I'm the one who brought up the
> problem. I'm not sure I like it better than have a search pattern (~R,
> maybe?) for when reverse_name has come up with something. It seems a little
> kludgy to make one header behave differently, rather than allowing the hook
> to be more specfic. In particular, I expect that there will be occasions
> when one wants the reverse_name to be overridden and occasions when one
> does not, even for the same user. (Example: I *always* want mail sent to
> the local LAN to have my short address, regardless of what address received
> the email. For everything else, though, I want reverse_name to supersede.)

I believe the following approach is a good compromise.  This patch adds
a reply-hook command which is just like the send-hook, except that it
matches against the message you are replying to rather than the message
you are sending.  All reply-hook's are execute prior to send-hook's.
However, you can inhibit send-hook's in the reply case by using the
pattern '! ~Q' (not-replied) in the send-hook to tell when reply-hook's
have been executed.

Therefore, your above example would become:

set reverse_name

reply-hook . 'unmy_hdr from'
# if i was not listed as an explicit recipient, use a default from:
# address
reply-hook '! ~p' 'my_hdr From: Long Form <[EMAIL PROTECTED]>'

# when not replying, clear the default from: addrss from the last email
send-hook '! ~Q' 'unmy_hdr from'

# always use a short address for local email
send-hook '! ~t @' 'my_hdr From: Short Form <short>'

Incidentally, this reply-hook also solves another problem.  Say that I
use [EMAIL PROTECTED] when replying to email from the mutt-* lists.  Right now
I would have something like:
        send-hook '~Cmutt' 'my_hdr from: [EMAIL PROTECTED]'
so that when I reply to this list, the proper return address is set.
However, if I do a personal reply to a post on the list, that hook will
not be triggered and my default from address will be used instead.  The
reply-hook lets me do
        reply-hook '~Cmutt' 'my_hdr from: [EMAIL PROTECTED]'
so that when I do a personal reply to a message sent to mutt-users, my
return address is set to [EMAIL PROTECTED] as I want it to.

> Even better than a boolean search pattern would be a search pattern that
> gives the current from address (only applicable to send-hook, maybe?),
> which might have been generated from $from or reverse_name or my_hdr (in or
> out of a send-hook).

You can't do a substitution, but you can figure out which address was
used by reverse_name.  Consider the following example:

set alternates=me@(mutt|sigpipe)\.org

# match when i use [EMAIL PROTECTED] as default from:
send-hook '~f me@mutt\.org' '...'

# match when i use [EMAIL PROTECTED] as default from:
send-hook '~f me@sigpipe\.org' '...'
Index: hook.c
===================================================================
RCS file: /home/roessler/cvs/mutt/hook.c,v
retrieving revision 3.3
diff -u -r3.3 hook.c
--- hook.c      5 Feb 2002 21:30:31 -0000       3.3
+++ hook.c      17 Jul 2002 17:27:57 -0000
@@ -1,5 +1,5 @@
 /* 
- * Copyright (C) 1996-2000 Michael R. Elkins <[EMAIL PROTECTED]>, and others
+ * Copyright (C) 1996-2002 Michael R. Elkins <[EMAIL PROTECTED]>, and others
  *
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -65,7 +65,7 @@
     goto error;
   }
 
-  mutt_extract_token (&command, s, (data & (M_FOLDERHOOK | M_SENDHOOK | 
M_ACCOUNTHOOK)) ?  M_TOKEN_SPACE : 0);
+  mutt_extract_token (&command, s, (data & (M_FOLDERHOOK | M_SENDHOOK | M_ACCOUNTHOOK 
+| M_REPLYHOOK)) ?  M_TOKEN_SPACE : 0);
 
   if (!command.data)
   {
@@ -118,7 +118,7 @@
        ptr->rx.not == not &&
        !mutt_strcmp (pattern.data, ptr->rx.pattern))
     {
-      if (data & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK))
+      if (data & (M_FOLDERHOOK | M_SENDHOOK | M_MESSAGEHOOK | M_ACCOUNTHOOK | 
+M_REPLYHOOK))
       {
        /* these hooks allow multiple commands with the same
         * pattern, so if we've already seen this pattern/command pair, just
@@ -147,10 +147,10 @@
       break;
   }
 
-  if (data & (M_SENDHOOK | M_SAVEHOOK | M_FCCHOOK | M_MESSAGEHOOK))
+  if (data & (M_SENDHOOK | M_SAVEHOOK | M_FCCHOOK | M_MESSAGEHOOK | M_REPLYHOOK))
   {
     if ((pat = mutt_pattern_comp (pattern.data,
-          (data & (M_SENDHOOK | M_FCCHOOK)) ? 0 : M_FULL_MSG,
+          (data & (M_SENDHOOK | M_REPLYHOOK | M_FCCHOOK)) ? 0 : M_FULL_MSG,
                                  err)) == NULL)
       goto error;
   }
Index: init.h
===================================================================
RCS file: /home/roessler/cvs/mutt/init.h,v
retrieving revision 3.17
diff -u -r3.17 init.h
--- init.h      7 Jul 2002 19:33:48 -0000       3.17
+++ init.h      17 Jul 2002 17:28:00 -0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2000 Michael R. Elkins <[EMAIL PROTECTED]>
+ * Copyright (C) 1996-2002 Michael R. Elkins <[EMAIL PROTECTED]>
  * 
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -2690,6 +2690,7 @@
   { "crypt-hook",      mutt_parse_hook,        M_CRYPTHOOK },
 #endif /* HAVE_PGP */
   { "push",            mutt_parse_push,        0 },
+  { "reply-hook",      mutt_parse_hook,        M_REPLYHOOK },
   { "reset",           parse_set,              M_SET_RESET },
   { "save-hook",       mutt_parse_hook,        M_SAVEHOOK },
   { "score",           mutt_parse_score,       0 },
Index: mutt.h
===================================================================
RCS file: /home/roessler/cvs/mutt/mutt.h,v
retrieving revision 3.8
diff -u -r3.8 mutt.h
--- mutt.h      20 Apr 2002 08:11:13 -0000      3.8
+++ mutt.h      17 Jul 2002 17:28:01 -0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 1996-2000 Michael R. Elkins <[EMAIL PROTECTED]>
+ * Copyright (C) 1996-2002 Michael R. Elkins <[EMAIL PROTECTED]>
  * 
  *     This program is free software; you can redistribute it and/or modify
  *     it under the terms of the GNU General Public License as published by
@@ -144,6 +144,7 @@
 #define M_CRYPTHOOK    (1<<8)
 #endif
 #define M_ACCOUNTHOOK  (1<<9)
+#define M_REPLYHOOK    (1<<10)
 
 /* tree characters for linearize_tree and print_enriched_string */
 #define M_TREE_LLCORNER                1
Index: send.c
===================================================================
RCS file: /home/roessler/cvs/mutt/send.c,v
retrieving revision 3.4
diff -u -r3.4 send.c
--- send.c      18 Feb 2002 14:55:31 -0000      3.4
+++ send.c      17 Jul 2002 17:28:02 -0000
@@ -1192,6 +1192,19 @@
       killfrom = 1;
     }
 
+    if ((flags & SENDREPLY) && cur)
+    {
+      /* change setting based upon message we are replying to */
+      mutt_message_hook (NULL, cur, M_REPLYHOOK);
+
+      /*
+       * set the replied flag for the message we are generating so that the
+       * user can use ~Q in a send-hook to know when reply-hook's are also
+       * being used.
+       */
+      msg->replied = 1;
+    }
+
     /* change settings based upon recipients */
     
     mutt_message_hook (NULL, msg, M_SENDHOOK);

Reply via email to