[Evolution-hackers] camel_header_unfold()
- From: Jules Colding <colding omesc com>
- To: Evolution Hackers <evolution-hackers gnome org>
- Subject: [Evolution-hackers] camel_header_unfold()
- Date: Mon, 28 Nov 2005 15:10:46 +0100
Hi,
Consider the camel_header_unfold() function:
char *
camel_header_unfold(const char *in)
{
char *out = g_malloc(strlen(in)+1);
const char *inptr = in;
char c, *o = out;
o = out;
while ((c = *inptr++)) {
if (c == '\n') {
if (camel_mime_is_lwsp(*inptr)) {
do {
inptr++;
} while (camel_mime_is_lwsp(*inptr));
*o++ = ' ';
} else {
*o++ = c;
}
} else {
*o++ = c;
}
}
*o = 0;
return out;
}
This function will skip any sequence of space (' '), tabs ('\t') and
newlines ('\n') as long as it starts with '\n'. How can that be right?
RFC 822, and RFC 2822 in particular, explicitly states that unfolding is
done by removing any CRLF ('\r' followed by '\n') that is immediately
followed by ' ' or '\t'.
I really can't see how camel_header_unfold() can unfold a message header
correctly.
The following should be better:
char*
unfold_rfc822_header(const char *rfc822_header)
{
char *retv = NULL;
char *dst = NULL;
retv = (char*)malloc(sizeof(char)*(strlen(rfc822_header) + 1));
if (!retv)
return NULL;
dst = retv;
while (1) {
if ('\0' == *rfc822_header)
break;
if (('\r' == *rfc822_header) && // using RFC 2822 section 2.2 to exclude testing for '\n'
((' ' == *(rfc822_header + 2)) || ('\t' == *(rfc822_header + 2)))) {
rfc822_header += 2;
}
*dst = *rfc822_header;
if (!dst)
break;
dst++;
rfc822_header++;
}
*dst = '\0';
if (strlen(retv) != strlen(rfc822_header))
retv = (char*)realloc((void*)retv, strlen(retv) + 1);
return retv;
}
Comments?
jules
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]