aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorNotZed <NotZed@HelixCode.com>2000-05-03 03:06:55 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-05-03 03:06:55 +0800
commit633171afd76f29e23b51628c752ad4c6d05bf4ea (patch)
tree8ed9377b1f0a1abb14c846c0575719771b856e01 /camel
parentb5ddb0c7c8c57e292e187f625f84e8523303e05a (diff)
downloadgsoc2013-evolution-633171afd76f29e23b51628c752ad4c6d05bf4ea.tar
gsoc2013-evolution-633171afd76f29e23b51628c752ad4c6d05bf4ea.tar.gz
gsoc2013-evolution-633171afd76f29e23b51628c752ad4c6d05bf4ea.tar.bz2
gsoc2013-evolution-633171afd76f29e23b51628c752ad4c6d05bf4ea.tar.lz
gsoc2013-evolution-633171afd76f29e23b51628c752ad4c6d05bf4ea.tar.xz
gsoc2013-evolution-633171afd76f29e23b51628c752ad4c6d05bf4ea.tar.zst
gsoc2013-evolution-633171afd76f29e23b51628c752ad4c6d05bf4ea.zip
Fix the previous overflow problem properly (can happen in 2 places).
2000-05-02 NotZed <NotZed@HelixCode.com> * camel-mime-parser.c (folder_scan_header): Fix the previous overflow problem properly (can happen in 2 places). (header_append): A new macro to include the code changed above, so it only appears in one place. (folder_scan_step): Change the content type to text/plain if the multipart is broken. Doesn't actually change the header though. (header_append): Also move the header-start tracking stuff here. Could be a static function to save code. svn path=/trunk/; revision=2751
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog11
-rw-r--r--camel/camel-mime-parser.c69
2 files changed, 41 insertions, 39 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index 0a07b05601..8f0281b0e2 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,14 @@
+2000-05-02 NotZed <NotZed@HelixCode.com>
+
+ * camel-mime-parser.c (folder_scan_header): Fix the previous
+ overflow problem properly (can happen in 2 places).
+ (header_append): A new macro to include the code changed above, so
+ it only appears in one place.
+ (folder_scan_step): Change the content type to text/plain if the
+ multipart is broken. Doesn't actually change the header though.
+ (header_append): Also move the header-start tracking stuff here.
+ Could be a static function to save code.
+
2000-05-02 <notzed@helixcode.com>
* camel-mime-part-utils.c
diff --git a/camel/camel-mime-parser.c b/camel/camel-mime-parser.c
index 6039c10d78..a8910f3984 100644
--- a/camel/camel-mime-parser.c
+++ b/camel/camel-mime-parser.c
@@ -529,6 +529,7 @@ folder_scan_skip_line(struct _header_scan_state *s)
return -1; /* not found */
}
+/* TODO: Is there any way to make this run faster? It gets called a lot ... */
static struct _header_scan_stack *
folder_boundary_check(struct _header_scan_state *s, const char *boundary, int *lastone)
{
@@ -561,6 +562,28 @@ folder_boundary_check(struct _header_scan_state *s, const char *boundary, int *l
return NULL;
}
+/* Copy the string start->inptr into the header buffer (s->outbuf),
+ grow if necessary
+ and track the start offset of the header */
+/* Basically an optimised version of g_byte_array_append() */
+#define header_append(s, start, inptr) \
+{ \
+ register int headerlen = inptr-start; \
+ \
+ if (headerlen >= (s->outend - s->outptr)) { \
+ register char *outnew; \
+ register int len = ((s->outend - s->outbuf)+headerlen)*2+1; \
+ outnew = g_realloc(s->outbuf, len); \
+ s->outptr = s->outptr - s->outbuf + outnew; \
+ s->outbuf = outnew; \
+ s->outend = outnew + len; \
+ } \
+ memcpy(s->outptr, start, headerlen); \
+ s->outptr += headerlen; \
+ if (s->header_start == -1) \
+ s->header_start = (start-s->inbuf) + s->seek; \
+}
+
static struct _header_scan_stack *
folder_scan_header(struct _header_scan_state *s, int *lastone)
{
@@ -613,31 +636,12 @@ retry:
while (inptr<=inend && (c = *inptr++)!='\n')
;
- /* allocate/append - this wont get executed unless we have *huge* headers,
- and then probably only once */
- {
- register int headerlen = inptr-start;
- register int len = (s->outend - s->outbuf);
- char *outnew;
-
- if (headerlen >= s->outend - s->outptr) {
- len = (len+headerlen)*2+1;
- outnew = g_realloc(s->outbuf, len);
- s->outptr = s->outptr - s->outbuf + outnew;
- s->outbuf = outnew;
- s->outend = outnew + len;
- }
- memcpy(s->outptr, start, headerlen);
- s->outptr += headerlen;
- }
+ header_append(s, start, inptr);
h(printf("outbuf[0] = %02x '%c' oubuf[1] = %02x '%c'\n",
s->outbuf[0], isprint(s->outbuf[0])?s->outbuf[0]:'.',
s->outbuf[1], isprint(s->outbuf[1])?s->outbuf[1]:'.'));
- if (s->header_start == -1)
- s->header_start = (start-s->inbuf) + s->seek;
-
if (c!='\n') {
s->midline = TRUE;
} else {
@@ -696,28 +700,12 @@ retry:
header_truncated:
- {
- register int headerlen = inptr-start;
- register int len = (s->outend - s->outbuf);
- char *outnew;
-
- if (headerlen >= len) {
- len = (len+headerlen)*2+1;
- outnew = g_realloc(s->outbuf, len);
- s->outptr = s->outptr - s->outbuf + outnew;
- s->outbuf = outnew;
- s->outend = outnew + len;
- }
- memcpy(s->outptr, start, headerlen);
- s->outptr += headerlen;
- }
+ header_append(s, start, inptr);
+
if (s->outptr>s->outbuf && s->outptr[-1] == '\n')
s->outptr--;
s->outptr[0] = 0;
- if (s->header_start == -1)
- s->header_start = (start-s->inbuf) + s->seek;
-
if (s->outbuf[0] == '\n'
|| (s->outbuf[0] == '\r' && s->outbuf[1]=='\n')) {
goto header_done;
@@ -1042,7 +1030,10 @@ tail_recurse:
sprintf(h->boundary, "--%s--", bound);
type = HSCAN_MULTIPART;
} else {
-#warning actually convert the multipart to text/plain here.
+ header_content_type_unref(ct);
+ ct = header_content_type_decode("text/plain");
+/* We can't quite do this, as it will mess up all the offsets ... */
+/* header_raw_replace(&h->headers, "Content-Type", "text/plain", offset);*/
g_warning("Multipart with no boundary, treating as text/plain");
}
} else if (!strcasecmp(ct->type, "message")) {