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

[patch] add ~q pattern



I would like to be able to do the following:
    
    1. If I'm replying to mail that was apparently sent to one of my
       addresses, reply from that address.

    2. Otherwise, choose a from address depending on the recipients.

The problem with this is that send-hooks have no way of knowing
whether reverse_name succeeded.  Consequently, I've been using
a scheme like this for a couple years (simplified for presentation):

    alternates '(aron|agriffis)@'
    set from=blank
    set reverse_name=yes

    # defaults
    send-hook '~f blank' 'my_hdr From: Aron Griffis <aron hp.com>'
    send-hook '~f blank' 'set postponed=+hp/postponed record=+hp/sent ...'

    # replies, when reverse_name succeeds
    send-hook '~P ~f @hp.com'      'set postponed=+hp/postponed record=+hp/sent 
...'
    send-hook '~P ~f @gentoo.org'  'set postponed=+g2/postponed record=+g2/sent 
...'

    # new messages and reverse_name failures
    send-hook '~f blank ~C @hp.com'     'my_hdr From: Aron Griffis <aron 
hp.com>'
    send-hook '~f blank ~C @hp.com'     'set postponed=+hp/postponed 
record=+hp/sent ...'
    send-hook '~f blank ~C @gentoo.org' 'my_hdr From: Aron Griffis <agriffis 
gentoo.org>'
    send-hook '~f blank ~C @gentoo.org' 'set postponed=+g2/postponed 
record=+g2/sent ...'

This hack generally works.  There are problems with setting
from=blank, for example the bounce-path generates Resent-From:
blank@xxxxxxxxxxxxxxx  Some of the problems can be mitigated, but
ultimately, setting from=blank is an undesirable hack.

A much better solution is to provide an indicator for a send-hook to
know whether reverse_name was successful for the current message.
This patch provides that ability and assigns it to ~q, which seems to
make sense considering the meaning of the surrounding matchers ~p ~P
and ~Q.

Regards,
Aron

Signed-off-by: Aron Griffis <aron@xxxxxx>

diff -r 469303b9c72d -r 8ec757c26d7e mutt.h
--- a/mutt.h    Mon Aug 07 11:46:57 2006 -0400
+++ b/mutt.h    Mon Aug 07 11:54:33 2006 -0400
@@ -233,6 +233,7 @@ enum
   M_SUBSCRIBED_LIST,
   M_PERSONAL_RECIP,
   M_PERSONAL_FROM,
+  M_REVERSED_NAME,
   M_ADDRESS,
   M_CRYPT_SIGN,
   M_CRYPT_VERIFIED,
@@ -719,6 +720,7 @@ typedef struct header
                                         * This flag is used by the 
maildir_trash
                                         * option.
                                         */
+  unsigned int reversed_name : 1;      /* did reverse_name succeed? */
   
   /* timezone of the sender of this message */
   unsigned int zhours : 5;
diff -r 469303b9c72d -r 8ec757c26d7e pattern.c
--- a/pattern.c Mon Aug 07 11:46:57 2006 -0400
+++ b/pattern.c Mon Aug 07 11:54:33 2006 -0400
@@ -79,6 +79,7 @@ Flags[] =
   { 'O', M_OLD,                        0,              NULL },
   { 'p', M_PERSONAL_RECIP,     0,              NULL },
   { 'P', M_PERSONAL_FROM,      0,              NULL },
+  { 'q', M_REVERSED_NAME,      0,              NULL },
   { 'Q', M_REPLIED,            0,              NULL },
   { 'r', M_DATE_RECEIVED,      0,              eat_date },
   { 'R', M_READ,               0,              NULL },
@@ -1106,6 +1107,8 @@ mutt_pattern_exec (struct pattern_t *pat
       return (pat->not ^ match_user (pat->alladdr, h->env->to, h->env->cc));
     case M_PERSONAL_FROM:
       return (pat->not ^ match_user (pat->alladdr, h->env->from, NULL));
+    case M_REVERSED_NAME:
+      return (pat->not ^ h->reversed_name);
     case M_COLLAPSED:
       return (pat->not ^ (h->collapsed && h->num_hidden > 1));
    case M_CRYPT_SIGN:
diff -r 469303b9c72d -r 8ec757c26d7e send.c
--- a/send.c    Mon Aug 07 11:46:57 2006 -0400
+++ b/send.c    Mon Aug 07 11:54:33 2006 -0400
@@ -1193,8 +1193,10 @@ ci_send_message (int flags,              /* send mod
      * have their aliases expanded.
      */
 
-    msg->env->from = set_reverse_name (cur->env);
-  }
+    msg->reversed_name = !!(msg->env->from = set_reverse_name (cur->env));
+  }
+  else
+    msg->reversed_name = 0;
 
   if (!msg->env->from && option (OPTUSEFROM) && !(flags & 
(SENDPOSTPONED|SENDRESEND)))
     msg->env->from = mutt_default_from ();