commit 29a9f5015363cfd6653f6242b383da09b25fce36
Author: Oswald Buddenhagen <[email protected]>
Date:   Sat Nov 9 14:35:07 2013 +0100

    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 <string.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <time.h>
 #include <sys/wait.h>
 
 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;

------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel

Reply via email to