diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-07-22 11:17:04 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-07-22 11:17:04 +0800 |
commit | b7a2c4682c91a8809eae7f55e783f93e652ee142 (patch) | |
tree | e33c747cb5eaed7a366bea4720f5298a894d839d /camel | |
parent | 3c2391e37e7389ab9e055e14de348c8fb7153038 (diff) | |
download | gsoc2013-evolution-b7a2c4682c91a8809eae7f55e783f93e652ee142.tar.gz gsoc2013-evolution-b7a2c4682c91a8809eae7f55e783f93e652ee142.tar.zst gsoc2013-evolution-b7a2c4682c91a8809eae7f55e783f93e652ee142.zip |
Only add a \r if the character before the \n wasn't already a \r - this
2002-07-21 Jeffrey Stedfast <fejj@ximian.com>
* 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
Diffstat (limited to 'camel')
-rw-r--r-- | camel/ChangeLog | 6 | ||||
-rw-r--r-- | camel/camel-mime-filter-crlf.c | 56 |
2 files changed, 38 insertions, 24 deletions
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 <fejj@ximian.com> + + * 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 <NotZed@Ximian.com> * 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; } |