]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: mail_parse_human_timestamp() - Add support for imap date-time
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 11 Apr 2023 08:01:15 +0000 (11:01 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Fri, 14 Apr 2023 15:59:41 +0000 (15:59 +0000)
src/lib-storage/mail-storage.c
src/lib-storage/mail-storage.h
src/lib-storage/test-mail-storage.c

index 40c17e17974c1c0a6a882eb69d9b8b38c6c0efea..e72ad81580d7f3ecd787821a6f138d204cf5bf3c 100644 (file)
@@ -3344,6 +3344,7 @@ int mail_parse_human_timestamp(const char *str, time_t *timestamp_r,
        struct tm tm;
        unsigned int secs;
        const char *error;
+       int tz;
 
        if (i_isdigit(str[0]) && i_isdigit(str[1]) &&
            i_isdigit(str[2]) && i_isdigit(str[3]) && str[4] == '-' &&
@@ -3359,9 +3360,13 @@ int mail_parse_human_timestamp(const char *str, time_t *timestamp_r,
                *utc_r = TRUE;
                return 0;
        } else if (imap_parse_date(str, timestamp_r)) {
-               /* imap date */
+               /* imap datetime */
                *utc_r = FALSE;
                return 0;
+       } else if (imap_parse_datetime(str, timestamp_r, &tz)) {
+               /* imap datetime */
+               *utc_r = TRUE;
+               return 0;
        } else if (str_to_time(str, timestamp_r) == 0) {
                /* unix timestamp */
                *utc_r = TRUE;
index b2895518a3bec328ba2d8e15c5e9cecbe11ad8c0..bf889ec4acd3a582e73b693b25b0a098546b889b 100644 (file)
@@ -1026,8 +1026,8 @@ void mail_generate_guid_128_hash(const char *guid, guid_128_t guid_128_r);
 
    Returns 0 and timestamp on success, -1 if the string couldn't be parsed.
    Currently supported string formats: yyyy-mm-dd (utc=FALSE),
-   imap date (utc=FALSE), unix timestamp (utc=TRUE), interval (e.g. n days,
-   utc=TRUE). */
+   imap date (utc=FALSE), imap date-time (utc=TRUE), unix timestamp (utc=TRUE),
+   interval (e.g. n days, utc=TRUE). */
 int mail_parse_human_timestamp(const char *str, time_t *timestamp_r,
                               bool *utc_r);
 
index a10cb07361c469652a9913a8a3f45f833ed9478a..3e728678a69fce8f3c9ef622c9d27b2a820064de 100644 (file)
@@ -15,6 +15,8 @@ static const struct test_globals {
        { "2022-01-21", 1642723200, TRUE },
        /* IMAP date */
        { "21-Jan-2022", 1642723200, FALSE },
+       /* IMAP datetime */
+       { "21-Jan-2022 10:00:00 +0300", 1642723200 + 7*3600, TRUE },
        /* UNIX timestamp */
        { "1642723200", 1642723200, TRUE },
 };
@@ -644,7 +646,7 @@ static void test_mail_parse_human_timestamp(void)
        time_t timestamp;
        bool is_utc;
 
-       test_begin("mail_parse_human_timestamp");
+       test_begin("mail_parse_human_timestamp()");
 
        for (unsigned int i = 0; i < N_ELEMENTS(human_timestamp_tests); i++) {
                ret = mail_parse_human_timestamp(human_timestamp_tests[i].str,