[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#771562: Pre-approval for libetpan/1.6-1



Package: release.debian.org
Severity: normal
User: release.debian.org@packages.debian.org
Usertags: unblock

Hi Release Team,

Libetpan's upstream has made a new release¹ targetted to
fix POODLE breakage (CVE-2014-3566) and some other bugfixes,
albeit one feature was added, hence the pre-approval request.

Unfortunately it also includes a large ammount of fixed
source file copyright/license headers which were missing,
but now causes some noise. These were excluded from the
filtered diff, but only when there were on other changes
in the file, so still some there.

Appart from that, most of changes not related to the above
bugfixes are type or typecast fixes (which cause also a
lot of noise, but still there). Diffstat summary is:

104 files changed, 1778 insertions(+), 1109 deletions(-)

No soname bump, and only added symbols, which is the good
part.

I'm attaching the filtered diff and the filterdiff list.

Thanks in advance,

unblock libetpan/1.6-1

¹ https://github.com/dinhviethoa/libetpan/releases/tag/1.6
-- 
  Ricardo Mones 
  ~
  You have the capacity to learn from mistakes. You'll learn a lot 
  today.                                           /usr/games/fortune
diff -Nru libetpan-1.5/build-windows/libetpan_version.h libetpan-1.6/build-windows/libetpan_version.h
--- libetpan-1.5/build-windows/libetpan_version.h	2014-06-11 12:21:46.000000000 +0200
+++ libetpan-1.6/build-windows/libetpan_version.h	2014-11-28 12:14:23.000000000 +0100
@@ -38,7 +38,7 @@
 #endif
 
 #ifndef LIBETPAN_VERSION_MINOR
-#define LIBETPAN_VERSION_MINOR 5
+#define LIBETPAN_VERSION_MINOR 6
 #endif
 
 #ifndef LIBETPAN_REENTRANT
diff -Nru libetpan-1.5/config.sub libetpan-1.6/config.sub
diff -Nru libetpan-1.5/configure libetpan-1.6/configure
diff -Nru libetpan-1.5/configure.ac libetpan-1.6/configure.ac
--- libetpan-1.5/configure.ac	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/configure.ac	2014-11-28 12:13:58.000000000 +0100
@@ -2,7 +2,7 @@
 # Process this file with autoconf to produce a configure script.
 
 m4_define([maj_version], [1])
-m4_define([min_version], [5])
+m4_define([min_version], [6])
 m4_define([api_current], [18])
 m4_define([api_revision], [0])
 m4_define([api_compatibility], [17])
@@ -228,7 +228,7 @@
   fi
   GNUTLSLIB=""
   AC_CHECK_HEADER(gnutls/gnutls.h, [
-   AC_CHECK_LIB(gnutls, gnutls_global_deinit, with_gnutls=yes, [GNUTLSLIB="-lgnutls -lgcrypt -lgpg-error -lz"])
+   AC_CHECK_LIB(gnutls, gnutls_global_deinit, with_gnutls=yes, [GNUTLSLIB="-lgnutls"])
   ])
   if test "x$with_gnutls" != "xyes"; then
    CPPFLAGS="$OCPPFLAGS"
@@ -240,7 +240,7 @@
 if test "x$with_gnutls" = "xyes"; then
   AC_DEFINE([USE_GNUTLS],1, [Define to use GnuTLS])
   AC_DEFINE([USE_SSL], 1, [Define to use OpenSSL])
-  GNUTLSLIB="-lgnutls -lgcrypt -lgpg-error -lz"
+  GNUTLSLIB="-lgnutls"
 else
   GNUTLSLIB=""
 fi
diff -Nru libetpan-1.5/debian/changelog libetpan-1.6/debian/changelog
--- libetpan-1.5/debian/changelog	2014-06-11 18:38:34.000000000 +0200
+++ libetpan-1.6/debian/changelog	2014-11-28 14:10:16.000000000 +0100
@@ -1,3 +1,19 @@
+libetpan (1.6-1) unstable; urgency=high
+
+  * New upstream release in response to CVE-2014-3566 (POODLE)
+  - SSLv3 is not forced anymore in SSL connections
+  * patches/10*.diff, patches/series, get-upstream-tarball
+  - Update patch, which was partially applied in github commit
+    1e2008cb6abdfe629f11ca2c1f21d399c52579a9, but it's now required
+    to generate the upstream tarball from the git tag. Removed from
+    series file but used now by get-upstream-tarball scriptlet.
+  * debian/libetpan17.symbols
+  - Update symbols file: 10 added, 0 removed
+  * debian/control
+  - Update Standards-Version to 3.9.6 (no other changes)
+
+ -- Ricardo Mones <mones@debian.org>  Fri, 28 Nov 2014 00:12:41 +0100
+
 libetpan (1.5-1) unstable; urgency=medium
 
   * New upstream release: not really, identical to 1.4.1 but version
diff -Nru libetpan-1.5/debian/control libetpan-1.6/debian/control
--- libetpan-1.5/debian/control	2014-06-11 18:38:34.000000000 +0200
+++ libetpan-1.6/debian/control	2014-11-28 14:10:16.000000000 +0100
@@ -7,7 +7,7 @@
 Build-Depends: debhelper (>= 9), autotools-dev, libtool, libdb-dev,
  libgnutls28-dev, liblockfile-dev, libsasl2-dev, libexpat1-dev,
  libcurl4-gnutls-dev (>= 7.16.4-5), docbook-dsssl, jade
-Standards-Version: 3.9.5
+Standards-Version: 3.9.6
 Vcs-Git: git://anonscm.debian.org/users/mones/libetpan.git
 Vcs-Browser: http://anonscm.debian.org/gitweb/?p=users/mones/libetpan.git
 
diff -Nru libetpan-1.5/debian/get-upstream-tarball libetpan-1.6/debian/get-upstream-tarball
--- libetpan-1.5/debian/get-upstream-tarball	2014-06-11 18:38:34.000000000 +0200
+++ libetpan-1.6/debian/get-upstream-tarball	2014-11-28 14:10:16.000000000 +0100
@@ -11,7 +11,7 @@
 test -d libetpan-${VER} && rm -rf libetpan-${VER}
 tar xzf ${1}.tar.gz
 test ! -d libetpan-${VER} && die "unexpected directory in tarball"
-cd libetpan-${VER} && ./autogen.sh > ../autogen.log 2>&1 && make dist > ../makedist.log 2>&1 && cd ..
+cd libetpan-${VER} && patch -p1 < $CURDIR/patches/10_unnecessary_linkage.diff && ./autogen.sh > ../autogen.log 2>&1 && make dist > ../makedist.log 2>&1 && cd ..
 test ! -f libetpan-${VER}/libetpan-${VER}.tar.gz && die "no tarball found after make dist"
 mv libetpan-${VER}/libetpan-${VER}.tar.gz . && rm -rf libetpan-${VER}
 tar xzf libetpan-${VER}.tar.gz
@@ -19,6 +19,6 @@
 tar cJf libetpan-${VER}.tar.xz libetpan-${VER} && rm -rf libetpan-${VER}
 test ! -s libetpan-${VER}.tar.xz && die "creating final tarball failed"
 mv -f $TEMPDIR/libetpan-${VER}.tar.xz $CURDIR/
-cd -
+cd $CURDIR
 echo "Done."
 exit 0
diff -Nru libetpan-1.5/debian/libetpan17.symbols libetpan-1.6/debian/libetpan17.symbols
--- libetpan-1.5/debian/libetpan17.symbols	2014-06-11 18:38:34.000000000 +0200
+++ libetpan-1.6/debian/libetpan17.symbols	2014-11-28 14:10:16.000000000 +0100
@@ -666,6 +666,7 @@
  mailimap_response_tagged_new@Base 1.0
  mailimap_search@Base 1.0
  mailimap_search_key_free@Base 1.0
+ mailimap_search_key_literalplus_send@Base 1.6
  mailimap_search_key_multiple_add@Base 1.0
  mailimap_search_key_new@Base 1.0
  mailimap_search_key_new_all@Base 1.0
@@ -698,6 +699,9 @@
  mailimap_search_key_new_xgmraw@Base 1.4
  mailimap_search_key_new_xgmthrid@Base 1.4
  mailimap_search_key_send@Base 1.4
+ mailimap_search_literalplus@Base 1.6
+ mailimap_search_literalplus_modseq@Base 1.6
+ mailimap_search_literalplus_send@Base 1.6
  mailimap_search_modseq@Base 1.4
  mailimap_search_result_free@Base 1.0
  mailimap_search_send@Base 1.0
@@ -827,6 +831,9 @@
  mailimap_uid_fetch_qresync_vanished@Base 1.4
  mailimap_uid_fetch_send@Base 1.0
  mailimap_uid_search@Base 1.0
+ mailimap_uid_search_literalplus@Base 1.6
+ mailimap_uid_search_literalplus_modseq@Base 1.6
+ mailimap_uid_search_literalplus_send@Base 1.6
  mailimap_uid_search_modseq@Base 1.4
  mailimap_uid_search_send@Base 1.0
  mailimap_uid_sort@Base 1.4
@@ -927,6 +934,7 @@
  mailimf_fields_write_mem@Base 1.0
  mailimf_from_free@Base 1.0
  mailimf_from_new@Base 1.0
+ mailimf_fws_atom_for_word_parse@Base 1.6
  mailimf_fws_atom_parse@Base 1.0
  mailimf_fws_parse@Base 1.0
  mailimf_fws_quoted_string_parse@Base 1.0
@@ -1170,6 +1178,7 @@
  mailmime_encoded_text_free@Base 1.0
  mailmime_encoded_word_free@Base 1.0
  mailmime_encoded_word_new@Base 1.0
+ mailmime_encoded_word_parse@Base 1.6
  mailmime_encoding_free@Base 1.0
  mailmime_encoding_parse@Base 1.0
  mailmime_extension_token_free@Base 1.0
@@ -1695,6 +1704,7 @@
  newsnntp_post@Base 1.0
  newsnntp_quit@Base 1.0
  newsnntp_set_logger@Base 1.4
+ newsnntp_set_progress_callback@Base 1.6
  newsnntp_set_timeout@Base 1.4
  newsnntp_socket_connect@Base 1.0
  newsnntp_ssl_connect@Base 1.0
diff -Nru libetpan-1.5/debian/patches/10_unnecessary_linkage.diff libetpan-1.6/debian/patches/10_unnecessary_linkage.diff
--- libetpan-1.5/debian/patches/10_unnecessary_linkage.diff	2014-06-11 18:38:34.000000000 +0200
+++ libetpan-1.6/debian/patches/10_unnecessary_linkage.diff	2014-11-28 14:10:16.000000000 +0100
@@ -1,41 +1,16 @@
 Description: Stop unnecessary linkage against -lgcrypt and -lgpg-error.
- Neither of these libraries are used by libetpan, see 
+ Neither of these libraries are used by libetpan, see
  "grep -Erli 'gpg_err|gcry'".
-Author: Andreas Metzler <ametzler@debian.org>
+ This version of the patch is just required to generate the orig tarball
+ from upstream git tag, hence has been removed from series file.
+Author: Andreas Metzler <ametzler@debian.org>, Ricardo Mones <mones@debian.org>
 Origin: vendor
-Last-Update: 2014-05-11
+Last-Update: 2014-11-24
 
---- libetpan-1.4.1.orig/configure
-+++ libetpan-1.4.1/configure
-@@ -16421,7 +16421,7 @@ $as_echo "$ac_cv_lib_gnutls_gnutls_globa
- if test "x$ac_cv_lib_gnutls_gnutls_global_deinit" = xyes; then :
-   with_gnutls=yes
- else
--  GNUTLSLIB="-lgnutls -lgcrypt -lgpg-error -lz"
-+  GNUTLSLIB="-lgnutls"
- fi
- 
- 
-@@ -16442,7 +16442,7 @@ $as_echo "#define USE_GNUTLS 1" >>confde
- 
- $as_echo "#define USE_SSL 1" >>confdefs.h
- 
--  GNUTLSLIB="-lgnutls -lgcrypt -lgpg-error -lz"
-+  GNUTLSLIB="-lgnutls"
- else
-   GNUTLSLIB=""
- fi
---- libetpan-1.4.1.orig/configure.ac
-+++ libetpan-1.4.1/configure.ac
-@@ -228,7 +228,7 @@ if test "x$with_gnutls" != "xno"; then
-   fi
-   GNUTLSLIB=""
-   AC_CHECK_HEADER(gnutls/gnutls.h, [
--   AC_CHECK_LIB(gnutls, gnutls_global_deinit, with_gnutls=yes, [GNUTLSLIB="-lgnutls -lgcrypt -lgpg-error -lz"])
-+   AC_CHECK_LIB(gnutls, gnutls_global_deinit, with_gnutls=yes, [GNUTLSLIB="-lgnutls"])
-   ])
-   if test "x$with_gnutls" != "xyes"; then
-    CPPFLAGS="$OCPPFLAGS"
+diff --git a/configure.ac b/configure.ac
+index 3fcea52..1e1cb82 100644
+--- a/configure.ac
++++ b/configure.ac
 @@ -240,7 +240,7 @@ fi
  if test "x$with_gnutls" = "xyes"; then
    AC_DEFINE([USE_GNUTLS],1, [Define to use GnuTLS])
diff -Nru libetpan-1.5/debian/patches/series libetpan-1.6/debian/patches/series
--- libetpan-1.5/debian/patches/series	2014-06-11 18:38:34.000000000 +0200
+++ libetpan-1.6/debian/patches/series	2014-11-28 14:10:16.000000000 +0100
@@ -1 +0,0 @@
-10_unnecessary_linkage.diff
diff -Nru libetpan-1.5/ltmain.sh libetpan-1.6/ltmain.sh
diff -Nru libetpan-1.5/src/data-types/mail_cache_db.c libetpan-1.6/src/data-types/mail_cache_db.c
--- libetpan-1.5/src/data-types/mail_cache_db.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/data-types/mail_cache_db.c	2014-10-31 22:41:02.000000000 +0100
@@ -348,7 +348,7 @@
     chashdatum hash_data;
     
     hash_key.data = db_key.data;
-    hash_key.len = db_key.size;
+    hash_key.len = (unsigned int) db_key.size;
 
     r = chash_get(exist, &hash_key, &hash_data);
     if (r < 0) {
@@ -475,7 +475,7 @@
     chashdatum hash_data;
     
     hash_key.data = db_key.data;
-    hash_key.len = db_key.size;
+    hash_key.len = (unsigned int) db_key.size;
     hash_data.data = NULL;
     hash_data.len = 0;
     
diff -Nru libetpan-1.5/src/data-types/maillock.c libetpan-1.6/src/data-types/maillock.c
--- libetpan-1.5/src/data-types/maillock.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/data-types/maillock.c	2014-10-31 22:41:02.000000000 +0100
@@ -255,7 +255,7 @@
     fd2 = open(lockfilename, O_WRONLY|O_EXCL|O_CREAT, 0);
     if (fd2 >= 0) {
       /* defeat lock checking programs which test pid */
-      r = write(fd2, "0", 2);
+      r = (int) write(fd2, "0", 2);
       close(fd2);
       break;
     }
diff -Nru libetpan-1.5/src/data-types/mailsasl.c libetpan-1.6/src/data-types/mailsasl.c
diff -Nru libetpan-1.5/src/data-types/mailsasl.h libetpan-1.6/src/data-types/mailsasl.h
diff -Nru libetpan-1.5/src/data-types/mailstream_cancel.c libetpan-1.6/src/data-types/mailstream_cancel.c
--- libetpan-1.5/src/data-types/mailstream_cancel.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/data-types/mailstream_cancel.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "mailstream_cancel.h"
 
 #ifdef HAVE_CONFIG_H
@@ -144,7 +174,7 @@
   
   ch = 0;
 #ifndef WIN32
-  r = write(cancel->ms_fds[1], &ch, 1);
+  r = (int) write(cancel->ms_fds[1], &ch, 1);
 #else
   SetEvent(ms_internal->event);
 #endif
@@ -155,7 +185,7 @@
 #ifndef WIN32
   char ch;
   int r;
-  r = read(cancel->ms_fds[0], &ch, 1);
+  r = (int) read(cancel->ms_fds[0], &ch, 1);
 #endif
 }
 
diff -Nru libetpan-1.5/src/data-types/mailstream_cancel.h libetpan-1.6/src/data-types/mailstream_cancel.h
diff -Nru libetpan-1.5/src/data-types/mailstream_cancel_types.h libetpan-1.6/src/data-types/mailstream_cancel_types.h
diff -Nru libetpan-1.5/src/data-types/mailstream_cfstream.c libetpan-1.6/src/data-types/mailstream_cfstream.c
--- libetpan-1.5/src/data-types/mailstream_cfstream.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/data-types/mailstream_cfstream.c	2014-10-31 22:41:02.000000000 +0100
@@ -179,11 +179,13 @@
 static void cfstream_data_close(struct mailstream_cfstream_data * cfstream_data)
 {
   if (cfstream_data->writeStream != NULL) {
+    CFWriteStreamSetClient(cfstream_data->writeStream, kCFStreamEventNone, NULL, NULL);
     CFWriteStreamClose(cfstream_data->writeStream);
     CFRelease(cfstream_data->writeStream);
     cfstream_data->writeStream = NULL;
   }
   if (cfstream_data->readStream != NULL) {
+    CFReadStreamSetClient(cfstream_data->readStream, kCFStreamEventNone, NULL, NULL);
     CFReadStreamClose(cfstream_data->readStream);
     CFRelease(cfstream_data->readStream);
     cfstream_data->readStream = NULL;
@@ -711,6 +713,17 @@
     int r;
     int done;
     
+    if (cfstream_data->cancelled) {
+      error = WAIT_RUNLOOP_EXIT_CANCELLED;
+      break;
+    }
+    if (cfstream_data->state == STATE_WAIT_IDLE) {
+      if (cfstream_data->idleInterrupted) {
+        error = WAIT_RUNLOOP_EXIT_INTERRUPTED;
+        break;
+      }
+    }
+
     done = 0;
     switch (cfstream_data->state) {
       case STATE_OPEN_READ_DONE:
@@ -774,16 +787,6 @@
       error = WAIT_RUNLOOP_EXIT_TIMEOUT;
       break;
     }
-    if (cfstream_data->cancelled) {
-      error = WAIT_RUNLOOP_EXIT_CANCELLED;
-      break;
-    }
-    if (cfstream_data->state == STATE_WAIT_IDLE) {
-      if (cfstream_data->idleInterrupted) {
-        error = WAIT_RUNLOOP_EXIT_INTERRUPTED;
-        break;
-      }
-    }
   }
   
   if (read_scheduled) {
@@ -978,12 +981,22 @@
       return -1;
     if (cfstream_data->readSSLResult < 0)
       return -1;
-    CFArrayRef certs = CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySSLPeerCertificates);
-    if (certs == NULL) {
+    
+    SecTrustRef secTrust = (SecTrustRef)CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySSLPeerTrust);
+    if (secTrust == NULL) {
+      // No trust, wait more.
+      continue;
+    }
+    
+    // SecTrustEvaluate() needs to be called before SecTrustGetCertificateCount() in Mac OS X <= 10.8
+    SecTrustEvaluate(secTrust, NULL);
+    CFIndex count = SecTrustGetCertificateCount(secTrust);
+    CFRelease(secTrust);
+    
+    if (count == 0) {
       // No certificates, wait more.
       continue;
     }
-    CFRelease(certs);
     break;
   }
   
@@ -1148,18 +1161,21 @@
 {
 #if HAVE_CFNETWORK
   struct mailstream_cfstream_data * cfstream_data;
-  CFArrayRef certs;
   unsigned int i;
   carray * result;
   
   cfstream_data = (struct mailstream_cfstream_data *) s->data;
-  certs = CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySSLPeerCertificates);
-  if (certs == NULL)
+  SecTrustRef secTrust = (SecTrustRef)CFReadStreamCopyProperty(cfstream_data->readStream, kCFStreamPropertySSLPeerTrust);
+  if (secTrust == NULL)
     return NULL;
   
+  // SecTrustEvaluate() needs to be called before SecTrustGetCertificateCount() in Mac OS X <= 10.8
+  SecTrustEvaluate(secTrust, NULL);
+  CFIndex count = SecTrustGetCertificateCount(secTrust);
+  
   result = carray_new(4);
-  for(i = 0 ; i < CFArrayGetCount(certs) ; i ++) {
-    SecCertificateRef cert = (SecCertificateRef) CFArrayGetValueAtIndex(certs, i);
+  for(i = 0 ; i < count ; i ++) {
+    SecCertificateRef cert = (SecCertificateRef) SecTrustGetCertificateAtIndex(secTrust, i);
     CFDataRef data = SecCertificateCopyData(cert);
     CFIndex length = CFDataGetLength(data);
     const UInt8 * bytes = CFDataGetBytePtr(data);
@@ -1169,7 +1185,7 @@
     CFRelease(data);
   }
   
-  CFRelease(certs);
+  CFRelease(secTrust);
   
   return result;
 #else
diff -Nru libetpan-1.5/src/data-types/mailstream_compress.c libetpan-1.6/src/data-types/mailstream_compress.c
--- libetpan-1.5/src/data-types/mailstream_compress.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/data-types/mailstream_compress.c	2014-10-31 22:41:02.000000000 +0100
@@ -99,7 +99,7 @@
   mailstream_low * s;
     
   /* stores the original mailstream */
-  struct mailstream_compress_data * compress_data = malloc(sizeof(* compress_data));
+  struct mailstream_compress_data * compress_data = calloc(1, sizeof(* compress_data));
   if (compress_data == NULL)
     goto err;
 
@@ -166,7 +166,7 @@
   do {
     /* if there is no compressed data, read more */
     if (strm->avail_in == 0) {
-      int read = data->ms->driver->mailstream_read(data->ms, data->input_buf, CHUNK_SIZE);
+      int read = (int) data->ms->driver->mailstream_read(data->ms, data->input_buf, CHUNK_SIZE);
       if (read <= 0) {
         return read;
       }
@@ -176,7 +176,7 @@
 
     /* set the output buffer */
     strm->next_out = buf;
-    strm->avail_out = count;
+    strm->avail_out = (int) count;
 
     /* uncompress any waiting data */
     zr = inflate(strm, Z_NO_FLUSH);
@@ -209,7 +209,7 @@
 
   strm->next_in = (Bytef *)buf;
   /* we won't try to compress more than CHUNK_SIZE at a time so we always have enough buffer space */
-  int compress_len = MIN(count, CHUNK_SIZE);
+  int compress_len = MIN((int) count, CHUNK_SIZE);
   strm->avail_in = compress_len;
   strm->avail_out = CHUNK_SIZE;
   strm->next_out = data->output_buf;
@@ -244,7 +244,7 @@
 {
 #if HAVE_ZLIB
   compress_data * data = s->data;
-  return data->ms->driver->mailstream_close(data->ms);
+  return mailstream_low_close(data->ms);
 #else
   return 0;
 #endif
@@ -274,7 +274,7 @@
 {
 #if HAVE_ZLIB
   compress_data * data = s->data;
-  data->ms->driver->mailstream_free(data->ms);
+  mailstream_low_free(data->ms);
   if (data->compress_stream) {
     deflateEnd(data->compress_stream);
     free(data->compress_stream);
diff -Nru libetpan-1.5/src/data-types/mailstream_low.c libetpan-1.6/src/data-types/mailstream_low.c
--- libetpan-1.5/src/data-types/mailstream_low.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/data-types/mailstream_low.c	2014-10-31 22:41:02.000000000 +0100
@@ -93,7 +93,7 @@
       f = fopen(LOG_FILE, "a"); \
       umask(old_mask); \
       if (f != NULL) { \
-        int nmemb; \
+        size_t nmemb; \
         maillock_write_lock(LOG_FILE, fileno(f)); \
         nmemb = fwrite((buf), 1, (size), f); \
         maillock_write_unlock(LOG_FILE, fileno(f)); \
@@ -120,7 +120,7 @@
       f = fopen(LOG_FILE, "a"); \
       umask(old_mask); \
       if (f != NULL) { \
-        int nmemb; \
+        size_t nmemb; \
         maillock_write_lock(LOG_FILE, fileno(f)); \
         nmemb = fwrite((buf), 1, (size), f); \
         maillock_write_unlock(LOG_FILE, fileno(f)); \
@@ -147,7 +147,7 @@
       f = fopen(LOG_FILE, "a"); \
       umask(old_mask); \
       if (f != NULL) { \
-        int nmemb; \
+        size_t nmemb; \
         maillock_write_lock(LOG_FILE, fileno(f)); \
         nmemb = fputs((str), f); \
         maillock_write_unlock(LOG_FILE, fileno(f)); \
diff -Nru libetpan-1.5/src/data-types/mailstream_ssl.c libetpan-1.6/src/data-types/mailstream_ssl.c
--- libetpan-1.5/src/data-types/mailstream_ssl.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/data-types/mailstream_ssl.c	2014-10-31 22:41:02.000000000 +0100
@@ -152,7 +152,6 @@
 #	define MUTEX_LOCK(x)
 #	define MUTEX_UNLOCK(x)
 #endif
-static int gnutls_init_not_required = 0;
 static int openssl_init_done = 0;
 #endif
 
@@ -242,11 +241,6 @@
 
 void mailstream_gnutls_init_not_required(void)
 {
-#ifdef USE_SSL
-  MUTEX_LOCK(&ssl_lock);
-  gnutls_init_not_required = 1;
-  MUTEX_UNLOCK(&ssl_lock);
-#endif
 }
 
 void mailstream_openssl_init_not_required(void)
@@ -282,8 +276,7 @@
     openssl_init_done = 1;
   }
 #else
-  if (!gnutls_init_not_required)
-    gnutls_global_init();
+  gnutls_global_init();
 #endif
   MUTEX_UNLOCK(&ssl_lock);
 #endif
@@ -666,8 +659,7 @@
   gnutls_deinit(ssl_data->session);
 
   MUTEX_LOCK(&ssl_lock);
-  if(!gnutls_init_not_required)
-    gnutls_global_deinit();
+  gnutls_global_deinit();
   MUTEX_UNLOCK(&ssl_lock);
 
   ssl_data->session = NULL;
@@ -845,7 +837,7 @@
   while (1) {
     int ssl_r;
     
-    r = SSL_read(ssl_data->ssl_conn, buf, count);
+    r = SSL_read(ssl_data->ssl_conn, buf, (int) count);
     if (r > 0)
       return r;
     
@@ -993,7 +985,7 @@
   if (r <= 0)
     return r;
   
-  r = SSL_write(ssl_data->ssl_conn, buf, count);
+  r = SSL_write(ssl_data->ssl_conn, buf, (int) count);
   if (r > 0)
     return r;
   
diff -Nru libetpan-1.5/src/data-types/mailstream_ssl_private.h libetpan-1.6/src/data-types/mailstream_ssl_private.h
diff -Nru libetpan-1.5/src/data-types/mmapstring_private.h libetpan-1.6/src/data-types/mmapstring_private.h
diff -Nru libetpan-1.5/src/data-types/timeutils.h libetpan-1.6/src/data-types/timeutils.h
diff -Nru libetpan-1.5/src/driver/implementation/db/dbdriver.c libetpan-1.6/src/driver/implementation/db/dbdriver.c
--- libetpan-1.5/src/driver/implementation/db/dbdriver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/db/dbdriver.c	2014-10-31 22:41:02.000000000 +0100
@@ -504,19 +504,19 @@
     if (!deleted) {
       snprintf(key_value, sizeof(key_value), "%lu", (unsigned long) num);
       key.data = key_value;
-      key.len = strlen(key_value);
+      key.len = (unsigned int) strlen(key_value);
       chash_set(msg_table, &key, &value, NULL);
       
       snprintf(key_value, sizeof(key_value), "%lu-envelope",
           (unsigned long) num);
       key.data = key_value;
-      key.len = strlen(key_value);
+      key.len = (unsigned int) strlen(key_value);
       chash_set(msg_table, &key, &value, NULL);
       
       snprintf(key_value, sizeof(key_value), "%lu-flags",
           (unsigned long) num);
       key.data = key_value;
-      key.len = strlen(key_value);
+      key.len = (unsigned int) strlen(key_value);
       chash_set(msg_table, &key, &value, NULL);
       
       i ++;
@@ -1039,7 +1039,7 @@
   
   size = 0;
   snprintf(key, sizeof(key), "%lu", (unsigned long) num);
-  r = mail_cache_db_get_size(maildb, key, strlen(key), &size);
+  r = mail_cache_db_get_size(maildb, key, (size_t) strlen(key), &size);
   /* ignore error */
   
   r = mailmessage_init(msg, session, db_message_driver,
@@ -1065,7 +1065,7 @@
 {
   uint32_t msg_num;
   
-  msg_num = strtoul(uid, NULL, 10);
+  msg_num = (uint32_t) strtoul(uid, NULL, 10);
   
   return get_message(session, msg_num, result);
 }
diff -Nru libetpan-1.5/src/driver/implementation/feed/feeddriver.c libetpan-1.6/src/driver/implementation/feed/feeddriver.c
--- libetpan-1.5/src/driver/implementation/feed/feeddriver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/feed/feeddriver.c	2014-10-31 22:41:02.000000000 +0100
@@ -390,7 +390,7 @@
   if (mmap_string_append(mmapstr, "?Q?") == NULL)
     return -1;
   
-  col = mmapstr->len;
+  col = (int) mmapstr->len;
   
   cur = word;
   for(i = 0 ; i < size ; i ++) {
@@ -409,7 +409,7 @@
       if (mmap_string_append(mmapstr, " ") == NULL)
         return -1;
       
-      old_pos = mmapstr->len;
+      old_pos = (int) mmapstr->len;
       
       if (mmap_string_append(mmapstr, "=?") == NULL)
         return -1;
@@ -418,7 +418,7 @@
       if (mmap_string_append(mmapstr, "?Q?") == NULL)
         return -1;
       
-      col = mmapstr->len - old_pos;
+      col = (int) mmapstr->len - old_pos;
     }
     
     do_quote_char = 0;
diff -Nru libetpan-1.5/src/driver/implementation/feed/feeddriver_message.c libetpan-1.6/src/driver/implementation/feed/feeddriver_message.c
--- libetpan-1.5/src/driver/implementation/feed/feeddriver_message.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/feed/feeddriver_message.c	2014-10-31 22:41:02.000000000 +0100
@@ -196,5 +196,5 @@
   }
   
   msg = msg_info->msg_data;
-  return msg->msg_length;
+  return (int) msg->msg_length;
 }
diff -Nru libetpan-1.5/src/driver/implementation/imap/imapdriver.c libetpan-1.6/src/driver/implementation/imap/imapdriver.c
--- libetpan-1.5/src/driver/implementation/imap/imapdriver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/imap/imapdriver.c	2014-10-31 22:41:02.000000000 +0100
@@ -686,6 +686,9 @@
   uint32_t unseen;
   int r;
   
+  messages = 0;
+  recent = 0;
+  unseen = 0;
   r = imapdriver_status_folder(session, mb, &messages, &recent, &unseen);
   if (r != MAIL_NO_ERROR)
     return r;
@@ -1207,12 +1210,12 @@
   if (uid == NULL)
     return MAIL_ERROR_INVAL;
 
-  uidvalidity = strtoul(uid, &p1, 10);
+  uidvalidity = (uint32_t) strtoul(uid, &p1, 10);
   if (p1 == uid || * p1 != '-')
     return MAIL_ERROR_INVAL;
 
   p1++;
-  num = strtoul(p1, &p2, 10);
+  num = (uint32_t) strtoul(p1, &p2, 10);
   if (p2 == p1 || * p2 != '\0')
     return MAIL_ERROR_INVAL;
   
@@ -1233,9 +1236,12 @@
 {
   int r;
 
-  r = mailimap_authenticate(get_imap_session(session),
-      auth_type, server_fqdn, local_ip_port, remote_ip_port,
-      login, auth_name, password, realm);
+  if (strcasecmp(auth_type, "xoauth2") == 0)
+    r = mailimap_oauth2_authenticate(get_imap_session(session), auth_name, password);
+  else
+    r = mailimap_authenticate(get_imap_session(session),
+        auth_type, server_fqdn, local_ip_port, remote_ip_port,
+        login, auth_name, password, realm);
   
   return imap_error_to_mail_error(r);
 }
diff -Nru libetpan-1.5/src/driver/implementation/imap/imapdriver_cached.c libetpan-1.6/src/driver/implementation/imap/imapdriver_cached.c
--- libetpan-1.5/src/driver/implementation/imap/imapdriver_cached.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/imap/imapdriver_cached.c	2014-10-31 22:41:02.000000000 +0100
@@ -316,7 +316,7 @@
       }
       msg = carray_get(env_list->msg_tab, i);
       cache_item->uid = msg->msg_index;
-      cache_item->size = msg->msg_size;
+      cache_item->size = (uint32_t) msg->msg_size;
     
       carray_set(data->imap_uid_list, i, cache_item);
     }
@@ -934,7 +934,7 @@
     
     get_uid_from_filename(msg_uid);
     key.data = msg_uid;
-    key.len = strlen(msg_uid) + 1;
+    key.len = (unsigned int) strlen(msg_uid) + 1;
     value.data = NULL;
     value.len = 0;
     chash_set(keys_uid, &key, &value, NULL);
@@ -951,14 +951,14 @@
     chash_key(iter, &key);
     uid = key.data;
     
-    uidvalidity = strtoul(uid, &p1, 10);
+    uidvalidity = (uint32_t) strtoul(uid, &p1, 10);
     if (p1 == uid || * p1 != '-')
       continue;
     
     data->imap_uidvalidity = uidvalidity;
     
     p1++;
-    indx = strtoul(p1, &p2, 10);
+    indx = (uint32_t) strtoul(p1, &p2, 10);
     if (p2 == p1 || * p2 != '\0')
       continue;
     
@@ -1514,12 +1514,12 @@
   if (uid == NULL)
     return MAIL_ERROR_INVAL;
 
-  uidvalidity = strtoul(uid, &p1, 10);
+  uidvalidity = (uint32_t) strtoul(uid, &p1, 10);
   if (p1 == uid || * p1 != '-')
     return MAIL_ERROR_INVAL;
 
   p1++;
-  num = strtoul(p1, &p2, 10);
+  num = (uint32_t) strtoul(p1, &p2, 10);
   if (p2 == p1 || * p2 != '\0')
     return MAIL_ERROR_INVAL;
  
diff -Nru libetpan-1.5/src/driver/implementation/imap/imapdriver_message.c libetpan-1.6/src/driver/implementation/imap/imapdriver_message.c
--- libetpan-1.5/src/driver/implementation/imap/imapdriver_message.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/imap/imapdriver_message.c	2014-10-31 22:41:02.000000000 +0100
@@ -1086,7 +1086,9 @@
     mailimap_fetch_att_free(fetch_att);
     return MAIL_ERROR_MEMORY;
   }
-
+  
+  text = NULL;
+  text_length = 0;
   r = fetch_imap(msg_info, fetch_type, &text, &text_length);
 
   mailimap_fetch_type_free(fetch_type);
diff -Nru libetpan-1.5/src/driver/implementation/imap/imapdriver_tools.c libetpan-1.6/src/driver/implementation/imap/imapdriver_tools.c
--- libetpan-1.5/src/driver/implementation/imap/imapdriver_tools.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/imap/imapdriver_tools.c	2014-10-31 22:41:02.000000000 +0100
@@ -2991,6 +2991,10 @@
     }
 
     pindex = clist_content(cur);
+    if (pindex == NULL) {
+      // Make clang static analyzer happy.
+      break;
+    }
 
     if (!previous_valid) {
       first_seq = * pindex;
diff -Nru libetpan-1.5/src/driver/implementation/imap/imapdriver_tools_private.h libetpan-1.6/src/driver/implementation/imap/imapdriver_tools_private.h
diff -Nru libetpan-1.5/src/driver/implementation/imap/imapstorage.h libetpan-1.6/src/driver/implementation/imap/imapstorage.h
--- libetpan-1.5/src/driver/implementation/imap/imapstorage.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/imap/imapstorage.h	2014-10-31 22:41:02.000000000 +0100
@@ -69,6 +69,8 @@
   @param login is the login of the IMAP4rev1 account.
 
   @param password is the password of the IMAP4rev1 account.
+    If performing OAuth2 login, use the OAuth2 token here
+    instead of password.
 
   @param cached if this value is != 0, a persistant cache will be
     stored on local system.
diff -Nru libetpan-1.5/src/driver/implementation/maildir/maildirdriver.c libetpan-1.6/src/driver/implementation/maildir/maildirdriver.c
--- libetpan-1.5/src/driver/implementation/maildir/maildirdriver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/maildir/maildirdriver.c	2014-10-31 22:41:02.000000000 +0100
@@ -353,6 +353,9 @@
   uint32_t unseen;
   int r;
   
+  messages = 0;
+  recent = 0;
+  unseen = 0;
   r = status_folder(session, mb, &messages, &recent, &unseen);
   if (r != MAIL_NO_ERROR)
     return r;
@@ -410,7 +413,7 @@
     goto exit;
   
   key.data = uid;
-  key.len = strlen(uid);
+  key.len = (unsigned int) strlen(uid);
   r = chash_get(md->mdir_msg_hash, &key, &value);
   if (r < 0)
     goto exit;
@@ -503,7 +506,7 @@
     msg = carray_get(env_list->msg_tab, i);
     
     key.data = msg->msg_uid;
-    key.len = strlen(msg->msg_uid);
+    key.len = (unsigned int) strlen(msg->msg_uid);
     r = chash_get(md->mdir_msg_hash, &key, &value);
     if (r < 0)
       continue;
diff -Nru libetpan-1.5/src/driver/implementation/maildir/maildirdriver_cached.c libetpan-1.6/src/driver/implementation/maildir/maildirdriver_cached.c
--- libetpan-1.5/src/driver/implementation/maildir/maildirdriver_cached.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/maildir/maildirdriver_cached.c	2014-10-31 22:41:02.000000000 +0100
@@ -523,7 +523,7 @@
     goto exit;
   
   key.data = uid;
-  key.len = strlen(uid);
+  key.len = (unsigned int) strlen(uid);
   r = chash_get(md->mdir_msg_hash, &key, &value);
   if (r < 0)
     goto exit;
@@ -581,7 +581,7 @@
     value.len = 0;
     
     key.data = msg->msg_uid;
-    key.len = strlen(msg->msg_uid);
+    key.len = (unsigned int) strlen(msg->msg_uid);
     r = chash_set(hash_exist, &key, &value, NULL);
     if (r < 0) {
       res = MAIL_ERROR_MEMORY;
@@ -591,7 +591,7 @@
     snprintf(key_str, sizeof(key_str), "uid-%lu",
         (unsigned long) msg->msg_index);
     key.data = key_str;
-    key.len = strlen(key_str);
+    key.len = (unsigned int) strlen(key_str);
     r = chash_set(hash_exist, &key, &value, NULL);
     if (r < 0) {
       res = MAIL_ERROR_MEMORY;
@@ -623,9 +623,9 @@
   struct mail_cache_db * uid_db;
   void * value;
   size_t value_len;
-  unsigned long i;
   struct maildir_cached_session_state_data * data;
   char key[PATH_MAX];
+  unsigned int i;
   
   data = get_cached_data(session);
   
diff -Nru libetpan-1.5/src/driver/implementation/maildir/maildirdriver_cached_message.c libetpan-1.6/src/driver/implementation/maildir/maildirdriver_cached_message.c
--- libetpan-1.5/src/driver/implementation/maildir/maildirdriver_cached_message.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/maildir/maildirdriver_cached_message.c	2014-10-31 22:41:02.000000000 +0100
@@ -327,7 +327,7 @@
     return MAIL_ERROR_BAD_STATE;
   
   key.data = msg_info->msg_uid;
-  key.len = strlen(msg_info->msg_uid);
+  key.len = (unsigned int) strlen(msg_info->msg_uid);
   r = chash_get(md->mdir_msg_hash, &key, &value);
   if (r < 0)
     return MAIL_ERROR_MSG_NOT_FOUND;
diff -Nru libetpan-1.5/src/driver/implementation/maildir/maildirdriver_message.c libetpan-1.6/src/driver/implementation/maildir/maildirdriver_message.c
--- libetpan-1.5/src/driver/implementation/maildir/maildirdriver_message.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/maildir/maildirdriver_message.c	2014-10-31 22:41:02.000000000 +0100
@@ -246,7 +246,7 @@
     return MAIL_ERROR_BAD_STATE;
   
   key.data = msg_info->msg_uid;
-  key.len = strlen(msg_info->msg_uid);
+  key.len = (unsigned int) strlen(msg_info->msg_uid);
   r = chash_get(md->mdir_msg_hash, &key, &value);
   if (r < 0)
     return MAIL_ERROR_MSG_NOT_FOUND;
diff -Nru libetpan-1.5/src/driver/implementation/mbox/mboxdriver.c libetpan-1.6/src/driver/implementation/mbox/mboxdriver.c
--- libetpan-1.5/src/driver/implementation/mbox/mboxdriver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/mbox/mboxdriver.c	2014-10-31 22:41:02.000000000 +0100
@@ -497,7 +497,7 @@
   if (uid == NULL)
     return MAIL_ERROR_INVAL;
 
-  num = strtoul(uid, &p, 10);
+  num = (uint32_t) strtoul(uid, &p, 10);
   if (p == uid || * p != '-')
     return MAIL_ERROR_INVAL;
 
diff -Nru libetpan-1.5/src/driver/implementation/mbox/mboxdriver_cached.c libetpan-1.6/src/driver/implementation/mbox/mboxdriver_cached.c
--- libetpan-1.5/src/driver/implementation/mbox/mboxdriver_cached.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/mbox/mboxdriver_cached.c	2014-10-31 22:41:02.000000000 +0100
@@ -519,7 +519,7 @@
     goto free_mmapstr;
   }
 
-  r = fwrite(mmapstr->str, 1, mmapstr->len, f);
+  r = (int) fwrite(mmapstr->str, 1, mmapstr->len, f);
   if ((size_t) r != mmapstr->len) {
     res = MAIL_ERROR_FILE;
     goto free_mmapstr;
@@ -1320,7 +1320,7 @@
   if (uid == NULL)
     return MAIL_ERROR_INVAL;
 
-  num = strtoul(uid, &p, 10);
+  num = (uint32_t) strtoul(uid, &p, 10);
   if (p == uid || * p != '-')
     return MAIL_ERROR_INVAL;
 
diff -Nru libetpan-1.5/src/driver/implementation/mh/mhdriver.c libetpan-1.6/src/driver/implementation/mh/mhdriver.c
--- libetpan-1.5/src/driver/implementation/mh/mhdriver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/mh/mhdriver.c	2014-10-31 22:41:02.000000000 +0100
@@ -861,7 +861,7 @@
   if (uid == NULL)
     return MAIL_ERROR_INVAL;
 
-  indx = strtoul(uid, &p, 10);
+  indx = (uint32_t) strtoul(uid, &p, 10);
   if (p == uid || * p != '-')
     return MAIL_ERROR_INVAL;
   
diff -Nru libetpan-1.5/src/driver/implementation/mh/mhdriver_cached.c libetpan-1.6/src/driver/implementation/mh/mhdriver_cached.c
--- libetpan-1.5/src/driver/implementation/mh/mhdriver_cached.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/mh/mhdriver_cached.c	2014-10-31 22:41:02.000000000 +0100
@@ -287,7 +287,7 @@
     goto free_mmapstr;
   }
 
-  r = fwrite(mmapstr->str, 1, mmapstr->len, f);
+  r = (int) fwrite(mmapstr->str, 1, mmapstr->len, f);
   if ((size_t) r != mmapstr->len) {
     res = MAIL_ERROR_FILE;
     goto free_mmapstr;
@@ -1281,7 +1281,7 @@
   if (uid == NULL)
     return MAIL_ERROR_INVAL;
 
-  indx = strtoul(uid, &p, 10);
+  indx = (uint32_t) strtoul(uid, &p, 10);
   if (p == uid || * p != '-')
     return MAIL_ERROR_INVAL;
   
diff -Nru libetpan-1.5/src/driver/implementation/mime-message/mime_message_driver.c libetpan-1.6/src/driver/implementation/mime-message/mime_message_driver.c
--- libetpan-1.5/src/driver/implementation/mime-message/mime_message_driver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/mime-message/mime_message_driver.c	2014-10-31 22:41:02.000000000 +0100
@@ -471,6 +471,7 @@
   char * msg;
   int r;
 
+  msg = NULL;
   r = fetch(msg_info, &msg, result);
   if (r != MAIL_NO_ERROR) {
     return r;
diff -Nru libetpan-1.5/src/driver/implementation/nntp/nntpdriver.c libetpan-1.6/src/driver/implementation/nntp/nntpdriver.c
--- libetpan-1.5/src/driver/implementation/nntp/nntpdriver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/nntp/nntpdriver.c	2014-10-31 22:41:02.000000000 +0100
@@ -1182,7 +1182,7 @@
   if (uid == NULL)
     return MAIL_ERROR_INVAL;
   
-  num = strtoul(uid, &p, 10);
+  num = (uint32_t) strtoul(uid, &p, 10);
   if ((p == uid) || (* p != '\0'))
     return MAIL_ERROR_INVAL;
   
diff -Nru libetpan-1.5/src/driver/implementation/nntp/nntpdriver_cached.c libetpan-1.6/src/driver/implementation/nntp/nntpdriver_cached.c
--- libetpan-1.5/src/driver/implementation/nntp/nntpdriver_cached.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/nntp/nntpdriver_cached.c	2014-10-31 22:41:02.000000000 +0100
@@ -1061,7 +1061,7 @@
   if (uid == NULL)
     return MAIL_ERROR_INVAL;
   
-  num = strtoul(uid, &p, 10);
+  num = (uint32_t) strtoul(uid, &p, 10);
   if ((p == uid) || (* p != '\0'))
     return MAIL_ERROR_INVAL;
   
diff -Nru libetpan-1.5/src/driver/implementation/pop3/pop3driver.c libetpan-1.6/src/driver/implementation/pop3/pop3driver.c
--- libetpan-1.5/src/driver/implementation/pop3/pop3driver.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/pop3/pop3driver.c	2014-10-31 22:41:02.000000000 +0100
@@ -306,6 +306,7 @@
   uint32_t count;
   int r;
   
+  count = 0;
   r = pop3driver_messages_number(session, mb, &count);
   if (r != MAIL_NO_ERROR)
     return r;
diff -Nru libetpan-1.5/src/driver/implementation/pop3/pop3driver_cached.c libetpan-1.6/src/driver/implementation/pop3/pop3driver_cached.c
--- libetpan-1.5/src/driver/implementation/pop3/pop3driver_cached.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/implementation/pop3/pop3driver_cached.c	2014-10-31 22:41:02.000000000 +0100
@@ -598,6 +598,9 @@
   uint32_t unseen;
   int r;
   
+  messages = 0;
+  recent = 0;
+  unseen = 0;
   r = pop3driver_cached_status_folder(session, mb,
       &messages, &recent, &unseen);
   if (r != MAIL_NO_ERROR)
diff -Nru libetpan-1.5/src/driver/interface/maildriver.h libetpan-1.6/src/driver/interface/maildriver.h
--- libetpan-1.5/src/driver/interface/maildriver.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/interface/maildriver.h	2014-10-31 22:41:02.000000000 +0100
@@ -585,7 +585,7 @@
   @param remote_ip_port remote IP:port (server)
   @param login          login
   @param auth_name      authentication name
-  @param password       password
+  @param password       password (or token for OAuth2 login)
   @param realm          realm
 
   @return MAIL_NO_ERROR is returned on success, MAIL_ERROR_XXX is returned
diff -Nru libetpan-1.5/src/driver/interface/maildriver_tools.c libetpan-1.6/src/driver/interface/maildriver_tools.c
--- libetpan-1.5/src/driver/interface/maildriver_tools.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/interface/maildriver_tools.c	2014-10-31 22:41:02.000000000 +0100
@@ -664,7 +664,7 @@
       snprintf(keyname, PATH_MAX, "%s-envelope", msg->msg_uid);
       
       key.data = keyname;
-      key.len = strlen(keyname);
+      key.len = (unsigned int) strlen(keyname);
       r = chash_set(hash_exist, &key, &value, NULL);
       if (r < 0) {
         res = MAIL_ERROR_MEMORY;
@@ -676,7 +676,7 @@
       snprintf(keyname, PATH_MAX, "%s-flags", msg->msg_uid);
       
       key.data = keyname;
-      key.len = strlen(keyname);
+      key.len = (unsigned int) strlen(keyname);
       r = chash_set(hash_exist, &key, &value, NULL);
       if (r < 0) {
         res = MAIL_ERROR_MEMORY;
@@ -741,7 +741,7 @@
     msg = carray_get(env_list->msg_tab, i);
       
     key.data = msg->msg_uid;
-    key.len = strlen(msg->msg_uid);
+    key.len = (unsigned int) strlen(msg->msg_uid);
     value.data = NULL;
     value.len = 0;
     r = chash_set(hash_exist, &key, &value, NULL);
@@ -774,7 +774,7 @@
       continue;
     
     key.data = keyname;
-    key.len = strlen(keyname);
+    key.len = (unsigned int) strlen(keyname);
     
     r = chash_get(hash_exist, &key, &value);
     if (r < 0) {
diff -Nru libetpan-1.5/src/driver/interface/mailstorage_tools.c libetpan-1.6/src/driver/interface/mailstorage_tools.c
--- libetpan-1.5/src/driver/interface/mailstorage_tools.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/interface/mailstorage_tools.c	2014-10-31 22:41:02.000000000 +0100
@@ -75,7 +75,7 @@
 static void do_exec_command(int fd, const char *command,
     char *servername, uint16_t port)
 {
-  int i, maxopen;
+  long i, maxopen;
 #ifndef HAVE_SETENV
   char env_buffer[ENV_BUFFER_SIZE];
 #endif
@@ -127,7 +127,7 @@
   
   maxopen = sysconf(_SC_OPEN_MAX);
   for (i=3; i < maxopen; i++)
-    close(i);
+    close((int) i);
   
 #ifdef TIOCNOTTY
   /* Detach from the controlling tty if we have one. Otherwise,
@@ -279,7 +279,7 @@
   case CONNECTION_TYPE_COMMAND_TLS:
 #if HAVE_CFNETWORK
     if (mailstream_cfstream_enabled) {
-      int ssl_level = MAILSTREAM_CFSTREAM_SSL_LEVEL_SSLv3;
+      int ssl_level = MAILSTREAM_CFSTREAM_SSL_LEVEL_NEGOCIATED_SSL;
       mailstream_cfstream_set_ssl_level(stream, ssl_level);
       mailstream_cfstream_set_ssl_verification_mask(stream, MAILSTREAM_CFSTREAM_SSL_NO_VERIFICATION);
       r = mailstream_cfstream_set_ssl_enabled(stream, 1);
diff -Nru libetpan-1.5/src/driver/tools/imfcache.c libetpan-1.6/src/driver/tools/imfcache.c
--- libetpan-1.5/src/driver/tools/imfcache.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/tools/imfcache.c	2014-10-31 22:41:02.000000000 +0100
@@ -226,7 +226,7 @@
     if (r != MAIL_NO_ERROR)
       return r;
     
-    r = mailimf_cache_int_write(mmapstr, indx, length);
+    r = mailimf_cache_int_write(mmapstr, indx, (uint32_t) length);
     if (r != MAIL_NO_ERROR)
       return r;
     
diff -Nru libetpan-1.5/src/driver/tools/mailthread.c libetpan-1.6/src/driver/tools/mailthread.c
--- libetpan-1.5/src/driver/tools/mailthread.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/driver/tools/mailthread.c	2014-10-31 22:41:02.000000000 +0100
@@ -772,7 +772,7 @@
       }
       else {
 	hashkey.data = msgid;
-	hashkey.len = strlen(msgid);
+	hashkey.len = (unsigned int) strlen(msgid);
 	
 	if (chash_get(msg_id_hash, &hashkey, &hashdata) == 0)
 	  msgid = mailimf_get_message_id();
@@ -801,7 +801,7 @@
       }
       
       hashkey.data = msgid;
-      hashkey.len = strlen(msgid);
+      hashkey.len = (unsigned int) strlen(msgid);
       
       hashdata.data = env_tree;
       hashdata.len = 0;
@@ -858,7 +858,7 @@
 	msgid = clist_content(cur_ref);
 
 	hashkey.data = msgid;
-	hashkey.len = strlen(msgid);
+	hashkey.len = (unsigned int) strlen(msgid);
 	
 	r = chash_get(msg_id_hash, &hashkey, &hashdata);
 	if (r < 0) {
@@ -884,7 +884,7 @@
 	  }
 
 	  hashkey.data = msgid;
-	  hashkey.len = strlen(msgid);
+	  hashkey.len = (unsigned int) strlen(msgid);
 	    
 	  hashdata.data = env_cur_tree;
 	  hashdata.len = 0;
@@ -1062,7 +1062,7 @@
       */
 
       key.data = base_subject;
-      key.len = strlen(base_subject);
+      key.len = (unsigned int) strlen(base_subject);
 
       r = chash_get(subject_hash, &key, &data);
 
@@ -1166,7 +1166,7 @@
       */
 
       key.data = env_tree->node_base_subject;
-      key.len = strlen(env_tree->node_base_subject);
+      key.len = (unsigned int) strlen(env_tree->node_base_subject);
 
       r = chash_get(subject_hash, &key, &data);
       if (r < 0)
diff -Nru libetpan-1.5/src/dummy.cpp libetpan-1.6/src/dummy.cpp
diff -Nru libetpan-1.5/src/engine/mailengine.c libetpan-1.6/src/engine/mailengine.c
--- libetpan-1.5/src/engine/mailengine.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/engine/mailengine.c	2014-10-31 22:41:02.000000000 +0100
@@ -286,7 +286,7 @@
   int r;
   
   key.data = uid;
-  key.len = strlen(uid);
+  key.len = (unsigned int) strlen(uid);
   r = chash_get(ref_info->uid_hash, &key, &data);
   if (r < 0)
     return NULL;
@@ -381,7 +381,7 @@
   
   if (msg->msg_uid != NULL) {
     key.data = msg->msg_uid;
-    key.len = strlen(msg->msg_uid);
+    key.len = (unsigned int) strlen(msg->msg_uid);
     data.data = msg;
     data.len = 0;
     
@@ -411,7 +411,7 @@
 
   if (msg->msg_uid != NULL) {
     key.data = msg->msg_uid;
-    key.len = strlen(msg->msg_uid);
+    key.len = (unsigned int) strlen(msg->msg_uid);
     
     chash_delete(ref_info->uid_hash, &key, NULL);
   }
diff -Nru libetpan-1.5/src/engine/mailprivacy_gnupg.c libetpan-1.6/src/engine/mailprivacy_gnupg.c
--- libetpan-1.5/src/engine/mailprivacy_gnupg.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/engine/mailprivacy_gnupg.c	2014-10-31 22:41:02.000000000 +0100
@@ -1717,7 +1717,7 @@
   int res;
 
   * recipient = '\0';
-  remaining = size;
+  remaining = size - 1;
   
 	mailimf_single_fields_init(&single_fields, fields);
   
@@ -3003,9 +3003,9 @@
   }
   
   key.data = buf;
-  key.len = strlen(buf) + 1;
+  key.len = (unsigned int) strlen(buf) + 1;
   value.data = passphrase;
-  value.len = strlen(passphrase) + 1;
+  value.len = (unsigned int) strlen(passphrase) + 1;
   
   r = chash_set(passphrase_hash, &key, &value, NULL);
   if (r < 0) {
@@ -3034,7 +3034,7 @@
     return NULL;
   
   key.data = buf;
-  key.len = strlen(buf) + 1;
+  key.len = (unsigned int) strlen(buf) + 1;
   
   r = chash_get(passphrase_hash, &key, &value);
   if (r < 0)
diff -Nru libetpan-1.5/src/engine/mailprivacy_smime.c libetpan-1.6/src/engine/mailprivacy_smime.c
--- libetpan-1.5/src/engine/mailprivacy_smime.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/engine/mailprivacy_smime.c	2014-10-31 22:41:02.000000000 +0100
@@ -1320,9 +1320,9 @@
   strip_string(buf);
   
   key.data = buf;
-  key.len = strlen(buf);
+  key.len = (unsigned int) strlen(buf);
   data.data = filename;
-  data.len = strlen(filename) + 1;
+  data.len = (unsigned int) strlen(filename) + 1;
   
   chash_set(hash, &key, &data, NULL);
 }
@@ -1342,7 +1342,7 @@
   
   strip_string(buf);
   key.data = buf;
-  key.len = strlen(buf);
+  key.len = (unsigned int) strlen(buf);
   r = chash_get(hash, &key, &data);
   if (r < 0)
     return NULL;
@@ -1873,9 +1873,9 @@
   }
   
   key.data = buf;
-  key.len = strlen(buf) + 1;
+  key.len = (unsigned int) strlen(buf) + 1;
   value.data = passphrase;
-  value.len = strlen(passphrase) + 1;
+  value.len = (unsigned int) strlen(passphrase) + 1;
   
   r = chash_set(passphrase_hash, &key, &value, NULL);
   if (r < 0) {
@@ -1904,7 +1904,7 @@
     return NULL;
   
   key.data = buf;
-  key.len = strlen(buf) + 1;
+  key.len = (unsigned int) strlen(buf) + 1;
   
   r = chash_get(passphrase_hash, &key, &value);
   if (r < 0)
diff -Nru libetpan-1.5/src/engine/mailprivacy_tools.c libetpan-1.6/src/engine/mailprivacy_tools.c
--- libetpan-1.5/src/engine/mailprivacy_tools.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/engine/mailprivacy_tools.c	2014-10-31 22:41:02.000000000 +0100
@@ -1221,36 +1221,6 @@
 }
 
 
-struct mailmime_parameter *
-mailmime_param_new_with_data(char * name, char * value)
-{
-  char * param_name;
-  char * param_value;
-  struct mailmime_parameter * param;
-
-  param_name = strdup(name);
-  if (param_name == NULL)
-    goto err;
-  
-  param_value = strdup(value);
-  if (param_value == NULL)
-    goto free_name;
-  
-  param = mailmime_parameter_new(param_name, param_value);
-  if (param == NULL)
-    goto free_value;
-  
-  return param;
-  
- free_value:
-  free(param_value);
- free_name:
-  free(param_name);
- err:
-  return NULL;
-}
-
-
 int mailprivacy_fetch_decoded_to_file(struct mailprivacy * privacy,
     char * filename, size_t size,
     mailmessage * msg, struct mailmime * mime)
@@ -1560,7 +1530,7 @@
       close(passphrase_input[0]);
       
       if ((passphrase != NULL) && (strlen(passphrase) > 0)) {
-        r = write(passphrase_input[1], passphrase, strlen(passphrase));
+        r = (int) write(passphrase_input[1], passphrase, strlen(passphrase));
         if (r != (int) strlen(passphrase)) {
           close(passphrase_input[1]);
           return ERROR_PASSPHRASE_FILE;
@@ -1568,7 +1538,7 @@
       }
       else {
         /* dummy password */
-        r = write(passphrase_input[1], "*dummy*", 7);
+        r = (int) write(passphrase_input[1], "*dummy*", 7);
         if (r != 7) {
           close(passphrase_input[1]);
           return ERROR_PASSPHRASE_FILE;
diff -Nru libetpan-1.5/src/engine/mailprivacy_tools.h libetpan-1.6/src/engine/mailprivacy_tools.h
--- libetpan-1.5/src/engine/mailprivacy_tools.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/engine/mailprivacy_tools.h	2014-10-31 22:41:02.000000000 +0100
@@ -107,10 +107,6 @@
 mailmime_content_dup(struct mailmime_content * content);
 
 LIBETPAN_EXPORT
-struct mailmime_parameter *
-mailmime_param_new_with_data(char * name, char * value);
-
-LIBETPAN_EXPORT
 int mailprivacy_fetch_decoded_to_file(struct mailprivacy * privacy,
     char * filename, size_t size,
     mailmessage * msg, struct mailmime * mime);
diff -Nru libetpan-1.5/src/engine/mailprivacy_tools_private.h libetpan-1.6/src/engine/mailprivacy_tools_private.h
diff -Nru libetpan-1.5/src/low-level/feed/date.c libetpan-1.6/src/low-level/feed/date.c
--- libetpan-1.5/src/low-level/feed/date.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/feed/date.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include <time.h>
 #include <ctype.h>
 #include <string.h>
@@ -46,6 +76,7 @@
   int apply_offset;
   struct tm ts;
   int local_time;
+  time_t result;
   
   len = strlen(str);
   current_index = 0;
@@ -150,15 +181,15 @@
   ts.tm_year = year - 1900;
   
   if (local_time) {
-    value = mktime(&ts);
+    result = mktime(&ts);
   }
   else {
-    value = mail_mkgmtime(&ts);
+    result = mail_mkgmtime(&ts);
     if (apply_offset)
-      value -= offset;
+      result -= offset;
   }
   
-  return value;
+  return result;
 }
 
 /*
@@ -186,6 +217,7 @@
   int apply_offset;
   struct tm ts;
   int local_time;
+  time_t result;
   
   len = strlen(str);
   current_index = 0;
@@ -329,15 +361,15 @@
   ts.tm_year = year - 1900;
   
   if (local_time) {
-    value = mktime(&ts);
+    result = mktime(&ts);
   }
   else {
-    value = mail_mkgmtime(&ts);
+    result = mail_mkgmtime(&ts);
     if (apply_offset)
-      value -= offset;
+      result -= offset;
   }
   
-  return value;
+  return result;
 }
 
 time_t newsfeed_iso8601_date_parse(const char * str)
diff -Nru libetpan-1.5/src/low-level/feed/date.h libetpan-1.6/src/low-level/feed/date.h
diff -Nru libetpan-1.5/src/low-level/feed/newsfeed_item_enclosure.c libetpan-1.6/src/low-level/feed/newsfeed_item_enclosure.c
diff -Nru libetpan-1.5/src/low-level/feed/newsfeed_item_enclosure.h libetpan-1.6/src/low-level/feed/newsfeed_item_enclosure.h
diff -Nru libetpan-1.5/src/low-level/feed/newsfeed_private.c libetpan-1.6/src/low-level/feed/newsfeed_private.c
diff -Nru libetpan-1.5/src/low-level/feed/newsfeed_private.h libetpan-1.6/src/low-level/feed/newsfeed_private.h
diff -Nru libetpan-1.5/src/low-level/feed/newsfeed_types.h libetpan-1.6/src/low-level/feed/newsfeed_types.h
diff -Nru libetpan-1.5/src/low-level/feed/parser.h libetpan-1.6/src/low-level/feed/parser.h
diff -Nru libetpan-1.5/src/low-level/imap/condstore.c libetpan-1.6/src/low-level/imap/condstore.c
--- libetpan-1.5/src/low-level/imap/condstore.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/condstore.c	2014-10-31 22:41:02.000000000 +0100
@@ -331,44 +331,61 @@
 	return key;
 }
 
-int mailimap_search_modseq(mailimap * session, const char * charset,
-	struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
+static int search_modseq(mailimap * session, const char * charset,
+                         struct mailimap_search_key * key,
+                         int uid_enabled, int literalplus_enabled,
+                         clist ** result, uint64_t * p_mod_sequence_value)
 {
   struct mailimap_response * response;
   int r;
   int error_code;
   struct mailimap_condstore_search * search_data;
   clistiter * cur;
-
+  
   if (session->imap_state != MAILIMAP_STATE_SELECTED)
     return MAILIMAP_ERROR_BAD_STATE;
-
+  
   r = mailimap_send_current_tag(session);
   if (r != MAILIMAP_NO_ERROR)
     return r;
-
-  r = mailimap_search_send(session->imap_stream, charset, key);
+  
+  if (literalplus_enabled) {
+    if (uid_enabled) {
+      r = mailimap_uid_search_literalplus_send(session->imap_stream, charset, key);
+    }
+    else {
+      r = mailimap_search_literalplus_send(session->imap_stream, charset, key);
+    }
+  }
+  else {
+    if (uid_enabled) {
+      r = mailimap_uid_search_send(session->imap_stream, charset, key);
+    }
+    else {
+      r = mailimap_search_send(session->imap_stream, charset, key);
+    }
+  }
   if (r != MAILIMAP_NO_ERROR)
     return r;
-
+  
   r = mailimap_crlf_send(session->imap_stream);
   if (r != MAILIMAP_NO_ERROR)
     return r;
-
+  
   if (mailstream_flush(session->imap_stream) == -1)
     return MAILIMAP_ERROR_STREAM;
-
+  
   if (mailimap_read_line(session) == NULL)
     return MAILIMAP_ERROR_STREAM;
-
+  
   r = mailimap_parse_response(session, &response);
   if (r != MAILIMAP_NO_ERROR)
     return r;
-
+  
   search_data = NULL;
   for(cur = clist_begin(session->imap_response_info->rsp_extension_list) ; cur != NULL ; cur = clist_next(cur)) {
     struct mailimap_extension_data * ext_data;
-
+    
     ext_data = clist_content(cur);
     if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_CONDSTORE) {
       continue;
@@ -376,12 +393,12 @@
     if (ext_data->ext_type != MAILIMAP_CONDSTORE_TYPE_SEARCH_DATA) {
       continue;
     }
-
+    
     search_data = ext_data->ext_data;
     ext_data->ext_data = NULL;
     break;
   }
-
+  
   if (search_data == NULL) {
     * result = session->imap_response_info->rsp_search_result;
     if (p_mod_sequence_value != NULL) {
@@ -395,98 +412,49 @@
     search_data->cs_search_result = NULL;
     mailimap_condstore_search_free(search_data);
   }
-
+  
   error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
-
+  
   mailimap_response_free(response);
-
+  
   switch (error_code) {
     case MAILIMAP_RESP_COND_STATE_OK:
-    return MAILIMAP_NO_ERROR;
-
+      return MAILIMAP_NO_ERROR;
+      
     default:
-    return MAILIMAP_ERROR_SEARCH;
+      if (uid_enabled) {
+        return MAILIMAP_ERROR_UID_SEARCH;
+      }
+      else {
+        return MAILIMAP_ERROR_SEARCH;
+      }
   }
 }
 
-int mailimap_uid_search_modseq(mailimap * session, const char * charset,
+int mailimap_search_modseq(mailimap * session, const char * charset,
 	struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
 {
-  struct mailimap_response * response;
-  int r;
-  int error_code;
-  struct mailimap_condstore_search * search_data;
-  clistiter * cur;
-
-  if (session->imap_state != MAILIMAP_STATE_SELECTED)
-    return MAILIMAP_ERROR_BAD_STATE;
-
-  r = mailimap_send_current_tag(session);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  r = mailimap_uid_search_send(session->imap_stream, charset, key);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  r = mailimap_crlf_send(session->imap_stream);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  if (mailstream_flush(session->imap_stream) == -1)
-    return MAILIMAP_ERROR_STREAM;
-
-  if (mailimap_read_line(session) == NULL)
-    return MAILIMAP_ERROR_STREAM;
-
-  r = mailimap_parse_response(session, &response);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  search_data = NULL;
-  for(cur = clist_begin(session->imap_response_info->rsp_extension_list) ; cur != NULL ; cur = clist_next(cur)) {
-    struct mailimap_extension_data * ext_data;
-    
-    ext_data = clist_content(cur);
-    if (ext_data->ext_extension->ext_id != MAILIMAP_EXTENSION_CONDSTORE) {
-      continue;
-    }
-    if (ext_data->ext_type != MAILIMAP_CONDSTORE_TYPE_SEARCH_DATA) {
-      continue;
-    }
-    
-    search_data = ext_data->ext_data;
-    ext_data->ext_data = NULL;
-    break;
-  }
-
-  if (search_data == NULL) {
-    * result = session->imap_response_info->rsp_search_result;
-    if (p_mod_sequence_value != NULL) {
-      * p_mod_sequence_value = 0;
-    }
-    session->imap_response_info->rsp_search_result = NULL;
-  }
-  else {
-    * result = search_data->cs_search_result;
-    if (p_mod_sequence_value != NULL) {
-      * p_mod_sequence_value = search_data->cs_modseq_value;
-    }
-    search_data->cs_search_result = NULL;
-    mailimap_condstore_search_free(search_data);
-  }
-  
-  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
+  return search_modseq(session, charset, key, 0, 0, result, p_mod_sequence_value);
+}
 
-  mailimap_response_free(response);
+int mailimap_uid_search_modseq(mailimap * session, const char * charset,
+	struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
+{
+  return search_modseq(session, charset, key, 1, 0, result, p_mod_sequence_value);
+}
 
-  switch (error_code) {
-  case MAILIMAP_RESP_COND_STATE_OK:
-    return MAILIMAP_NO_ERROR;
+LIBETPAN_EXPORT
+int mailimap_search_literalplus_modseq(mailimap * session, const char * charset,
+                                       struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
+{
+  return search_modseq(session, charset, key, 0, 1, result, p_mod_sequence_value);
+}
 
-  default:
-    return MAILIMAP_ERROR_UID_SEARCH;
-  }
+LIBETPAN_EXPORT
+int mailimap_uid_search_literalplus_modseq(mailimap * session, const char * charset,
+                                           struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value)
+{
+  return search_modseq(session, charset, key, 1, 1, result, p_mod_sequence_value);
 }
 
 int mailimap_select_condstore(mailimap * session, const char * mb, uint64_t * p_mod_sequence_value)
@@ -958,6 +926,7 @@
       struct mailimap_condstore_search * search_data;
       struct mailimap_extension_data * ext_data;
       
+      search_data = NULL;
       r = search_data_parse(fd, buffer, &cur_token, &search_data);
       if (r != MAILIMAP_NO_ERROR)
         return r;
diff -Nru libetpan-1.5/src/low-level/imap/condstore.h libetpan-1.6/src/low-level/imap/condstore.h
--- libetpan-1.5/src/low-level/imap/condstore.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/condstore.h	2014-10-31 22:41:02.000000000 +0100
@@ -78,6 +78,14 @@
 	struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value);
 
 LIBETPAN_EXPORT
+int mailimap_search_literalplus_modseq(mailimap * session, const char * charset,
+                                       struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value);
+  
+LIBETPAN_EXPORT
+int mailimap_uid_search_literalplus_modseq(mailimap * session, const char * charset,
+                                           struct mailimap_search_key * key, clist ** result, uint64_t * p_mod_sequence_value);
+
+LIBETPAN_EXPORT
 int mailimap_select_condstore(mailimap * session, const char * mb, uint64_t * p_mod_sequence_value);
 
 LIBETPAN_EXPORT
diff -Nru libetpan-1.5/src/low-level/imap/idle.c libetpan-1.6/src/low-level/imap/idle.c
diff -Nru libetpan-1.5/src/low-level/imap/idle.h libetpan-1.6/src/low-level/imap/idle.h
diff -Nru libetpan-1.5/src/low-level/imap/mailimap.c libetpan-1.6/src/low-level/imap/mailimap.c
--- libetpan-1.5/src/low-level/imap/mailimap.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap.c	2014-10-31 22:41:02.000000000 +0100
@@ -1551,14 +1551,14 @@
     if (result != NULL)
       * result = session->imap_sasl.sasl_login;
     if (len != NULL)
-      * len = strlen(session->imap_sasl.sasl_login);
+      * len = (unsigned) strlen(session->imap_sasl.sasl_login);
     return SASL_OK;
     
   case SASL_CB_AUTHNAME:
     if (result != NULL)
       * result = session->imap_sasl.sasl_auth_name;
     if (len != NULL)
-      * len = strlen(session->imap_sasl.sasl_auth_name);
+      * len = (unsigned) strlen(session->imap_sasl.sasl_auth_name);
     return SASL_OK;
   }
   
@@ -1741,12 +1741,12 @@
     }
     
     if (got_response) {
-      size_t response_len;
+      unsigned int response_len;
       char * decoded;
       unsigned int decoded_len;
       unsigned int max_decoded;
       
-      response_len = strlen(response_base64);
+      response_len = (unsigned int) strlen(response_base64);
       max_decoded = response_len * 3 / 4;
       decoded = malloc(max_decoded + 1);
       if (decoded == NULL) {
@@ -1964,53 +1964,7 @@
 mailimap_search(mailimap * session, const char * charset,
     struct mailimap_search_key * key, clist ** result)
 {
-#if 0
-  struct mailimap_response * response;
-  int r;
-  int error_code;
-
-  if (session->imap_state != MAILIMAP_STATE_SELECTED)
-    return MAILIMAP_ERROR_BAD_STATE;
-
-  r = mailimap_send_current_tag(session);
-  if (r != MAILIMAP_NO_ERROR)
-	return r;
-
-  r = mailimap_search_send(session->imap_stream, charset, key);
-  if (r != MAILIMAP_NO_ERROR)
-	return r;
-
-  r = mailimap_crlf_send(session->imap_stream);
-  if (r != MAILIMAP_NO_ERROR)
-	return r;
-
-  if (mailstream_flush(session->imap_stream) == -1)
-    return MAILIMAP_ERROR_STREAM;
-
-  if (mailimap_read_line(session) == NULL)
-    return MAILIMAP_ERROR_STREAM;
-
-  r = mailimap_parse_response(session, &response);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  * result = session->imap_response_info->rsp_search_result;
-  session->imap_response_info->rsp_search_result = NULL;
-
-  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
-
-  mailimap_response_free(response);
-
-  switch (error_code) {
-  case MAILIMAP_RESP_COND_STATE_OK:
-    return MAILIMAP_NO_ERROR;
-
-  default:
-    return MAILIMAP_ERROR_SEARCH;
-  }
-#else
   return mailimap_search_modseq(session, charset, key, result, NULL);
-#endif
 }
 
 LIBETPAN_EXPORT
@@ -2018,53 +1972,19 @@
 mailimap_uid_search(mailimap * session, const char * charset,
     struct mailimap_search_key * key, clist ** result)
 {
-#if 0
-  struct mailimap_response * response;
-  int r;
-  int error_code;
-
-  if (session->imap_state != MAILIMAP_STATE_SELECTED)
-    return MAILIMAP_ERROR_BAD_STATE;
-
-  r = mailimap_send_current_tag(session);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  r = mailimap_uid_search_send(session->imap_stream, charset, key);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  r = mailimap_crlf_send(session->imap_stream);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  if (mailstream_flush(session->imap_stream) == -1)
-    return MAILIMAP_ERROR_STREAM;
-
-  if (mailimap_read_line(session) == NULL)
-    return MAILIMAP_ERROR_STREAM;
-
-  r = mailimap_parse_response(session, &response);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  * result = session->imap_response_info->rsp_search_result;
-  session->imap_response_info->rsp_search_result = NULL;
-
-  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
-
-  mailimap_response_free(response);
+  return mailimap_uid_search_modseq(session, charset, key, result, NULL);
+}
 
-  switch (error_code) {
-  case MAILIMAP_RESP_COND_STATE_OK:
-    return MAILIMAP_NO_ERROR;
+LIBETPAN_EXPORT int mailimap_search_literalplus(mailimap * session, const char * charset,
+                                                struct mailimap_search_key * key, clist ** result)
+{
+  return mailimap_search_literalplus_modseq(session, charset, key, result, NULL);
+}
 
-  default:
-    return MAILIMAP_ERROR_UID_SEARCH;
-  }
-#else
-  return mailimap_uid_search_modseq(session, charset, key, result, NULL);
-#endif
+LIBETPAN_EXPORT int mailimap_uid_search_literalplus(mailimap * session, const char * charset,
+                                                    struct mailimap_search_key * key, clist ** result)
+{
+  return mailimap_uid_search_literalplus_modseq(session, charset, key, result, NULL);
 }
 
 LIBETPAN_EXPORT
@@ -2074,62 +1994,6 @@
   clist_free(search_result);
 }
 
-#if 0
-LIBETPAN_EXPORT
-int
-mailimap_select(mailimap * session, const char * mb)
-{
-  struct mailimap_response * response;
-  int r;
-  int error_code;
-
-  if ((session->imap_state != MAILIMAP_STATE_AUTHENTICATED) &&
-      (session->imap_state != MAILIMAP_STATE_SELECTED))
-    return MAILIMAP_ERROR_BAD_STATE;
-
-  r = mailimap_send_current_tag(session);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  r = mailimap_select_send(session->imap_stream, mb);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-  
-  r = mailimap_crlf_send(session->imap_stream);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  if (mailstream_flush(session->imap_stream) == -1)
-    return MAILIMAP_ERROR_STREAM;
-
-  if (mailimap_read_line(session) == NULL)
-    return MAILIMAP_ERROR_STREAM;
-
-  if (session->imap_selection_info != NULL)
-    mailimap_selection_info_free(session->imap_selection_info);
-  session->imap_selection_info = mailimap_selection_info_new();
-
-  r = mailimap_parse_response(session, &response);
-  if (r != MAILIMAP_NO_ERROR)
-    return r;
-
-  error_code = response->rsp_resp_done->rsp_data.rsp_tagged->rsp_cond_state->rsp_type;
-
-  mailimap_response_free(response);
-
-  switch (error_code) {
-  case MAILIMAP_RESP_COND_STATE_OK:
-    session->imap_state = MAILIMAP_STATE_SELECTED;
-    return MAILIMAP_NO_ERROR;
-
-  default:
-    mailimap_selection_info_free(session->imap_selection_info);
-    session->imap_selection_info = NULL;
-    session->imap_state = MAILIMAP_STATE_AUTHENTICATED;
-    return MAILIMAP_ERROR_SELECT;
-  }
-}
-#else
 LIBETPAN_EXPORT
 int
 mailimap_select(mailimap * session, const char * mb)
@@ -2137,7 +2001,6 @@
 	uint64_t dummy;
 	return mailimap_select_condstore_optional(session, mb, 0, &dummy);
 }
-#endif
 
 LIBETPAN_EXPORT
 int
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_compress.c libetpan-1.6/src/low-level/imap/mailimap_compress.c
--- libetpan-1.5/src/low-level/imap/mailimap_compress.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_compress.c	2014-10-31 22:41:02.000000000 +0100
@@ -101,6 +101,7 @@
     res = MAILIMAP_ERROR_STREAM;
     goto err;
   }
+  mailstream_low_set_timeout(compressed_stream, session->imap_timeout);
   mailstream_set_low(session->imap_stream, compressed_stream);
   
   return MAILIMAP_NO_ERROR;
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_extension_types.h libetpan-1.6/src/low-level/imap/mailimap_extension_types.h
diff -Nru libetpan-1.5/src/low-level/imap/mailimap.h libetpan-1.6/src/low-level/imap/mailimap.h
--- libetpan-1.5/src/low-level/imap/mailimap.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap.h	2014-10-31 22:41:02.000000000 +0100
@@ -490,6 +490,48 @@
     struct mailimap_search_key * key, clist ** result);
 
 /*
+ mailimap_search_literalplus()
+
+ All mails that match the given criteria will be returned
+ their numbers in the result list.
+ LITERAL+ feature will be used to send strings.
+
+ @param session  IMAP session
+ @param charset  This indicates the charset of the strings that appears
+ in the searching criteria
+ @param key      This is the searching criteria
+ @param result   The result is a clist of (uint32_t *) and will be
+ stored in (* result).
+
+ @return the return code is one of MAILIMAP_ERROR_XXX or
+ MAILIMAP_NO_ERROR codes
+*/
+
+LIBETPAN_EXPORT int mailimap_search_literalplus(mailimap * session, const char * charset,
+                                                struct mailimap_search_key * key, clist ** result);
+
+/*
+ mailimap_uid_search_literalplus()
+
+ All mails that match the given criteria will be returned
+ their numbers in the result list.
+ LITERAL+ feature will be used to send strings.
+
+ @param session  IMAP session
+ @param charset  This indicates the charset of the strings that appears
+ in the searching criteria
+ @param key      This is the searching criteria
+ @param result   The result is a clist of (uint32_t *) and will be
+ stored in (* result).
+ 
+ @return the return code is one of MAILIMAP_ERROR_XXX or
+ MAILIMAP_NO_ERROR codes
+*/
+
+LIBETPAN_EXPORT int mailimap_uid_search_literalplus(mailimap * session, const char * charset,
+                                                    struct mailimap_search_key * key, clist ** result);
+
+/*
    mailimap_search_result_free()
 
    This function will free the result of the a search.
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_helper.c libetpan-1.6/src/low-level/imap/mailimap_helper.c
--- libetpan-1.5/src/low-level/imap/mailimap_helper.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_helper.c	2014-10-31 22:41:02.000000000 +0100
@@ -188,7 +188,7 @@
 }
 
 int mailimap_append_simple(mailimap * session, const char * mailbox,
-			   const char * content, uint32_t size)
+			   const char * content, size_t size)
 {
   return mailimap_append(session, mailbox, NULL, NULL, content, size);
 }
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_helper.h libetpan-1.6/src/low-level/imap/mailimap_helper.h
--- libetpan-1.5/src/low-level/imap/mailimap_helper.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_helper.h	2014-10-31 22:41:02.000000000 +0100
@@ -54,7 +54,7 @@
 			    clist ** result);
 
 int mailimap_append_simple(mailimap * session, const char * mailbox,
-			   const char * content, uint32_t size);
+			   const char * content, size_t size);
 
 int mailimap_login_simple(mailimap * session,
 			  const char * userid, const char * password);
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_id_parser.c libetpan-1.6/src/low-level/imap/mailimap_id_parser.c
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_id_parser.h libetpan-1.6/src/low-level/imap/mailimap_id_parser.h
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_id_sender.c libetpan-1.6/src/low-level/imap/mailimap_id_sender.c
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_id_sender.h libetpan-1.6/src/low-level/imap/mailimap_id_sender.h
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_id_types.c libetpan-1.6/src/low-level/imap/mailimap_id_types.c
--- libetpan-1.5/src/low-level/imap/mailimap_id_types.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_id_types.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,7 +1,39 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "mailimap_id_types.h"
 
 #include <stdlib.h>
 
+#include "mailimap_types.h"
+
 struct mailimap_id_params_list * mailimap_id_params_list_new(clist * items)
 {
   struct mailimap_id_params_list * list;
@@ -38,8 +70,8 @@
 
 void mailimap_id_param_free(struct mailimap_id_param * param)
 {
-  free(param->idpa_name);
-  free(param->idpa_value);
+  mailimap_string_free(param->idpa_name);
+  mailimap_nstring_free(param->idpa_value);
   free(param);
 }
 
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_id_types.h libetpan-1.6/src/low-level/imap/mailimap_id_types.h
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_keywords.c libetpan-1.6/src/low-level/imap/mailimap_keywords.c
--- libetpan-1.5/src/low-level/imap/mailimap_keywords.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_keywords.c	2014-10-31 22:41:02.000000000 +0100
@@ -56,7 +56,7 @@
 					  size_t * indx,
 					  const char * token)
 {
-  int len;
+  size_t len;
   size_t cur_token;
   int r;
 
@@ -87,7 +87,7 @@
 int mailimap_char_parse(mailstream * fd, MMAPString * buffer,
 			size_t * indx, char token)
 {
-  int cur_token;
+  size_t cur_token;
 
   cur_token = * indx;
 
@@ -201,7 +201,7 @@
 }
 
 
-const char * mailimap_status_att_get_token_str(size_t indx)
+const char * mailimap_status_att_get_token_str(int indx)
 {
   return mailimap_get_token_str(indx, status_att_tab);
 }
@@ -228,7 +228,7 @@
 }
 
 
-const char * mailimap_month_get_token_str(size_t indx)
+const char * mailimap_month_get_token_str(int indx)
 {
   return mailimap_get_token_str(indx, month_tab);
 }
@@ -253,7 +253,7 @@
 }
 
 
-const char * mailimap_flag_get_token_str(size_t indx)
+const char * mailimap_flag_get_token_str(int indx)
 {
   return mailimap_get_token_str(indx, mailimap_flag_tab);
 }
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_keywords.h libetpan-1.6/src/low-level/imap/mailimap_keywords.h
--- libetpan-1.5/src/low-level/imap/mailimap_keywords.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_keywords.h	2014-10-31 22:41:02.000000000 +0100
@@ -61,18 +61,18 @@
 
 int mailimap_status_att_get_token_value(mailstream * fd, MMAPString * buffer,
 					size_t * indx);
-const char * mailimap_status_att_get_token_str(size_t indx);
+const char * mailimap_status_att_get_token_str(int indx);
 
 
 int mailimap_month_get_token_value(mailstream * fd, MMAPString * buffer,
 				   size_t * indx);
-const char * mailimap_month_get_token_str(size_t indx);
+const char * mailimap_month_get_token_str(int indx);
 
 
 int mailimap_flag_get_token_value(mailstream * fd, MMAPString * buffer,
 				  size_t * indx);
 
-const char * mailimap_flag_get_token_str(size_t indx);
+const char * mailimap_flag_get_token_str(int indx);
 
 int mailimap_encoding_get_token_value(mailstream * fd, MMAPString * buffer,
 				      size_t * indx);
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_oauth2.c libetpan-1.6/src/low-level/imap/mailimap_oauth2.c
--- libetpan-1.5/src/low-level/imap/mailimap_oauth2.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_oauth2.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "mailimap_oauth2.h"
 
 #include <string.h>
@@ -104,9 +134,9 @@
   char * ptr;
   char * full_auth_string;
   char * full_auth_string_b64;
-  int auth_user_len;
-  int access_token_len;
-  int full_auth_string_len;
+  size_t auth_user_len;
+  size_t access_token_len;
+  size_t full_auth_string_len;
   int res;
   
   full_auth_string = NULL;
@@ -129,7 +159,7 @@
   ptr = memcpy(ptr + access_token_len, "\1\1\0", 3);
   
   /* Convert to base64 */
-  full_auth_string_b64 = encode_base64(full_auth_string, full_auth_string_len);
+  full_auth_string_b64 = encode_base64(full_auth_string, (int) full_auth_string_len);
   if (full_auth_string_b64 == NULL) {
     res = MAILIMAP_ERROR_MEMORY;
     goto free;
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_oauth2.h libetpan-1.6/src/low-level/imap/mailimap_oauth2.h
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_parser.c libetpan-1.6/src/low-level/imap/mailimap_parser.c
--- libetpan-1.5/src/low-level/imap/mailimap_parser.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_parser.c	2014-10-31 22:41:02.000000000 +0100
@@ -4400,7 +4400,7 @@
   if (localtime_r(&t, &lt) == NULL)
     return 0;
   
-  off = (mail_mkgmtime(&lt) - mail_mkgmtime(&gmt)) * 100 / (60 * 60);
+  off = (int) ((mail_mkgmtime(&lt) - mail_mkgmtime(&gmt)) * 100 / (60 * 60));
   
   return off;
 }
@@ -5661,16 +5661,17 @@
   cur_token = * indx;
   type = MAILIMAP_FLAG_PERM_ERROR; /* XXX - removes a gcc warning */
   
-  r = mailimap_flag_parse(fd, buffer, &cur_token, &flag,
-			  progr_rate, progr_fun);
+  r = mailimap_token_case_insensitive_parse(fd, buffer,
+                                            &cur_token, "\\*");
   if (r == MAILIMAP_NO_ERROR)
-    type = MAILIMAP_FLAG_PERM_FLAG;
+    type = MAILIMAP_FLAG_PERM_ALL;
 
   if (r == MAILIMAP_ERROR_PARSE) {
-    r = mailimap_token_case_insensitive_parse(fd, buffer,
-					      &cur_token, "\\*");
+    r = mailimap_flag_parse(fd, buffer, &cur_token, &flag,
+                            progr_rate, progr_fun);
     if (r == MAILIMAP_NO_ERROR)
-      type = MAILIMAP_FLAG_PERM_ALL;
+      type = MAILIMAP_FLAG_PERM_FLAG;
+
   }
 
   if (r != MAILIMAP_NO_ERROR) {
@@ -5960,7 +5961,7 @@
     goto err;
   }
   
-  left = buffer->len - cur_token;
+  left = (uint32_t) (buffer->len - cur_token);
   
   if (left >= number) {
     if (number > 0)
@@ -8970,6 +8971,7 @@
   struct mailimap_response_done * resp_done;
   int r;
   int res;
+  clistiter * iter;
   
   cur_token = * indx;
   cont_req_or_resp_data_list = NULL;
@@ -8991,6 +8993,19 @@
   if ((r != MAILIMAP_NO_ERROR) && (r != MAILIMAP_ERROR_PARSE))
     return r;
   
+  if (r == MAILIMAP_NO_ERROR) {
+    for(iter = clist_begin(cont_req_or_resp_data_list) ; iter != NULL ; iter = clist_next(iter)) {
+      struct mailimap_cont_req_or_resp_data * cont_req_or_resp_data = clist_content(iter);
+      if (cont_req_or_resp_data->rsp_type != MAILIMAP_RESP_RESP_DATA) {
+        continue;
+      }
+      if (cont_req_or_resp_data->rsp_data.rsp_resp_data->rsp_type == MAILIMAP_RESP_DATA_TYPE_COND_BYE) {
+        res = MAILIMAP_ERROR_STREAM;
+        goto free_list;
+      }
+    }
+  }
+  
   r = mailimap_response_done_parse(fd, buffer, &cur_token, &resp_done,
                                    progr_rate, progr_fun);
   if (r != MAILIMAP_NO_ERROR) {
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_sender.c libetpan-1.6/src/low-level/imap/mailimap_sender.c
--- libetpan-1.5/src/low-level/imap/mailimap_sender.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_sender.c	2014-10-31 22:41:02.000000000 +0100
@@ -40,6 +40,7 @@
 #include "mailstream.h"
 #include "mailimap_keywords.h"
 #include "mailimap_sender.h"
+#include "mailimap_parser.h"
 #include "clist.h"
 #include "mail.h"
 #include "base64.h"
@@ -63,6 +64,7 @@
 
 
 
+static int is_ascii(const char * str);
 
 static int mailimap_atom_send(mailstream * fd, const char * atom);
 
@@ -176,7 +178,11 @@
 
 static int mailimap_userid_send(mailstream * fd, const char * user);
 
+static int mailimap_astring_literalplus_send(mailstream * fd, const char * astring,
+                                             int literalplus_enabled);
 
+static int
+mailimap_literalplus_count_send(mailstream * fd, size_t count);
 
 
 
@@ -408,6 +414,36 @@
   return 1;
 }
 
+static int mailimap_literalplus_send(mailstream * fd, const char * literal)
+{
+  size_t len;
+  size_t literal_len;
+  int r;
+  
+  len = strlen(literal);
+  literal_len = mailstream_get_data_crlf_size(literal, len);
+  
+  r = mailimap_literalplus_count_send(fd, literal_len);
+  if (r != MAILIMAP_NO_ERROR)
+    return r;
+  r = mailimap_literal_data_send(fd, literal, literal_len, 0, NULL);
+  if (r != MAILIMAP_NO_ERROR)
+    return r;
+  
+  return MAILIMAP_NO_ERROR;
+}
+
+static int mailimap_astring_literalplus_send(mailstream * fd, const char * astring,
+                                             int literalplus_enabled)
+{
+  if (is_ascii(astring) || !literalplus_enabled) {
+    return mailimap_astring_send(fd, astring);
+  }
+  else {
+    return mailimap_literalplus_send(fd, astring);
+  }
+}
+
 int mailimap_astring_send(mailstream * fd, const char * astring)
 {
   /*
@@ -1508,7 +1544,7 @@
 		      progress_function * progr_fun)
 {
   size_t len;
-  uint32_t literal_len;
+  size_t literal_len;
   int r;
   
   len = strlen(literal);
@@ -1528,36 +1564,53 @@
   "{" number "}" CRLF
 */
 
-int
-mailimap_literal_count_send(mailstream * fd, uint32_t count)
+static int literal_count_send(mailstream * fd, size_t count, int literalplus_enabled)
 {
   int r;
   
   r = mailimap_char_send(fd, '{');
   if (r != MAILIMAP_NO_ERROR)
     return r;
-
-  r = mailimap_number_send(fd, count);
+  
+  r = mailimap_number_send(fd, (uint32_t) count);
   if (r != MAILIMAP_NO_ERROR)
     return r;
-
+  
+  if (literalplus_enabled) {
+    r = mailimap_char_send(fd, '+');
+    if (r != MAILIMAP_NO_ERROR)
+      return r;
+  }
+  
   r = mailimap_char_send(fd, '}');
   if (r != MAILIMAP_NO_ERROR)
     return r;
-
+  
   r = mailimap_crlf_send(fd);
   if (r != MAILIMAP_NO_ERROR)
     return r;
-
+  
   return MAILIMAP_NO_ERROR;
 }
 
+int
+mailimap_literal_count_send(mailstream * fd, size_t count)
+{
+  return literal_count_send(fd, count, 0);
+}
+
+static int
+mailimap_literalplus_count_send(mailstream * fd, size_t count)
+{
+  return literal_count_send(fd, count, 1);
+}
+
 /*
   *CHAR8
 */
 
 int
-mailimap_literal_data_send(mailstream * fd, const char * literal, uint32_t len,
+mailimap_literal_data_send(mailstream * fd, const char * literal, size_t len,
 			   size_t progr_rate,
 			   progress_function * progr_fun)
 {
@@ -1565,7 +1618,7 @@
 }
 
 int
-mailimap_literal_data_send_with_context(mailstream * fd, const char * literal, uint32_t len,
+mailimap_literal_data_send_with_context(mailstream * fd, const char * literal, size_t len,
                                         mailprogress_function * progr_fun,
                                         void * context)
 {
@@ -1835,6 +1888,18 @@
   return MAILIMAP_NO_ERROR;
 }
 
+static int is_ascii(const char * str)
+{
+  const char * p = str;
+  while (* p != 0) {
+    if ((unsigned char) * p >= 128) {
+      return 0;
+    }
+    p ++;
+  }
+  return 1;
+}
+
 /*
 =>   search-key      = "ALL" / "ANSWERED" / "BCC" SP astring /
                      "BEFORE" SP date / "BODY" SP astring /
@@ -1855,7 +1920,6 @@
                      "(" search-key *(SP search-key) ")"
 */
 
-
 static int mailimap_search_key_need_to_send_charset(struct mailimap_search_key * key)
 {
   clistiter * cur;
@@ -1863,157 +1927,156 @@
   int r;
   
   switch (key->sk_type) {
-
-  case MAILIMAP_SEARCH_KEY_ALL:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_ANSWERED:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_BCC:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_BEFORE:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_BODY:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_CC:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_DELETED:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_FLAGGED:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_FROM:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_KEYWORD:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_NEW:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_OLD:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_ON:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_RECENT:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_SEEN:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_SINCE:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_SUBJECT:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_TEXT:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_TO:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_UNANSWERED:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_UNDELETED:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_UNFLAGGED:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_UNKEYWORD:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_UNSEEN:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_DRAFT:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_HEADER:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_LARGER:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_NOT:
-    return mailimap_search_key_need_to_send_charset(key->sk_data.sk_not);    
-
-  case MAILIMAP_SEARCH_KEY_OR:
-    return mailimap_search_key_need_to_send_charset(key->sk_data.sk_or.sk_or1) ||
-        mailimap_search_key_need_to_send_charset(key->sk_data.sk_or.sk_or2);
-    
-  case MAILIMAP_SEARCH_KEY_SENTBEFORE:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_SENTON:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_SENTSINCE:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_SMALLER:
-    return 0;
-    
-  case MAILIMAP_SEARCH_KEY_UID:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_UNDRAFT:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_SET:
-    return 0;
-
-  case MAILIMAP_SEARCH_KEY_XGMTHRID:
-    return 1;
-
-  case MAILIMAP_SEARCH_KEY_MULTIPLE:
+      
+    case MAILIMAP_SEARCH_KEY_ALL:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_ANSWERED:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_BCC:
+      return !is_ascii(key->sk_data.sk_bcc);
+      
+    case MAILIMAP_SEARCH_KEY_BEFORE:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_BODY:
+      return !is_ascii(key->sk_data.sk_body);
+      
+    case MAILIMAP_SEARCH_KEY_CC:
+      return !is_ascii(key->sk_data.sk_cc);
+      
+    case MAILIMAP_SEARCH_KEY_DELETED:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_FLAGGED:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_FROM:
+      return !is_ascii(key->sk_data.sk_from);
+      
+    case MAILIMAP_SEARCH_KEY_KEYWORD:
+      return !is_ascii(key->sk_data.sk_keyword);
+      
+    case MAILIMAP_SEARCH_KEY_NEW:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_OLD:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_ON:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_RECENT:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_SEEN:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_SINCE:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_SUBJECT:
+      return !is_ascii(key->sk_data.sk_subject);
+      
+    case MAILIMAP_SEARCH_KEY_TEXT:
+      return !is_ascii(key->sk_data.sk_text);
+      
+    case MAILIMAP_SEARCH_KEY_TO:
+      return !is_ascii(key->sk_data.sk_to);
+      
+    case MAILIMAP_SEARCH_KEY_UNANSWERED:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_UNDELETED:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_UNFLAGGED:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_UNKEYWORD:
+      return !is_ascii(key->sk_data.sk_unkeyword);
+      
+    case MAILIMAP_SEARCH_KEY_UNSEEN:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_DRAFT:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_HEADER:
+      return !is_ascii(key->sk_data.sk_header.sk_header_name) || !is_ascii(key->sk_data.sk_header.sk_header_value);
+      
+    case MAILIMAP_SEARCH_KEY_LARGER:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_NOT:
+      return mailimap_search_key_need_to_send_charset(key->sk_data.sk_not);
+      
+    case MAILIMAP_SEARCH_KEY_OR:
+      return mailimap_search_key_need_to_send_charset(key->sk_data.sk_or.sk_or1) ||
+      mailimap_search_key_need_to_send_charset(key->sk_data.sk_or.sk_or2);
+      
+    case MAILIMAP_SEARCH_KEY_SENTBEFORE:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_SENTON:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_SENTSINCE:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_SMALLER:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_UID:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_UNDRAFT:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_SET:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_XGMTHRID:
+      return 0;
+      
+    case MAILIMAP_SEARCH_KEY_MULTIPLE:
     {
       cur = clist_begin(key->sk_data.sk_multiple);
-
+      
       if (cur == NULL)
-          return 0;
-
+        return 0;
+      
       elt = (struct mailimap_search_key *) clist_content(cur);
       r = mailimap_search_key_need_to_send_charset(elt);
       if (r != 0)
-          return r;
+        return r;
       cur = clist_next(cur);
-
+      
       while (cur != NULL) {
-                     
-          elt = (struct mailimap_search_key *) clist_content(cur);
-          r = mailimap_search_key_need_to_send_charset(elt);
-          if (r != 0)
-              return r;
-          cur = clist_next(cur);
+        
+        elt = (struct mailimap_search_key *) clist_content(cur);
+        r = mailimap_search_key_need_to_send_charset(elt);
+        if (r != 0)
+          return r;
+        cur = clist_next(cur);
       }
-
+      
       return 0;
     }   
       
-  case MAILIMAP_SEARCH_KEY_MODSEQ:
-    return 0;    
-
-  case MAILIMAP_SEARCH_KEY_XGMMSGID:
-    return 0;
-    
-  default:
-    /* don't know, better send */
-    return 1;
+    case MAILIMAP_SEARCH_KEY_MODSEQ:
+      return 0;    
+      
+    case MAILIMAP_SEARCH_KEY_XGMMSGID:
+      return 0;
+      
+    default:
+      /* don't know, better send */
+      return 1;
   }
 }
 
-
 /*
    response        = *(continue-req / response-data) response-done
 
@@ -2111,6 +2174,61 @@
   return mailimap_search_send(fd, charset, key);
 }
 
+int mailimap_search_literalplus_send(mailstream * fd, const char * charset,
+                                     struct mailimap_search_key * key)
+{
+  int r;
+  int needToSendCharset = 1;
+  
+  r = mailimap_token_send(fd, "SEARCH");
+  if (r != MAILIMAP_NO_ERROR)
+    return r;
+  
+  needToSendCharset = mailimap_search_key_need_to_send_charset(key);
+  
+  if (charset != NULL && needToSendCharset) {
+    r = mailimap_space_send(fd);
+    if (r != MAILIMAP_NO_ERROR)
+      return r;
+    
+    r = mailimap_token_send(fd, "CHARSET");
+    if (r != MAILIMAP_NO_ERROR)
+      return r;
+    r = mailimap_space_send(fd);
+    if (r != MAILIMAP_NO_ERROR)
+      return r;
+    r = mailimap_astring_send(fd, charset);
+    if (r != MAILIMAP_NO_ERROR)
+      return r;
+  }
+  
+  r = mailimap_space_send(fd);
+  if (r != MAILIMAP_NO_ERROR)
+    return r;
+  
+  r = mailimap_search_key_literalplus_send(fd, key);
+  if (r != MAILIMAP_NO_ERROR)
+    return r;
+  
+  return MAILIMAP_NO_ERROR;
+}
+
+int mailimap_uid_search_literalplus_send(mailstream * fd, const char * charset,
+                                         struct mailimap_search_key * key)
+{
+  int r;
+  
+  r = mailimap_token_send(fd, "UID");
+  if (r != MAILIMAP_NO_ERROR)
+    return r;
+  
+  r = mailimap_space_send(fd);
+  if (r != MAILIMAP_NO_ERROR)
+    return r;
+  
+  return mailimap_search_literalplus_send(fd, charset, key);
+}
+
 /*
 =>   search-key      = "ALL" / "ANSWERED" / "BCC" SP astring /
                      "BEFORE" SP date / "BODY" SP astring /
@@ -2132,438 +2250,450 @@
 */
 
 
-int mailimap_search_key_send(mailstream * fd,
-   				struct mailimap_search_key * key)
+static int search_key_send(mailstream * fd,
+                           struct mailimap_search_key * key,
+                           int literalplus_enabled)
 {
   int r;
   
   switch (key->sk_type) {
-
-  case MAILIMAP_SEARCH_KEY_ALL:
-    return mailimap_token_send(fd, "ALL");
-
-  case MAILIMAP_SEARCH_KEY_ANSWERED:
-    return mailimap_token_send(fd, "ANSWERED");
-
-  case MAILIMAP_SEARCH_KEY_BCC:
-    r = mailimap_token_send(fd, "BCC");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_astring_send(fd, key->sk_data.sk_bcc);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_BEFORE:
-    r = mailimap_token_send(fd, "BEFORE");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_date_send(fd, key->sk_data.sk_before);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_BODY:
-    r = mailimap_token_send(fd, "BODY");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_astring_send(fd, key->sk_data.sk_body);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_CC:
-    r = mailimap_token_send(fd, "CC");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_astring_send(fd, key->sk_data.sk_cc);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_DELETED:
-    return mailimap_token_send(fd, "DELETED");
-
-  case MAILIMAP_SEARCH_KEY_FLAGGED:
-    return mailimap_token_send(fd, "FLAGGED");
-
-  case MAILIMAP_SEARCH_KEY_FROM:
-    r = mailimap_token_send(fd, "FROM");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_astring_send(fd, key->sk_data.sk_from);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_KEYWORD:
-    r = mailimap_token_send(fd, "KEYWORD");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_flag_keyword_send(fd, key->sk_data.sk_keyword);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_NEW:
-    return mailimap_token_send(fd, "NEW");
-
-  case MAILIMAP_SEARCH_KEY_OLD:
-    return mailimap_token_send(fd, "OLD");
-
-  case MAILIMAP_SEARCH_KEY_ON:
-    r = mailimap_token_send(fd, "ON");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_date_send(fd, key->sk_data.sk_on);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_RECENT:
-    return mailimap_token_send(fd, "RECENT");
-
-  case MAILIMAP_SEARCH_KEY_SEEN:
-    return mailimap_token_send(fd, "SEEN");
-
-  case MAILIMAP_SEARCH_KEY_SINCE:
-    r = mailimap_token_send(fd, "SINCE");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_date_send(fd, key->sk_data.sk_since);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_SUBJECT:
-    r = mailimap_token_send(fd, "SUBJECT");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_astring_send(fd, key->sk_data.sk_subject);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_TEXT:
-    r = mailimap_token_send(fd, "TEXT");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_astring_send(fd, key->sk_data.sk_text);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_TO:
-    r = mailimap_token_send(fd, "TO");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_astring_send(fd, key->sk_data.sk_text);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_UNANSWERED:
-    return mailimap_token_send(fd, "UNANSWERED");
-
-  case MAILIMAP_SEARCH_KEY_UNDELETED:
-    return mailimap_token_send(fd, "UNDELETED");
-
-  case MAILIMAP_SEARCH_KEY_UNFLAGGED:
-    return mailimap_token_send(fd, "UNFLAGGED");
-
-  case MAILIMAP_SEARCH_KEY_UNKEYWORD:
-    r = mailimap_token_send(fd, "UNKEYWORD");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_flag_keyword_send(fd, key->sk_data.sk_keyword);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_UNSEEN:
-    return mailimap_token_send(fd, "UNSEEN");
-
-  case MAILIMAP_SEARCH_KEY_DRAFT:
-    return mailimap_token_send(fd, "DRAFT");
-
-  case MAILIMAP_SEARCH_KEY_HEADER:
-    r = mailimap_token_send(fd, "HEADER");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_header_fld_name_send(fd,
-      key->sk_data.sk_header.sk_header_name);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_astring_send(fd,
-      key->sk_data.sk_header.sk_header_value);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_LARGER:
-    r = mailimap_token_send(fd, "LARGER");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_number_send(fd, key->sk_data.sk_larger);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_NOT:
-    r = mailimap_token_send(fd, "NOT");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_search_key_send(fd, key->sk_data.sk_not);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_OR:
-    r = mailimap_token_send(fd, "OR");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_search_key_send(fd, key->sk_data.sk_or.sk_or1);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_search_key_send(fd, key->sk_data.sk_or.sk_or2);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_SENTBEFORE:
-    r = mailimap_token_send(fd, "SENTBEFORE");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_date_send(fd, key->sk_data.sk_sentbefore);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_SENTON:
-    r = mailimap_token_send(fd, "SENTON");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_date_send(fd, key->sk_data.sk_senton);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_SENTSINCE:
-    r = mailimap_token_send(fd, "SENTSINCE");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_date_send(fd, key->sk_data.sk_sentsince);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_SMALLER:
-    r = mailimap_token_send(fd, "SMALLER");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_number_send(fd, key->sk_data.sk_smaller);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-    
-  case MAILIMAP_SEARCH_KEY_UID:
-    r = mailimap_token_send(fd, "UID");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_set_send(fd, key->sk_data.sk_set);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_UNDRAFT:
-    return mailimap_token_send(fd, "UNDRAFT");
-
-  case MAILIMAP_SEARCH_KEY_SET:
-    return mailimap_set_send(fd, key->sk_data.sk_set);
-
-  case MAILIMAP_SEARCH_KEY_XGMTHRID:
-    r = mailimap_token_send(fd, "X-GM-THRID");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_uint64_send(fd, key->sk_data.sk_xgmthrid);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_XGMMSGID:
-    r = mailimap_token_send(fd, "X-GM-MSGID");
-    if (r != MAILIMAP_NO_ERROR)
+      
+    case MAILIMAP_SEARCH_KEY_ALL:
+      return mailimap_token_send(fd, "ALL");
+      
+    case MAILIMAP_SEARCH_KEY_ANSWERED:
+      return mailimap_token_send(fd, "ANSWERED");
+      
+    case MAILIMAP_SEARCH_KEY_BCC:
+      r = mailimap_token_send(fd, "BCC");
+      if (r != MAILIMAP_NO_ERROR)
         return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
         return r;
-    r = mailimap_uint64_send(fd, key->sk_data.sk_xgmmsgid);
-    if (r != MAILIMAP_NO_ERROR)
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_bcc, literalplus_enabled);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_BEFORE:
+      r = mailimap_token_send(fd, "BEFORE");
+      if (r != MAILIMAP_NO_ERROR)
         return r;
-    return MAILIMAP_NO_ERROR;
-  
-  case MAILIMAP_SEARCH_KEY_XGMRAW:
-    r = mailimap_token_send(fd, "X-GM-RAW");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    r = mailimap_quoted_send(fd, key->sk_data.sk_xgmraw);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    return MAILIMAP_NO_ERROR;
-
-  case MAILIMAP_SEARCH_KEY_MULTIPLE:
-    r = mailimap_oparenth_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-
-    r = mailimap_struct_spaced_list_send(fd, key->sk_data.sk_multiple,
-      (mailimap_struct_sender *) mailimap_search_key_send);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-
-    r = mailimap_cparenth_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-
-    return MAILIMAP_NO_ERROR;
-	case MAILIMAP_SEARCH_KEY_MODSEQ:
-    r = mailimap_token_send(fd, "MODSEQ");
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    
-    if (key->sk_data.sk_modseq.sk_entry_name != NULL) {
       r = mailimap_space_send(fd);
       if (r != MAILIMAP_NO_ERROR)
         return r;
+      r = mailimap_date_send(fd, key->sk_data.sk_before);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
       
-      mailimap_dquote_send(fd);
-      r = mailimap_token_send(fd, "/flags/");
+    case MAILIMAP_SEARCH_KEY_BODY:
+      r = mailimap_token_send(fd, "BODY");
       if (r != MAILIMAP_NO_ERROR)
         return r;
-      if (key->sk_data.sk_modseq.sk_entry_name->fl_type != MAILIMAP_FLAG_KEYWORD) {
-        r = mailimap_token_send(fd, "\\");
-        if (r != MAILIMAP_NO_ERROR)
-          return r;
-      }
-      r = mailimap_flag_send(fd, key->sk_data.sk_modseq.sk_entry_name);
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_body, literalplus_enabled);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_CC:
+      r = mailimap_token_send(fd, "CC");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_cc, literalplus_enabled);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_DELETED:
+      return mailimap_token_send(fd, "DELETED");
+      
+    case MAILIMAP_SEARCH_KEY_FLAGGED:
+      return mailimap_token_send(fd, "FLAGGED");
+      
+    case MAILIMAP_SEARCH_KEY_FROM:
+      r = mailimap_token_send(fd, "FROM");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_from, literalplus_enabled);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_KEYWORD:
+      r = mailimap_token_send(fd, "KEYWORD");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_flag_keyword_send(fd, key->sk_data.sk_keyword);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_NEW:
+      return mailimap_token_send(fd, "NEW");
+      
+    case MAILIMAP_SEARCH_KEY_OLD:
+      return mailimap_token_send(fd, "OLD");
+      
+    case MAILIMAP_SEARCH_KEY_ON:
+      r = mailimap_token_send(fd, "ON");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_date_send(fd, key->sk_data.sk_on);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_RECENT:
+      return mailimap_token_send(fd, "RECENT");
+      
+    case MAILIMAP_SEARCH_KEY_SEEN:
+      return mailimap_token_send(fd, "SEEN");
+      
+    case MAILIMAP_SEARCH_KEY_SINCE:
+      r = mailimap_token_send(fd, "SINCE");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_date_send(fd, key->sk_data.sk_since);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_SUBJECT:
+      r = mailimap_token_send(fd, "SUBJECT");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_subject, literalplus_enabled);
       if (r != MAILIMAP_NO_ERROR)
         return r;
-      mailimap_dquote_send(fd);
+      return MAILIMAP_NO_ERROR;
       
+    case MAILIMAP_SEARCH_KEY_TEXT:
+      r = mailimap_token_send(fd, "TEXT");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_text, literalplus_enabled);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_TO:
+      r = mailimap_token_send(fd, "TO");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_text, literalplus_enabled);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_UNANSWERED:
+      return mailimap_token_send(fd, "UNANSWERED");
+      
+    case MAILIMAP_SEARCH_KEY_UNDELETED:
+      return mailimap_token_send(fd, "UNDELETED");
+      
+    case MAILIMAP_SEARCH_KEY_UNFLAGGED:
+      return mailimap_token_send(fd, "UNFLAGGED");
+      
+    case MAILIMAP_SEARCH_KEY_UNKEYWORD:
+      r = mailimap_token_send(fd, "UNKEYWORD");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_unkeyword, literalplus_enabled);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_UNSEEN:
+      return mailimap_token_send(fd, "UNSEEN");
+      
+    case MAILIMAP_SEARCH_KEY_DRAFT:
+      return mailimap_token_send(fd, "DRAFT");
+      
+    case MAILIMAP_SEARCH_KEY_HEADER:
+      r = mailimap_token_send(fd, "HEADER");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_header_fld_name_send(fd, key->sk_data.sk_header.sk_header_name);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_astring_literalplus_send(fd, key->sk_data.sk_header.sk_header_value,
+                                            literalplus_enabled);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_LARGER:
+      r = mailimap_token_send(fd, "LARGER");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_number_send(fd, key->sk_data.sk_larger);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_NOT:
+      r = mailimap_token_send(fd, "NOT");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_search_key_send(fd, key->sk_data.sk_not);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_OR:
+      r = mailimap_token_send(fd, "OR");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
       r = mailimap_space_send(fd);
       if (r != MAILIMAP_NO_ERROR)
         return r;
+      r = mailimap_search_key_send(fd, key->sk_data.sk_or.sk_or1);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_search_key_send(fd, key->sk_data.sk_or.sk_or2);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_SENTBEFORE:
+      r = mailimap_token_send(fd, "SENTBEFORE");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_date_send(fd, key->sk_data.sk_sentbefore);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_SENTON:
+      r = mailimap_token_send(fd, "SENTON");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_date_send(fd, key->sk_data.sk_senton);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_SENTSINCE:
+      r = mailimap_token_send(fd, "SENTSINCE");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_date_send(fd, key->sk_data.sk_sentsince);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_SMALLER:
+      r = mailimap_token_send(fd, "SMALLER");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_number_send(fd, key->sk_data.sk_smaller);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_UID:
+      r = mailimap_token_send(fd, "UID");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_set_send(fd, key->sk_data.sk_set);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_UNDRAFT:
+      return mailimap_token_send(fd, "UNDRAFT");
+      
+    case MAILIMAP_SEARCH_KEY_SET:
+      return mailimap_set_send(fd, key->sk_data.sk_set);
+      
+    case MAILIMAP_SEARCH_KEY_XGMTHRID:
+      r = mailimap_token_send(fd, "X-GM-THRID");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_uint64_send(fd, key->sk_data.sk_xgmthrid);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_XGMMSGID:
+      r = mailimap_token_send(fd, "X-GM-MSGID");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_uint64_send(fd, key->sk_data.sk_xgmmsgid);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_XGMRAW:
+      r = mailimap_token_send(fd, "X-GM-RAW");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      r = mailimap_quoted_send(fd, key->sk_data.sk_xgmraw);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      return MAILIMAP_NO_ERROR;
+      
+    case MAILIMAP_SEARCH_KEY_MULTIPLE:
+      r = mailimap_oparenth_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      
+      r = mailimap_struct_spaced_list_send(fd, key->sk_data.sk_multiple,
+                                           (mailimap_struct_sender *) mailimap_search_key_send);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      
+      r = mailimap_cparenth_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      
+      return MAILIMAP_NO_ERROR;
+    case MAILIMAP_SEARCH_KEY_MODSEQ:
+      r = mailimap_token_send(fd, "MODSEQ");
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      
+      if (key->sk_data.sk_modseq.sk_entry_name != NULL) {
+        r = mailimap_space_send(fd);
+        if (r != MAILIMAP_NO_ERROR)
+          return r;
         
-      switch (key->sk_data.sk_modseq.sk_entry_type_req) {
-      	case MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_PRIV:
-          r = mailimap_token_send(fd, "priv");
-          if (r != MAILIMAP_NO_ERROR)
-            return r;
-          break;
-      	case MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_SHARED:
-          r = mailimap_token_send(fd, "shared");
-          if (r != MAILIMAP_NO_ERROR)
-            return r;
-          break;
-      	case MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_ALL:
-          r = mailimap_token_send(fd, "all");
+        mailimap_dquote_send(fd);
+        r = mailimap_token_send(fd, "/flags/");
+        if (r != MAILIMAP_NO_ERROR)
+          return r;
+        if (key->sk_data.sk_modseq.sk_entry_name->fl_type != MAILIMAP_FLAG_KEYWORD) {
+          r = mailimap_token_send(fd, "\\");
           if (r != MAILIMAP_NO_ERROR)
             return r;
-          break;
+        }
+        r = mailimap_flag_send(fd, key->sk_data.sk_modseq.sk_entry_name);
+        if (r != MAILIMAP_NO_ERROR)
+          return r;
+        mailimap_dquote_send(fd);
+        
+        r = mailimap_space_send(fd);
+        if (r != MAILIMAP_NO_ERROR)
+          return r;
+        
+        switch (key->sk_data.sk_modseq.sk_entry_type_req) {
+          case MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_PRIV:
+            r = mailimap_token_send(fd, "priv");
+            if (r != MAILIMAP_NO_ERROR)
+              return r;
+            break;
+          case MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_SHARED:
+            r = mailimap_token_send(fd, "shared");
+            if (r != MAILIMAP_NO_ERROR)
+              return r;
+            break;
+          case MAILIMAP_SEARCH_KEY_MODSEQ_ENTRY_TYPE_REQ_ALL:
+            r = mailimap_token_send(fd, "all");
+            if (r != MAILIMAP_NO_ERROR)
+              return r;
+            break;
+        }
       }
-    }
-    
-    r = mailimap_space_send(fd);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    
-    r = mailimap_mod_sequence_value_send(fd, key->sk_data.sk_modseq.sk_modseq_valzer);
-    if (r != MAILIMAP_NO_ERROR)
-      return r;
-    
-    return MAILIMAP_NO_ERROR;
-   
-  default:
-    /* should not happend */
-    return MAILIMAP_ERROR_INVAL;
+      
+      r = mailimap_space_send(fd);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      
+      r = mailimap_mod_sequence_value_send(fd, key->sk_data.sk_modseq.sk_modseq_valzer);
+      if (r != MAILIMAP_NO_ERROR)
+        return r;
+      
+      return MAILIMAP_NO_ERROR;
+      
+    default:
+      /* should not happend */
+      return MAILIMAP_ERROR_INVAL;
   }
 }
 
+int mailimap_search_key_send(mailstream * fd,
+                             struct mailimap_search_key * key)
+{
+  return search_key_send(fd, key, 0);
+}
+
+int mailimap_search_key_literalplus_send(mailstream * fd,
+                                         struct mailimap_search_key * key)
+{
+  return search_key_send(fd, key, 1);
+}
+
 int mailimap_mod_sequence_value_send(mailstream * fd, uint64_t number)
 {
   return mailimap_uint64_send(fd, number);
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_sender.h libetpan-1.6/src/low-level/imap/mailimap_sender.h
--- libetpan-1.5/src/low-level/imap/mailimap_sender.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_sender.h	2014-10-31 22:41:02.000000000 +0100
@@ -118,10 +118,18 @@
 mailimap_uid_search_send(mailstream * fd, const char * charset,
 			 struct mailimap_search_key * key);
 
+int mailimap_search_literalplus_send(mailstream * fd, const char * charset,
+                                     struct mailimap_search_key * key);
+
+int mailimap_uid_search_literalplus_send(mailstream * fd, const char * charset,
+                                         struct mailimap_search_key * key);
 
 int mailimap_search_key_send(mailstream * fd,
                              struct mailimap_search_key * key);
-  
+
+int mailimap_search_key_literalplus_send(mailstream * fd,
+                                         struct mailimap_search_key * key);
+
 int
 mailimap_select_send(mailstream * fd, const char * mb, int condstore);
 
@@ -157,15 +165,15 @@
 		      progress_function * progr_fun);
 
 int
-mailimap_literal_count_send(mailstream * fd, uint32_t count);
+mailimap_literal_count_send(mailstream * fd, size_t count);
 
 int
-mailimap_literal_data_send(mailstream * fd, const char * literal, uint32_t len,
+mailimap_literal_data_send(mailstream * fd, const char * literal, size_t len,
 			   size_t progr_rate,
 			   progress_function * progr_fun);
 
 int
-mailimap_literal_data_send_with_context(mailstream * fd, const char * literal, uint32_t len,
+mailimap_literal_data_send_with_context(mailstream * fd, const char * literal, size_t len,
                                         mailprogress_function * progr_fun,
                                         void * context);
 
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_sort.c libetpan-1.6/src/low-level/imap/mailimap_sort.c
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_sort_types.c libetpan-1.6/src/low-level/imap/mailimap_sort_types.c
diff -Nru libetpan-1.5/src/low-level/imap/mailimap_ssl.c libetpan-1.6/src/low-level/imap/mailimap_ssl.c
--- libetpan-1.5/src/low-level/imap/mailimap_ssl.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/mailimap_ssl.c	2014-10-31 22:41:02.000000000 +0100
@@ -137,5 +137,5 @@
 
 static int mailimap_cfssl_connect_voip(mailimap * f, const char * server, uint16_t port, int voip_enabled)
 {
-    return mailimap_cfssl_connect_voip_ssl_level(f, server, port, voip_enabled, MAILSTREAM_CFSTREAM_SSL_LEVEL_SSLv3);
+    return mailimap_cfssl_connect_voip_ssl_level(f, server, port, voip_enabled, MAILSTREAM_CFSTREAM_SSL_LEVEL_NEGOCIATED_SSL);
 }
diff -Nru libetpan-1.5/src/low-level/imap/qresync.c libetpan-1.6/src/low-level/imap/qresync.c
--- libetpan-1.5/src/low-level/imap/qresync.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/qresync.c	2014-10-31 22:41:02.000000000 +0100
@@ -304,8 +304,10 @@
     if (* fetch_result != NULL) {
       mailimap_fetch_list_free(* fetch_result);
     }
-    if (* p_vanished != NULL) {
-      mailimap_qresync_vanished_free(* p_vanished);
+    if (p_vanished != NULL) {
+      if (* p_vanished != NULL) {
+        mailimap_qresync_vanished_free(* p_vanished);
+      }
     }
     return MAILIMAP_ERROR_SELECT;
   }
diff -Nru libetpan-1.5/src/low-level/imap/uidplus.c libetpan-1.6/src/low-level/imap/uidplus.c
--- libetpan-1.5/src/low-level/imap/uidplus.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/uidplus.c	2014-10-31 22:41:02.000000000 +0100
@@ -252,7 +252,7 @@
 
 LIBETPAN_EXPORT
 int mailimap_uidplus_append_simple(mailimap * session, const char * mailbox,
-    const char * content, uint32_t size,
+    const char * content, size_t size,
     uint32_t * uidvalidity_result,
     uint32_t * uid_result)
 {
diff -Nru libetpan-1.5/src/low-level/imap/uidplus.h libetpan-1.6/src/low-level/imap/uidplus.h
--- libetpan-1.5/src/low-level/imap/uidplus.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/uidplus.h	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #ifndef UIDPLUS_H
 
 #define UIDPLUS_H
@@ -40,7 +70,7 @@
 
 LIBETPAN_EXPORT
 int mailimap_uidplus_append_simple(mailimap * session, const char * mailbox,
-    const char * content, uint32_t size,
+    const char * content, size_t size,
     uint32_t * uidvalidity_result,
     uint32_t * uid_result);
 
diff -Nru libetpan-1.5/src/low-level/imap/uidplus_parser.c libetpan-1.6/src/low-level/imap/uidplus_parser.c
--- libetpan-1.5/src/low-level/imap/uidplus_parser.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/uidplus_parser.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "uidplus_parser.h"
 
 #include <stdio.h>
diff -Nru libetpan-1.5/src/low-level/imap/uidplus_parser.h libetpan-1.6/src/low-level/imap/uidplus_parser.h
--- libetpan-1.5/src/low-level/imap/uidplus_parser.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/uidplus_parser.h	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #ifndef UIDPLUS_PARSER_H
 
 #define UIDPLUS_PARSER_H
diff -Nru libetpan-1.5/src/low-level/imap/uidplus_sender.c libetpan-1.6/src/low-level/imap/uidplus_sender.c
--- libetpan-1.5/src/low-level/imap/uidplus_sender.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/uidplus_sender.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "uidplus_sender.h"
 
 #include "mailimap_sender.h"
diff -Nru libetpan-1.5/src/low-level/imap/uidplus_sender.h libetpan-1.6/src/low-level/imap/uidplus_sender.h
--- libetpan-1.5/src/low-level/imap/uidplus_sender.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/uidplus_sender.h	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #ifndef UIDPLUS_SENDER_H
 
 #define UIDPLUS_SENDER_H
diff -Nru libetpan-1.5/src/low-level/imap/uidplus_types.c libetpan-1.6/src/low-level/imap/uidplus_types.c
--- libetpan-1.5/src/low-level/imap/uidplus_types.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/uidplus_types.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "uidplus_types.h"
 
 #include <stdio.h>
diff -Nru libetpan-1.5/src/low-level/imap/uidplus_types.h libetpan-1.6/src/low-level/imap/uidplus_types.h
--- libetpan-1.5/src/low-level/imap/uidplus_types.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/uidplus_types.h	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #ifndef UIDPLUS_TYPES_H
 
 #define UIDPLUS_TYPES_H
diff -Nru libetpan-1.5/src/low-level/imap/xgmmsgid.c libetpan-1.6/src/low-level/imap/xgmmsgid.c
--- libetpan-1.5/src/low-level/imap/xgmmsgid.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/xgmmsgid.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "xgmmsgid.h"
 
 #include <string.h>
diff -Nru libetpan-1.5/src/low-level/imap/xgmmsgid.h libetpan-1.6/src/low-level/imap/xgmmsgid.h
--- libetpan-1.5/src/low-level/imap/xgmmsgid.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/xgmmsgid.h	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #ifndef XGMMSGID_H
 #define XGMMSGID_H
 
diff -Nru libetpan-1.5/src/low-level/imap/xgmthrid.c libetpan-1.6/src/low-level/imap/xgmthrid.c
--- libetpan-1.5/src/low-level/imap/xgmthrid.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/xgmthrid.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "xgmthrid.h"
 
 #include <string.h>
diff -Nru libetpan-1.5/src/low-level/imap/xgmthrid.h libetpan-1.6/src/low-level/imap/xgmthrid.h
--- libetpan-1.5/src/low-level/imap/xgmthrid.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/xgmthrid.h	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #ifndef XGMTHRID_H
 #define XGMTHRID_H
 
diff -Nru libetpan-1.5/src/low-level/imap/xlist.c libetpan-1.6/src/low-level/imap/xlist.c
--- libetpan-1.5/src/low-level/imap/xlist.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imap/xlist.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,12 +1,33 @@
 /*
- *  xlist.c
- *  libetpan
+ * libEtPan! -- a mail stuff library
  *
- *  Created by DINH Viêt Hoà on 30/3/11.
- *  Copyright 2011 __MyCompanyName__. All rights reserved.
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
  *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
-
 #include "xlist.h"
 
 #include <stdlib.h>
diff -Nru libetpan-1.5/src/low-level/imf/mailimf.c libetpan-1.6/src/low-level/imf/mailimf.c
--- libetpan-1.5/src/low-level/imf/mailimf.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imf/mailimf.c	2014-10-31 22:41:02.000000000 +0100
@@ -55,6 +55,7 @@
 #include "mmapstring.h"
 #include <stdlib.h>
 #include <string.h>
+#include "mailmime_decode.h"
 
 #ifndef TRUE
 #define TRUE 1
@@ -1216,6 +1217,56 @@
   return res;
 }
 
+int mailimf_fws_atom_for_word_parse(const char * message, size_t length,
+                                    size_t * indx, char ** result)
+{
+  size_t end;
+  size_t cur_token;
+  int r;
+  int res;
+  struct mailmime_encoded_word * word;
+  int has_fwd;
+  char * atom;
+  
+  cur_token = * indx;
+  
+  r = mailimf_fws_parse(message, length, &cur_token);
+  if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
+    res = r;
+    goto err;
+  }
+  
+  end = cur_token;
+  
+  r = mailmime_encoded_word_parse(message, length, &cur_token, &word, &has_fwd);
+  if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
+    res = r;
+    goto err;
+  }
+  
+  if (r == MAILIMF_ERROR_PARSE) {
+    return mailimf_fws_atom_parse(message, length, indx, result);
+  }
+  
+  mailmime_encoded_word_free(word);
+  
+  atom = malloc(cur_token - end + 1);
+  if (atom == NULL) {
+    res = MAILIMF_ERROR_MEMORY;
+    goto err;
+  }
+  strncpy(atom, message + end, cur_token - end);
+  atom[cur_token - end] = '\0';
+  
+  * result = atom;
+  * indx = cur_token;
+  
+  return MAILIMF_NO_ERROR;
+  
+err:
+  return res;
+}
+
 int mailimf_fws_atom_parse(const char * message, size_t length,
 			   size_t * indx, char ** result)
 {
@@ -1590,7 +1641,7 @@
 
   cur_token = * indx;
 
-  r = mailimf_fws_atom_parse(message, length, &cur_token, &word);
+  r = mailimf_fws_atom_for_word_parse(message, length, &cur_token, &word);
 
   if (r == MAILIMF_ERROR_PARSE)
     r = mailimf_fws_quoted_string_parse(message, length, &cur_token, &word);
@@ -6379,6 +6430,7 @@
     goto err;
   }
 
+  addr_list = NULL;
   r = mailimf_address_list_parse(message, length, &cur_token, &addr_list);
   if ((r != MAILIMF_NO_ERROR) && (r != MAILIMF_ERROR_PARSE)) {
     res = r;
diff -Nru libetpan-1.5/src/low-level/imf/mailimf_types_helper.c libetpan-1.6/src/low-level/imf/mailimf_types_helper.c
--- libetpan-1.5/src/low-level/imf/mailimf_types_helper.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imf/mailimf_types_helper.c	2014-10-31 22:41:02.000000000 +0100
@@ -1306,7 +1306,7 @@
   if (localtime_r(&t, &lt) == NULL)
     return NULL;
 
-  off = (mail_mkgmtime(&lt) - mail_mkgmtime(&gmt)) * 100 / (60 * 60);
+  off = (int) ((mail_mkgmtime(&lt) - mail_mkgmtime(&gmt)) * 100 / (60 * 60));
 
   date_time = mailimf_date_time_new(lt.tm_mday, lt.tm_mon + 1, lt.tm_year + 1900,
 				    lt.tm_hour, lt.tm_min, lt.tm_sec,
diff -Nru libetpan-1.5/src/low-level/imf/mailimf_write_file.c libetpan-1.6/src/low-level/imf/mailimf_write_file.c
--- libetpan-1.5/src/low-level/imf/mailimf_write_file.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imf/mailimf_write_file.c	2014-10-31 22:41:02.000000000 +0100
@@ -42,7 +42,7 @@
   
   f = data;
   
-  return fwrite(str, 1, length, f);
+  return (int) fwrite(str, 1, length, f);
 }
 
 LIBETPAN_EXPORT
diff -Nru libetpan-1.5/src/low-level/imf/mailimf_write_mem.c libetpan-1.6/src/low-level/imf/mailimf_write_mem.c
--- libetpan-1.5/src/low-level/imf/mailimf_write_mem.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imf/mailimf_write_mem.c	2014-10-31 22:41:02.000000000 +0100
@@ -45,7 +45,7 @@
   if (mmap_string_append_len(f, str, length) == NULL)
     return 0;
   else
-    return length;
+    return (int) length;
 }
 
 int mailimf_string_write_mem(MMAPString * f, int * col,
diff -Nru libetpan-1.5/src/low-level/imf/Makefile.am libetpan-1.6/src/low-level/imf/Makefile.am
--- libetpan-1.5/src/low-level/imf/Makefile.am	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imf/Makefile.am	2014-10-31 22:41:02.000000000 +0100
@@ -37,7 +37,8 @@
 	mailimf_write_generic.h mailimf_write_mem.h
 
 AM_CPPFLAGS = -I$(top_builddir)/include \
-	-I$(top_srcdir)/src/data-types
+	-I$(top_srcdir)/src/data-types \
+  -I$(top_srcdir)/src/low-level/mime
 
 noinst_LTLIBRARIES = libimf.la
 
diff -Nru libetpan-1.5/src/low-level/imf/Makefile.in libetpan-1.6/src/low-level/imf/Makefile.in
--- libetpan-1.5/src/low-level/imf/Makefile.in	2014-06-11 12:21:32.000000000 +0200
+++ libetpan-1.6/src/low-level/imf/Makefile.in	2014-11-28 12:14:05.000000000 +0100
@@ -382,7 +382,8 @@
 	mailimf_write_generic.h mailimf_write_mem.h
 
 AM_CPPFLAGS = -I$(top_builddir)/include \
-	-I$(top_srcdir)/src/data-types
+	-I$(top_srcdir)/src/data-types \
+  -I$(top_srcdir)/src/low-level/mime
 
 noinst_LTLIBRARIES = libimf.la
 libimf_la_SOURCES = \
diff -Nru libetpan-1.5/src/low-level/maildir/maildir.c libetpan-1.6/src/low-level/maildir/maildir.c
--- libetpan-1.5/src/low-level/maildir/maildir.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/maildir/maildir.c	2014-10-31 22:41:02.000000000 +0100
@@ -280,7 +280,7 @@
       chashdatum key;
       
       key.data = msg->msg_uid;
-      key.len = strlen(msg->msg_uid);
+      key.len = (unsigned int) strlen(msg->msg_uid);
       chash_delete(md->mdir_msg_hash, &key, NULL);
       
       carray_delete(md->mdir_msg_list, i);
@@ -315,7 +315,7 @@
   }
   
   key.data = msg->msg_uid;
-  key.len = strlen(msg->msg_uid);
+  key.len = (unsigned int) strlen(msg->msg_uid);
   value.data = msg;
   value.len = 0;
   
@@ -654,7 +654,7 @@
   int r;
   
   key.data = (void *) uid;
-  key.len = strlen(uid);
+  key.len = (unsigned int) strlen(uid);
   r = chash_get(md->mdir_msg_hash, &key, &value);
   if (r < 0)
     return NULL;
@@ -686,7 +686,7 @@
   int res;
 
   key.data = (void *) uid;
-  key.len = strlen(uid);
+  key.len = (unsigned int) strlen(uid);
   r = chash_get(md->mdir_msg_hash, &key, &value);
   if (r < 0) {
     res = MAILDIR_ERROR_NOT_FOUND;
@@ -730,7 +730,7 @@
   char * dup_filename;
 
   key.data = (void *) uid;
-  key.len = strlen(uid);
+  key.len = (unsigned int) strlen(uid);
   r = chash_get(md->mdir_msg_hash, &key, &value);
   if (r < 0) {
     res = MAILDIR_ERROR_NOT_FOUND;
diff -Nru libetpan-1.5/src/low-level/mbox/mailmbox.c libetpan-1.6/src/low-level/mbox/mailmbox.c
--- libetpan-1.5/src/low-level/mbox/mailmbox.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mbox/mailmbox.c	2014-10-31 22:41:02.000000000 +0100
@@ -1165,10 +1165,10 @@
 {
   int r;
   int res;
-  unsigned long i;
   size_t cur_offset;
   char * dest;
   size_t size;
+  int i;
 
   size = 0;
   for(i = 0 ; i < carray_count(folder->mb_tab) ; i ++) {
diff -Nru libetpan-1.5/src/low-level/mbox/mailmbox_parse.c libetpan-1.6/src/low-level/mbox/mailmbox_parse.c
--- libetpan-1.5/src/low-level/mbox/mailmbox_parse.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mbox/mailmbox_parse.c	2014-10-31 22:41:02.000000000 +0100
@@ -73,7 +73,7 @@
   size_t cur_token;
   int r;
   size_t hlen;
-  size_t uid;
+  uint32_t uid;
   int end;
 
   cur_token = * indx;
@@ -96,7 +96,7 @@
 	  while (str[begin] == ' ')
 	    begin ++;
 	  
-	  uid = strtoul(str + begin, NULL, 10);
+	  uid = (uint32_t) strtoul(str + begin, NULL, 10);
 	}
       }
       
diff -Nru libetpan-1.5/src/low-level/mh/mailmh.c libetpan-1.6/src/low-level/mh/mailmh.c
--- libetpan-1.5/src/low-level/mh/mailmh.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mh/mailmh.c	2014-10-31 22:41:02.000000000 +0100
@@ -253,7 +253,7 @@
   }
   else {
     key.data = pathname;
-    key.len = strlen(pathname);
+    key.len = (unsigned int) strlen(pathname);
     r = chash_get(root->fl_subfolders_hash, &key, &data);
     if (r < 0)
       return NULL;
@@ -327,7 +327,7 @@
 	continue;
 
       if (S_ISREG(buf.st_mode)) {
-	indx = strtoul(ent->d_name, NULL, 10);
+	indx = (uint32_t) strtoul(ent->d_name, NULL, 10);
 	if (indx != 0) {
 	  struct mailmh_msg_info * msg_info;
 	  unsigned int array_index;
@@ -379,7 +379,7 @@
 	}
 
 	key.data = ent->d_name;
-	key.len = strlen(ent->d_name);
+	key.len = (unsigned int) strlen(ent->d_name);
 	r = chash_get(folder->fl_subfolders_hash, &key, &data);
 	if (r < 0) {
 	  subfolder = mailmh_folder_new(folder, ent->d_name);
@@ -397,7 +397,7 @@
 	  subfolder->fl_array_index = array_index;
 	  
 	  key.data = subfolder->fl_filename;
-	  key.len = strlen(subfolder->fl_filename);
+	  key.len = (unsigned int) strlen(subfolder->fl_filename);
 	  data.data = subfolder;
 	  data.len = 0;
 	  r = chash_set(folder->fl_subfolders_hash, &key, &data, NULL);
@@ -482,7 +482,7 @@
   folder->fl_array_index = array_index;
 
   key.data = folder->fl_filename;
-  key.len = strlen(folder->fl_filename);
+  key.len = (unsigned int) strlen(folder->fl_filename);
   data.data = folder;
   data.len = 0;
 
@@ -506,7 +506,7 @@
   parent = folder->fl_parent;
 
   key.data = folder->fl_filename;
-  key.len = strlen(folder->fl_filename);
+  key.len = (unsigned int) strlen(folder->fl_filename);
   
   r = chash_get(parent->fl_subfolders_hash, &key, &data);
   if (r < 0)
@@ -637,7 +637,7 @@
 				       uint32_t indx, char ** result)
 {
   char * filename;
-  int len;
+  size_t len;
 
   len = strlen(folder->fl_filename) + 20;
   filename = malloc(len);
@@ -833,6 +833,7 @@
   chashdatum key;
   chashdatum data;
 
+  filename = NULL;
   r = mailmh_folder_get_message_filename(folder, indx, &filename);
   if (filename == NULL) {
     res = r;
diff -Nru libetpan-1.5/src/low-level/mime/mailmime.c libetpan-1.6/src/low-level/mime/mailmime.c
--- libetpan-1.5/src/low-level/mime/mailmime.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mime/mailmime.c	2014-10-31 22:41:02.000000000 +0100
@@ -1301,7 +1301,7 @@
 {
   int r;
 
-  r = mailmime_token_parse(message, length, indx, result);
+  r = mailimf_atom_parse(message, length, indx, result);
 
   if (r == MAILIMF_ERROR_PARSE)
     r = mailimf_quoted_string_parse(message, length, indx, result);
diff -Nru libetpan-1.5/src/low-level/mime/mailmime_content.c libetpan-1.6/src/low-level/mime/mailmime_content.c
--- libetpan-1.5/src/low-level/mime/mailmime_content.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mime/mailmime_content.c	2014-10-31 22:41:02.000000000 +0100
@@ -1171,7 +1171,7 @@
   /* XXX - this should be unquoted properly, should use
      mailimf_quoted_string_parse() */
   if (boundary != NULL) {
-    int len;
+    size_t len;
     char * new_boundary;
 
     len = strlen(boundary);
diff -Nru libetpan-1.5/src/low-level/mime/mailmime_decode.c libetpan-1.6/src/low-level/mime/mailmime_decode.c
--- libetpan-1.5/src/low-level/mime/mailmime_decode.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mime/mailmime_decode.c	2014-10-31 22:41:02.000000000 +0100
@@ -87,12 +87,7 @@
                                 size_t * indx,
                                 char ** result, int * p_has_fwd);
 
-static int
-mailmime_encoded_word_parse(const char * message, size_t length,
-                            size_t * indx,
-                            struct mailmime_encoded_word ** result,
-                            int * p_has_fwd);
-     
+    
 
 enum {
   TYPE_ERROR,
@@ -368,10 +363,10 @@
   return res;
 }
 
-static int mailmime_encoded_word_parse(const char * message, size_t length,
-                                       size_t * indx,
-                                       struct mailmime_encoded_word ** result,
-                                       int * p_has_fwd)
+int mailmime_encoded_word_parse(const char * message, size_t length,
+                                size_t * indx,
+                                struct mailmime_encoded_word ** result,
+                                int * p_has_fwd)
 {
   size_t cur_token;
   char * charset;
diff -Nru libetpan-1.5/src/low-level/mime/mailmime_decode.h libetpan-1.6/src/low-level/mime/mailmime_decode.h
--- libetpan-1.5/src/low-level/mime/mailmime_decode.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mime/mailmime_decode.h	2014-10-31 22:41:02.000000000 +0100
@@ -49,6 +49,12 @@
     size_t * indx, const char * tocode,
     char ** result);
 
+int
+mailmime_encoded_word_parse(const char * message, size_t length,
+                            size_t * indx,
+                            struct mailmime_encoded_word ** result,
+                            int * p_has_fwd);
+
 #ifdef __cplusplus
 }
 #endif
diff -Nru libetpan-1.5/src/low-level/mime/mailmime_types_helper.c libetpan-1.6/src/low-level/mime/mailmime_types_helper.c
--- libetpan-1.5/src/low-level/mime/mailmime_types_helper.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mime/mailmime_types_helper.c	2014-10-31 22:41:02.000000000 +0100
@@ -1396,3 +1396,32 @@
   return mailmime_data_new(MAILMIME_DATA_FILE, encoding, encoded, NULL, 0, filename);
 }
 
+
+struct mailmime_parameter *
+mailmime_param_new_with_data(char * name, char * value)
+{
+  char * param_name;
+  char * param_value;
+  struct mailmime_parameter * param;
+
+  param_name = strdup(name);
+  if (param_name == NULL)
+    goto err;
+  
+  param_value = strdup(value);
+  if (param_value == NULL)
+    goto free_name;
+  
+  param = mailmime_parameter_new(param_name, param_value);
+  if (param == NULL)
+    goto free_value;
+  
+  return param;
+  
+ free_value:
+  free(param_value);
+ free_name:
+  free(param_name);
+ err:
+  return NULL;
+}
diff -Nru libetpan-1.5/src/low-level/mime/mailmime_types_helper.h libetpan-1.6/src/low-level/mime/mailmime_types_helper.h
--- libetpan-1.5/src/low-level/mime/mailmime_types_helper.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mime/mailmime_types_helper.h	2014-10-31 22:41:02.000000000 +0100
@@ -191,6 +191,10 @@
     char * filename, int encoding_type);
 
 LIBETPAN_EXPORT
+struct mailmime_parameter *
+mailmime_param_new_with_data(char * name, char * value);
+
+LIBETPAN_EXPORT
 char * mailmime_generate_boundary(void);
 
 #ifdef __cplusplus
diff -Nru libetpan-1.5/src/low-level/mime/mailmime_write_file.c libetpan-1.6/src/low-level/mime/mailmime_write_file.c
--- libetpan-1.5/src/low-level/mime/mailmime_write_file.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mime/mailmime_write_file.c	2014-10-31 22:41:02.000000000 +0100
@@ -62,7 +62,7 @@
   
   f = data;
   
-  return fwrite(str, 1, length, f);
+  return (int) fwrite(str, 1, length, f);
 }
 
 
diff -Nru libetpan-1.5/src/low-level/mime/mailmime_write_generic.c libetpan-1.6/src/low-level/mime/mailmime_write_generic.c
--- libetpan-1.5/src/low-level/mime/mailmime_write_generic.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/mime/mailmime_write_generic.c	2014-10-31 22:41:02.000000000 +0100
@@ -859,6 +859,12 @@
         goto free_boundary;
       }
 
+      if (boundary == NULL) {
+        // Make clang static analyzer happy.
+        res = MAILIMF_ERROR_MEMORY;
+        goto free_boundary;
+      }
+      
       r = mailimf_string_write_driver(do_write, data, col, boundary, strlen(boundary));
       if (r != MAILIMF_NO_ERROR) {
         res = r;
@@ -890,6 +896,12 @@
       goto free_boundary;
     }
     
+    if (boundary == NULL) {
+      // Make clang static analyzer happy.
+      res = MAILIMF_ERROR_MEMORY;
+      goto free_boundary;
+    }
+    
     r = mailimf_string_write_driver(do_write, data, col, boundary, strlen(boundary));
     if (r != MAILIMF_NO_ERROR) {
       res = r;
@@ -1323,7 +1335,6 @@
             
           case '\r':
             state = STATE_CR;
-            len ++;
             i ++;
             break;
             
diff -Nru libetpan-1.5/src/low-level/nntp/newsnntp.c libetpan-1.6/src/low-level/nntp/newsnntp.c
--- libetpan-1.5/src/low-level/nntp/newsnntp.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/nntp/newsnntp.c	2014-10-31 22:41:02.000000000 +0100
@@ -108,7 +108,9 @@
     goto free_stream_buffer;
 
 	f->nntp_timeout = 0;
-
+	f->nntp_progress_fun = NULL;
+	f->nntp_progress_context = NULL;
+  
   f->nntp_logger = NULL;
   f->nntp_logger_context = NULL;
 
@@ -520,7 +522,7 @@
 
 /* ******************** POST ******************************** */
 
-static void send_data(newsnntp * f, const char * message, uint32_t size)
+static void send_data(newsnntp * f, const char * message, size_t size)
 {
   mailstream_send_data(f->nntp_stream, message, size,
 		       f->nntp_progr_rate, f->nntp_progr_fun);
@@ -1360,6 +1362,9 @@
     return NEWSNNTP_ERROR_STREAM;
 
   r = parse_response(f, response);
+  if (f->nntp_response == NULL) {
+    return NEWSNNTP_ERROR_UNEXPECTED_RESPONSE;
+  }
 
   switch (r) {
   case 111:
@@ -1812,7 +1817,7 @@
 {
   int code;
 
-  code = strtol(response, &response, 10);
+  code = (int) strtol(response, &response, 10);
 
   if (response == NULL) {
     f->nntp_response = NULL;
@@ -1840,7 +1845,7 @@
 {
   return mailstream_read_multiline(f->nntp_stream, size,
 				   f->nntp_stream_buffer, multiline_buffer,
-				   f->nntp_progr_rate, f->nntp_progr_fun, NULL, NULL);
+				   f->nntp_progr_rate, f->nntp_progr_fun, f->nntp_progress_fun, f->nntp_progress_context);
 }
 
 
@@ -1861,15 +1866,15 @@
 
   line = response;
 
-  count = strtoul(line, &line, 10);
+  count = (uint32_t) strtoul(line, &line, 10);
   if (!parse_space(&line))
     return FALSE;
 
-  first = strtoul(line, &line, 10);
+  first = (uint32_t) strtoul(line, &line, 10);
   if (!parse_space(&line))
     return FALSE;
 
-  last = strtoul(line, &line, 10);
+  last = (uint32_t) strtoul(line, &line, 10);
   if (!parse_space(&line))
     return FALSE;
 
@@ -1918,11 +1923,11 @@
     group_name = line;
     line = p;
 
-    last = strtol(line, &line, 10);
+    last = (uint32_t)strtol(line, &line, 10);
     if (!parse_space(&line))
       continue;
 
-    first = strtol(line, &line, 10);
+    first = (uint32_t)strtol(line, &line, 10);
     if (!parse_space(&line))
       continue;
 
@@ -2133,7 +2138,7 @@
 
     p = line;
 
-    weight = strtoul(p, &remaining, 10);
+    weight = (uint32_t)strtoul(p, &remaining, 10);
     p = remaining;
     parse_space(&p);
       
@@ -2319,7 +2324,7 @@
     if (mailstream_is_end_multiline(line))
       break;
     
-    article = strtoul(line, &line, 10);
+    article = (uint32_t) strtoul(line, &line, 10);
     if (!parse_space(&line))
       continue;
     
@@ -2555,10 +2560,15 @@
   session->nntp_logger(session, log_type, str, size, session->nntp_logger_context);
 }
 
-LIBETPAN_EXPORT
 void newsnntp_set_logger(newsnntp * session, void (* logger)(newsnntp * session, int log_type,
     const char * str, size_t size, void * context), void * logger_context)
 {
   session->nntp_logger = logger;
   session->nntp_logger_context = logger_context;
 }
+
+void newsnntp_set_progress_callback(newsnntp * f, mailprogress_function * progr_fun, void * context)
+{
+	f->nntp_progress_fun = progr_fun;
+	f->nntp_progress_context = context;
+}
diff -Nru libetpan-1.5/src/low-level/nntp/newsnntp.h libetpan-1.6/src/low-level/nntp/newsnntp.h
--- libetpan-1.5/src/low-level/nntp/newsnntp.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/nntp/newsnntp.h	2014-10-31 22:41:02.000000000 +0100
@@ -84,7 +84,7 @@
 void newsnntp_free(newsnntp * session);
 
 /*
-   newsnntp_set_logger() get the network timeout of the NNTP session.
+   newsnntp_set_logger() set a logger for the connection.
    
    @param session         NNTP session
    @param logger          logger function. See mailstream_types.h to know possible log_type values.
@@ -97,6 +97,15 @@
 void newsnntp_set_logger(newsnntp * session, void (* logger)(newsnntp * session, int log_type,
                                                              const char * str, size_t size, void * context), void * logger_context);
 
+/*
+   newsnntp_set_progress_callback() set NNTP progression callbacks.
+   
+   @param session           NNTP session
+   @param progr_fun         callback function.
+*/
+
+LIBETPAN_EXPORT
+void newsnntp_set_progress_callback(newsnntp * f, mailprogress_function * progr_fun, void * context);
 
 /*
    newsnntp_set_timeout() set the network timeout of the NNTP session.
diff -Nru libetpan-1.5/src/low-level/nntp/newsnntp_ssl.c libetpan-1.6/src/low-level/nntp/newsnntp_ssl.c
--- libetpan-1.5/src/low-level/nntp/newsnntp_ssl.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/nntp/newsnntp_ssl.c	2014-10-31 22:41:02.000000000 +0100
@@ -123,6 +123,6 @@
 
 static int newsnntp_cfssl_connect(newsnntp * f, const char * server, uint16_t port)
 {
-    return newsnntp_cfssl_connect_ssl_level(f, server, port, MAILSTREAM_CFSTREAM_SSL_LEVEL_SSLv3);
+    return newsnntp_cfssl_connect_ssl_level(f, server, port, MAILSTREAM_CFSTREAM_SSL_LEVEL_NEGOCIATED_SSL);
 }
 
diff -Nru libetpan-1.5/src/low-level/nntp/newsnntp_types.h libetpan-1.6/src/low-level/nntp/newsnntp_types.h
--- libetpan-1.5/src/low-level/nntp/newsnntp_types.h	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/nntp/newsnntp_types.h	2014-10-31 22:41:02.000000000 +0100
@@ -83,7 +83,7 @@
 
   int nntp_readonly;
 
-  uint32_t nntp_progr_rate;
+  size_t nntp_progr_rate;
   progress_function * nntp_progr_fun;
   
   MMAPString * nntp_stream_buffer;
@@ -95,6 +95,9 @@
   
   void (* nntp_logger)(newsnntp * session, int log_type, const char * str, size_t size, void * context);
   void * nntp_logger_context;
+  
+  mailprogress_function * nntp_progress_fun;
+  void * nntp_progress_context;
 };
 
 struct newsnntp_group_info
@@ -108,7 +111,7 @@
 
 struct newsnntp_group_time {
   char * grp_name;
-  uint32_t grp_date;
+  time_t grp_date;
   char * grp_email;
 };
 
diff -Nru libetpan-1.5/src/low-level/pop3/mailpop3.c libetpan-1.6/src/low-level/pop3/mailpop3.c
--- libetpan-1.5/src/low-level/pop3/mailpop3.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/pop3/mailpop3.c	2014-10-31 22:41:02.000000000 +0100
@@ -327,7 +327,7 @@
   char * begin_timestamp;
   char * end_timestamp;
   char * timestamp;
-  int len_timestamp;
+  size_t len_timestamp;
 
   if (response == NULL)
     return NULL;
@@ -498,8 +498,8 @@
   /* calculate md5 sum */
 
   MD5Init(&md5context);
-  MD5Update(&md5context, (const unsigned char *) f->pop3_timestamp, strlen (f->pop3_timestamp));
-  MD5Update(&md5context, (const unsigned char *) password, strlen (password));
+  MD5Update(&md5context, (const unsigned char *) f->pop3_timestamp, (unsigned int) strlen (f->pop3_timestamp));
+  MD5Update(&md5context, (const unsigned char *) password, (unsigned int) strlen (password));
   MD5Final(md5digest, &md5context);
   
   cmd_ptr = md5string;
@@ -1146,12 +1146,12 @@
     if (mailstream_is_end_multiline(line))
       break;
 
-    indx = strtol(line, &line, 10);
+    indx = (unsigned int) strtol(line, &line, 10);
 
     if (!parse_space(&line))
       continue;
 
-    size = strtol(line, &line, 10);
+    size = (uint32_t) strtol(line, &line, 10);
     
     msg = mailpop3_msg_info_new(indx, size, NULL);
     if (msg == NULL)
@@ -1198,7 +1198,7 @@
     if (mailstream_is_end_multiline(line))
       break;
     
-    indx = strtol(line, &line, 10);
+    indx = (unsigned int) strtol(line, &line, 10);
 
     if (!parse_space(&line))
       continue;
@@ -1320,7 +1320,7 @@
 static int parse_stat_response(mailpop3 * f, struct mailpop3_stat_response ** result)
 {
   unsigned int count;
-  size_t size;
+  uint32_t size;
   struct mailpop3_stat_response * resp;
   char * line;
 
@@ -1333,7 +1333,7 @@
   if (!parse_space(&line))
     goto err;
 
-  size = (size_t) strtol(line, &line, 10);  
+  size = (uint32_t) strtol(line, &line, 10);
 
   resp = mailpop3_stat_response_new(count, size);
   if(resp == NULL)
@@ -1398,14 +1398,14 @@
     if (result != NULL)
       * result = session->pop3_sasl.sasl_login;
     if (len != NULL)
-      * len = strlen(session->pop3_sasl.sasl_login);
+      * len = (unsigned) strlen(session->pop3_sasl.sasl_login);
     return SASL_OK;
     
   case SASL_CB_AUTHNAME:
     if (result != NULL)
       * result = session->pop3_sasl.sasl_auth_name;
     if (len != NULL)
-      * len = strlen(session->pop3_sasl.sasl_auth_name);
+      * len = (unsigned) strlen(session->pop3_sasl.sasl_auth_name);
     return SASL_OK;
   }
   
@@ -1551,14 +1551,18 @@
     
     case RESPONSE_AUTH_CONT:
       {
-        size_t response_len;
+        unsigned int response_len;
         char * decoded;
         unsigned int decoded_len;
         unsigned int max_decoded;
         int got_response;
         
         got_response = 1;
-        if (* f->pop3_response == '\0')
+        if (f->pop3_response == NULL) {
+          // Make clang static analyzer happy.
+          got_response = 0;
+        }
+        else if (* f->pop3_response == '\0')
           got_response = 0;
         
         if (got_response) {
@@ -1572,7 +1576,7 @@
           if (p != NULL) {
             * p = '\0';
           }
-          response_len = strlen(f->pop3_response);
+          response_len = (unsigned int) strlen(f->pop3_response);
           max_decoded = response_len * 3 / 4;
           decoded = malloc(max_decoded + 1);
           if (decoded == NULL) {
diff -Nru libetpan-1.5/src/low-level/pop3/mailpop3_ssl.c libetpan-1.6/src/low-level/pop3/mailpop3_ssl.c
--- libetpan-1.5/src/low-level/pop3/mailpop3_ssl.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/pop3/mailpop3_ssl.c	2014-10-31 22:41:02.000000000 +0100
@@ -124,5 +124,5 @@
 
 static int mailpop3_cfssl_connect(mailpop3 * f, const char * server, uint16_t port)
 {
-    return mailpop3_cfssl_connect_ssl_level(f, server, port, MAILSTREAM_CFSTREAM_SSL_LEVEL_SSLv3);
+    return mailpop3_cfssl_connect_ssl_level(f, server, port, MAILSTREAM_CFSTREAM_SSL_LEVEL_NEGOCIATED_SSL);
 }
diff -Nru libetpan-1.5/src/low-level/smtp/mailsmtp.c libetpan-1.6/src/low-level/smtp/mailsmtp.c
--- libetpan-1.5/src/low-level/smtp/mailsmtp.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/smtp/mailsmtp.c	2014-10-31 22:41:02.000000000 +0100
@@ -990,7 +990,7 @@
   int code;
   int cont = 0;
 
-  code = strtol(response, &message, 10);
+  code = (int) strtol(response, &message, 10);
   if (* message == ' ')
     mmap_string_append(session->response_buffer, message + 1);
   else if (* message == '-') {
@@ -1140,14 +1140,14 @@
     if (result != NULL)
       * result = session->smtp_sasl.sasl_login;
     if (len != NULL)
-      * len = strlen(session->smtp_sasl.sasl_login);
+      * len = (unsigned) strlen(session->smtp_sasl.sasl_login);
     return SASL_OK;
     
   case SASL_CB_AUTHNAME:
     if (result != NULL)
       * result = session->smtp_sasl.sasl_auth_name;
     if (len != NULL)
-      * len = strlen(session->smtp_sasl.sasl_auth_name);
+      * len = (unsigned) strlen(session->smtp_sasl.sasl_auth_name);
     return SASL_OK;
   }
   
@@ -1316,7 +1316,7 @@
     
     case 334:
       {
-        size_t response_len;
+        unsigned int response_len;
         char * decoded;
         unsigned int decoded_len;
         unsigned int max_decoded;
@@ -1331,7 +1331,7 @@
           * p = '\0';
         }
         
-        response_len = strlen(session->response);
+        response_len = (unsigned int) strlen(session->response);
         max_decoded = response_len * 3 / 4;
         decoded = malloc(max_decoded + 1);
         if (decoded == NULL) {
diff -Nru libetpan-1.5/src/low-level/smtp/mailsmtp_oauth2.c libetpan-1.6/src/low-level/smtp/mailsmtp_oauth2.c
--- libetpan-1.5/src/low-level/smtp/mailsmtp_oauth2.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/smtp/mailsmtp_oauth2.c	2014-10-31 22:41:02.000000000 +0100
@@ -1,3 +1,33 @@
+/*
+ * libEtPan! -- a mail stuff library
+ *
+ * Copyright (C) 2001, 2014 - DINH Viet Hoa
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the libEtPan! project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
 #include "mailsmtp_oauth2.h"
 
 #include <string.h>
@@ -39,9 +69,9 @@
   char * ptr;
   char * full_auth_string;
   char * full_auth_string_b64;
-  int auth_user_len;
-  int access_token_len;
-  int full_auth_string_len;
+  size_t auth_user_len;
+  size_t access_token_len;
+  size_t full_auth_string_len;
   int res;
   
   full_auth_string = NULL;
@@ -64,7 +94,7 @@
   ptr = memcpy(ptr + access_token_len, "\1\1\0", 3);
   
   /* Convert to base64 */
-  full_auth_string_b64 = encode_base64(full_auth_string, full_auth_string_len);
+  full_auth_string_b64 = encode_base64(full_auth_string, (int) full_auth_string_len);
   if (full_auth_string_b64 == NULL) {
     res = MAILSMTP_ERROR_MEMORY;
     goto free;
diff -Nru libetpan-1.5/src/low-level/smtp/mailsmtp_oauth2.h libetpan-1.6/src/low-level/smtp/mailsmtp_oauth2.h
diff -Nru libetpan-1.5/src/low-level/smtp/mailsmtp_private.h libetpan-1.6/src/low-level/smtp/mailsmtp_private.h
diff -Nru libetpan-1.5/src/low-level/smtp/mailsmtp_ssl.c libetpan-1.6/src/low-level/smtp/mailsmtp_ssl.c
--- libetpan-1.5/src/low-level/smtp/mailsmtp_ssl.c	2014-05-05 18:49:32.000000000 +0200
+++ libetpan-1.6/src/low-level/smtp/mailsmtp_ssl.c	2014-10-31 22:41:02.000000000 +0100
@@ -95,7 +95,11 @@
 
   stream = mailstream_ssl_open_with_callback_timeout(s, session->smtp_timeout, callback, data);
   if (stream == NULL) {
-    close(s);
+#ifdef WIN32
+	closesocket(s);
+#else
+	close(s);
+#endif
     return MAILSMTP_ERROR_SSL;
   }
 
@@ -126,5 +130,5 @@
 static int mailsmtp_cfssl_connect(mailsmtp * session,
                                   const char * server, uint16_t port)
 {
-    return mailsmtp_cfssl_connect_ssl_level(session, server, port, MAILSTREAM_CFSTREAM_SSL_LEVEL_SSLv3);
+    return mailsmtp_cfssl_connect_ssl_level(session, server, port, MAILSTREAM_CFSTREAM_SSL_LEVEL_NEGOCIATED_SSL);
 }
diff -Nru libetpan-1.5/src/main/libetpan_version.h libetpan-1.6/src/main/libetpan_version.h
--- libetpan-1.5/src/main/libetpan_version.h	2014-06-11 12:21:44.000000000 +0200
+++ libetpan-1.6/src/main/libetpan_version.h	2014-11-28 12:14:21.000000000 +0100
@@ -38,7 +38,7 @@
 #endif
 
 #ifndef LIBETPAN_VERSION_MINOR
-#define LIBETPAN_VERSION_MINOR 5
+#define LIBETPAN_VERSION_MINOR 6
 #endif
 
 #ifndef LIBETPAN_REENTRANT
diff -Nru libetpan-1.5/src/windows/dirent.c libetpan-1.6/src/windows/dirent.c
diff -Nru libetpan-1.5/src/windows/misc.c libetpan-1.6/src/windows/misc.c
diff -Nru libetpan-1.5/src/windows/mmap.c libetpan-1.6/src/windows/mmap.c
diff -Nru libetpan-1.5/src/windows/time_r.c libetpan-1.6/src/windows/time_r.c
diff -Nru libetpan-1.5/src/windows/win_etpan.h libetpan-1.6/src/windows/win_etpan.h
diff -Nru libetpan-1.5/src/windows/win_init.cpp libetpan-1.6/src/windows/win_init.cpp
*/config.sub
*/configure
*/ltmain.sh
*/mailsasl.[ch]
*/mailstream_cancel.h
*/mailstream_cancel_types.h
*/mailstream_ssl_private.h
*/mmapstring_private.h
*/imapdriver_tools_private.h
*/timeutils.h
*/dummy.cpp
*/mailprivacy_tools_private.h
*/date.h
*/newsfeed_item_enclosure.[ch]
*/newsfeed_private.[ch]
*/newsfeed_types.h
*/parser.h
*/idle.[ch]
*/mailimap_extension_types.h
*/mailsmtp_oauth2.h
*/mailsmtp_private.h
*/mailimap_id_parser.[ch]
*/mailimap_id_sender.[ch]
*/mailimap_id_types.h
*/mailimap_oauth2.h
*/mailimap_sort.c
*/mailimap_sort_types.c
*/win_init.cpp
*/win_etpan.h
*/time_r.c
*/mmap.c
*/misc.c
*/dirent.c

Reply to: