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

Re: match replies in a send-hook



Aron Griffis wrote:  [Mon Jul 09 2007, 05:12:41PM EDT]
> As far as I can tell, there's no way to determine in a send-hook if
> the message is a reply.  Is that right?

I'll explain a bit more what I'm trying to accomplish.

I want to send mails with my From address determined by the following
algorithm:
  1. reverse_name if possible
  2. otherwise, depending on the recipients

Here is a solution to this problem.  Note that mutt's priority order
for setting From is:
  1. set by my_hdr
  2. set by reverse_name
  3. $from

----------------------------------------------------------------------
# Current mutt

alternates '(^|[-<, ])(aron|agriffis|aron.griffis)@'
set from="Aron Griffis <agriffis@xxxxxxxx>" # default needed for (b)ounce
set reverse_name=yes

# Recipient-based hooks; setting $from isn't effective here
send-hook '~C @foo.org'      'my_hdr From: Aron Griffis <agriffis@xxxxxxx>'
send-hook '~C @work1.com'    'my_hdr From: Aron Griffis <agriffis@xxxxxxxxx>'
send-hook '~C @partner1.com' 'my_hdr From: Aron Griffis <agriffis@xxxxxxxxx>'
send-hook '~C @work2.com'    'my_hdr From: Aron Griffis <agriffis@xxxxxxxxx>'

# After recipient-based hooks, try to determine if the message is
# a reply for which reverse_name succeeded.  The best we can do is
# look at the subject and hope this is definitive.  In that case, kill
# the custom header in favor of reverse_name.
send-hook '~s "^Re:"' unmy_hdr From

----------------------------------------------------------------------
# Mutt with patch http://article.gmane.org/gmane.mail.mutt.devel/14042

alternates '(^|[-<, ])(aron|agriffis|aron.griffis)@'
set from="Aron Griffis <agriffis@xxxxxxxx>" # default needed for (b)ounce
set reverse_name=yes

# Recipient-based hooks
send-hook '~C @foo.org'      'set from="Aron Griffis <agriffis@xxxxxxx>"'
send-hook '~C @work1.com'    'set from="Aron Griffis <agriffis@xxxxxxxxx>"'
send-hook '~C @partner1.com' 'set from="Aron Griffis <agriffis@xxxxxxxxx>"'
send-hook '~C @work2.com'    'set from="Aron Griffis <agriffis@xxxxxxxxx>"'

----------------------------------------------------------------------
Frankly, I'm of two minds regarding the patch-based solution.

PRO: The ~s "^Re:" send-hook is hackish and best avoided.  It could
     also be avoided with the q-pattern patch but that met zero
     feedback last time I posted it.  http://n01se.net/paste/850

PRO: Modifying $from is advantageous because it affects the envelope
     sender as well as the From: header.  This is important when
     sending mail from multiple accounts using a single mutt instance.

CON: Modifying $from will affect messages sent after the current one,
     including *bounced* messages.  To counter this, you'll find
     a pretty serious hack.  There are three ways to return to the
     index from the compose menu.  Either you send the message, abort
     it, or postpone it.
        macro compose P '<postpone-message><enter-command> set ...<enter>'
        macro compose q '<exit><enter-command> set ...<enter>'
        macro compose y '<send-message><enter-command> set ...<enter>'

     ...and of course it's worse than that.  If you want different
     settings for different folders, it gets deep quick.  Full details
     at http://n01se.net/agriffis/skel.hg/?file/tip/muttrc.in

Oh well.  Now that I've written all this, I'm not certain it's
anything but a rant about my frustration trying to find an elegant
solution to a seemingly simple problem in mutt.  Probably what's
needed to alleviate this frustration is:

  1. reply-hooks should run inline with send-hooks instead of before
     them.  The only difference between reply-hooks and send-hooks
     should be which message they're matching against.

  2. send-hooks should be able to recognize when they're running on
     a message that is a reply.  Something better than the subject
     hack.

  3. send-hooks should be able to tell if reverse_name succeeded or
     failed.  Right now there is no way to do this short of extremely
     ugly hacks (think of "reply-hook . set from=bogus")

  4. There should be a way to run send-hooks on ALL sent messages
     including bounced messages.  Presently no hooks run when
     a message is bounced, so you just have to get lucky with the
     folder-hook settings when you hit 'b'.

Is anybody else frustrated by these shortcomings or is it just me?
Did anybody really read this entire message? :-)

Aron