[dovecot-cvs] dovecot/src/lib-mail istream-header-filter.c, 1.39, 1.40 message-body-search.c, 1.34, 1.35 message-body-search.h, 1.10, 1.11 message-decoder.c, 1.10, 1.11 message-header-parser.c, 1.6, 1.7 message-header-parser.h, 1.4, 1.5 message-parser.c, 1.85, 1.86 message-parser.h, 1.37, 1.38

tss at dovecot.org tss at dovecot.org
Wed Apr 4 12:27:36 EEST 2007


Update of /var/lib/cvs/dovecot/src/lib-mail
In directory talvi:/tmp/cvs-serv25146/lib-mail

Modified Files:
	istream-header-filter.c message-body-search.c 
	message-body-search.h message-decoder.c 
	message-header-parser.c message-header-parser.h 
	message-parser.c message-parser.h 
Log Message:
Header parser has now flags parameter to tell it how to handle linefeeds.
Changed message parser's boolean parameter to enum as well.



Index: istream-header-filter.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/istream-header-filter.c,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -d -r1.39 -r1.40
--- istream-header-filter.c	1 Mar 2007 11:13:56 -0000	1.39
+++ istream-header-filter.c	4 Apr 2007 09:27:30 -0000	1.40
@@ -79,7 +79,7 @@
 
 	if (mstream->hdr_ctx == NULL) {
 		mstream->hdr_ctx =
-			message_parse_header_init(mstream->input, NULL, FALSE);
+			message_parse_header_init(mstream->input, NULL, 0);
 	}
 
 	buffer_copy(mstream->hdr_buf, 0,

Index: message-body-search.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-body-search.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- message-body-search.c	3 Apr 2007 18:43:30 -0000	1.34
+++ message-body-search.c	4 Apr 2007 09:27:32 -0000	1.35
@@ -161,6 +161,8 @@
 			struct istream *input,
 			const struct message_part *parts)
 {
+	const enum message_header_parser_flags hdr_parser_flags =
+		MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE;
 	struct message_parser_ctx *parser_ctx;
 	struct message_block raw_block, block;
 	int ret = 0;
@@ -171,7 +173,7 @@
 
 	parser_ctx =
 		message_parser_init_from_parts((struct message_part *)parts,
-					       input, TRUE);
+					       input, hdr_parser_flags, 0);
 
 	while ((ret = message_parser_parse_next_block(parser_ctx,
 						      &raw_block)) > 0) {

Index: message-body-search.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-body-search.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- message-body-search.h	3 Apr 2007 18:05:28 -0000	1.10
+++ message-body-search.h	4 Apr 2007 09:27:33 -0000	1.11
@@ -5,8 +5,7 @@
 struct message_body_search_context;
 
 /* Returns 1 if ok, 0 if unknown charset, -1 if key contains invalid characters
-   in given charset. If charset is NULL, the key isn't assumed to be in any
-   specific charset but is compared to message data without any translation. */
+   in given charset. */
 int message_body_search_init(pool_t pool, const char *key, const char *charset,
 			     bool search_header,
 			     struct message_body_search_context **ctx_r);

Index: message-decoder.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-decoder.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- message-decoder.c	4 Apr 2007 06:15:31 -0000	1.10
+++ message-decoder.c	4 Apr 2007 09:27:33 -0000	1.11
@@ -78,7 +78,7 @@
 	bool unknown_charset;
 
 	if (charset == NULL || charset_is_utf8(charset)) {
-		/* ASCII */
+		/* ASCII / UTF-8 */
 		_charset_utf8_ucase(data, size, ctx->buf, ctx->buf->used);
 		return TRUE;
 	}

Index: message-header-parser.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-header-parser.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- message-header-parser.c	4 Apr 2007 08:57:55 -0000	1.6
+++ message-header-parser.c	4 Apr 2007 09:27:33 -0000	1.7
@@ -17,14 +17,14 @@
 	buffer_t *value_buf;
 	size_t skip;
 
-	unsigned int skip_initial_lwsp:1;
+	enum message_header_parser_flags flags;
 	unsigned int skip_line:1;
 	unsigned int has_nuls:1;
 };
 
 struct message_header_parser_ctx *
 message_parse_header_init(struct istream *input, struct message_size *hdr_size,
-			  bool skip_initial_lwsp)
+			  enum message_header_parser_flags flags)
 {
 	struct message_header_parser_ctx *ctx;
 
@@ -32,7 +32,7 @@
 	ctx->input = input;
 	ctx->hdr_size = hdr_size;
 	ctx->name = str_new(default_pool, 128);
-	ctx->skip_initial_lwsp = skip_initial_lwsp;
+	ctx->flags = flags;
 
 	if (hdr_size != NULL)
 		memset(hdr_size, 0, sizeof(*hdr_size));
@@ -72,8 +72,10 @@
 
 	startpos = 0; colon_pos = UINT_MAX;
 
-	last_crlf = line->crlf_newline;
-	last_no_newline = line->no_newline;
+	last_crlf = line->crlf_newline &&
+		(ctx->flags & MESSAGE_HEADER_PARSER_FLAG_DROP_CR) == 0;
+	last_no_newline = line->no_newline ||
+		(ctx->flags & MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE) != 0;
 	line->no_newline = FALSE;
 	line->crlf_newline = FALSE;
 
@@ -284,7 +286,7 @@
 
 		line->value = msg + colon_pos+1;
 		line->value_len = size - colon_pos - 1;
-		if (ctx->skip_initial_lwsp) {
+		if (ctx->flags & MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP) {
 			/* get value. skip all LWSP after ':'. Note that
 			   RFC2822 doesn't say we should, but history behind
 			   it..
@@ -341,7 +343,17 @@
 				buffer_append_c(ctx->value_buf, '\r');
 			buffer_append_c(ctx->value_buf, '\n');
 		}
-		buffer_append(ctx->value_buf, line->value, line->value_len);
+		if ((ctx->flags & MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE) &&
+		    line->value_len > 0 && line->value[0] != ' ') {
+			i_assert(IS_LWSP(line->value[0]));
+
+			buffer_append_c(ctx->value_buf, ' ');
+			buffer_append(ctx->value_buf,
+				      line->value + 1, line->value_len - 1);
+		} else {
+			buffer_append(ctx->value_buf,
+				      line->value, line->value_len);
+		}
 		line->full_value = buffer_get_data(ctx->value_buf,
 						   &line->full_value_len);
 	} else {
@@ -369,13 +381,14 @@
 
 #undef message_parse_header
 void message_parse_header(struct istream *input, struct message_size *hdr_size,
+			  enum message_header_parser_flags flags,
 			  message_header_callback_t *callback, void *context)
 {
 	struct message_header_parser_ctx *hdr_ctx;
 	struct message_header_line *hdr;
 	int ret;
 
-	hdr_ctx = message_parse_header_init(input, hdr_size, TRUE);
+	hdr_ctx = message_parse_header_init(input, hdr_size, flags);
 	while ((ret = message_parse_header_next(hdr_ctx, &hdr)) > 0)
 		callback(hdr, context);
 	i_assert(ret != 0);

Index: message-header-parser.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-header-parser.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- message-header-parser.h	15 Dec 2006 18:10:57 -0000	1.4
+++ message-header-parser.h	4 Apr 2007 09:27:33 -0000	1.5
@@ -7,6 +7,15 @@
 struct message_size;
 struct message_header_parser_ctx;
 
+enum message_header_parser_flags {
+	/* Don't add LWSP after "header: " to value. */
+	MESSAGE_HEADER_PARSER_FLAG_SKIP_INITIAL_LWSP	= 0x01,
+	/* Don't add CRs to full_value even if input had them */
+	MESSAGE_HEADER_PARSER_FLAG_DROP_CR		= 0x02,
+	/* Convert [CR+]LF+LWSP to a space character */
+	MESSAGE_HEADER_PARSER_FLAG_CLEAN_ONELINE	= 0x04
+};
+
 struct message_header_line {
 	const char *name;
 	size_t name_len;
@@ -34,13 +43,9 @@
 typedef void message_header_callback_t(struct message_header_line *hdr,
 				       void *context);
 
-/* skip_initial_lwsp controls if we should skip LWSP after "header: ".
-   Note that there may not be the single whitespace after "header:", and that
-   "header : " is also possible. These two conditions can't be determined from
-   struct message_header_line. */
 struct message_header_parser_ctx *
 message_parse_header_init(struct istream *input, struct message_size *hdr_size,
-			  bool skip_initial_lwsp);
+			  enum message_header_parser_flags flags);
 void message_parse_header_deinit(struct message_header_parser_ctx **ctx);
 
 /* Read and return next header line. Returns 1 if header is returned, 0 if
@@ -54,15 +59,16 @@
 
 /* Read and parse the header from the given stream. */
 void message_parse_header(struct istream *input, struct message_size *hdr_size,
+			  enum message_header_parser_flags flags,
 			  message_header_callback_t *callback, void *context);
 #ifdef CONTEXT_TYPE_SAFETY
-#  define message_parse_header(input, hdr_size, callback, context) \
+#  define message_parse_header(input, hdr_size, flags, callback, context) \
 	({(void)(1 ? 0 : callback((struct message_header_line *)0, context)); \
-	  message_parse_header(input, hdr_size, \
+	  message_parse_header(input, hdr_size, flags, \
 		(message_header_callback_t *)callback, context); })
 #else
-#  define message_parse_header(input, hdr_size, callback, context) \
-	  message_parse_header(input, hdr_size, \
+#  define message_parse_header(input, hdr_size, flags, callback, context) \
+	  message_parse_header(input, hdr_size, flags, \
 		(message_header_callback_t *)callback, context)
 #endif
 

Index: message-parser.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-parser.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- message-parser.c	3 Apr 2007 16:22:40 -0000	1.85
+++ message-parser.c	4 Apr 2007 09:27:33 -0000	1.86
@@ -25,6 +25,9 @@
 	struct istream *input;
 	struct message_part *parts, *part;
 
+	enum message_header_parser_flags hdr_flags;
+	enum message_parser_flags flags;
+
 	const char *last_boundary;
 	struct message_boundary *boundaries;
 
@@ -37,7 +40,6 @@
 	int (*parse_next_block)(struct message_parser_ctx *ctx,
 				struct message_block *block_r);
 
-	unsigned int return_body_blocks:1;
 	unsigned int part_seen_content_type:1;
 };
 
@@ -534,7 +536,7 @@
 
 	ctx->hdr_parser_ctx =
 		message_parse_header_init(ctx->input, &ctx->part->header_size,
-					  TRUE);
+					  ctx->hdr_flags);
 	ctx->part_seen_content_type = FALSE;
 
 	ctx->parse_next_block = parse_next_header;
@@ -610,7 +612,7 @@
 	if (ctx->part->children != NULL) {
 		ctx->parse_next_block = preparsed_parse_next_header_init;
 		ctx->part = ctx->part->children;
-	} else if (ctx->return_body_blocks) {
+	} else if ((ctx->flags & MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK) == 0) {
 		ctx->parse_next_block = preparsed_parse_body_init;
 	} else {
 		preparsed_skip_to_next(ctx);
@@ -652,14 +654,17 @@
 	i_stream_skip(ctx->input, ctx->part->physical_pos -
 		      ctx->input->v_offset);
 
-	ctx->hdr_parser_ctx = message_parse_header_init(ctx->input, NULL, TRUE);
+	ctx->hdr_parser_ctx =
+		message_parse_header_init(ctx->input, NULL, ctx->hdr_flags);
 
 	ctx->parse_next_block = preparsed_parse_next_header;
 	return preparsed_parse_next_header(ctx, block_r);
 }
 
 struct message_parser_ctx *
-message_parser_init(pool_t part_pool, struct istream *input)
+message_parser_init(pool_t part_pool, struct istream *input,
+		    enum message_header_parser_flags hdr_flags,
+		    enum message_parser_flags flags)
 {
 	struct message_parser_ctx *ctx;
 	pool_t pool;
@@ -668,6 +673,8 @@
 	ctx = p_new(pool, struct message_parser_ctx, 1);
 	ctx->parser_pool = pool;
 	ctx->part_pool = part_pool;
+	ctx->hdr_flags = hdr_flags;
+	ctx->flags = flags;
 	ctx->input = input;
 	ctx->parts = ctx->part = part_pool == NULL ? NULL :
 		p_new(part_pool, struct message_part, 1);
@@ -677,12 +684,13 @@
 
 struct message_parser_ctx *
 message_parser_init_from_parts(struct message_part *parts,
-			       struct istream *input, bool return_body_blocks)
+			       struct istream *input,
+			       enum message_header_parser_flags hdr_flags,
+			       enum message_parser_flags flags)
 {
 	struct message_parser_ctx *ctx;
 
-	ctx = message_parser_init(NULL, input);
-	ctx->return_body_blocks = return_body_blocks;
+	ctx = message_parser_init(NULL, input, hdr_flags, flags);
 	ctx->parts = ctx->part = parts;
 	ctx->parse_next_block = preparsed_parse_next_header_init;
 	return ctx;

Index: message-parser.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-mail/message-parser.h,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- message-parser.h	3 Apr 2007 16:22:40 -0000	1.37
+++ message-parser.h	4 Apr 2007 09:27:34 -0000	1.38
@@ -4,6 +4,10 @@
 #include "message-header-parser.h"
 #include "message-size.h"
 
+enum message_parser_flags {
+	MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK	= 0x01
+};
+
 /* Note that these flags are used directly by message-parser-serialize, so
    existing flags can't be changed without breaking backwards compatibility */
 enum message_part_flags {
@@ -60,11 +64,15 @@
 /* Initialize message parser. part_spool specifies where struct message_parts
    are allocated from. */
 struct message_parser_ctx *
-message_parser_init(pool_t part_pool, struct istream *input);
+message_parser_init(pool_t part_pool, struct istream *input,
+		    enum message_header_parser_flags hdr_flags,
+		    enum message_parser_flags flags);
 /* Use preparsed parts to speed up parsing. */
 struct message_parser_ctx *
 message_parser_init_from_parts(struct message_part *parts,
-			       struct istream *input, bool return_body_blocks);
+			       struct istream *input,
+			       enum message_header_parser_flags hdr_flags,
+			       enum message_parser_flags flags);
 struct message_part *message_parser_deinit(struct message_parser_ctx **ctx);
 
 /* Read the next block of a message. Returns 1 if block is returned, 0 if



More information about the dovecot-cvs mailing list