changeset 1920:1f0b8dadb2e8

package vmime: cherry picked fixes
author Mark Brand <mabrand@mabrand.nl>
date Mon, 04 Jul 2011 17:17:59 +0200
parents f839103829f8
children cbb3d98df94b
files src/vmime-1-fixes.patch
diffstat 1 files changed, 328 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/vmime-1-fixes.patch	Thu Jun 30 11:30:20 2011 +0200
+++ b/src/vmime-1-fixes.patch	Mon Jul 04 17:17:59 2011 +0200
@@ -44,7 +44,7 @@
 From c6f077e695b75d9ff9a32d1621f6a320c8ce70f1 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Tue, 30 Nov 2010 14:57:03 +0000
-Subject: [PATCH 01/16] Initialize and delete object.
+Subject: [PATCH 01/20] Initialize and delete object.
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@577 5301114d-f842-0410-bbdd-996ee0417009
 
@@ -72,13 +72,13 @@
  
  		void go(IMAPParser& parser, string& line, string::size_type* currentPos)
 -- 
-1.7.5.4
+1.7.6
 
 
 From 41203315eacf53230dd7bdb0cf2b0d1078ddee39 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Wed, 8 Dec 2010 08:52:54 +0000
-Subject: [PATCH 02/16] No extra space between ':' and '<' in MAIL FROM and
+Subject: [PATCH 02/20] No extra space between ':' and '<' in MAIL FROM and
  RCPT TO. Wait for server response after QUIT and
  before closing connection.
 
@@ -115,13 +115,13 @@
  		if ((resp = readResponse())->getCode() != 250)
  		{
 -- 
-1.7.5.4
+1.7.6
 
 
 From 969b56f4bd61ddb8277c04ac2a1e35e029ec058b Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Fri, 10 Dec 2010 16:24:06 +0000
-Subject: [PATCH 03/16] Fixed unit test after bug fix.
+Subject: [PATCH 03/20] Fixed unit test after bug fix.
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@580 5301114d-f842-0410-bbdd-996ee0417009
 
@@ -139,13 +139,13 @@
  				localSend("250 OK\r\n");
  			}
 -- 
-1.7.5.4
+1.7.6
 
 
 From 50743da0712b216533acdc09069f1bfc81f988c6 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Fri, 10 Dec 2010 16:54:38 +0000
