On Fri, Aug 07, 2009 at 02:17:20PM -0500, Kyle Wheeler wrote:
> On Saturday, August  8 at 01:55 AM, quoth Erik Christiansen:
> > Well, I've gone back for the third time, to check what happens on 
> > compose (m), and list reply (L). In my now disused cross-gcc 
> > mailbox, with no send-hook and no "Reply-To:" in the test email, 
> > both cases follow the default:
> >
> > send-hook .    'my_hdr  Reply-To: m...@domain.on.net'
> 
> Do they have that Reply-To header for the FIRST message you send?

Yes. Starting mutt, changing to the avr-gcc folder, and typing 'm' 'n',
the Reply-To: header has my address. 

> Do you specify a Reply-To header (with my_hdr) anywhere outside of a
> hook?

No. The only "my_hdr  Reply-To:" lines are the 8 send-hooks; one
default, and 7 with '~C some_list_address'.

> I have no doubt that it works *repeatably*, if by "repeatably" you 
> mean "I composed several test messages in a row, and each successive 
> test had the right Reply-To header". My point is that if you compose a  
> message to avr-gcc-l...@nongnu.org, and then immediately afterwords 
> compose a message to someone else (me, say), that this second message 
> will have a Reply-To header intended for the avg-gcc list (unless I'm 
> misunderstanding what you're doing).

On following the first message (above) with a list reply, the header
switches to:

Reply-To: avr-gcc-l...@nongnu.org

After ":wq" and abort, and typing 'm' 'n', the Reply-To: header has my
address again. Thus it is repeatably switching the header as desired.

> > During list reply, is the send-hook just acting as a reply hook, 
> > triggering on the message to which I'm replying?
> 
> No, send-hook ALWAYS matches itself against the NEW message you are 
> composing, even if that new message is a reply to some other message.

Then it seems to be triggering on the "To: avr-gcc-l...@nongnu.org",
auto-inserted for the list reply. Ah, yes, when I compose a new message
to the list, inserting the address in vim, the Reply-To: header remains
at the default.

Since I always post to lists by hitting 'L' and deleting headers such as
"In-Reply_To:", the send-hook works well enough to get by.

>    Example 2:
>      You have a message sent to the mutt mailing list by m...@mydomain.
>      This message is, of course, addressed to mutt-us...@mutt.org.
>      Because it is a mailing list message, when you reply to it, your
>      new message will ALSO be addressed to mutt-us...@mutt.org. Thus,
>      both the following hooks would trigger:
> 
>          reply-hook '~C mutt-users' '...'
>          send-hook  '~C mutt-users' '...'

IIUC, that is what is satisfactorily setting "Reply-To:", so long as I
use 'L' and not 'm' to reply to the list.

>      The reason is that both messages (the original and the reply) are
>      addressed to mutt-users. But of the following two hooks, only the
>      send-hook would trigger:
> 
>          reply-hook '~P' '...'
>          send-hook  '~P' '...'
> 
>      That is because the new message you are composing will be *FROM*
>      you (which is what ~P matches against), but the list message
>      you're responding to isn't FROM you, it's from m...@mydomain.
> 
> The reason the manual talks about reply-hooks and send-hooks in the 
> same breath is that they're *triggered* at approximately the same time 
> (i.e. AFTER you told mutt you want to compose a reply, but BEFORE your 
> $editor runs). When composing a new message that is not a reply, none 
> of the reply-hooks are triggered, no matter what their patterns are, 
> but send-hooks WILL be triggered (if their patterns match).
> 
> Does that help straighten it out?

Yes. Many thanks for the detailed account. I'll certainly keep it for
future reference.

> ALL of mutt's hooks have effects that lasts beyond their immediate 
> context. In fact, ALL hooks are considered to make "permanent" changes 
> (at least, permanent until another hook changes it again). One of the 
> biggest reasons for that is so that mutt's hooks can do *ANYTHING*. If 
> mutt was expected to limit the impact of hooks to just a limited 
> context, it would have to save the state of EVERYTHING and restore it 
> when exiting that context. (You'll note that such "context" is never 
> discussed or hinted at in mutt's manual.)

That doesn't seem to be the case if the context were the content of the
current email. Nothing need be saved, and nothing needs to be restored.
My hope while searching for a simple way to modify one header on the
current email can be likened to shell behaviour. An "ls /tmp" does not
mandate "cd /tmp". It is only because mutt can't modify the headers of
the current message, based on the current message, without clobbering
templates, that it becomes so complicated. I accept now that mutt can't
do that.

> By the way: why are you so determined to mangle the Reply-To header in 
> the first place? So many lists mangle the Reply-To header anyway... 
> mutt supports the Mail-Reply-To header, and automatically generates 
> it. (See the description of the $followup_to setting, as well as 
> http://cr.yp.to/proto/replyto.html)

Having never seen this header before, I don't know whether other mail
clients will respect it. I didn't see how it would help solve the
original problem, i.e. how to set two different reply headers in the
current message, depending on recipients of the current message, in a
way that leaves no permanent effect, achieved innately or by using a
default reset.

> Here's another thought that I had... When you compose a new message, 
> mutt builds it on disk in a temporary file. What you're wishing that 
> the my_hdr command did was modify that temporary file. BUT, here's the 
> thing: mutt has a *generic* method of modifying that temporary file. 
> Actually, it has TWO generic methods. The first is the $editor 
> setting, which can be abused for whatever you like. The other is the 
> <filter-entry> command (usually bound to F by default). So, for 
> example, instead of your original hook:
> 
> > send-hook '~C avr-gcc-l...@nongnu.org' 'my_hdr  Reply-To: 
> > avr-gcc-l...@nongnu.org'
> 
> I think this would do something close to the right thing:
> 
>      send-hook '~C avr-gcc-l...@nongnu.org' \
>      'push <filter-entry>awk "BEGIN{print \"Reply-To: 
> avr-gcc-l...@nongnu.org\"}{print}<enter>'
> 
> Or, since you have procmail, you could use `formail`:
> 
>      send-hook '~C avr-gcc-l...@nongnu.org' \
>      'push "<filter-entry>formail -bfI \"Reply-To: 
> avr-gcc-l...@nongnu.org\"<enter>"'
> 
> The only downside is that the message would only get filtered *after* 
> $editor runs, so if you use $edit_headers, your editor wouldn't see 
> the modified Reply-To header. But it would work.
> 
> Perusing the help screen from the compose menu gives me another idea:
> 
>      send-hook '~C avr-gcc-l...@nongnu.org' \
>      'push <edit-reply-to><kill-line>avr-gcc-l...@nongnu.org<enter>'
> 
> Same semantics, but avoids the need to fuss with external programs.
> 
> Anyway, I hope that helps.

Are you kidding? :-) That smorgasbord is not just brain food, it is a
feast.

My proposed "abuse" of $editor to shunt the composed message through a
"mutt_awkmenter" script was just a more complicated way to achieve what
you've distilled into a single send-hook with integral script.

But trying:
send-hook '~C dva...@internode.on.net' \
   'push "<filter-entry>formail -bfI \"Reply-To: eleph...@the_zoo.com\"<enter>"'

Even after '".muttrc" ... written', then starting a new mutt instance, an
email to dva...@internode.on.net still has:

Reply-To: dva...@internode.on.net

The awk version fared no better, so I looked for a variable to turn
filtering on. It seems that's not needed. Then I installed mutt 1.5.17,
postfix, and awk on a ubuntu Hardy Heron box. Still filtering isn't
working for me. That one flashes up "push: too many arguments", yet I
have the quotes and spaces just as in your example. (Plus an extra "
after <enter> in the awk example.)

I'm grateful for all the effort you've put into explaining how this
aspect of mutt works, and for the wealth of solutions, even if I have
too many thumbs to make them work immediately.

Many thanks,
Erik

-- 
If at first you don't succeed, destroy all evidence that you tried.
                           - Ralf Hildebrandt, on postfix-users.

Reply via email to