aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-filter-crlf.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/camel-mime-filter-crlf.c')
-rw-r--r--camel/camel-mime-filter-crlf.c56
1 files changed, 32 insertions, 24 deletions
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;
}