diff options
Diffstat (limited to 'imap4d/search.c')
-rw-r--r-- | imap4d/search.c | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/imap4d/search.c b/imap4d/search.c index 003796447..758bdb556 100644 --- a/imap4d/search.c +++ b/imap4d/search.c @@ -1,5 +1,5 @@ /* GNU Mailutils -- a suite of utilities for electronic mail - Copyright (C) 1999-2019 Free Software Foundation, Inc. + Copyright (C) 1999-2024 Free Software Foundation, Inc. GNU Mailutils is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -51,7 +51,8 @@ enum node_type node_and, node_or, node_not, - node_value + node_value, + node_false }; struct value @@ -223,7 +224,7 @@ struct parsebuf int arg; /* Argument number */ char *token; /* Current token */ int isuid; /* UIDs instead of msgnos are required */ - char *err_mesg; /* Error message if a parse error occured */ + char *err_mesg; /* Error message if a parse error occurred */ struct mem_chain *alloc; /* Chain of objects allocated during parsing */ char *charset; /* Charset, other than US-ASCII requested */ @@ -618,10 +619,11 @@ parse_simple_key (struct parsebuf *pb) if (!condp->name) { mu_msgset_t msgset = parse_msgset_create (pb, mbox, MU_MSGSET_NUM); + int rc = mu_msgset_parse_imap (msgset, + pb->isuid ? MU_MSGSET_UID : MU_MSGSET_NUM, + pb->token, NULL); - if (mu_msgset_parse_imap (msgset, - pb->isuid ? MU_MSGSET_UID : MU_MSGSET_NUM, - pb->token, NULL) == 0) + if (rc == 0) { struct search_node *np = parse_alloc (pb, sizeof *np); np->type = node_value; @@ -639,11 +641,19 @@ parse_simple_key (struct parsebuf *pb) return node; } - else + else if (rc == MU_ERR_PARSE) { pb->err_mesg = "Unknown search criterion"; return NULL; } + else + { + /* MU_ERR_NOENT or similar */ + node = parse_alloc (pb, sizeof *node); + node->type = node_false; + parse_gettoken (pb, 0); + return node; + } } node = parse_alloc (pb, sizeof *node); @@ -783,6 +793,11 @@ evaluate_node (struct search_node *node, struct parsebuf *pb, case node_value: *val = node->v.value; break; + + case node_false: + val->type = value_number; + val->v.number = 0; + break; } } @@ -802,10 +817,10 @@ search_run (struct parsebuf *pb) return value.v.number != 0; } -/* Helper functions for evaluationg conditions */ +/* Helper functions for evaluating conditions */ -/* Scan the header of a message for the occurence of field named `name'. - Return true if any of the occurences contained substring `value' */ +/* Scan the header of a message for the occurrence of field named `name'. + Return true if any of the occurrences contained substring `value' */ static int _scan_header (struct parsebuf *pb, char *name, char *value) { @@ -837,7 +852,7 @@ _scan_header (struct parsebuf *pb, char *name, char *value) free (hval); hval = tmp; } - result = unistr_is_substring (hval, needle); + result = unistr_is_substring_dn (hval, needle); free (hval); } if (!(rc == 0 || rc == MU_ERR_NOENT)) @@ -861,7 +876,7 @@ _header_date (struct parsebuf *pb, time_t *timep) return 1; } -/* Scan all header fields for the occurence of a substring `text' */ +/* Scan all header fields for the occurrence of a substring `text' */ static int _scan_header_all (struct parsebuf *pb, char *text) { @@ -901,7 +916,7 @@ _scan_header_all (struct parsebuf *pb, char *text) free (hval); hval = tmp; } - result = unistr_is_substring (hval, needle); + result = unistr_is_substring_dn (hval, needle); free (hval); } free (needle); @@ -973,7 +988,7 @@ _match_text (struct parsebuf *pb, mu_message_t msg, mu_content_type_t ct, while ((rc = mu_stream_getline (str, &buffer, &bufsize, &n)) == 0 && n > 0) { - result = unistr_is_substring (buffer, needle); + result = unistr_is_substring_dn (buffer, needle); if (result) break; } |