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

Re: hook syntax (was: Multiple accounts (using Gmail))



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Thursday, March  5 at 08:25 AM, quoth Bill Moseley:
>On Thu, Mar 05, 2009 at 01:54:26AM -0600, Kyle Wheeler wrote:
>> My point was that if you use some sort of hook for setting the From 
>> header, you can use that same hook for changing whatever settings.
>
> Ok, so I have this working to change my signature and from header 
> when replying to a message sent *to* my gmail account (regardless of 
> which folder the mail is in).

Right then, you can use that to change your smtp_url at the same time.

> I'm not 100% clear on the syntax -- that is, when I have to quote 
> (the unmy_hdr line seems to work w/o the quotes where the set 
> signature requires the single quotes).

It's an issue of parsing. Mutt re-parses (and thus de-quotes) hook 
commands when they are triggered. This allows for lots of complex 
embedding, but can result in some confusion.

So, doing something like 'unmy_hdr From', no matter how many times you 
re-parse that, it looks the same. On the other hand, something like 
'set signature="echo foo|"' will change as it gets re-parsed. Let's 
take your examples:

>reply-hook . unmy_hdr From

When the hook is established (i.e. read from the file), it will be 
understood as:

     reply-hook
     .
     unmy_hdr
     From

And when it gets triggered, it will be understood as

     unmy_hdr
     From

>reply-hook . 'set signature="echo Bill Moseley; echo moseley@xxxxxxxx|"'

When it gets established:

     reply-hook
     .
     set signature="echo Bill Moseley; echo moseley@xxxxxxxx|"

And when it gets triggered, it will be understood as:

     set
     signature="echo Bill Moseley; echo moseley@xxxxxxxx|"

Compare that to what happens if you leave off the first set of quotes, 
like this:

     reply-hook . set signature="echo Bill Moseley; echo moseley@xxxxxxxx|"

When that gets established, it will be understood as:

     reply-hook
     .
     set
     signature=echo Bill Moseley; echo moseley@xxxxxxxx|

And then when it gets triggered, it will be understood as:

     set
     signature=echo
     Bill
     Moseley;
     echo
     moseley@xxxxxxxx|

Do you see how that can lead to trouble?

>But, then I have a new problem:
>
>reply-hook seems to override the folder-hook, right?

All hooks override all other hooks, if that makes any sense. It works 
in a "last hook wins" method.

>So this reply-hook takes precedence over the folder-hook.

Yes.

>reply-hook . 'set signature="echo Bill Moseley.; echo moseley@xxxxxxxx|"'
>
>folder-hook =lists.mutt 'set signature=$HOME/.signature_mutt'
>
>How can I have a signature take precedence over the reply-hook
>when in the mutt folder?

Use the folder-hook to change the reply-hook (or something the 
reply-hook relies on).

>Do I have to nest the reply-hook inside a folder-hook?  And if so, can
>someone provide an example of they syntax?

Yes... but the problem is that you're using a folder-hook for 
something it was never intended to be used for. Using the folder-hook  
to change your signature is like using the message-hook to change the 
subject line of future composed messages... you *can*, but it's going 
to be difficult to get right.
I think it makes far more sense to base that sort of information on 
who you're sending to than on what folder you happen to be looking at. 
And, when you do that, the solution ends up being fairly simple. For 
example:

     reply-hook . \
                'set signature=~/.standardsig.txt'

     reply-hook '~e owner-mutt-users@xxxxxxxx' \
                'set signature=~/.muttsig.txt'

Yes, you *can* embed reply-hooks in folder-hooks, but then things get 
ugly because you'd need to unhook things (the unhook is there to 
prevent mutt from building up absurdly long chains of redundant 
hooks), which interacts badly with any other reply-hooks you happen to 
have (i.e. they'd need to be re-established within the folder-hook 
too):

     folder-hook . \
                 'unhook reply-hook ; \
                  reply-hook . "set signature=stdsig.txt"; \
                  reply-hook "~C me@gmail" "set signature=gmailsig.txt"'

     folder-hook =lists.mutt \
                 'unhook reply-hook ; \
                  set signature=muttsig.txt'

Does that make sense?

~Kyle
- -- 
Necessity is the plea for every infringement of human freedom. It is 
the argument of tyrants; it is the creed of slaves.
                                            -- William Pitt the Younger
-----BEGIN PGP SIGNATURE-----
Comment: Thank you for using encryption!

iEYEARECAAYFAkmwIKkACgkQBkIOoMqOI16F3wCg40KmBjyLSgAXerrmZ9ofAPXI
QZIAoOmwav8HyeXtVHaZ4jBjr25tYCFq
=T0B0
-----END PGP SIGNATURE-----