The so-called “negative lookarounds” are a lesser known and rather useful feature of regular expressions—for instance, you can use these to construct an expression matching on any text, but “dog” or “cat”. Or, in ORF’s context, match on any email address, but those ending in “@mydomain.org”.
This comes very handy with ORF’s exception lists. For instance, let’s assume you want to turn on Greylisting for just a few selected local recipients. It makes sense, some mailboxes are just too important to suffer the delay that normally comes with the technology. As ORF has a Recipient Exception List for Greylisting, this is something you can do right away—yet I doubt you’d love adding 990 excepted local recipients to the list, just for the sake of enabling Greylisting for 10 non-excepted recipients (and then keep that list up to date, for a 1000-mailbox company). Of course, there is a better solution and yes, it is negative lookarounds.
In this particular case, a negative lookbehind regex will help. This is what it looks like for one email address (a@example.com):
.*(?<!^a@example\.com)$
Both a@example.com and b@example.com:
.*(?<!^a@example\.com)(?<!^b@example\.com)$
a@example.com, b@example.com and c@example.com:
.*(?<!^a@example\.com)(?<!^b@example\.com)(?<!^c@example\.com)$
The first regex will match anything, but a@example.com. The second regex will match anything, but a@example.com or b@example.com. The third one—you already figured it out.
The logic around exception lists gets a little complicated, but how this would translate to human language is: “Make an exception if the recipient address is anything, but a@example.com”. Note that all addresses must be listed in the same regex: if you tell ORF to “Make an exception if the recipient address is anything, but a@example.com”, ORF will look no further, because it already knows the zzz@example.com is excepted, regardless if you have a second similar statement about b@example.com. What you really need to tell ORF is “Make an exception if the recipient address is anything, but a@example.com or b@example.com or c@example.com”, in a single step, using the combination technique above.
Just a few ideas what can be done with the help of this trick:
- To enable certain tests for specific domains or recipents only.
- To disable Recipient Validation for all domains, but one or a few.
- To blacklist all .dat attachments except winmail.dat.
- To blacklist all attachments, except .pdf and .doc ones.
And the list goes on. You can learn more about lookaround assertions at regular-expressions.info and in the PCRE manual.