[evolution-patches] 41163, pgp attachment problem



The multipart-signed code was assuming the end of line character was
only 1 character long.

in the test case eol's were \r\n so it was adding a blank line to the
start of the part, which got decoded as end of headers, so the content
was treated as text/plain.

 Z

? 19564.diff
? a
? a.out
? buildtable
? c.diff
? camel-f.c
? camel-object-bag.c
? camel-service.2.c
? camel-smime.c
? camel-smime.h
? camel-stream-ssl.c
? camel-stream-ssl.h
? cvf.c
? diff
? filter.diff
? log
? merged.msg
? mt.diff
? mylock
? new
? old
? out.ps
? outbox
? race.txt
? search.txt
? test-from.c
? test.c
? trace
? trash.diff
? typescript
? vfolder.txt
? vfolders.xml
? providers/cache
? providers/file
? providers/local/camel-mbox-provider.c
? providers/local/swummary.txt
? providers/mbox/Makefile
? providers/mbox/Makefile.in
? providers/mbox/an
? providers/mh/Makefile
? providers/mh/Makefile.in
? providers/vee/Makefile
? providers/vee/Makefile.in
? providers/vee/camel-vee-folder.c.save
? providers/vee/camel-vee-folder.c.save2
? providers/vee/diff
? providers/vee/libcamelvee.urls
? tests/a.out
? tests/test.c
? tests/data/addr.txt
? tests/data/bg_BG.cp1251.windows-1251.txt
? tests/data/ca.iso-8859-1.txt
? tests/data/cs.ISO-8859-2.txt
? tests/data/da.ISO-8859-1.txt
? tests/data/de.ISO-8859-1.txt
? tests/data/el.iso-8859-7.txt
? tests/data/en_GB.iso-8859-1.txt
? tests/data/es.iso-8859-1.txt
? tests/data/et.iso-8859-1.txt
? tests/data/eu.iso-8859-1.txt
? tests/data/fi.iso-8859-15.txt
? tests/data/fr.ISO-8859-1.txt
? tests/data/ga.iso-8859-1.txt
? tests/data/gl.iso-8859-1.txt
? tests/data/hu.iso-8859-2.txt
? tests/data/it.iso-8859-1.txt
? tests/data/ja.euc-jp.txt
? tests/data/ko.euc-kr.txt
? tests/data/lt.iso-8859-13.txt
? tests/data/nl.iso-8859-1.txt
? tests/data/no.iso-8859-1.txt
? tests/data/pl.iso-8859-2.txt
? tests/data/pt.iso-8859-1.txt
? tests/data/pt_BR.iso-8859-1.txt
? tests/data/ru.koi8-r.txt
? tests/data/sk.iso-8859-2.txt
? tests/data/sl.iso-8859-2.txt
? tests/data/sp.iso-8859-5.txt
? tests/data/sr.iso-8859-2.txt
? tests/data/sv.iso-8859-1.txt
? tests/data/ta.TSCII.txt
? tests/data/test-lines.h
? tests/data/tr.iso-8859-9.txt
? tests/data/uk.koi8-u.txt
? tests/data/wa.iso-8859-1.txt
? tests/data/zh_CN.GB2312.gb2312.txt
? tests/data/zh_TW.Big5.big5.txt
? tests/folder/trace
? tests/message/uni.txt
? tests/mime-filter/test-html.c
? tests/stream/readwrite.c
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/camel/ChangeLog,v
retrieving revision 1.1794
diff -u -3 -r1.1794 ChangeLog
--- ChangeLog	10 Apr 2003 17:13:13 -0000	1.1794
+++ ChangeLog	17 Apr 2003 01:55:20 -0000
@@ -1,3 +1,10 @@
+2003-04-17  Not Zed  <NotZed Ximian com>
+
+	* camel-multipart-signed.c (parse_content): Dont assume adding 1
+	to line length will go to the next line.  e.g. for dos lines that
+	end in \r\n.  Fix for #41163.
+	(parse_boundary): util function to help above.
+
 2003-04-10  Jeffrey Stedfast  <fejj ximian com>
 
 	* providers/smtp/camel-smtp-transport.c: Turn off debugging if
Index: camel-mime-part-utils.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-mime-part-utils.c,v
retrieving revision 1.86
diff -u -3 -r1.86 camel-mime-part-utils.c
--- camel-mime-part-utils.c	27 Mar 2003 06:05:46 -0000	1.86
+++ camel-mime-part-utils.c	17 Apr 2003 01:55:26 -0000
@@ -422,7 +422,7 @@
 	CamelContentType *ct;
 	
 	ct = camel_mime_parser_content_type (mp);