-Subject: [PATCH 04/16] Fixed boundary parsing (thanks to John van der Kamp,
+Subject: [PATCH 04/20] Fixed boundary parsing (thanks to John van der Kamp,
  Zarafa).
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@581 5301114d-f842-0410-bbdd-996ee0417009
@@ -228,13 +228,13 @@
  
  		vmime::bodyPart p;
 -- 
-1.7.5.4
+1.7.6
 
 
 From b6d2b4765c9472ff333cace13c57c6af0e866ee0 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Fri, 21 Jan 2011 15:28:06 +0000
-Subject: [PATCH 05/16] Fixed possible infinite loop (thanks to John van der
+Subject: [PATCH 05/20] Fixed possible infinite loop (thanks to John van der
  Kamp, Zarafa).
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@582 5301114d-f842-0410-bbdd-996ee0417009
@@ -281,13 +281,13 @@
  VMIME_TEST_SUITE_END
  
 -- 
-1.7.5.4
+1.7.6
 
 
 From 022339ab63430d792d0314f51dd7854eabd5736e Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Fri, 28 Jan 2011 12:11:08 +0000
-Subject: [PATCH 06/16] Fixed possible read to invalid memory location (thanks
+Subject: [PATCH 06/20] Fixed possible read to invalid memory location (thanks
  to Alexander Konovalov).
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@583 5301114d-f842-0410-bbdd-996ee0417009
@@ -306,13 +306,13 @@
  					else
  						state->lastCharIsSpace = false;
 -- 
-1.7.5.4
+1.7.6
 
 
 From 7f1024917b3df6be013e18a2e0f0f1b13f4d112b Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Wed, 9 Mar 2011 18:03:31 +0000
-Subject: [PATCH 07/16] Fixed bug #3174903. Fixed word parsing when buffer
+Subject: [PATCH 07/20] Fixed bug #3174903. Fixed word parsing when buffer
  does not end with NL. Fixed 'no encoding' when
  forced.
 
@@ -514,13 +514,13 @@
  VMIME_TEST_SUITE_END
  
 -- 
-1.7.5.4
+1.7.6
 
 
 From 1c0648c2a3ee4072869446755c8a7604614752e1 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Sun, 27 Mar 2011 11:26:55 +0000
-Subject: [PATCH 08/16] Allow static linking in mingw-cross-env. Added 'iconv'
+Subject: [PATCH 08/20] Allow static linking in mingw-cross-env. Added 'iconv'
  and uses 'ws2_32' instead of 'winsock32' (#3213487).
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@585 5301114d-f842-0410-bbdd-996ee0417009
@@ -549,13 +549,13 @@
  
  # -- getaddrinfo (POSIX)
 -- 
-1.7.5.4
+1.7.6
 
 
 From c6c596b10702a98b59978c81c01dc7f4f33157c9 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Thu, 31 Mar 2011 19:13:03 +0000
-Subject: [PATCH 09/16] Flush stateful data from iconv (thanks to John van der
+Subject: [PATCH 09/20] Flush stateful data from iconv (thanks to John van der
  Kamp, Zarafa).
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@586 5301114d-f842-0410-bbdd-996ee0417009
@@ -632,13 +632,13 @@
  	// Conversion to hexadecimal for easier debugging
  	static const vmime::string toHex(const vmime::string str)
 -- 
-1.7.5.4
+1.7.6
 
 
 From dce9b255556d59773bbbdd9027fd1b1bd5627886 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Fri, 10 Jun 2011 19:39:09 +0000
-Subject: [PATCH 10/16] Requested email change.
+Subject: [PATCH 10/20] Requested email change.
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@587 5301114d-f842-0410-bbdd-996ee0417009
 (cherry picked from commit 418a39a7d33921672bd1c4beb31c8a31bc87d8dd)
@@ -657,13 +657,13 @@
   - Georg Sauthoff <gsauthof@techfak.uni-bielefeld.de>
   - Pierre Thierry <nowhere.man@levallois.eu.org> (patches for STL algorithms)
 -- 
-1.7.5.4
+1.7.6
 
 
 From 42612622a7c42aac7bef1605d9ba8117aa651789 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Tue, 14 Jun 2011 18:37:54 +0000
-Subject: [PATCH 11/16] Fixed compilation issue following namespace change.
+Subject: [PATCH 11/20] Fixed compilation issue following namespace change.
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@588 5301114d-f842-0410-bbdd-996ee0417009
 (cherry picked from commit 4008955783ef566b98b16762c7bfa28df26e9198)
@@ -695,13 +695,13 @@
  		std::vector <vmime::string> props = e->getAvailableProperties();
  
 -- 
-1.7.5.4
+1.7.6
 
 
 From 43346ae2d6c39af2ed16e64cc6d7f89f427a0fee Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Sun, 19 Jun 2011 17:51:33 +0000
-Subject: [PATCH 12/16] Fixed parsing of an attachment filename that is
+Subject: [PATCH 12/20] Fixed parsing of an attachment filename that is
  between 66 and 76 characters long (Zarafa).
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@589 5301114d-f842-0410-bbdd-996ee0417009
@@ -722,13 +722,13 @@
  		switch (value[i])
  		{
 -- 
-1.7.5.4
+1.7.6
 
 
 From 5ef189953965b639a9038da337e104592417c465 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Sun, 19 Jun 2011 18:08:12 +0000
-Subject: [PATCH 13/16] Correctly generate attachment names which are long and
+Subject: [PATCH 13/20] Correctly generate attachment names which are long and
  have high characters for Outlook Express (Zarafa).
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@590 5301114d-f842-0410-bbdd-996ee0417009
@@ -863,13 +863,13 @@
  #endif // !VMIME_ALWAYS_GENERATE_7BIT_PARAMETER
  
 -- 
-1.7.5.4
+1.7.6
 
 
 From caa3cbc0fe9218d3d494bfed1afed2ee620a2e4e Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Sun, 19 Jun 2011 18:16:49 +0000
-Subject: [PATCH 14/16] Alias for UTF-7 charset.
+Subject: [PATCH 14/20] Alias for UTF-7 charset.
 
 git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@591 5301114d-f842-0410-bbdd-996ee0417009
 (cherry picked from commit f7ad17cffea462faf8cbe4f785644da0f3ee812a)
@@ -900,13 +900,13 @@
  
  	if (newPosition)
 -- 
-1.7.5.4
+1.7.6
 
 
 From 97d992cda306d96a8dda948abb9806ee2c2ce587 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Sun, 19 Jun 2011 18:39:35 +0000
-Subject: [PATCH 15/16] Fixed messageBuilder to accept an empty mailbox group
+Subject: [PATCH 15/20] Fixed messageBuilder to accept an empty mailbox group
  in 'To:' field, to allow for undisclosed-recipients
  (Zarafa).
 
@@ -939,13 +939,13 @@
  	if (!m_to.isEmpty())
  		msg->getHeader()->To()->setValue(m_to);
 -- 
-1.7.5.4
+1.7.6
 
 
 From db98569ef427f9f3fac9a9dcc25ab8b6f2b3bd91 Mon Sep 17 00:00:00 2001
 From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
 Date: Sun, 19 Jun 2011 18:49:55 +0000
-Subject: [PATCH 16/16] Added support for mailboxes that specify an (encoded)
+Subject: [PATCH 16/20] Added support for mailboxes that specify an (encoded)
  full name with an empty email address, set by a <>
  marker (Zarafa).
 
@@ -1014,5 +1014,301 @@
  VMIME_TEST_SUITE_END
  
 -- 
-1.7.5.4
+1.7.6
+
+
+From aa5ab140e90a6222e5f03b337711444be845fbd0 Mon Sep 17 00:00:00 2001
+From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
+Date: Fri, 24 Jun 2011 15:46:23 +0000
+Subject: [PATCH 17/20] Added missing libs in pkg-config file.
+
+git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@594 5301114d-f842-0410-bbdd-996ee0417009
+(cherry picked from commit 960f2195516eb776eea7b7e4f92612192edfdcd9)
+
+diff --git a/SConstruct b/SConstruct
+index 6e8aba2..4c0cb0e 100644
+--- a/SConstruct
++++ b/SConstruct
+@@ -1089,7 +1089,7 @@ def generateAutotools(target, source, env):
+ 	vmime_pc_in.write("Description: " + packageDescription + "\n")
+ 	vmime_pc_in.write("Version: @VERSION@\n")
+ 	vmime_pc_in.write("Requires: @GSASL_REQUIRED@\n")
+-	vmime_pc_in.write("Libs: -L${libdir} -l@GENERIC_VERSIONED_LIBRARY_NAME@ @GSASL_LIBS@ @LIBGNUTLS_LIBS@ @LIBICONV@ @PTHREAD_LIBS@ @VMIME_ADDITIONAL_PC_LIBS@\n")
++	vmime_pc_in.write("Libs: -L${libdir} -l@GENERIC_VERSIONED_LIBRARY_NAME@ @GSASL_LIBS@ @LIBGNUTLS_LIBS@ @LIBICONV@ @PTHREAD_LIBS@ @LIBICONV@ @PTHREAD_LIBS@ @VMIME_ADDITIONAL_PC_LIBS@\n")
+ 	#vmime_pc_in.write("Cflags: -I${includedir}/@GENERIC_VERSIONED_LIBRARY_NAME@\n")
+ 	vmime_pc_in.write("Cflags: -I${includedir}/ @LIBGNUTLS_CFLAGS@\n")
+ 	vmime_pc_in.close()
+-- 
+1.7.6
+
+
+From bf98b31b36ba2228d4f1c25cd3f7680d47cc8910 Mon Sep 17 00:00:00 2001
+From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
+Date: Sat, 25 Jun 2011 17:07:53 +0000
+Subject: [PATCH 18/20] Fixed parsing of empty body parts (thanks to John van
+ der Kamp, from Zarafa).
+
+git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@595 5301114d-f842-0410-bbdd-996ee0417009
+(cherry picked from commit 9f9084b71b4e3c96edc6513020984ef76fe26e0c)
+
+diff --git a/src/body.cpp b/src/body.cpp
+index 8596833..9d7d57f 100644
+--- a/src/body.cpp
++++ b/src/body.cpp
+@@ -197,6 +197,11 @@ void body::parse(const string& buffer, const string::size_type position,
+ 			{
+ 				ref <bodyPart> part = vmime::create <bodyPart>();
+ 
++				// End before start may happen on empty bodyparts (directly
++				// successive boundaries without even a line-break)
++				if (partEnd < partStart)
++					std::swap(partStart, partEnd);
++
+ 				part->parse(buffer, partStart, partEnd, NULL);
+ 				part->m_parent = m_part;
+ 
+diff --git a/tests/parser/bodyPartTest.cpp b/tests/parser/bodyPartTest.cpp
+index b129913..075b8f9 100644
+--- a/tests/parser/bodyPartTest.cpp
++++ b/tests/parser/bodyPartTest.cpp
+@@ -36,6 +36,7 @@ VMIME_TEST_SUITE_BEGIN
+ 		VMIME_TEST(testParseMissingLastBoundary)
+ 		VMIME_TEST(testPrologEpilog)
+ 		VMIME_TEST(testPrologEncoding)
++		VMIME_TEST(testSuccessiveBoundaries)
+ 	VMIME_TEST_LIST_END
+ 
+ 
+@@ -181,5 +182,23 @@ VMIME_TEST_SUITE_BEGIN
+ 		VASSERT_EQ("epilog", "Epilog text", msg->getBody()->getEpilogText());
+ 	}
+ 
++	void testSuccessiveBoundaries()
++	{
++		vmime::string str =
++			"Content-Type: multipart/mixed; boundary=\"MY-BOUNDARY\""
++			"\r\n\r\n"
++			"--MY-BOUNDARY\r\nHEADER1\r\n\r\nBODY1\r\n"
++			"--MY-BOUNDARY\r\n"
++			"--MY-BOUNDARY--\r\n";
++
++		vmime::bodyPart p;
++		p.parse(str);
++
++		VASSERT_EQ("count", 2, p.getBody()->getPartCount());
++
++		VASSERT_EQ("part1-body", "BODY1", extractContents(p.getBody()->getPartAt(0)->getBody()->getContents()));
++		VASSERT_EQ("part2-body", "", extractContents(p.getBody()->getPartAt(1)->getBody()->getContents()));
++	}
++
+ VMIME_TEST_SUITE_END
+ 
+-- 
+1.7.6
+
+
+From a256cc5632b86098d9106ab46ef7fceef34caf5a Mon Sep 17 00:00:00 2001
+From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
+Date: Sun, 26 Jun 2011 08:19:11 +0000
+Subject: [PATCH 19/20] Use gnutls_priority_set_direct() instead of GNUTLS
+ deprecated functions.
+
+git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@596 5301114d-f842-0410-bbdd-996ee0417009
+(cherry picked from commit 318848aa87761214a6f21c1ea1a9776a7bcbf83c)
 
+diff --git a/SConstruct b/SConstruct
+index 4c0cb0e..6e9a399 100644
+--- a/SConstruct
++++ b/SConstruct
+@@ -816,6 +816,7 @@ else:
+ config_hpp.write('// -- TLS/SSL support\n')
+ if env['with_tls'] == 'yes':
+ 	config_hpp.write('#define VMIME_HAVE_TLS_SUPPORT 1\n')
++	config_hpp.write('#define HAVE_GNUTLS_PRIORITY_FUNCS 1\n')
+ else:
+ 	config_hpp.write('#define VMIME_HAVE_TLS_SUPPORT 0\n')
+ 
+@@ -1626,11 +1627,42 @@ if test "x$conf_tls" = "xyes"; then
+ 	else
+ 		AC_MSG_ERROR(can't find an usable version of GNU TLS library)
+ 	fi
++
++	# -- check for gnutls_priority_set_direct() function
++	if test "x$have_gnutls" = "xyes"; then
++		AC_MSG_CHECKING(for gnutls_priority_set_direct)
++
++		LIBS_save="$LIBS"
++		LIBS="$LIBS $LIBGNUTLS_LIBS"
++		CPPFLAGS_save="$CPPFLAGS"
++		CPPFLAGS="$CPPFLAGS $LIBGNUTLS_CFLAGS"
++
++		AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <gnutls/gnutls.h>],
++		                                [gnutls_session s; gnutls_priority_set_direct(s, NULL, NULL);])],
++		               [have_gnutls_priority_funcs=yes],
++		               [have_gnutls_priority_funcs=no])
++
++		CPPFLAGS="$CPPFLAGS_save"
++		LIBS="$LIBS_save"
++
++		AC_MSG_RESULT([$have_gnutls_priority_funcs])
++
++		if test "x$have_gnutls_priority_funcs" = "xyes"; then
++			AM_CONDITIONAL(HAVE_GNUTLS_PRIORITY_FUNCS, true)
++			HAVE_GNUTLS_PRIORITY_FUNCS=1
++		else
++			AM_CONDITIONAL(HAVE_GNUTLS_PRIORITY_FUNCS, false)
++			HAVE_GNUTLS_PRIORITY_FUNCS=0
++		fi
++	fi
+ else
+ 	AM_CONDITIONAL(VMIME_HAVE_TLS_SUPPORT, false)
+ 	VMIME_HAVE_TLS_SUPPORT=0
+ fi
+ 
++AC_SUBST(LIBGNUTLS_CFLAGS)
++AC_SUBST(LIBGNUTLS_LIBS)
++
+ # ** platform handlers
+ 
+ VMIME_BUILTIN_PLATFORMS=''
+@@ -1919,6 +1951,7 @@ typedef unsigned ${VMIME_TYPE_INT32} vmime_uint32;
+ #define VMIME_HAVE_SASL_SUPPORT ${VMIME_HAVE_SASL_SUPPORT}
+ // -- TLS support
+ #define VMIME_HAVE_TLS_SUPPORT ${VMIME_HAVE_TLS_SUPPORT}
++#define HAVE_GNUTLS_PRIORITY_FUNCS ${HAVE_GNUTLS_PRIORITY_FUNCS}
+ // -- Messaging support
+ #define VMIME_HAVE_MESSAGING_FEATURES ${VMIME_HAVE_MESSAGING_FEATURES}
+ """)
+diff --git a/src/net/tls/TLSSession.cpp b/src/net/tls/TLSSession.cpp
+index 010c007..af73a05 100644
+--- a/src/net/tls/TLSSession.cpp
++++ b/src/net/tls/TLSSession.cpp
+@@ -123,6 +123,21 @@ TLSSession::TLSSession(ref <security::cert::certificateVerifier> cv)
+ 
+ 	// Sets some default priority on the ciphers, key exchange methods,
+ 	// macs and compression methods.
++#if HAVE_GNUTLS_PRIORITY_FUNCS
++
++	if ((res = gnutls_priority_set_direct
++		(*m_gnutlsSession, "NORMAL:%SSL3_RECORD_VERSION", NULL)) != 0)
++	{
++		if ((res = gnutls_priority_set_direct
++			(*m_gnutlsSession, "NORMAL", NULL)) != 0)
++		{
++			throwTLSException
++				("gnutls_priority_set_direct", res);
++		}
++	}
++
++#else  // !HAVE_GNUTLS_PRIORITY_FUNCS
++
+ 	gnutls_set_default_priority(*m_gnutlsSession);
+ 
+ 	// Sets the priority on the certificate types supported by gnutls.
+@@ -197,6 +212,8 @@ TLSSession::TLSSession(ref <security::cert::certificateVerifier> cv)
+ 
+ 	gnutls_compression_set_priority(*m_gnutlsSession, compressionPriority);
+ 
++#endif // !HAVE_GNUTLS_PRIORITY_FUNCS
++
+ 	// Initialize credentials
+ 	gnutls_credentials_set(*m_gnutlsSession,
+ 		GNUTLS_CRD_ANON, g_gnutlsGlobal.anonCred);
+-- 
+1.7.6
+
+
+From f50943c55df6889a4b1e65ed9918a1ab5d12a321 Mon Sep 17 00:00:00 2001
+From: vincent-richard <vincent-richard@5301114d-f842-0410-bbdd-996ee0417009>
+Date: Sun, 26 Jun 2011 12:47:25 +0000
+Subject: [PATCH 20/20] Fixed encoding of whitespace. Fixed old test case.
+
+git-svn-id: https://vmime.svn.sourceforge.net/svnroot/vmime/trunk@597 5301114d-f842-0410-bbdd-996ee0417009
+(cherry picked from commit 70a0282a3f96febf973475a298ac95ffaab82c3c)
+
+diff --git a/src/text.cpp b/src/text.cpp
+index 2454456..66c3b35 100644
+--- a/src/text.cpp
++++ b/src/text.cpp
+@@ -320,12 +320,6 @@ void text::createFromString(const string& in, const charset& ch)
+ 					}
+ 					else
+ 					{
+-						if (count)
+-						{
+-							ref <word> w = getWordAt(getWordCount() - 1);
+-							w->getBuffer() += ' ';
+-						}
+-
+ 						appendWord(vmime::create <word>
+ 							(chunk, charset(charsets::US_ASCII)));
+ 
+diff --git a/tests/parser/textTest.cpp b/tests/parser/textTest.cpp
+index 746ac94..43ec836 100644
+--- a/tests/parser/textTest.cpp
++++ b/tests/parser/textTest.cpp
+@@ -53,6 +53,8 @@ VMIME_TEST_SUITE_BEGIN
+ 
+ 		VMIME_TEST(testFoldingAscii)
+ 		VMIME_TEST(testForcedNonEncoding)
++
++		VMIME_TEST(testBugFix20110511)
+ 	VMIME_TEST_LIST_END
+ 
+ 
+@@ -149,7 +151,7 @@ VMIME_TEST_SUITE_BEGIN
+ 		VASSERT_EQ("2.1", 3, t2.getWordCount());
+ 		VASSERT_EQ("2.2", "some ASCII characters and special chars: ", t2.getWordAt(0)->getBuffer());
+ 		VASSERT_EQ("2.3", vmime::charset(vmime::charsets::US_ASCII), t2.getWordAt(0)->getCharset());
+-		VASSERT_EQ("2.4", "\xf1\xf2\xf3\xf4 ", t2.getWordAt(1)->getBuffer());
++		VASSERT_EQ("2.4", "\xf1\xf2\xf3\xf4", t2.getWordAt(1)->getBuffer());
+ 		VASSERT_EQ("2.5", c2, t2.getWordAt(1)->getCharset());
+ 		VASSERT_EQ("2.6", "and then more ASCII chars.", t2.getWordAt(2)->getBuffer());
+ 		VASSERT_EQ("2.7", vmime::charset(vmime::charsets::US_ASCII), t2.getWordAt(2)->getCharset());
+@@ -453,5 +455,43 @@ VMIME_TEST_SUITE_BEGIN
+ 		VASSERT_EQ("received.long", "from User\r\n (Ee9GMqZQ8t7IQwftfAFHd2KyScCYRrFSJ50tKEoXv2bVCG4HcPU80GGWiFabAvG77FekpGgF1h@[127.0.0.1])\r\n by servername.hostname.com with esmtp id 1NGTS9-2C0sqG0; Fri, 4 Dec 2009\r\n 09:23:49 +0100", r.generate(78));
+ 	}
+ 
++	void testBugFix20110511()
++	{
++		/*
++
++		 Using the latest version of vmime (0.9.1), encoding the following string: Jean
++		 Gwenaël Dutourd will result in:
++		 Jean =?utf-8?Q?Gwena=C3=ABl_?= Dutourd
++		 However, decoding this will result in Jean Gwenaël  Dutourd (notice two spaces
++		 between the last 2 words).  The encoder adds a _ after the second word, but
++		 since the last word is not encoded, the space between them is not ignored, and
++		 is decoded into an additional space.
++
++		 See: http://sourceforge.net/projects/vmime/forums/forum/237357/topic/4531365
++
++		*/
++
++		const std::string DECODED_TEXT = "Jean Gwenaël Dutourd";
++		const std::string ENCODED_TEXT = "Jean =?utf-8?Q?Gwena=C3=ABl?= Dutourd";
++
++		// Encode
++		VASSERT_EQ("encode", ENCODED_TEXT,
++			vmime::text::newFromString(DECODED_TEXT, vmime::charset("utf-8"))->generate());
++
++		// Decode
++		vmime::text t;
++		t.parse(ENCODED_TEXT);
++
++		// -- words
++		std::ostringstream oss; oss << t;
++		VASSERT_EQ("decode1",
++			"[text: [[word: charset=us-ascii, buffer=Jean ],"
++			        "[word: charset=utf-8, buffer=Gwenaël],"
++				  "[word: charset=us-ascii, buffer= Dutourd]]]", oss.str());
++
++		// -- getWholeBuffer
++		VASSERT_EQ("decode2", DECODED_TEXT, t.getWholeBuffer());
++	}
++
+ VMIME_TEST_SUITE_END
+ 
+-- 
+1.7.6
+