changeset 13109:2ab237202629

lib-storage: Added FUZZY search key that adds fuzzy=TRUE to its child args.
author Timo Sirainen <tss@iki.fi>
date Tue, 26 Jul 2011 14:09:49 +0300
parents a16971f5937b
children 2beef586a46a
files src/lib-storage/mail-search-register-imap.c src/lib-storage/mail-search.h
diffstat 2 files changed, 33 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-search-register-imap.c	Tue Jul 26 13:55:22 2011 +0300
+++ b/src/lib-storage/mail-search-register-imap.c	Tue Jul 26 14:09:49 2011 +0300
@@ -426,6 +426,35 @@
 	return sarg;
 }
 
+static void mail_search_arg_set_fuzzy(struct mail_search_arg *sarg)
+{
+	for (; sarg != NULL; sarg = sarg->next) {
+		sarg->fuzzy = TRUE;
+		switch (sarg->type) {
+		case SEARCH_OR:
+		case SEARCH_SUB:
+		case SEARCH_INTHREAD:
+			mail_search_arg_set_fuzzy(sarg->value.subargs);
+			break;
+		default:
+			break;
+		}
+	}
+}
+
+static struct mail_search_arg *
+imap_search_fuzzy(struct mail_search_build_context *ctx)
+{
+	struct mail_search_arg *sarg;
+
+	if (mail_search_build_key(ctx, ctx->parent, &sarg) < 0)
+		return NULL;
+	i_assert(sarg->next == NULL);
+
+	mail_search_arg_set_fuzzy(sarg);
+	return sarg;
+}
+
 static struct mail_search_arg *
 imap_search_inthread(struct mail_search_build_context *ctx)
 {
@@ -535,6 +564,9 @@
 	/* SEARCHRES extension: */
 	{ "$", imap_search_last_result },
 
+	/* FUZZY extension: */
+	{ "FUZZY", imap_search_fuzzy },
+
 	/* Other Dovecot extensions: */
 	{ "INTHREAD", imap_search_inthread },
 	{ "X-GUID", imap_search_x_guid },
--- a/src/lib-storage/mail-search.h	Tue Jul 26 13:55:22 2011 +0300
+++ b/src/lib-storage/mail-search.h	Tue Jul 26 14:09:49 2011 +0300
@@ -94,6 +94,7 @@
 	unsigned int match_not:1; /* result = !result */
 	unsigned int match_always:1; /* result = 1 always */
 	unsigned int nonmatch_always:1; /* result = 0 always */
+	unsigned int fuzzy:1; /* use fuzzy matching for this arg */
 
 	int result; /* -1 = unknown, 0 = unmatched, 1 = matched */
 };