[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

5.3 Triggers

Triggers are conditional statements that use the value of the `Subject' header to alter the control flow. Syntactically, a trigger is:

 
trigger [flags] pattern
  action-list
done

Here, pattern is the pattern against which the `Subject' header is checked, flags are optional flags controlling the type of regular expression used (see section Regular Expressions). For backward compatibility, the keyword rule may be used instead of trigger.

The trigger acts as follows: First, the value of the `Subject' header is matched against the pattern `@@'pattern. If it matches, then the matched part is removed from the `Subject', and the action-list is executed.

Basically, putting aside the possibility to use different flavors of regular expressions, a trigger is equivalent to the following statement:

 
if header[Subject] :posix "(.*)@@pattern"
  modify header [Subject] "\1"
  action-list
fi

Thus, adding the `@@rule-name' code to the `Subject' header of your message, triggers a rule named rule-name, specified in a user configuration file. For example:

 
BEGIN RULE
trigger :basic "^gpg-encrypt-john"
   gpg-encrypt "john's_gpg_key"
done
END

Now, if you send an email with the subject ending on `@@gpg-encrypt-john' (e.g.: `Subject: hello John!@@gpg-encrypt-john'), it will be encrypted with John's public key. The trigger will remove the `@@' and the characters following it, so John will only receive a message with `hello John!' as a subject.

Another example shows an even more dynamic trigger, that is using a substitution and back-references:

 
---BEGIN RULE---
trigger :extended "^gpg-encrypt:(.*)"
   gpg-encrypt "\1"
   add [X-GPG-Comment] "Encrypted for \1"
done
---END---

To encrypt a message to user e.g. `John', simply send an email with a subject `hello John!@@gpg-encrypt:john's_gpg_key'. This way, you decide at a run time which public key should be used, without creating separate rules for each user.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated on May, 24 2014 using texi2html 1.76.