Monday, March 7, 2011

How to use Boolean Operators in GMail filters

 In short we have the following options


or --> OR (All caps is necessary)
and -->
not --> "-" (Minus sign)


Here is the official Google video




Here are a few site that explains how to use Boolean operators:


http://blogwaffe.com/2006/01/30/gmail-filters-and-boolean-operators/
http://mail.google.com/support/bin/answer.py?hl=en&answer=8931


Reproducing the instructions from the first site (read the discussion after the post as well...):


"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."

No comments: