diff --git a/camel/providers/imap/camel-imap-utils.c b/camel/providers/imap/camel-imap-utils.c
index e4ee339..e9d89ae 100644
--- a/camel/providers/imap/camel-imap-utils.c
+++ b/camel/providers/imap/camel-imap-utils.c
@@ -911,9 +911,9 @@ imap_body_decode (const gchar **in, CamelMessageContentInfo *ci, CamelFolder *fo
 			child->parent = ci;
 			tail->next = child;
 			tail = child;
-		} while (*inptr == '(');
+		} while (inptr && *inptr == '(');
 
-		if (*inptr++ != ' ')
+		if (!inptr || *inptr++ != ' ')
 			return NULL;
 
 		if (g_ascii_strncasecmp (inptr, "nil", 3) != 0) {
@@ -926,7 +926,7 @@ imap_body_decode (const gchar **in, CamelMessageContentInfo *ci, CamelFolder *fo
 		ctype = camel_content_type_new ("multipart", subtype ? subtype : "mixed");
 		g_free (subtype);
 
-		if (*inptr++ != ')') {
+		if (!inptr || *inptr++ != ')') {
 			camel_content_type_unref (ctype);
 			return NULL;
 		}
@@ -975,7 +975,7 @@ imap_body_decode (const gchar **in, CamelMessageContentInfo *ci, CamelFolder *fo
 		if (parse_params (&inptr, ctype) == -1)
 			goto exception;
 
-		if (*inptr++ != ' ')
+		if (!inptr || *inptr++ != ' ')
 			goto exception;
 
 		/* content-id */
@@ -1030,7 +1030,7 @@ imap_body_decode (const gchar **in, CamelMessageContentInfo *ci, CamelFolder *fo
 
 		if (camel_content_type_is (ctype, "message", "rfc822")) {
 			/* body_type_msg */
-			if (*inptr++ != ' ')
+			if (!inptr || *inptr++ != ' ')
 				goto exception;
 
 			/* envelope */
@@ -1070,6 +1070,9 @@ imap_body_decode (const gchar **in, CamelMessageContentInfo *ci, CamelFolder *fo
 		ci->encoding = encoding;
 		ci->size = size;
 		ci->childs = child;
+
+		if (*inptr == ' ' && inptr[1] == '(' && inptr[2] == '\"')
+			inptr++;
 	}
 
 	*in = inptr;
