diff --git a/main/rfc1867.c b/main/rfc1867.c
index b3f94ec..7613119 100644
--- a/main/rfc1867.c
+++ b/main/rfc1867.c
@@ -33,6 +33,8 @@
 #include "php_variables.h"
 #include "rfc1867.h"
 #include "ext/standard/php_string.h"
+#include "ext/standard/php_smart_str.h"
+

 #define DEBUG_FILE_UPLOAD ZEND_DEBUG

@@ -462,6 +464,66 @@ static int find_boundary(multipart_buffer *self, char *boundary TSRMLS_DC)
 static int multipart_buffer_headers(multipart_buffer *self, zend_llist *header TSRMLS_DC)
 {
 	char *line;
+	mime_header_entry entry = {0};
+	smart_str buf_value = {0};
+	char *key = NULL;
+
+	/* didn't find boundary, abort */
+	if (!find_boundary(self, self->boundary TSRMLS_CC)) {
+		return 0;
+	}
+
+	/* get lines of text, or CRLF_CRLF */
+
+	while( (line = get_line(self TSRMLS_CC)) && line[0] != '\0' )
+	{
+		/* add header to table */
+		char *value = NULL;
+
+		/*if (php_rfc1867_encoding_translation(TSRMLS_C)) {
+			//self->input_encoding = zend_multibyte_encoding_detector((unsigned char *)line, strlen(line), self->detect_order, self->detect_order_size TSRMLS_CC);
+		}*/
+
+		/* space in the beginning means same header */
+		if (!isspace(line[0])) {
+			value = strchr(line, ':');
+		}
+
+		if (value) {
+			if(buf_value.c && key) {
+				/* new entry, add the old one to the list */
+				smart_str_0(&buf_value);
+				entry.key = key;
+				entry.value = buf_value.c;
+				zend_llist_add_element(header, &entry);
+				buf_value.c = NULL;
+				key = NULL;
+			}
+
+			*value = '\0';
+			do { value++; } while(isspace(*value));
+
+			key = estrdup(line);
+			smart_str_appends(&buf_value, value);
+		} else if (buf_value.c) { /* If no ':' on the line, add to previous line */
+			smart_str_appends(&buf_value, line);
+		} else {
+			continue;
+		}
+	}
+	if(buf_value.c && key) {
+		/* add the last one to the list */
+		smart_str_0(&buf_value);
+		entry.key = key;
+		entry.value = buf_value.c;
+		zend_llist_add_element(header, &entry);
+	}
+
+	return 1;
+}
+static int multipart_buffer_headers_bak(multipart_buffer *self, zend_llist *header TSRMLS_DC)
+{
+	char *line;
 	mime_header_entry prev_entry, entry;
 	int prev_len, cur_len;

