dovecot-2.0: lib-storage: Added mail_search_args_match_mailbox()
dovecot at dovecot.org
dovecot at dovecot.org
Wed Apr 28 22:09:22 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/71e40ea473cf
changeset: 11199:71e40ea473cf
user: Timo Sirainen <tss at iki.fi>
date: Wed Apr 28 22:02:59 2010 +0300
description:
lib-storage: Added mail_search_args_match_mailbox()
diffstat:
src/lib-storage/mail-search.c | 59 +++++++++++++++++++++++++++++
src/lib-storage/mail-search.h | 5 ++
2 files changed, 64 insertions(+), 0 deletions(-)
diffs (84 lines):
diff -r d5ca3aebc4ee -r 71e40ea473cf src/lib-storage/mail-search.c
--- a/src/lib-storage/mail-search.c Wed Apr 28 22:02:10 2010 +0300
+++ b/src/lib-storage/mail-search.c Wed Apr 28 22:02:59 2010 +0300
@@ -524,6 +524,65 @@
return buffer_get_data(headers, NULL);
}
+static bool
+mail_search_args_match_mailbox_arg(const struct mail_search_arg *arg,
+ const char *vname, char sep)
+{
+ const struct mail_search_arg *subarg;
+ bool ret;
+
+ switch (arg->type) {
+ case SEARCH_OR:
+ subarg = arg->value.subargs;
+ for (; subarg != NULL; subarg = subarg->next) {
+ if (mail_search_args_match_mailbox_arg(subarg,
+ vname, sep))
+ return TRUE;
+ }
+ return FALSE;
+ case SEARCH_SUB:
+ case SEARCH_INTHREAD:
+ subarg = arg->value.subargs;
+ for (; subarg != NULL; subarg = subarg->next) {
+ if (!mail_search_args_match_mailbox_arg(subarg,
+ vname, sep))
+ return FALSE;
+ }
+ return TRUE;
+ case SEARCH_MAILBOX:
+ ret = strcmp(arg->value.str, vname) == 0;
+ return ret != arg->not;
+ case SEARCH_MAILBOX_GLOB: {
+ T_BEGIN {
+ struct imap_match_glob *glob;
+
+ glob = imap_match_init(pool_datastack_create(),
+ arg->value.str, TRUE, sep);
+ ret = imap_match(glob, vname) == IMAP_MATCH_YES;
+ } T_END;
+ return ret != arg->not;
+ }
+ default:
+ break;
+ }
+ return TRUE;
+}
+
+bool mail_search_args_match_mailbox(struct mail_search_args *args,
+ const char *vname, char sep)
+{
+ const struct mail_search_arg *arg;
+
+ if (!args->simplified)
+ mail_search_args_simplify(args);
+
+ for (arg = args->args; arg != NULL; arg = arg->next) {
+ if (!mail_search_args_match_mailbox_arg(arg, vname, sep))
+ return FALSE;
+ }
+ return TRUE;
+}
+
static struct mail_keywords *
mail_search_keywords_merge(struct mailbox *box,
struct mail_keywords **_kw1,
diff -r d5ca3aebc4ee -r 71e40ea473cf src/lib-storage/mail-search.h
--- a/src/lib-storage/mail-search.h Wed Apr 28 22:02:10 2010 +0300
+++ b/src/lib-storage/mail-search.h Wed Apr 28 22:02:59 2010 +0300
@@ -168,6 +168,11 @@
mail_search_args_analyze(struct mail_search_arg *args,
bool *have_headers, bool *have_body);
+/* Returns FALSE if search query contains MAILBOX[_GLOB] args such that the
+ query can never match any messages in the given mailbox. */
+bool mail_search_args_match_mailbox(struct mail_search_args *args,
+ const char *vname, char sep);
+
/* Simplify/optimize search arguments. Afterwards all OR/SUB args are
guaranteed to have not=FALSE. */
void mail_search_args_simplify(struct mail_search_args *args);
More information about the dovecot-cvs
mailing list