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

Re: unable to use send2-hook / group pattern for automatic



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

On Monday, November  5 at 05:01 PM, quoth Gregor Zattler:
> I want to use this group feature to switch encryption on and off 
> depending on emailaddresses:

:) I do that a lot myself.

> send2-hook "." "set crypt_autosign=no"
> send2-hook "." "set crypt_autoencrypt=no"
> send2-hook "^%Cgpg-full" "set crypt_autosign=yes"
> send2-hook "^%Cgpg-full" "set crypt_autoencrypt=yes"

These are bad hooks for several reasons. 

> The manual states: "send2-hook is matched every time a message is 
> changed, either by editing it, or by using the compose menu to 
> change its recipients or subject."

Other changes trigger a send2-hook as well, such as every time a 
message's encryption status is changed. If the action you've specified 
did what you thought it did, you'd have essentially put mutt into an 
infinite loop.

> Therefore the encryption status should be evaluated every time I 
> edit the email.

Wrong. Configuration variables are ONLY consulted when setting up an 
email for the first time. You can think of them as defaults. Changing 
their value from the compose menu does not affect the message you are 
sending. The way to change whether a message is going to be encrypted 
or not from the compose menu is to use the pgp-menu that's right there 
in the middle of the screen rather than by changing configuration 
variables.

As an example, this would be more effective (DO NOT USE THIS HOOK! YOU 
WILL CREATE AN INFINITE LOOP IN MUTT!):

     send2-hook '^%C gpg-full' 'push <pgp-menu>s'

Now, since we are actually getting something to happen now, the real 
question becomes: how do we avoid the infinite loop? Well, that's 
easy! Don't trigger the hook except on messages that are not already 
signed/encrypted:

     send2-hook '!~g !~G ^%C gpg-full' 'push <pgp-menu>b'

Then, of course, you want to disable things if you have other non-pgp 
recipients, so you need another hook:

     send2-hook '(~G|~g) !~%C gpg-full' 'push <pgp-menu>f'

Exactly what you do, of course, depends on the behavior you want. For 
example, I prefer to sign *ALL* of my messages just to subtly 
encourage people to use encryption, but I only want to encrypt 
messages to people that do use encryption. Thus, I use the following 
hooks:

# note that this works because it triggers before $crypt_autoencrypt 
# is consulted by mutt
send-hook '!~G ^%C pgp' 'set crypt_autoencrypt=yes' 
# this one makes the above a little more active
send2-hook '((~g !~G)|(~G !~g)) ^%C pgp' 'push <pgp-menu>b'
# this one makes sure that people who can't read it won't get 
# encrypted mail
send2-hook '~G !^%C pgp' 'push <pgp-menu>s'

But that's relatively easy. The REALLY fancy stuff comes when you have 
friends who are pine users and thus CANNOT use PGP-MIME and so require 
*inline* pgp all the dang time. This is tough to do in mutt because 
there's no pattern to match messages that use inline pgp signatures, 
but it can be done. Any guesses how it's done? ;)

(hint: think $my_* variables)

~Kyle
- -- 
A man cannot be held responsible for what his mind does while he's 
asleep.
                                                     -- Jean Luc Picard
-----BEGIN PGP SIGNATURE-----
Comment: Thank you for using encryption!

iD8DBQFHL0eQBkIOoMqOI14RAkHYAKDwLp1pEIEHWTza9ZPMmy+jmc6AygCghP4Z
6n/HKx5qKUdBo3ODF+TNahQ=
=1q7y
-----END PGP SIGNATURE-----