Re: [Evolution-hackers] camel_header_unfold()



On Mon, 2005-11-28 at 15:10 +0100, Jules Colding wrote:
> 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.
> 

I see what you are thinking, but by the time this code is run on any
input, the \r has already been stripped and you cannot, by definition,
have \n\n in a header (it terminates the header block so we don't have
to worry about that).

I suppose the following modification could be made to be more clear:

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 (*inptr == ' ' || *inptr == '\t') {
				do {
					inptr++;
				} while (*inptr == ' ' || *inptr == '\t');
				*o++ = ' ';
			} else {
				*o++ = c;
			}
		} else {
			*o++ = c;
		}
	}
	*o = 0;

	return out;
}

-- 
Jeffrey Stedfast
Evolution Hacker - Novell, Inc.
fejj ximian com  - www.novell.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]