'Extend the given query to one narrowed by the given term, and return the result.
This method satisfies an important security property: the returned
query never includes a message that the given query didn\'t.  In
particular, if the given query will only find messages that a given
user can legitimately see, then so will the returned query.'

def add_term(self, query, term):

    operator = term['operator']
    operand = term['operand']
    negated = term.get('negated', False)
    method_name = ('by_' + operator.replace('-', '_'))
    method = getattr(self, method_name, None)
    if (method is None):
        raise BadNarrowOperator(('unknown    operator    ' + operator))
    if negated:
        maybe_negate = not_
    else:
        maybe_negate = (lambda cond: cond)
    return method(query, operand, maybe_negate)
