From: Stephan Bosch Date: Thu, 19 Mar 2020 00:19:40 +0000 (+0100) Subject: imap: Implement the standard SAVEDATE capability. X-Git-Tag: 2.3.11.2~486 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4569e0407c367cd4c9b6b66a93dda7dc00a37bd;p=thirdparty%2Fdovecot%2Fcore.git imap: Implement the standard SAVEDATE capability. --- diff --git a/configure.ac b/configure.ac index 0185039feb..dfb59021d7 100644 --- a/configure.ac +++ b/configure.ac @@ -787,7 +787,7 @@ dnl ** dnl IDLE doesn't really belong to banner. It's there just to make Blackberries dnl happy, because otherwise BIS server disables push email. capability_banner="IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE" -capability="$capability_banner SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY STATUS=SIZE" +capability="$capability_banner SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY STATUS=SIZE SAVEDATE" AC_DEFINE_UNQUOTED(CAPABILITY_STRING, "$capability", [IMAP capabilities]) AC_DEFINE_UNQUOTED(CAPABILITY_BANNER_STRING, "$capability_banner", [IMAP capabilities advertised in banner]) diff --git a/src/imap/imap-fetch.c b/src/imap/imap-fetch.c index e9b3b9f84a..4f5a231118 100644 --- a/src/imap/imap-fetch.c +++ b/src/imap/imap-fetch.c @@ -889,6 +889,33 @@ bool imap_fetch_uid_init(struct imap_fetch_init_context *ctx) return TRUE; } +static int imap_fetch_savedate(struct imap_fetch_context *ctx, struct mail *mail, + void *context ATTR_UNUSED) +{ + time_t date; + int ret; + + ret = mail_get_save_date(mail, &date); + if (ret < 0) + return -1; + + if (ret == 0) + str_append(ctx->state.cur_str, "SAVEDATE NIL "); + else { + str_printfa(ctx->state.cur_str, "SAVEDATE \"%s\" ", + imap_to_datetime(date)); + } + return 1; +} + +static bool imap_fetch_savedate_init(struct imap_fetch_init_context *ctx) +{ + ctx->fetch_ctx->fetch_data |= MAIL_FETCH_SAVE_DATE; + imap_fetch_add_handler(ctx, IMAP_FETCH_HANDLER_FLAG_BUFFERED, + "NIL", imap_fetch_savedate, NULL); + return TRUE; +} + static int fetch_guid(struct imap_fetch_context *ctx, struct mail *mail, void *context ATTR_UNUSED) { @@ -993,6 +1020,7 @@ imap_fetch_default_handlers[] = { { "RFC822", imap_fetch_rfc822_init }, { "SNIPPET", imap_fetch_snippet_init }, { "UID", imap_fetch_uid_init }, + { "SAVEDATE", imap_fetch_savedate_init }, { "X-GUID", fetch_guid_init }, { "X-MAILBOX", fetch_x_mailbox_init }, { "X-REAL-UID", fetch_x_real_uid_init }, diff --git a/src/lib-storage/mail-search-args-imap.c b/src/lib-storage/mail-search-args-imap.c index da5d45325d..73aab6c82f 100644 --- a/src/lib-storage/mail-search-args-imap.c +++ b/src/lib-storage/mail-search-args-imap.c @@ -144,7 +144,7 @@ bool mail_search_arg_to_imap(string_t *dest, const struct mail_search_arg *arg, str_append(dest, "BEFORE"); break; case MAIL_SEARCH_DATE_TYPE_SAVED: - str_append(dest, "X-SAVEDBEFORE"); + str_append(dest, "SAVEDBEFORE"); break; } if (mail_search_arg_to_imap_date(dest, arg)) @@ -171,7 +171,7 @@ bool mail_search_arg_to_imap(string_t *dest, const struct mail_search_arg *arg, str_append(dest, "ON"); break; case MAIL_SEARCH_DATE_TYPE_SAVED: - str_append(dest, "X-SAVEDON"); + str_append(dest, "SAVEDON"); break; } if (!mail_search_arg_to_imap_date(dest, arg)) { @@ -191,7 +191,7 @@ bool mail_search_arg_to_imap(string_t *dest, const struct mail_search_arg *arg, str_append(dest, "SINCE"); break; case MAIL_SEARCH_DATE_TYPE_SAVED: - str_append(dest, "X-SAVEDSINCE"); + str_append(dest, "SAVEDSINCE"); break; } if (mail_search_arg_to_imap_date(dest, arg)) diff --git a/src/lib-storage/mail-search-register-human.c b/src/lib-storage/mail-search-register-human.c index 2ff0a6ae03..8e82bdc263 100644 --- a/src/lib-storage/mail-search-register-human.c +++ b/src/lib-storage/mail-search-register-human.c @@ -73,6 +73,12 @@ CALLBACK_DATE(savedbefore, SEARCH_BEFORE, MAIL_SEARCH_DATE_TYPE_SAVED) CALLBACK_DATE(savedon, SEARCH_ON, MAIL_SEARCH_DATE_TYPE_SAVED) CALLBACK_DATE(savedsince, SEARCH_SINCE, MAIL_SEARCH_DATE_TYPE_SAVED) +static struct mail_search_arg * +human_search_savedatesupported(struct mail_search_build_context *ctx) +{ + return mail_search_build_new(ctx, SEARCH_SAVEDATESUPPORTED); +} + static struct mail_search_arg * arg_new_human_size(struct mail_search_build_context *ctx, enum mail_search_arg_type type) @@ -157,6 +163,7 @@ static const struct mail_search_register_arg human_register_args[] = { { "SAVEDBEFORE", human_search_savedbefore }, { "SAVEDON", human_search_savedon }, { "SAVEDSINCE", human_search_savedsince }, + { "SAVEDATESUPPORTED", human_search_savedatesupported }, { "X-SAVEDBEFORE", human_search_savedbefore }, { "X-SAVEDON", human_search_savedon }, { "X-SAVEDSINCE", human_search_savedsince }, diff --git a/src/lib-storage/mail-search-register-imap.c b/src/lib-storage/mail-search-register-imap.c index b64fb5f135..c888b9e195 100644 --- a/src/lib-storage/mail-search-register-imap.c +++ b/src/lib-storage/mail-search-register-imap.c @@ -11,6 +11,7 @@ #include "mail-search-register.h" #include "mail-search-parser.h" #include "mail-search-build.h" +#include "mail-search-build.h" #include "mail-search-mime-build.h" struct mail_search_register *mail_search_register_imap; @@ -186,10 +187,20 @@ CALLBACK_DATE(sentbefore, SEARCH_BEFORE, MAIL_SEARCH_DATE_TYPE_SENT) CALLBACK_DATE(senton, SEARCH_ON, MAIL_SEARCH_DATE_TYPE_SENT) CALLBACK_DATE(sentsince, SEARCH_SINCE, MAIL_SEARCH_DATE_TYPE_SENT) +CALLBACK_DATE(savedbefore, SEARCH_BEFORE, MAIL_SEARCH_DATE_TYPE_SAVED) +CALLBACK_DATE(savedon, SEARCH_ON, MAIL_SEARCH_DATE_TYPE_SAVED) +CALLBACK_DATE(savedsince, SEARCH_SINCE, MAIL_SEARCH_DATE_TYPE_SAVED) + CALLBACK_DATE(x_savedbefore, SEARCH_BEFORE, MAIL_SEARCH_DATE_TYPE_SAVED) CALLBACK_DATE(x_savedon, SEARCH_ON, MAIL_SEARCH_DATE_TYPE_SAVED) CALLBACK_DATE(x_savedsince, SEARCH_SINCE, MAIL_SEARCH_DATE_TYPE_SAVED) +static struct mail_search_arg * +imap_search_savedatesupported(struct mail_search_build_context *ctx) +{ + return mail_search_build_new(ctx, SEARCH_SAVEDATESUPPORTED); +} + static struct mail_search_arg * arg_new_size(struct mail_search_build_context *ctx, enum mail_search_arg_type type) @@ -559,6 +570,11 @@ static const struct mail_search_register_arg imap_register_args[] = { { "SENTBEFORE", imap_search_sentbefore }, { "SENTON", imap_search_senton }, { "SENTSINCE", imap_search_sentsince }, + { "SAVEDBEFORE", imap_search_savedbefore }, + { "SAVEDON", imap_search_savedon }, + { "SAVEDSINCE", imap_search_savedsince }, + { "SAVEDATESUPPORTED", imap_search_savedatesupported }, + /* FIXME: remove these in v2.4: */ { "X-SAVEDBEFORE", imap_search_x_savedbefore }, { "X-SAVEDON", imap_search_x_savedon }, { "X-SAVEDSINCE", imap_search_x_savedsince }, diff --git a/src/lib-storage/test-mail-search-args-imap.c b/src/lib-storage/test-mail-search-args-imap.c index 698ff53fa8..c6cda9c41c 100644 --- a/src/lib-storage/test-mail-search-args-imap.c +++ b/src/lib-storage/test-mail-search-args-imap.c @@ -25,9 +25,12 @@ static const struct { { "SENTBEFORE 20-May-2015", "SENTBEFORE \"20-May-2015\"" }, { "SENTON 20-May-2015", "SENTON \"20-May-2015\"" }, { "SENTSINCE 20-May-2015", "SENTSINCE \"20-May-2015\"" }, - { "X-SAVEDBEFORE 20-May-2015", "X-SAVEDBEFORE \"20-May-2015\"" }, - { "X-SAVEDON 20-May-2015", "X-SAVEDON \"20-May-2015\"" }, - { "X-SAVEDSINCE 20-May-2015", "X-SAVEDSINCE \"20-May-2015\"" }, + { "SAVEDBEFORE 20-May-2015", "SAVEDBEFORE \"20-May-2015\"" }, + { "SAVEDON 20-May-2015", "SAVEDON \"20-May-2015\"" }, + { "SAVEDSINCE 20-May-2015", "SAVEDSINCE \"20-May-2015\"" }, + { "X-SAVEDBEFORE 20-May-2015", "SAVEDBEFORE \"20-May-2015\"" }, + { "X-SAVEDON 20-May-2015", "SAVEDON \"20-May-2015\"" }, + { "X-SAVEDSINCE 20-May-2015", "SAVEDSINCE \"20-May-2015\"" }, { "OLDER 1", NULL }, { "OLDER 1000", NULL }, { "YOUNGER 1", NULL },