]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Implemented WITHIN extension.
authorTimo Sirainen <tss@iki.fi>
Sun, 16 Mar 2008 09:25:47 +0000 (11:25 +0200)
committerTimo Sirainen <tss@iki.fi>
Sun, 16 Mar 2008 09:25:47 +0000 (11:25 +0200)
--HG--
branch : HEAD

configure.in
src/lib-storage/index/index-search.c
src/lib-storage/mail-search-build.c
src/lib-storage/mail-search.h

index 5614bc5828fc266b7f2185ccb0925e5c41c52c8e..287081d4833d644c31d197a58708eeaeb113d277 100644 (file)
@@ -2119,7 +2119,7 @@ dnl **
 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"
index 414fd7d9a2f7866cf8583910488f91adbbf09a22..fcf0aa382dc5954a778448d9a8d8d0ac72ccdd97 100644 (file)
@@ -206,8 +206,11 @@ static int search_arg_match_cached(struct index_search_context *ctx,
                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 @@ static int search_arg_match_cached(struct index_search_context *ctx,
                   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:
index 72e76e3674a74ae0e6f0c6b35620d99212d3bc9a..1e6e381d77224cb612cb46e4e665e375fee42f5c 100644 (file)
@@ -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 @@ arg_new_date(struct search_build_data *data,
        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 @@ static bool search_arg_build(struct search_build_data *data,
 
                        (*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 @@ static bool search_arg_build(struct search_build_data *data,
                        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> */
index 8a10e4d26023c4c6e60b798d45c21109bef63c74..1f738423ba96209077b64e919f45b454f9f2ce8e 100644 (file)
@@ -44,6 +44,12 @@ enum mail_search_arg_type {
        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 @@ struct mail_search_arg {
                enum mail_flags flags;
                struct mail_keywords *keywords;
                struct mail_search_modseq *modseq;
+               enum mail_search_arg_flag search_flags;
        } value;
 
         void *context;