changeset 7640:c78e9204f3f2 HEAD

Implemented WITHIN extension.
author Timo Sirainen <tss@iki.fi>
date Sun, 16 Mar 2008 11:25:47 +0200
parents 03146f02403f
children d5cae1f5fb6a
files configure.in src/lib-storage/index/index-search.c src/lib-storage/mail-search-build.c src/lib-storage/mail-search.h
diffstat 4 files changed, 59 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/configure.in	Sun Mar 16 11:05:53 2008 +0200
+++ b/configure.in	Sun Mar 16 11:25:47 2008 +0200
@@ -2119,7 +2119,7 @@
 dnl ** capabilities
 dnl **
 
-capability="IMAP4rev1 SASL-IR SORT THREAD=REFERENCES MULTIAPPEND UNSELECT LITERAL+ IDLE CHILDREN NAMESPACE LOGIN-REFERRALS UIDPLUS LIST-EXTENDED I18NLEVEL=1 ENABLE CONDSTORE QRESYNC ESEARCH SEARCHRES"
+capability="IMAP4rev1 SASL-IR SORT THREAD=REFERENCES MULTIAPPEND UNSELECT LITERAL+ IDLE CHILDREN NAMESPACE LOGIN-REFERRALS UIDPLUS LIST-EXTENDED I18NLEVEL=1 ENABLE CONDSTORE QRESYNC ESEARCH SEARCHRES WITHIN"
 AC_DEFINE_UNQUOTED(CAPABILITY_STRING, "$capability", IMAP capabilities)
 
 CFLAGS="$CFLAGS $EXTRA_CFLAGS"
--- a/src/lib-storage/index/index-search.c	Sun Mar 16 11:05:53 2008 +0200
+++ b/src/lib-storage/index/index-search.c	Sun Mar 16 11:25:47 2008 +0200
@@ -206,8 +206,11 @@
 		if (mail_get_received_date(ctx->mail, &date) < 0)
 			return -1;
 
-		tm = localtime(&date);
-		date += utc_offset(tm, date)*60;
+		if ((arg->value.search_flags &
+		     MAIL_SEARCH_ARG_FLAG_USE_TZ) == 0) {
+			tm = localtime(&date);
+			date += utc_offset(tm, date)*60;
+		}
 
 		switch (arg->type) {
 		case SEARCH_BEFORE:
@@ -230,7 +233,9 @@
 		   in searches. date is returned as UTC, so change it. */
 		if (mail_get_date(ctx->mail, &date, &timezone_offset) < 0)
 			return -1;
-		date += timezone_offset * 60;
+		if ((arg->value.search_flags &
+		     MAIL_SEARCH_ARG_FLAG_USE_TZ) == 0)
+			date += timezone_offset * 60;
 
 		switch (arg->type) {
 		case SEARCH_SENTBEFORE:
--- a/src/lib-storage/mail-search-build.c	Sun Mar 16 11:05:53 2008 +0200
+++ b/src/lib-storage/mail-search-build.c	Sun Mar 16 11:25:47 2008 +0200
@@ -1,6 +1,7 @@
 /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "ioloop.h"
 #include "imap-date.h"
 #include "imap-parser.h"
 #include "imap-messageset.h"
@@ -129,6 +130,33 @@
 	return TRUE;
 }
 
+#define ARG_NEW_INTERVAL(type) \
+	arg_new_interval(data, args, next_sarg, type)
+static bool
+arg_new_interval(struct search_build_data *data,
+		 const struct imap_arg **args,
+		 struct mail_search_arg **next_sarg,
+		 enum mail_search_arg_type type)
+{
+	struct mail_search_arg *sarg;
+	const char *value;
+	unsigned long interval;
+	char *p;
+
+	*next_sarg = sarg = search_arg_new(data->pool, type);
+	if (!arg_get_next(data, args, &value))
+		return FALSE;
+
+	interval = strtoul(value, &p, 10);
+	if (interval == 0 || *p != '\0') {
+		data->error = "Invalid search interval parameter";
+		return FALSE;
+	}
+	sarg->value.search_flags = MAIL_SEARCH_ARG_FLAG_USE_TZ;
+	sarg->value.time = ioloop_time - interval;
+	return TRUE;
+}
+
 #define ARG_NEW_HEADER(type, hdr_name) \
 	arg_new_header(data, args, next_sarg, type, hdr_name)
 static bool
@@ -422,6 +450,15 @@
 
 			(*next_sarg)->not = TRUE;
 			return TRUE;
+		} if (strcmp(str, "OLDER") == 0) {
+			/* <interval> - WITHIN extension */
+			if (!ARG_NEW_INTERVAL(SEARCH_BEFORE))
+				return FALSE;
+
+			/* we need to match also equal, but standard BEFORE
+			   compares with "<" */
+			(*next_sarg)->value.time++;
+			return TRUE;
 		}
 		break;
 	case 'R':
@@ -515,6 +552,12 @@
 			return TRUE;
 		}
 		break;
+	case 'Y':
+		if (strcmp(str, "YOUNGER") == 0) {
+			/* <interval> - WITHIN extension */
+			return ARG_NEW_INTERVAL(SEARCH_SINCE);
+		}
+		break;
 	case 'X':
 		if (strcmp(str, "X-BODY-FAST") == 0) {
 			/* <string> */
--- a/src/lib-storage/mail-search.h	Sun Mar 16 11:05:53 2008 +0200
+++ b/src/lib-storage/mail-search.h	Sun Mar 16 11:25:47 2008 +0200
@@ -44,6 +44,12 @@
 	SEARCH_MODSEQ
 };
 
+enum mail_search_arg_flag {
+	/* For (SENT)BEFORE/SINCE/ON searches: Don't drop timezone from
+	   comparisons */
+	MAIL_SEARCH_ARG_FLAG_USE_TZ	= 0x01,
+};
+
 enum mail_search_modseq_type {
 	MAIL_SEARCH_MODSEQ_TYPE_ANY = 0,
 	MAIL_SEARCH_MODSEQ_TYPE_PRIVATE,
@@ -68,6 +74,7 @@
 		enum mail_flags flags;
 		struct mail_keywords *keywords;
 		struct mail_search_modseq *modseq;
+		enum mail_search_arg_flag search_flags;
 	} value;
 
         void *context;