diff --git a/src/lib-sieve/plugins/body/ext-body-common.c b/src/lib-sieve/plugins/body/ext-body-common.c
index 45767de5ce89153589c9a2df41a1a3e60a0d0d0d..d3fe81452bbe825002a8aff1a170122e72d20447 100644
--- a/src/lib-sieve/plugins/body/ext-body-common.c
+++ b/src/lib-sieve/plugins/body/ext-body-common.c
@@ -62,8 +62,7 @@ static bool _is_wanted_content_type
 		if (wanted_subtype == NULL) {
 			/* match only main type */
 			if (strlen(*wanted_types) == type_len &&
-			    strncasecmp(*wanted_types, content_type,
-					type_len) == 0)
+			  strncasecmp(*wanted_types, content_type, type_len) == 0)
 				return TRUE;
 		} else {
 			/* match whole type/subtype */
@@ -162,12 +161,21 @@ static const char *_parse_content_type(const struct message_header_line *hdr)
 	struct rfc822_parser_context parser;
 	string_t *content_type;
 
+	/* Initialize parsing */
 	rfc822_parser_init(&parser, hdr->full_value, hdr->full_value_len, NULL);
 	(void)rfc822_skip_lwsp(&parser);
 
+	/* Parse content type */
 	content_type = t_str_new(64);
 	if (rfc822_parse_content_type(&parser, content_type) < 0)
 		return "";
+
+	/* Header field must end here, otherwise content-type is invalid after all */
+	(void)rfc822_skip_lwsp(&parser);
+	if ( parser.data != parser.end && *parser.data != ';' )
+		return "";
+
+	/* Success */
 	return str_c(content_type);
 }