From 62a60997c3ee8b42cfe7b7329bc17561b7d2cd92 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 9 Nov 2013 14:35:07 +0100 Subject: [PATCH] make use of strptime() portable it does not (officially) support the %z conversion, so re-implement that part by hand. --- src/drv_imap.c | 22 ++++++++++++++++++---- src/main.c | 2 ++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index 0c5b0a4..a0013b1 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -816,6 +816,23 @@ parse_namespace_rsp_p3( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED ) return LIST_OK; } +static time_t +parse_date( const char *str ) +{ + char *end; + time_t date; + int hours, mins; + struct tm datetime; + + if (!(end = strptime( str, "%d-%b-%Y %H:%M:%S ", &datetime ))) + return -1; + if ((date = mktime( &datetime )) == -1) + return -1; + if (sscanf( end, "%3d%2d", &hours, &mins ) != 2) + return -1; + return date - (hours * 60 + mins) * 60 - timezone; +} + static int parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED ) { @@ -827,7 +844,6 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED ) int uid = 0, mask = 0, status = 0, size = 0; unsigned i; time_t date = 0; - struct tm datetime; if (!is_list( list )) { error( "IMAP error: bogus FETCH response\n" ); @@ -872,9 +888,7 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED ) } else if (!strcmp( "INTERNALDATE", tmp->val )) { tmp = tmp->next; if (is_atom( tmp )) { - if (strptime( tmp->val, "%d-%b-%Y %H:%M:%S %z", &datetime )) - date = mktime( &datetime ); - else + if ((date = parse_date( tmp->val )) == -1) error( "IMAP error: unable to parse INTERNALDATE format\n" ); } else error( "IMAP error: unable to parse INTERNALDATE\n" ); diff --git a/src/main.c b/src/main.c index 2f03d7d..39211cf 100644 --- a/src/main.c +++ b/src/main.c @@ -28,6 +28,7 @@ #include #include #include +#include #include int Pid; /* for maildir and imap */ @@ -219,6 +220,7 @@ main( int argc, char **argv ) char *config = 0, *opt, *ochar; int cops = 0, op, pseudo = 0; + tzset(); gethostname( Hostname, sizeof(Hostname) ); if ((ochar = strchr( Hostname, '.' ))) *ochar = 0;