aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorNot Zed <NotZed@Ximian.com>2003-04-17 11:09:37 +0800
committerMichael Zucci <zucchi@src.gnome.org>2003-04-17 11:09:37 +0800
commit6b479c5f9f5c831748275b9d82ce4123d1fc7afd (patch)
treee6c55c6b3abc5590939259c0132226ab6cf7d081 /camel
parentc4e57e0db3e808604665742df5d7b025b2765d68 (diff)
downloadgsoc2013-evolution-6b479c5f9f5c831748275b9d82ce4123d1fc7afd.tar
gsoc2013-evolution-6b479c5f9f5c831748275b9d82ce4123d1fc7afd.tar.gz
gsoc2013-evolution-6b479c5f9f5c831748275b9d82ce4123d1fc7afd.tar.bz2
gsoc2013-evolution-6b479c5f9f5c831748275b9d82ce4123d1fc7afd.tar.lz
gsoc2013-evolution-6b479c5f9f5c831748275b9d82ce4123d1fc7afd.tar.xz
gsoc2013-evolution-6b479c5f9f5c831748275b9d82ce4123d1fc7afd.tar.zst
gsoc2013-evolution-6b479c5f9f5c831748275b9d82ce4123d1fc7afd.zip
Dont assume adding 1 to line length will go to the next line. e.g. for dos
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. svn path=/trunk/; revision=20874
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog7
-rw-r--r--camel/camel-mime-part-utils.c2
-rw-r--r--camel/camel-multipart-signed.c63
3 files changed, 46 insertions, 26 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 78d6f813c4..aed9ecda3f 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -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-15 Jeffrey Stedfast <fejj@ximian.com>
* camel-gpg-context.c (gpg_verify): The gpg child process exiting
diff --git a/camel/camel-mime-part-utils.c b/camel/camel-mime-part-utils.c
index 2c9c03e104..33442f2b20 100644
--- a/camel/camel-mime-part-utils.c
+++ b/camel/camel-mime-part-utils.c
@@ -422,7 +422,7 @@ camel_mime_part_construct_content_from_parser (CamelMimePart *dw, CamelMimeParse
CamelContentType *ct;
ct = camel_mime_parser_content_type (mp);
-
+
switch (camel_mime_parser_state (mp)) {
case HSCAN_HEADER:
d(printf("Creating body part\n"));
diff --git a/camel/camel-multipart-signed.c b/camel/camel-multipart-signed.c
index 79252c85d0..a5c4cc3dff 100644
--- a/camel/camel-multipart-signed.c
+++ b/camel/camel-multipart-signed.c
@@ -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 @@ camel_multipart_signed_new (void)
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 @@ static int
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 @@ parse_content(CamelMultipartSigned *mps)
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;
}