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
This commit is contained in:
Jeffrey Stedfast
2002-07-22 03:17:04 +00:00
committed by Jeffrey Stedfast
parent 3c2391e37e
commit b7a2c4682c
2 changed files with 38 additions and 24 deletions

View File

@ -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

View File

@ -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;
}