Browse Source

make use of strptime() portable

it does not (officially) support the %z conversion, so re-implement that
part by hand.
wip/maildir-uid-dupes-test
Oswald Buddenhagen 11 years ago
parent
commit
62a60997c3
  1. 22
      src/drv_imap.c
  2. 2
      src/main.c

22
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; 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 static int
parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED ) 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; int uid = 0, mask = 0, status = 0, size = 0;
unsigned i; unsigned i;
time_t date = 0; time_t date = 0;
struct tm datetime;
if (!is_list( list )) { if (!is_list( list )) {
error( "IMAP error: bogus FETCH response\n" ); 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 )) { } else if (!strcmp( "INTERNALDATE", tmp->val )) {
tmp = tmp->next; tmp = tmp->next;
if (is_atom( tmp )) { if (is_atom( tmp )) {
if (strptime( tmp->val, "%d-%b-%Y %H:%M:%S %z", &datetime )) if ((date = parse_date( tmp->val )) == -1)
date = mktime( &datetime );
else
error( "IMAP error: unable to parse INTERNALDATE format\n" ); error( "IMAP error: unable to parse INTERNALDATE format\n" );
} else } else
error( "IMAP error: unable to parse INTERNALDATE\n" ); error( "IMAP error: unable to parse INTERNALDATE\n" );

2
src/main.c

@ -28,6 +28,7 @@
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <signal.h> #include <signal.h>
#include <time.h>
#include <sys/wait.h> #include <sys/wait.h>
int Pid; /* for maildir and imap */ int Pid; /* for maildir and imap */
@ -219,6 +220,7 @@ main( int argc, char **argv )
char *config = 0, *opt, *ochar; char *config = 0, *opt, *ochar;
int cops = 0, op, pseudo = 0; int cops = 0, op, pseudo = 0;
tzset();
gethostname( Hostname, sizeof(Hostname) ); gethostname( Hostname, sizeof(Hostname) );
if ((ochar = strchr( Hostname, '.' ))) if ((ochar = strchr( Hostname, '.' )))
*ochar = 0; *ochar = 0;

Loading…
Cancel
Save