From 5d5a0461ce9908af1241f52012dc343096f5ecbe Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 7 Oct 2017 14:17:25 +0200 Subject: [PATCH 01/10] bump version --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 5da4ac0..c7dcce9 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_INIT([isync], [1.3.0]) +AC_INIT([isync], [1.3.1]) AC_CONFIG_HEADERS([autodefs.h]) AM_INIT_AUTOMAKE From c9cd1b59fb1b85cddaa407773d2545150c359e8c Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 7 Oct 2017 14:46:50 +0200 Subject: [PATCH 02/10] git-ignore tar ball signatures --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 05a49c7..310c028 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ /install-sh /isync.spec /isync-*.tar.gz +/isync-*.tar.gz.asc /missing /patch-stamp /stamp-h From 5aab050198159ba868bc9140cb59443f5212ce77 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 7 Oct 2017 14:09:39 +0200 Subject: [PATCH 03/10] don't forward-declare SSL types any more our current project structure precludes the clash between some indirect include of ssl.h and our definition of 'S' (or 'M', i don't remember) that happened on some system, so there is no need to avoid including it any more. this avoids complaints from some more picky compilers, as re-defining typedefs (even to the same thing) is illegal before C11. --- src/socket.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/socket.h b/src/socket.h index cd0c632..36ebe09 100644 --- a/src/socket.h +++ b/src/socket.h @@ -30,9 +30,7 @@ #endif #ifdef HAVE_LIBSSL -typedef struct ssl_st SSL; -typedef struct ssl_ctx_st SSL_CTX; -typedef struct stack_st _STACK; +# include enum { SSLv3 = 2, From 094af8720cae202f76f8b1c46d47a40361a7ad8b Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 7 Oct 2017 14:30:31 +0200 Subject: [PATCH 04/10] limit -Wmaybe-uninitialized suppression to gcc >= 4.3 apple gcc 4.2 complains about the use of the pragma inside a function. clang also complains, but because the pragma is entirely unknown to it. as neither compiler emits the bogus warning in the first place, there is no point in suppressing it anyway. --- src/util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util.c b/src/util.c index 9576b65..3b624bd 100644 --- a/src/util.c +++ b/src/util.c @@ -519,13 +519,13 @@ map_name( const char *arg, char **result, int reserve, const char *in, const cha for (ll = 0; ll < inl; ll++) if (arg[i + ll] != in[ll]) goto rnexti; -#ifdef __GNUC__ +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && !defined(__clang__) # pragma GCC diagnostic push /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42145 */ # pragma GCC diagnostic ignored "-Wmaybe-uninitialized" #endif memcpy( p, out, outl ); -#ifdef __GNUC__ +#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && !defined(__clang__) # pragma GCC diagnostic pop #endif p += outl; From c75001aa7dcc095cb05bd29a08e027b2cae60a44 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 15 Oct 2017 11:34:50 +0200 Subject: [PATCH 05/10] add check for perl and its version --- configure.ac | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/configure.ac b/configure.ac index c7dcce9..c901352 100644 --- a/configure.ac +++ b/configure.ac @@ -11,6 +11,23 @@ fi CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE" +AC_CHECK_PROG(PERL, perl, perl) +if test "x$PERL" = "x"; then + AC_MSG_ERROR([perl not found]) +fi + +need_perl=5.14 +AC_CACHE_CHECK([whether perl is recent enough], ob_cv_perl_ver, [ + if $PERL -e "use v$need_perl;"; then + ob_cv_perl_ver=yes + else + ob_cv_perl_ver=no + fi +]) +if test "x$ob_cv_perl_ver" = "xno"; then + AC_MSG_ERROR([perl is too old]) +fi + AC_CACHE_CHECK([whether strftime supports %z], ob_cv_strftime_z, [AC_TRY_RUN( [#include From 53e8e794887025cbec7bc053f96c06a55273c40e Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 15 Oct 2017 16:46:49 +0200 Subject: [PATCH 06/10] remove pointless conditional in assignment of ctx->delimiter amends 72c2d695a. --- src/drv_imap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index 56d71cb..bc85aeb 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -2250,7 +2250,7 @@ imap_open_store_namespace( imap_store_t *ctx ) ctx->state = SST_HALF; ctx->prefix = cfg->gen.path; - ctx->delimiter[0] = cfg->delimiter ? cfg->delimiter : 0; + ctx->delimiter[0] = cfg->delimiter; if (((!ctx->prefix && cfg->use_namespace) || !cfg->delimiter) && CAP(NAMESPACE)) { /* get NAMESPACE info */ if (!ctx->got_namespace) From c29eceaeeda5e0cc91f830fd49b96a3b6c1d5751 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 15 Oct 2017 16:14:20 +0200 Subject: [PATCH 07/10] make map_name() interpret empty strings as "no separator" empty strings were previously meaningless, and starting with 72c2d695a, failure to handle them lead to bogus results when the IMAP hierarchy separator is legitimately empty (when the server genuinely supports none and none is manually configured). non-null can be asserted more cleanly than null-or-non-empty, so change the api like that. incidentally, this also removes the need to work around gcc's bogus warning in -Os mode. problem found by "Casper Ti. Vector" --- src/config.c | 2 ++ src/main.c | 4 ++-- src/sync.c | 2 +- src/util.c | 27 ++++++++++----------------- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/src/config.c b/src/config.c index 20f09d9..8ddfe26 100644 --- a/src/config.c +++ b/src/config.c @@ -355,6 +355,8 @@ load_config( const char *where, int pseudo ) if (store) { if (!store->max_size) store->max_size = INT_MAX; + if (!store->flat_delim) + store->flat_delim = ""; *storeapp = store; storeapp = &store->next; *storeapp = 0; diff --git a/src/main.c b/src/main.c index 3ba4323..eadd81f 100644 --- a/src/main.c +++ b/src/main.c @@ -983,7 +983,7 @@ store_connected( int sts, void *aux ) flags |= LIST_INBOX; } else if (c == '/') { /* Flattened sub-folders of INBOX actually end up in Path. */ - if (mvars->ctx[t]->conf->flat_delim) + if (mvars->ctx[t]->conf->flat_delim[0]) flags |= LIST_PATH; else flags |= LIST_INBOX; @@ -1027,7 +1027,7 @@ store_listed( int sts, string_list_t *boxes, void *aux ) return; case DRV_OK: for (box = boxes; box; box = box->next) { - if (mvars->ctx[t]->conf->flat_delim) { + if (mvars->ctx[t]->conf->flat_delim[0]) { string_list_t *nbox; if (map_name( box->string, (char **)&nbox, offsetof(string_list_t, string), mvars->ctx[t]->conf->flat_delim, "/" ) < 0) { error( "Error: flattened mailbox name '%s' contains canonical hierarchy delimiter\n", box->string ); diff --git a/src/sync.c b/src/sync.c index 8f2b4a2..7397db2 100644 --- a/src/sync.c +++ b/src/sync.c @@ -1014,7 +1014,7 @@ sync_boxes( store_t *ctx[], const char *names[], int present[], channel_conf_t * svars->orig_name[t] = (!names[t] || (ctx[t]->conf->map_inbox && !strcmp( ctx[t]->conf->map_inbox, names[t] ))) ? "INBOX" : names[t]; - if (!ctx[t]->conf->flat_delim) { + if (!ctx[t]->conf->flat_delim[0]) { svars->box_name[t] = nfstrdup( svars->orig_name[t] ); } else if (map_name( svars->orig_name[t], &svars->box_name[t], 0, "/", ctx[t]->conf->flat_delim ) < 0) { error( "Error: canonical mailbox name '%s' contains flattened hierarchy delimiter\n", svars->orig_name[t] ); diff --git a/src/util.c b/src/util.c index 3b624bd..f4dce49 100644 --- a/src/util.c +++ b/src/util.c @@ -479,19 +479,20 @@ map_name( const char *arg, char **result, int reserve, const char *in, const cha char *p; int i, l, ll, num, inl, outl; + assert( arg ); l = strlen( arg ); - if (!in) { + assert( in ); + inl = strlen( in ); + if (!inl) { copy: *result = nfmalloc( reserve + l + 1 ); memcpy( *result + reserve, arg, l + 1 ); return 0; } - inl = strlen( in ); - if (out) { - outl = strlen( out ); - if (inl == outl && !memcmp( in, out, inl )) - goto copy; - } + assert( out ); + outl = strlen( out ); + if (inl == outl && !memcmp( in, out, inl )) + goto copy; for (num = 0, i = 0; i < l; ) { for (ll = 0; ll < inl; ll++) if (arg[i + ll] != in[ll]) @@ -500,7 +501,7 @@ map_name( const char *arg, char **result, int reserve, const char *in, const cha i += inl; continue; fout: - if (out) { + if (outl) { for (ll = 0; ll < outl; ll++) if (arg[i + ll] != out[ll]) goto fnexti; @@ -511,7 +512,7 @@ map_name( const char *arg, char **result, int reserve, const char *in, const cha } if (!num) goto copy; - if (!out) + if (!outl) return -2; *result = nfmalloc( reserve + l + num * (outl - inl) + 1 ); p = *result + reserve; @@ -519,15 +520,7 @@ map_name( const char *arg, char **result, int reserve, const char *in, const cha for (ll = 0; ll < inl; ll++) if (arg[i + ll] != in[ll]) goto rnexti; -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && !defined(__clang__) -# pragma GCC diagnostic push -/* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=42145 */ -# pragma GCC diagnostic ignored "-Wmaybe-uninitialized" -#endif memcpy( p, out, outl ); -#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) && !defined(__clang__) -# pragma GCC diagnostic pop -#endif p += outl; i += inl; continue; From af1acdac9748910f6db8c8a3853ff72aeb948107 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 15 Oct 2017 16:52:43 +0200 Subject: [PATCH 08/10] make more use of equals() --- src/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index f4dce49..8c56a28 100644 --- a/src/util.c +++ b/src/util.c @@ -491,7 +491,7 @@ map_name( const char *arg, char **result, int reserve, const char *in, const cha } assert( out ); outl = strlen( out ); - if (inl == outl && !memcmp( in, out, inl )) + if (equals( in, inl, out, outl )) goto copy; for (num = 0, i = 0; i < l; ) { for (ll = 0; ll < inl; ll++) From 0a5a84793283bae245d64fbf634f651b433afe0d Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sat, 18 Nov 2017 09:57:05 +0100 Subject: [PATCH 09/10] fix IMAP UID sequence in UIDNEXT determination fallback use just * instead of the rather nonsensical *:* (which davmail happens to actually barf at). amends 72be55b0. --- src/drv_imap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drv_imap.c b/src/drv_imap.c index bc85aeb..05afa09 100644 --- a/src/drv_imap.c +++ b/src/drv_imap.c @@ -2388,7 +2388,7 @@ imap_open_box_p2( imap_store_t *ctx, imap_cmd_t *gcmd, int response ) INIT_IMAP_CMD(imap_cmd_open_box_t, cmd, cmdp->callback, cmdp->callback_aux) cmd->gen.param.lastuid = 1; imap_exec( ctx, &cmd->gen, imap_open_box_p3, - "UID FETCH *:* (UID)" ); + "UID FETCH * (UID)" ); } static void From 507203293931aed82a14c59ba1c07b7c4601594d Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Sun, 8 Apr 2018 18:10:21 +0200 Subject: [PATCH 10/10] fix uidvalidity recovery with really long message-id headers re-using the file name buffer for the headers wasn't such a great idea, as _POSIX_PATH_MAX is only 256, while RFC2822 permits lines up to 1000 chars. and sure enough, i have a message with a whopping 470-char message-id header ... --- src/drv_maildir.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/drv_maildir.c b/src/drv_maildir.c index c4dd6c7..4a94696 100644 --- a/src/drv_maildir.c +++ b/src/drv_maildir.c @@ -1153,28 +1153,29 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) goto retry; } int off, in_msgid = 0; - while ((want_tuid || want_msgid) && fgets( nbuf, sizeof(nbuf), f )) { - int bufl = strlen( nbuf ); - if (bufl && nbuf[bufl - 1] == '\n') + char lnbuf[1000]; // Says RFC2822 + while ((want_tuid || want_msgid) && fgets( lnbuf, sizeof(lnbuf), f )) { + int bufl = strlen( lnbuf ); + if (bufl && lnbuf[bufl - 1] == '\n') --bufl; - if (bufl && nbuf[bufl - 1] == '\r') + if (bufl && lnbuf[bufl - 1] == '\r') --bufl; if (!bufl) break; - if (want_tuid && starts_with( nbuf, bufl, "X-TUID: ", 8 )) { + if (want_tuid && starts_with( lnbuf, bufl, "X-TUID: ", 8 )) { if (bufl < 8 + TUIDL) { error( "Maildir error: malformed X-TUID header (UID %u)\n", uid ); continue; } - memcpy( entry->tuid, nbuf + 8, TUIDL ); + memcpy( entry->tuid, lnbuf + 8, TUIDL ); want_tuid = 0; in_msgid = 0; continue; } - if (want_msgid && starts_with_upper( nbuf, bufl, "MESSAGE-ID:", 11 )) { + if (want_msgid && starts_with_upper( lnbuf, bufl, "MESSAGE-ID:", 11 )) { off = 11; } else if (in_msgid) { - if (!isspace( nbuf[0] )) { + if (!isspace( lnbuf[0] )) { in_msgid = 0; continue; } @@ -1182,13 +1183,13 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) } else { continue; } - while (off < bufl && isspace( nbuf[off] )) + while (off < bufl && isspace( lnbuf[off] )) off++; if (off == bufl) { in_msgid = 1; continue; } - entry->msgid = nfstrndup( nbuf + off, bufl - off ); + entry->msgid = nfstrndup( lnbuf + off, bufl - off ); want_msgid = 0; in_msgid = 0; }