1 #include "database-private.h"
5 #include "unicode-util.h"
7 /* _sexp is used for file scope symbols to avoid clashing with
8 * definitions from sexp.h */
10 /* sexp_binding structs attach name to a sexp and a defining
11 * context. The latter allows lazy evaluation of parameters whose
12 * definition contains other parameters. Lazy evaluation is needed
13 * because a primary goal of macros is to change the parent field for
17 typedef struct sexp_binding {
20 const struct sexp_binding *context;
21 const struct sexp_binding *next;
26 SEXP_FLAG_FIELD = 1 << 0,
27 SEXP_FLAG_BOOLEAN = 1 << 1,
28 SEXP_FLAG_SINGLE = 1 << 2,
29 SEXP_FLAG_WILDCARD = 1 << 3,
30 SEXP_FLAG_REGEX = 1 << 4,
31 SEXP_FLAG_DO_REGEX = 1 << 5,
32 SEXP_FLAG_EXPAND = 1 << 6,
33 SEXP_FLAG_DO_EXPAND = 1 << 7,
34 SEXP_FLAG_ORPHAN = 1 << 8,
35 SEXP_FLAG_RANGE = 1 << 9,
39 * define bitwise operators to hide casts */
42 operator| (_sexp_flag_t a, _sexp_flag_t b)
44 return static_cast<_sexp_flag_t>(
45 static_cast<unsigned>(a) | static_cast<unsigned>(b));
49 operator& (_sexp_flag_t a, _sexp_flag_t b)
51 return static_cast<_sexp_flag_t>(
52 static_cast<unsigned>(a) & static_cast<unsigned>(b));
57 Xapian::Query::op xapian_op;
58 Xapian::Query initial;
62 static _sexp_prefix_t prefixes[] =
64 { "and", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
66 { "attachment", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
67 SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD | SEXP_FLAG_EXPAND },
68 { "body", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
70 { "date", Xapian::Query::OP_INVALID, Xapian::Query::MatchAll,
72 { "from", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
73 SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
74 { "folder", Xapian::Query::OP_OR, Xapian::Query::MatchNothing,
75 SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
76 { "id", Xapian::Query::OP_OR, Xapian::Query::MatchNothing,
77 SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX },
78 { "infix", Xapian::Query::OP_INVALID, Xapian::Query::MatchAll,
79 SEXP_FLAG_SINGLE | SEXP_FLAG_ORPHAN },
80 { "is", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
81 SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
82 { "lastmod", Xapian::Query::OP_INVALID, Xapian::Query::MatchAll,
84 { "matching", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
85 SEXP_FLAG_DO_EXPAND },
86 { "mid", Xapian::Query::OP_OR, Xapian::Query::MatchNothing,
87 SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX },
88 { "mimetype", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
89 SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD | SEXP_FLAG_EXPAND },
90 { "not", Xapian::Query::OP_AND_NOT, Xapian::Query::MatchAll,
92 { "of", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
93 SEXP_FLAG_DO_EXPAND },
94 { "or", Xapian::Query::OP_OR, Xapian::Query::MatchNothing,
96 { "path", Xapian::Query::OP_OR, Xapian::Query::MatchNothing,
97 SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX },
98 { "property", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
99 SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
100 { "query", Xapian::Query::OP_INVALID, Xapian::Query::MatchNothing,
101 SEXP_FLAG_SINGLE | SEXP_FLAG_ORPHAN },
102 { "regex", Xapian::Query::OP_INVALID, Xapian::Query::MatchAll,
103 SEXP_FLAG_SINGLE | SEXP_FLAG_DO_REGEX },
104 { "rx", Xapian::Query::OP_INVALID, Xapian::Query::MatchAll,
105 SEXP_FLAG_SINGLE | SEXP_FLAG_DO_REGEX },
106 { "starts-with", Xapian::Query::OP_WILDCARD, Xapian::Query::MatchAll,
108 { "subject", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
109 SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
110 { "tag", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
111 SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
112 { "thread", Xapian::Query::OP_OR, Xapian::Query::MatchNothing,
113 SEXP_FLAG_FIELD | SEXP_FLAG_BOOLEAN | SEXP_FLAG_WILDCARD | SEXP_FLAG_REGEX | SEXP_FLAG_EXPAND },
114 { "to", Xapian::Query::OP_AND, Xapian::Query::MatchAll,
115 SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD | SEXP_FLAG_EXPAND },
119 static notmuch_status_t _sexp_to_xapian_query (notmuch_database_t *notmuch,
120 const _sexp_prefix_t *parent,
121 const _sexp_binding_t *env,
123 Xapian::Query &output);
125 static notmuch_status_t
126 _sexp_combine_query (notmuch_database_t *notmuch,
127 const _sexp_prefix_t *parent,
128 const _sexp_binding_t *env,
129 Xapian::Query::op operation,
132 Xapian::Query &output)
134 Xapian::Query subquery;
136 notmuch_status_t status;
138 /* if we run out elements, return accumulator */
142 return NOTMUCH_STATUS_SUCCESS;
145 status = _sexp_to_xapian_query (notmuch, parent, env, sx, subquery);
149 return _sexp_combine_query (notmuch,
153 Xapian::Query (operation, left, subquery),
157 static notmuch_status_t
158 _sexp_parse_phrase (std::string term_prefix, const char *phrase, Xapian::Query &output)
160 Xapian::Utf8Iterator p (phrase);
161 Xapian::Utf8Iterator end;
162 std::vector<std::string> terms;
165 Xapian::Utf8Iterator start;
166 while (p != end && ! Xapian::Unicode::is_wordchar (*p))
174 while (p != end && Xapian::Unicode::is_wordchar (*p))
178 std::string word (start, p);
179 word = Xapian::Unicode::tolower (word);
180 terms.push_back (term_prefix + word);
183 output = Xapian::Query (Xapian::Query::OP_PHRASE, terms.begin (), terms.end ());
184 return NOTMUCH_STATUS_SUCCESS;
187 static notmuch_status_t
188 _sexp_parse_wildcard (notmuch_database_t *notmuch,
189 const _sexp_prefix_t *parent,
190 unused(const _sexp_binding_t *env),
192 Xapian::Query &output)
195 std::string term_prefix = parent ? _notmuch_database_prefix (notmuch, parent->name) : "";
197 if (parent && ! (parent->flags & SEXP_FLAG_WILDCARD)) {
198 _notmuch_database_log (notmuch, "'%s' does not support wildcard queries\n", parent->name);
199 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
202 output = Xapian::Query (Xapian::Query::OP_WILDCARD,
203 term_prefix + Xapian::Unicode::tolower (match));
204 return NOTMUCH_STATUS_SUCCESS;
207 static notmuch_status_t
208 _sexp_parse_one_term (notmuch_database_t *notmuch, std::string term_prefix, const sexp_t *sx,
209 Xapian::Query &output)
211 Xapian::Stem stem = *(notmuch->stemmer);
213 if (sx->aty == SEXP_BASIC && unicode_word_utf8 (sx->val)) {
214 std::string term = Xapian::Unicode::tolower (sx->val);
216 output = Xapian::Query ("Z" + term_prefix + stem (term));
217 return NOTMUCH_STATUS_SUCCESS;
219 return _sexp_parse_phrase (term_prefix, sx->val, output);
225 _sexp_parse_regex (notmuch_database_t *notmuch,
226 const _sexp_prefix_t *prefix, const _sexp_prefix_t *parent,
227 unused(const _sexp_binding_t *env),
228 std::string val, Xapian::Query &output)
231 _notmuch_database_log (notmuch, "illegal '%s' outside field\n",
233 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
236 if (! (parent->flags & SEXP_FLAG_REGEX)) {
237 _notmuch_database_log (notmuch, "'%s' not supported in field '%s'\n",
238 prefix->name, parent->name);
239 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
242 std::string msg; /* ignored */
244 return _notmuch_regexp_to_query (notmuch, Xapian::BAD_VALUENO, parent->name,
249 static notmuch_status_t
250 _sexp_expand_query (notmuch_database_t *notmuch,
251 const _sexp_prefix_t *prefix, const _sexp_prefix_t *parent,
252 unused(const _sexp_binding_t *env), const sexp_t *sx, Xapian::Query &output)
254 Xapian::Query subquery;
255 notmuch_status_t status;
258 if (! (parent->flags & SEXP_FLAG_EXPAND)) {
259 _notmuch_database_log (notmuch, "'%s' unsupported inside '%s'\n", prefix->name, parent->name);
260 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
263 status = _sexp_combine_query (notmuch, NULL, NULL, prefix->xapian_op, prefix->initial, sx,
268 status = _notmuch_query_expand (notmuch, parent->name, subquery, output, msg);
270 _notmuch_database_log (notmuch, "error expanding query %s\n", msg.c_str ());
275 static notmuch_status_t
276 _sexp_parse_infix (notmuch_database_t *notmuch, const sexp_t *sx, Xapian::Query &output)
279 output = notmuch->query_parser->parse_query (sx->val, NOTMUCH_QUERY_PARSER_FLAGS);
280 } catch (const Xapian::QueryParserError &error) {
281 _notmuch_database_log (notmuch, "Syntax error in infix query: %s\n", sx->val);
282 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
283 } catch (const Xapian::Error &error) {
284 if (! notmuch->exception_reported) {
285 _notmuch_database_log (notmuch,
286 "A Xapian exception occurred parsing query: %s\n",
287 error.get_msg ().c_str ());
288 _notmuch_database_log_append (notmuch,
289 "Query string was: %s\n",
291 notmuch->exception_reported = true;
292 return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
295 return NOTMUCH_STATUS_SUCCESS;
298 static notmuch_status_t
299 _sexp_parse_header (notmuch_database_t *notmuch, const _sexp_prefix_t *parent,
300 const _sexp_binding_t *env, const sexp_t *sx, Xapian::Query &output)
302 _sexp_prefix_t user_prefix;
304 user_prefix.name = sx->list->val;
305 user_prefix.flags = SEXP_FLAG_FIELD | SEXP_FLAG_WILDCARD;
308 _notmuch_database_log (notmuch, "nested field: '%s' inside '%s'\n",
309 sx->list->val, parent->name);
310 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
313 parent = &user_prefix;
315 return _sexp_combine_query (notmuch, parent, env, Xapian::Query::OP_AND, Xapian::Query::MatchAll,
316 sx->list->next, output);
319 static _sexp_binding_t *
320 _sexp_bind (void *ctx, const _sexp_binding_t *env, const char *name, const sexp_t *sx, const
321 _sexp_binding_t *context)
323 _sexp_binding_t *binding = talloc (ctx, _sexp_binding_t);
325 binding->name = talloc_strdup (ctx, name);
327 binding->context = context;
332 static notmuch_status_t
333 maybe_apply_macro (notmuch_database_t *notmuch, const _sexp_prefix_t *parent,
334 const _sexp_binding_t *env, const sexp_t *sx, const sexp_t *args,
335 Xapian::Query &output)
337 const sexp_t *params, *param, *arg, *body;
338 void *local = talloc_new (notmuch);
339 _sexp_binding_t *new_env = NULL;
340 notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
342 if (sx->list->ty != SEXP_VALUE || strcmp (sx->list->val, "macro") != 0) {
343 status = NOTMUCH_STATUS_IGNORED;
347 params = sx->list->next;
349 if (! params || (params->ty != SEXP_LIST)) {
350 _notmuch_database_log (notmuch, "missing (possibly empty) list of arguments to macro\n");
351 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
357 _notmuch_database_log (notmuch, "missing body of macro\n");
358 status = NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
362 for (param = params->list, arg = args;
364 param = param->next, arg = arg->next) {
365 if (param->ty != SEXP_VALUE || param->aty != SEXP_BASIC) {
366 _notmuch_database_log (notmuch, "macro parameters must be unquoted atoms\n");
367 status = NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
370 new_env = _sexp_bind (local, new_env, param->val, arg, env);
373 if (param && ! arg) {
374 _notmuch_database_log (notmuch, "too few arguments to macro\n");
375 status = NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
379 if (! param && arg) {
380 _notmuch_database_log (notmuch, "too many arguments to macro\n");
381 status = NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
385 status = _sexp_to_xapian_query (notmuch, parent, new_env, body, output);
394 static notmuch_status_t
395 maybe_saved_squery (notmuch_database_t *notmuch, const _sexp_prefix_t *parent,
396 const _sexp_binding_t *env, const sexp_t *sx, Xapian::Query &output)
399 char *expansion = NULL;
400 notmuch_status_t status;
402 void *local = talloc_new (notmuch);
405 key = talloc_asprintf (local, "squery.%s", sx->list->val);
407 status = NOTMUCH_STATUS_OUT_OF_MEMORY;
411 status = notmuch_database_get_config (notmuch, key, &expansion);
414 if (EMPTY_STRING (expansion)) {
415 status = NOTMUCH_STATUS_IGNORED;
419 buf = talloc_strdup (local, expansion);
420 /* XXX TODO: free this memory */
421 saved_sexp = parse_sexp (buf, strlen (expansion));
423 _notmuch_database_log (notmuch, "invalid saved s-expression query: '%s'\n", expansion);
424 status = NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
428 status = maybe_apply_macro (notmuch, parent, env, saved_sexp, sx->list->next, output);
429 if (status == NOTMUCH_STATUS_IGNORED)
430 status = _sexp_to_xapian_query (notmuch, parent, env, saved_sexp, output);
439 static notmuch_status_t
440 _sexp_expand_param (notmuch_database_t *notmuch, const _sexp_prefix_t *parent,
441 const _sexp_binding_t *env, const char *name,
442 Xapian::Query &output)
444 for (; env; env = env->next) {
445 if (strcmp (name, env->name) == 0) {
446 return _sexp_to_xapian_query (notmuch, parent, env->context, env->sx,
450 _notmuch_database_log (notmuch, "undefined parameter %s\n", name);
451 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
454 static notmuch_status_t
455 _sexp_parse_range (notmuch_database_t *notmuch, const _sexp_prefix_t *prefix,
456 const sexp_t *sx, Xapian::Query &output)
458 const char *from, *to;
461 /* empty range matches everything */
463 output = Xapian::Query::MatchAll;
464 return NOTMUCH_STATUS_SUCCESS;
467 if (sx->ty == SEXP_LIST) {
468 _notmuch_database_log (notmuch, "expected atom as first argument of '%s'\n", prefix->name);
469 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
476 if (sx->next->ty == SEXP_LIST) {
477 _notmuch_database_log (notmuch, "expected atom as second argument of '%s'\n",
479 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
482 if (sx->next->next) {
483 _notmuch_database_log (notmuch, "'%s' expects maximum of two arguments\n", prefix->name);
484 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
490 if (strcmp (prefix->name, "date") == 0) {
491 notmuch_status_t status;
492 status = _notmuch_date_strings_to_query (NOTMUCH_VALUE_TIMESTAMP, from, to, output, msg);
495 _notmuch_database_log (notmuch, "%s\n", msg.c_str ());
500 if (strcmp (prefix->name, "lastmod") == 0) {
501 long from_idx, to_idx;
504 from_idx = std::stol (from);
505 } catch (std::logic_error &e) {
506 _notmuch_database_log (notmuch, "bad 'from' revision: '%s'\n", from);
507 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
511 to_idx = std::stol (to);
512 } catch (std::logic_error &e) {
513 _notmuch_database_log (notmuch, "bad 'to' revision: '%s'\n", to);
514 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
517 output = Xapian::Query (Xapian::Query::OP_VALUE_RANGE, NOTMUCH_VALUE_LAST_MOD,
518 Xapian::sortable_serialise (from_idx),
519 Xapian::sortable_serialise (to_idx));
520 return NOTMUCH_STATUS_SUCCESS;
523 _notmuch_database_log (notmuch, "unimplimented range prefix: '%s'\n", prefix->name);
524 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
527 /* Here we expect the s-expression to be a proper list, with first
528 * element defining and operation, or as a special case the empty
531 static notmuch_status_t
532 _sexp_to_xapian_query (notmuch_database_t *notmuch, const _sexp_prefix_t *parent,
533 const _sexp_binding_t *env, const sexp_t *sx, Xapian::Query &output)
535 notmuch_status_t status;
537 if (sx->ty == SEXP_VALUE && sx->aty == SEXP_BASIC && sx->val[0] == ',') {
538 return _sexp_expand_param (notmuch, parent, env, sx->val + 1, output);
541 if (sx->ty == SEXP_VALUE) {
542 std::string term_prefix = parent ? _notmuch_database_prefix (notmuch, parent->name) : "";
544 if (sx->aty == SEXP_BASIC && strcmp (sx->val, "*") == 0) {
545 return _sexp_parse_wildcard (notmuch, parent, env, "", output);
548 if (parent && (parent->flags & SEXP_FLAG_BOOLEAN)) {
549 output = Xapian::Query (term_prefix + sx->val);
550 return NOTMUCH_STATUS_SUCCESS;
554 return _sexp_parse_one_term (notmuch, term_prefix, sx, output);
556 Xapian::Query accumulator;
557 for (_sexp_prefix_t *prefix = prefixes; prefix->name; prefix++) {
558 if (prefix->flags & SEXP_FLAG_FIELD) {
559 Xapian::Query subquery;
560 term_prefix = _notmuch_database_prefix (notmuch, prefix->name);
561 status = _sexp_parse_one_term (notmuch, term_prefix, sx, subquery);
564 accumulator = Xapian::Query (Xapian::Query::OP_OR, accumulator, subquery);
567 output = accumulator;
568 return NOTMUCH_STATUS_SUCCESS;
574 output = Xapian::Query::MatchAll;
575 return NOTMUCH_STATUS_SUCCESS;
578 if (sx->list->ty == SEXP_LIST) {
579 _notmuch_database_log (notmuch, "unexpected list in field/operation position\n",
581 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
584 status = maybe_saved_squery (notmuch, parent, env, sx, output);
585 if (status != NOTMUCH_STATUS_IGNORED)
588 /* Check for user defined field */
589 if (_notmuch_string_map_get (notmuch->user_prefix, sx->list->val)) {
590 return _sexp_parse_header (notmuch, parent, env, sx, output);
593 if (strcmp (sx->list->val, "macro") == 0) {
594 _notmuch_database_log (notmuch, "macro definition not permitted here\n");
595 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
598 for (_sexp_prefix_t *prefix = prefixes; prefix && prefix->name; prefix++) {
599 if (strcmp (prefix->name, sx->list->val) == 0) {
600 if (prefix->flags & (SEXP_FLAG_FIELD | SEXP_FLAG_RANGE)) {
602 _notmuch_database_log (notmuch, "nested field: '%s' inside '%s'\n",
603 prefix->name, parent->name);
604 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
609 if (parent && (prefix->flags & SEXP_FLAG_ORPHAN)) {
610 _notmuch_database_log (notmuch, "'%s' not supported inside '%s'\n",
611 prefix->name, parent->name);
612 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
615 if ((prefix->flags & SEXP_FLAG_SINGLE) &&
616 (! sx->list->next || sx->list->next->next || sx->list->next->ty != SEXP_VALUE)) {
617 _notmuch_database_log (notmuch, "'%s' expects single atom as argument\n",
619 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
622 if (prefix->flags & SEXP_FLAG_RANGE)
623 return _sexp_parse_range (notmuch, prefix, sx->list->next, output);
625 if (strcmp (prefix->name, "infix") == 0) {
626 return _sexp_parse_infix (notmuch, sx->list->next, output);
629 if (strcmp (prefix->name, "query") == 0) {
630 return _notmuch_query_name_to_query (notmuch, sx->list->next->val, output);
633 if (prefix->xapian_op == Xapian::Query::OP_WILDCARD)
634 return _sexp_parse_wildcard (notmuch, parent, env, sx->list->next->val, output);
636 if (prefix->flags & SEXP_FLAG_DO_REGEX) {
637 return _sexp_parse_regex (notmuch, prefix, parent, env, sx->list->next->val, output);
640 if (prefix->flags & SEXP_FLAG_DO_EXPAND) {
641 return _sexp_expand_query (notmuch, prefix, parent, env, sx->list->next, output);
644 return _sexp_combine_query (notmuch, parent, env, prefix->xapian_op, prefix->initial,
645 sx->list->next, output);
649 _notmuch_database_log (notmuch, "unknown prefix '%s'\n", sx->list->val);
650 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
654 _notmuch_sexp_string_to_xapian_query (notmuch_database_t *notmuch, const char *querystr,
655 Xapian::Query &output)
657 const sexp_t *sx = NULL;
658 char *buf = talloc_strdup (notmuch, querystr);
660 sx = parse_sexp (buf, strlen (querystr));
662 _notmuch_database_log (notmuch, "invalid s-expression: '%s'\n", querystr);
663 return NOTMUCH_STATUS_BAD_QUERY_SYNTAX;
666 return _sexp_to_xapian_query (notmuch, NULL, NULL, sx, output);