From b7a2c4682c91a8809eae7f55e783f93e652ee142 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Mon, 22 Jul 2002 03:17:04 +0000 Subject: Only add a \r if the character before the \n wasn't already a \r - this 2002-07-21 Jeffrey Stedfast * camel-mime-filter-crlf.c (filter): Only add a \r if the character before the \n wasn't already a \r - this covers for when people add DOS files as attachments. Fixes bug #28056. ` svn path=/trunk/; revision=17521 --- camel/ChangeLog | 6 +++++ camel/camel-mime-filter-crlf.c | 56 ++++++++++++++++++++++++------------------ 2 files changed, 38 insertions(+), 24 deletions(-) (limited to 'camel') diff --git a/camel/ChangeLog b/camel/ChangeLog index 9e983fc53d..90cdcee296 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,9 @@ +2002-07-21 Jeffrey Stedfast + + * camel-mime-filter-crlf.c (filter): Only add a \r if the + character before the \n wasn't already a \r - this covers for when + people add DOS files as attachments. Fixes bug #28056. + 2002-07-19 Not Zed * camel-mime-part-utils.c (convert_buffer): Changed to use a diff --git a/camel/camel-mime-filter-crlf.c b/camel/camel-mime-filter-crlf.c index 57378bbc24..bd21ef991c 100644 --- a/camel/camel-mime-filter-crlf.c +++ b/camel/camel-mime-filter-crlf.c @@ -64,57 +64,65 @@ filter (CamelMimeFilter *f, char *in, size_t len, size_t prespace, char **out, size_t *outlen, size_t *outprespace) { CamelMimeFilterCRLF *crlf = (CamelMimeFilterCRLF *)f; + register const char *inptr; + const char *inend; gboolean do_dots; - char *p, *q; + char *outptr; do_dots = crlf->mode == CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS; + inptr = in; + inend = in + len; + if (crlf->direction == CAMEL_MIME_FILTER_CRLF_ENCODE) { camel_mime_filter_set_size (f, 3 * len, FALSE); - p = in; - q = f->outbuf; - while (p < in + len) { - if (*p == '\n') { + outptr = f->outbuf; + while (inptr < inend) { + if (*inptr == '\r') { + crlf->saw_cr = TRUE; + } else if (*inptr == '\n') { crlf->saw_lf = TRUE; - *q++ = '\r'; + if (!crlf->saw_cr) + *outptr++ = '\r'; + crlf->saw_cr = FALSE; } else { - if (do_dots && *p == '.' && crlf->saw_lf) - *q++ = '.'; + if (do_dots && *inptr == '.' && crlf->saw_lf) + *outptr++ = '.'; + crlf->saw_cr = FALSE; crlf->saw_lf = FALSE; } - *q++ = *p++; + *outptr++ = *inptr++; } } else { camel_mime_filter_set_size (f, len, FALSE); - p = in; - q = f->outbuf; - while (p < in + len) { - if (*p == '\r') { + outptr = f->outbuf; + while (inptr < inend) { + if (*inptr == '\r') { crlf->saw_cr = TRUE; } else { if (crlf->saw_cr) { crlf->saw_cr = FALSE; - if (*p == '\n') { + if (*inptr == '\n') { crlf->saw_lf = TRUE; - *q++ = *p++; + *outptr++ = *inptr++; continue; } else - *q++ = '\r'; + *outptr++ = '\r'; } - *q++ = *p; + *outptr++ = *inptr; } - if (do_dots && *p == '.') { + if (do_dots && *inptr == '.') { if (crlf->saw_lf) { crlf->saw_dot = TRUE; crlf->saw_lf = FALSE; - p++; + inptr++; } else if (crlf->saw_dot) { crlf->saw_dot = FALSE; } @@ -122,12 +130,12 @@ filter (CamelMimeFilter *f, char *in, size_t len, size_t prespace, crlf->saw_lf = FALSE; - p++; + inptr++; } } *out = f->outbuf; - *outlen = q - f->outbuf; + *outlen = outptr - f->outbuf; *outprespace = f->outpre; } @@ -143,7 +151,7 @@ static void reset (CamelMimeFilter *f) { CamelMimeFilterCRLF *crlf = (CamelMimeFilterCRLF *)f; - + crlf->saw_cr = FALSE; crlf->saw_lf = TRUE; crlf->saw_dot = FALSE; @@ -153,12 +161,12 @@ CamelMimeFilter * camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction, CamelMimeFilterCRLFMode mode) { CamelMimeFilterCRLF *crlf = CAMEL_MIME_FILTER_CRLF(camel_object_new (CAMEL_MIME_FILTER_CRLF_TYPE)); - + crlf->direction = direction; crlf->mode = mode; crlf->saw_cr = FALSE; crlf->saw_lf = TRUE; crlf->saw_dot = FALSE; - + return (CamelMimeFilter *)crlf; } -- cgit