Gmail filters and Boolean operators
If you haven’t heard me proselytize Gmail before, count yourself lucky; I tend to spout off about it. Yes, I know that Gmail is creepy. I understand all the privacy concerns and the potential to allow Google to earn lots of money off of my correspondence. It’s just so damn convenient.
But I digress.
Gmail allows its users to construct email filters to tag messages with various labels, forward things to different address and so forth by specifying the conditions an email must meet before the filter in question is applied. One can specify that the message be From a particular source, be sent To a certain address, contain specific text and so on. Since the filters are implemented as Gmail search queries, Gmail filters may also include basic boolean logic. For instance, you can create a filter that catches emails From bob@example.com OR sally@example.org. In terms of Gmail’s search syntax, this filter would be denoted as from:(bob@example.com OR sally@example.org). Similarly, NOTs are specified with minus signs, and spaces are used for ANDs.
Gmail’s filters, then, are fairly robust. However, the interface for writing filters is very limiting. The user is presented with five text boxes: From, To, Subject, Has The Words, Doesn’t Have. And that’s all the options we get. Suppose, instead of the above, I wanted to create a filter that caught messages From bob@example.com OR To sally@example.org. I can type ‘bob@example.com’ into the From box and ‘sally@example.org’ into the To box to try to construct such a filter. But Gmail does not offer me the ability to specify the boolean operator that should be applied between the From and To conditions; it assumes AND. I’m hosed.
But only at first glance. You can actually implement a relative OR between fields. A cursory internet search yielded the following clever solution.
In the From field, enter
bob@example.com) OR to:(sally@example.org
It’s the sneaky use of parentheses that makes it all work. Another solution would be to enter the entire search query into the Has The Words field:
from:(bob@example.com) OR to:(sally@example.org)
Though more straightforward, some will argue it isn’t as clean.
Anyway, don’t let Gmail’s (in this case) crappy interface stop you from making arbitrarily complicated filters.