Index: camel/camel-mime-utils.c
===================================================================
--- camel/camel-mime-utils.c	(revision 8939)
+++ camel/camel-mime-utils.c	(working copy)
@@ -2667,7 +2667,62 @@ header_decode_mailbox(const char **in, c
 			g_string_free (addr, TRUE);
 			addr = out;
 		}
-		
+
+		if (name) {
+			/* Some broken mailers send name encoded in =? ?= with spaces between words,
+			   which makes it difficult to decode word by word, so try to find such places
+			   in the name and decode them if possible. */
+			const char *startptr = NULL, *lastptr = NULL;
+			char *text;
+			GString *decoded_name = NULL;
+
+			inptr = name->str;
+			lastptr = inptr;
+			while (inptr && *inptr) {
+				if (!startptr && *inptr == '=' && inptr [1] == '?') {
+					startptr = inptr;
+				} else if (startptr && *inptr == '?' && inptr [1] == '=') {
+					if (is_rfc2047_encoded_word (startptr, (size_t)(inptr - startptr) + 2)) {
+						/* we have encoded word */
+						inptr ++;
+
+						if (!decoded_name)
+							decoded_name = g_string_sized_new (name->len + 1);
+
+						if (lastptr < startptr) {
+							/* copy everything between lastptr and startptr, it is not an encoded text */
+							g_string_append_len (decoded_name, lastptr, startptr - lastptr);
+						}
+
+						text = rfc2047_decode_word (startptr, inptr - startptr + 1, charset);
+						if (text) {
+							/* successfully decoded, append it as well */
+							g_string_append (decoded_name, text);
+							g_free (text);
+						} else {
+							/* broken decode? so keep it as it was */
+							g_string_append_len (decoded_name, startptr, inptr - startptr + 1);
+						}
+
+						lastptr = inptr + 1;
+					}
+
+					/* always start decoding from the beginning */
+					startptr = NULL;
+				}
+
+				inptr++;
+			}
+
+			if (decoded_name) {
+				if (lastptr < inptr)
+					g_string_append (decoded_name, lastptr);
+
+				g_string_free (name, TRUE);
+				name = decoded_name;
+			}
+		}
+
 		address = camel_header_address_new_name(name ? name->str : "", addr->str);
 	}
 	
Index: camel/ChangeLog
===================================================================
--- camel/ChangeLog	(revision 8939)
+++ camel/ChangeLog	(working copy)
@@ -1,3 +1,12 @@
+2008-06-06  Milan Crha  <mcrha@redhat.com>
+
+	** Fix for bug #523259
+
+	* camel-mime-utils.c: (header_decode_mailbox):
+	Before adding a mail address with a name, recheck whether the name
+	doesn't contain any encoded strings. Some broken mailers includes
+	spaces between encoded text, which breaks the decode system here.
+
 2008-05-29  Milan Crha  <mcrha@redhat.com>
 
 	** Part of fix for bug #534312
