Fwd: isync port: CopyArrivalDate broken; proposed fix

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Fwd: isync port: CopyArrivalDate broken; proposed fix

Klemens Nanni-2
Nothing much to add to Evan's nice report except the proper ports diff.

Regardless of how our strptime(3)'s "%e" turns out[0] and whether isync
upstream will accept a patch, I'd like to fix our port.

Patch description simply snatched from Evan;  more details don't hurt
here and I'm optimistic that the next release will obsolete this patch
(hunk) one way or another.

OK?

0: "strptime: %e and leading space"
https://marc.info/?l=openbsd-tech&m=155044284526535

Index: mail/isync/Makefile
===================================================================
RCS file: /cvs/ports/mail/isync/Makefile,v
retrieving revision 1.38
diff -u -p -r1.38 Makefile
--- mail/isync/Makefile 8 Nov 2018 11:05:32 -0000 1.38
+++ mail/isync/Makefile 16 Feb 2019 22:43:40 -0000
@@ -3,7 +3,7 @@
 COMMENT= synchronize IMAP4 and maildir mailboxes
 
 DISTNAME= isync-1.3.0
-REVISION= 4
+REVISION= 5
 
 CATEGORIES= mail
 MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=isync/}
Index: mail/isync/patches/patch-src_drv_imap_c
===================================================================
RCS file: /cvs/ports/mail/isync/patches/patch-src_drv_imap_c,v
retrieving revision 1.1
diff -u -p -r1.1 patch-src_drv_imap_c
--- mail/isync/patches/patch-src_drv_imap_c 8 May 2018 22:07:42 -0000 1.1
+++ mail/isync/patches/patch-src_drv_imap_c 18 Feb 2019 22:12:23 -0000
@@ -1,5 +1,10 @@
 $OpenBSD: patch-src_drv_imap_c,v 1.1 2018/05/08 22:07:42 kn Exp $
 
+The IMAP protocol specifies a date format beginning with a day-of-month
+space-padded to two characters. The %d specifier in glibc's strptime(3)
+will consume a space-padded day of month, but OpenBSD's %d only accepts
+leading zeroes.
+
 Index: src/drv_imap.c
 --- src/drv_imap.c.orig
 +++ src/drv_imap.c
@@ -12,6 +17,15 @@ Index: src/drv_imap.c
  #ifdef HAVE_LIBSSL
  enum { SSL_None, SSL_STARTTLS, SSL_IMAPS };
  #endif
+@@ -948,7 +950,7 @@ parse_date( const char *str )
+ struct tm datetime;
+
+ memset( &datetime, 0, sizeof(datetime) );
+- if (!(end = strptime( str, "%d-%b-%Y %H:%M:%S ", &datetime )))
++ if (!(end = strptime( str, "%n%d-%b-%Y %H:%M:%S ", &datetime )))
+ return -1;
+ if ((date = timegm( &datetime )) == -1)
+ return -1;
 @@ -3267,6 +3269,8 @@ imap_parse_store( conffile_t *cfg, store_conf_t **stor
  }
  acc_opt = 1;


Good day,

I am using mbsync(1) from the mail/isync port, mostly successfully.
However, the mbsync program aborts when I try to download messages from
an IMAP remote server with the CopyArrivalDate option enabled for the
channel. The issue appears to be an incompatibility in the strptime(3)
format string used by the parse_date function in upstream's
src/drv_imap.c. The IMAP protocol specifies a date format beginning with
a day-of-month space-padded to two characters. The %d specifier in
glibc's strptime(3) will consume a space-padded day of month, but
OpenBSD's %d only accepts leading zeroes. I believe this should be
fixable with the patch that follows my signature, which adds a leading
%n specifier. I'm new to OpenBSD and I'm using it from a smallish VPS
for now so I haven't been able to go through and try adding the patch to
the port and rebuilding it yet, but the change works when I extract the
parse_date function and try it on both conforming and nonconforming
timestamps, such as:

    " 4-Mar-2018 16:49:25 -0500"
    "14-Mar-2018 16:49:25 -0500"
    "04-Mar-2018 16:49:25 -0500"
    "4-Mar-2018 16:49:25 -0500"

My kernel details:

OpenBSD 6.4 (GENERIC) #6: Sat Jan 26 19:51:53 CET 2019
    [hidden email]:/usr/src/sys/arch/amd64/compile/GENERIC

Please let me know if I can give you any further information, reformat
the patch to make it easier for you, etc.

Regards,

Evan Silberman
[hidden email]

diff --git a/src/drv_imap.c b/src/drv_imap.c
index 58fc9d3..f1563c9 100644
--- a/src/drv_imap.c
+++ b/src/drv_imap.c
@@ -953,7 +953,7 @@ parse_date( const char *str )
        struct tm datetime;

        memset( &datetime, 0, sizeof(datetime) );
-       if (!(end = strptime( str, "%d-%b-%Y %H:%M:%S ", &datetime )))
+       if (!(end = strptime( str, "%n%d-%b-%Y %H:%M:%S ", &datetime )))
                return -1;
        if ((date = timegm( &datetime )) == -1)
                return -1;