diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2020-11-26 07:30:41 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2020-11-26 07:30:41 +0200 |
commit | 92ef2f82491ab16a9393fb7c83adaf2f1396e232 (patch) | |
tree | 0fd23a299e7e9483d63ac9dab1afd64d0dc172ca /libmailutils/datetime | |
parent | 1bcece404bf0ec7a2d2941511350e8f2a6f65736 (diff) | |
download | mailutils-92ef2f82491ab16a9393fb7c83adaf2f1396e232.tar.gz mailutils-92ef2f82491ab16a9393fb7c83adaf2f1396e232.tar.bz2 |
mboxrb: Keep timestamps in normalized form
* include/mailutils/datetime.h (mu_timezone_offset): New proto.
* libmailutils/datetime/scantime.c: New conversion: %Z (timezone
abbreviation).
* libmailutils/datetime/parsedate.y (mu_timezone_offset): New function.
Returns time offset in seconds corresponding to the given timezone
abbreviation.
* include/mailutils/sys/mboxrb.h (mu_mboxrb_hdr): Remove unneeded
enum.
(mu_mboxrb_message): Remove env_date_start,
New member "date" holds the string representation of the envelope
timestamp in normalized form - ctime(3), UTC.
* libproto/mbox/mboxrb.c (scan_message_finalize): New function.
(scan_message_begin): New function. When initializing the
message, timestamps in obsolete forms are converted to normalized
representation.
(mboxrb_rescan_unlocked): Use scan_message_finalize and
scan_message_begin.
* libproto/mbox/message.c (mboxrb_envelope_date): Get normalized
timestamp from the date member,
* libproto/mbox/tests/env.at: Reflect the above changes.
Diffstat (limited to 'libmailutils/datetime')
-rw-r--r-- | libmailutils/datetime/parsedate.y | 14 | ||||
-rw-r--r-- | libmailutils/datetime/scantime.c | 26 |
2 files changed, 39 insertions, 1 deletions
diff --git a/libmailutils/datetime/parsedate.y b/libmailutils/datetime/parsedate.y index 977713001..372cdb2eb 100644 --- a/libmailutils/datetime/parsedate.y +++ b/libmailutils/datetime/parsedate.y @@ -1209,6 +1209,20 @@ mu_parse_date (const char *p, time_t *rettime, const time_t *now) return mu_parse_date_dtl (p, now, rettime, NULL, NULL, NULL); } +int +mu_timezone_offset (const char *buf, int *off) +{ + SYMBOL const *tp; + + for (tp = tz_tab; tp->name; tp++) + if (mu_c_strcasecmp (buf, tp->name) == 0) + { + *off = - tp->value * 60; + return 0; + } + return -1; +} + #ifdef STANDALONE int main (int argc, char *argv[]) diff --git a/libmailutils/datetime/scantime.c b/libmailutils/datetime/scantime.c index 0b118b765..8e19a803b 100644 --- a/libmailutils/datetime/scantime.c +++ b/libmailutils/datetime/scantime.c @@ -538,7 +538,31 @@ mu_scan_datetime (const char *input, const char *fmt, } } break; - + + case 'Z': + /* Time-zone in abbreviated form */ + { + char tzs[6]; + p = mu_str_skip_class_comp (input, MU_CTYPE_SPACE); + n = p - input; + if (n > sizeof (tzs) - 1) + { + rc = MU_ERR_PARSE; + break; + } + memcpy (tzs, input, n); + tzs[n] = 0; + if (mu_timezone_offset (tzs, &n)) + { + rc = MU_ERR_PARSE; + break; + } + if (tz) + tz->utc_offset = n; + input = p; + } + break; + case '%': if (*input == '%') input++; |