Index: camel/camel-mime-utils.c
===================================================================
--- camel/camel-mime-utils.c	(revision 8597)
+++ camel/camel-mime-utils.c	(working copy)
@@ -741,10 +741,12 @@ quoted_decode(const unsigned char *in, s
 			}
 		} else if (c=='_') {
 			*outptr++ = 0x20;
-		} else if (c==' ' || c==0x09) {
-			/* FIXME: this is an error! ignore for now ... */
+		/* it's a violation against RFC to place spaces into the quoted text directly,
+		   but some clients/servers do this, so be kind to them... */
+		/* } else if (c==' ' || c==0x09) {
+			/ * FIXME: this is an error! ignore for now ... * /
 			ret = -1;
-			break;
+			break; */
 		} else {
 			*outptr++ = c;
 		}
@@ -1084,7 +1086,11 @@ rfc2047_decode_word (const char *in, siz
 		d(fprintf (stderr, "unknown encoding\n"));
 		return NULL;
 	}
-	
+
+	/* never return empty string, return rather NULL */
+	if (!declen)
+		return NULL;
+
 	len = (inptr - 3) - (instart + 2);
 	charenc = g_alloca (len + 1);
 	memcpy (charenc, in + 2, len);
@@ -1101,7 +1107,7 @@ rfc2047_decode_word (const char *in, siz
 	/* trim off the 'language' part if it's there... */
 	if ((p = strchr (charset, '*')))
 		*p = '\0';
-	
+
 	/* slight optimization? */
 	if (!g_ascii_strcasecmp (charset, "UTF-8")) {
 		p = (char *) decoded;
@@ -1248,7 +1254,7 @@ header_decode_text (const char *in, int 
 				}
 				
 				/* sanity check encoding type */
-				if (inptr[0] != '?' || !strchr ("BbQq", inptr[1]) || inptr[2] != '?')
+				if (inptr[0] != '?' || !strchr ("BbQq", inptr[1]) || !inptr[1] || inptr[2] != '?')
 					goto non_rfc2047;
 				
 				inptr += 3;
Index: camel/ChangeLog
===================================================================
--- camel/ChangeLog	(revision 8597)
+++ camel/ChangeLog	(working copy)
@@ -1,3 +1,14 @@
+2008-03-28  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #524704
+
+	* camel-mime-utils.c: (quoted_decode):
+	Allow direct spaces in a string.
+	* camel-mime-utils.c: (rfc2047_decode_word):
+	Do not return empty string in case of malformed text.
+	* camel-mime-utils.c: (header_decode_text):
+	Be sure we access only allocated memory.
+
 2008-03-27  Matthew Barnes  <mbarnes@redhat.com>
 
 	** Fixes part of bug #518710