-	
+
 	switch (camel_mime_parser_state (mp)) {
 	case HSCAN_HEADER:
 		d(printf("Creating body part\n"));
Index: camel-multipart-signed.c
===================================================================
RCS file: /cvs/gnome/evolution/camel/camel-multipart-signed.c,v
retrieving revision 1.7
diff -u -3 -r1.7 camel-multipart-signed.c
--- camel-multipart-signed.c	27 Feb 2003 04:53:03 -0000	1.7
+++ camel-multipart-signed.c	17 Apr 2003 01:55:28 -0000
@@ -50,7 +50,8 @@
 #include "camel-mime-filter-crlf.h"
 #include "camel-mime-filter-canon.h"
 
-#define d(x)
+#define d(x) /*(printf("%s(%d): ", __FILE__, __LINE__),(x))
+	       #include <stdio.h>;*/
 
 static void signed_add_part(CamelMultipart *multipart, CamelMimePart *part);
 static void signed_add_part_at(CamelMultipart *multipart, CamelMimePart *part, guint index);
@@ -179,6 +180,30 @@
 	return multipart;
 }
 
+/* find the next boundary @bound from @start, return the start of the actual data
+   @end points to the end of the data BEFORE the boundary */
+static char *parse_boundary(char *start, const char *bound, char **end)
+{
+	char *data, *begin;
+
+	begin = strstr(start, bound);
+	if (begin == NULL)
+		return NULL;
+
+	data = begin+strlen(bound);
+	if (begin > start && begin[-1] == '\n')
+		begin--;
+	if (begin > start && begin[-1] == '\r')
+		begin--;
+	if (data[0] == '\r')
+		data++;
+	if (data[0] == '\n')
+		data++;
+
+	*end = begin;
+	return data;
+}
+
 /* yeah yuck.
    Well, we could probably use the normal mime parser, but then it would change our
    headers.
@@ -187,7 +212,7 @@
 parse_content(CamelMultipartSigned *mps)
 {
 	CamelMultipart *mp = (CamelMultipart *)mps;
-	char *start, *end, *start2, *end2, *last;
+	char *start, *end, *start2, *end2, *last, *post;
 	CamelStreamMem *mem;
 	char *bound;
 	const char *boundary;
@@ -213,44 +238,32 @@
 	bound = alloca(strlen(boundary)+5);
 	sprintf(bound, "--%s", boundary);
 
-	start = strstr(mem->buffer->data, bound);
-	if (start == NULL) {
-		printf("construct from stream, cannot find first boundary\n");
+	start = parse_boundary(mem->buffer->data, bound, &end);
+	if (start == NULL || start[0] == 0)
 		return -1;
-	}
 
-	if (start > (char *)mem->buffer->data) {
+	if (end > (char *)mem->buffer->data) {
 		char *tmp = g_strndup(mem->buffer->data, start-(char *)mem->buffer->data-1);
 		camel_multipart_set_preface(mp, tmp);
 		g_free(tmp);
 	}
 
-	start += strlen(bound)+1;
-	if (start >= last)
+	start2 = parse_boundary(start, bound, &end);
+	if (start2 == NULL || start2[0] == 0)
 		return -1;
-	end = strstr(start, bound);
-	if (end == NULL) {
-		printf("construct from stream, cannot find second boundary\n");
-		return -1;
-	}
 
-	start2 = end + strlen(bound)+1;
-	if (start2 >= last)
-		return -1;
 	sprintf(bound, "--%s--", boundary);
-	end2 = strstr(start2, bound);
-	if (end2 == NULL) {
-		printf("construct from stream, cannot find last boundary\n");
+	post = parse_boundary(start2, bound, &end2);
+	if (post == NULL)
 		return -1;
-	}
 
-	if (end2+strlen(bound)+1 < last)
-		camel_multipart_set_postface(mp, end2+strlen(bound)+1);
+	if (post[0])
+		camel_multipart_set_postface(mp, post);
 
 	mps->start1 = start-(char *)mem->buffer->data;
-	mps->end1 = end-(char *)mem->buffer->data-1;
+	mps->end1 = end-(char *)mem->buffer->data;
 	mps->start2 = start2-(char *)mem->buffer->data;
-	mps->end2 = end2-(char *)mem->buffer->data-1;
+	mps->end2 = end2-(char *)mem->buffer->data;
 
 	return 0;
 }


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