[gmime] Improved premature header termination logic



commit 8db9427e70a87343b965d51ff34e50f12a4dafd4
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Fri Oct 19 22:53:03 2012 -0400

    Improved premature header termination logic

 gmime/gmime-parser.c |   27 +++++++++++++++++++++++++--
 1 files changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/gmime/gmime-parser.c b/gmime/gmime-parser.c
index 900cccd..9c5ec4f 100644
--- a/gmime/gmime-parser.c
+++ b/gmime/gmime-parser.c
@@ -972,7 +972,7 @@ enum {
 };
 
 static gboolean
-has_basic_headers (HeaderRaw *headers)
+has_message_headers (HeaderRaw *headers)
 {
 	unsigned int found = 0;
 	HeaderRaw *header;
@@ -996,6 +996,22 @@ has_basic_headers (HeaderRaw *headers)
 	return found != 0;
 }
 
+static gboolean
+has_content_headers (HeaderRaw *headers)
+{
+	HeaderRaw *header;
+	
+	header = headers;
+	while (header != NULL) {
+		if (!g_ascii_strcasecmp (header->name, "Content-Type"))
+			return TRUE;
+		
+		header = header->next;
+	}
+	
+	return FALSE;
+}
+
 static int
 parser_step_headers (GMimeParser *parser)
 {
@@ -1077,7 +1093,14 @@ parser_step_headers (GMimeParser *parser)
 						goto next_message;
 					
 					if (priv->headers != NULL) {
-						if (has_basic_headers (priv->headers)) {
+						if (priv->state == GMIME_PARSER_STATE_MESSAGE_HEADERS) {
+							if (has_message_headers (priv->headers)) {
+								/* probably the start of the content,
+								 * a broken mailer didn't terminate the
+								 * headers with an empty line. *sigh* */
+								goto content_start;
+							}
+						} else if (has_content_headers (priv->headers)) {
 							/* probably the start of the content,
 							 * a broken mailer didn't terminate the
 							 * headers with an empty line. *sigh* */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]