dovecot-2.0: imap_quote*() now have fix_text parameter. If it's ...

dovecot at dovecot.org dovecot at dovecot.org
Sat Aug 29 00:30:28 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/dad7264633a9
changeset: 9827:dad7264633a9
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Aug 28 17:27:08 2009 -0400
description:
imap_quote*() now have fix_text parameter. If it's not set, input isn't modified at all.

diffstat:

4 files changed, 41 insertions(+), 30 deletions(-)
src/lib-imap/imap-bodystructure.c |   26 +++++++++++++++-----------
src/lib-imap/imap-envelope.c      |    6 ++++--
src/lib-imap/imap-quote.c         |   17 +++++++++++------
src/lib-imap/imap-quote.h         |   22 +++++++++++-----------

diffs (196 lines):

diff -r 63b7223cce4b -r dad7264633a9 src/lib-imap/imap-bodystructure.c
--- a/src/lib-imap/imap-bodystructure.c	Fri Aug 28 17:01:41 2009 -0400
+++ b/src/lib-imap/imap-bodystructure.c	Fri Aug 28 17:27:08 2009 -0400
@@ -56,12 +56,11 @@ static void parse_content_type(struct me
 		if (value[i] == '/') {
 			data->content_subtype =
 				imap_quote(data->pool, str_data(str) + i + 1,
-					   str_len(str) - (i + 1));
+					   str_len(str) - (i + 1), TRUE);
 			break;
 		}
 	}
-	data->content_type =
-		imap_quote(data->pool, str_data(str), i);
+	data->content_type = imap_quote(data->pool, str_data(str), i, TRUE);
 
 	/* parse parameters and save them */
 	str_truncate(str, 0);
@@ -100,7 +99,8 @@ static void parse_content_transfer_encod
 	str = t_str_new(256);
 	if (rfc822_parse_mime_token(&parser, str) >= 0) {
 		data->content_transfer_encoding =
-			imap_quote(data->pool, str_data(str), str_len(str));
+			imap_quote(data->pool, str_data(str),
+				   str_len(str), TRUE);
 	}
 }
 
@@ -118,7 +118,7 @@ static void parse_content_disposition(st
 	if (rfc822_parse_mime_token(&parser, str) < 0)
 		return;
 	data->content_disposition =
-		imap_quote(data->pool, str_data(str), str_len(str));
+		imap_quote(data->pool, str_data(str), str_len(str), TRUE);
 
 	/* parse parameters and save them */
 	str_truncate(str, 0);
@@ -186,14 +186,18 @@ static void parse_content_header(struct 
 	switch (*name) {
 	case 'i':
 	case 'I':
-		if (strcasecmp(name, "ID") == 0 && d->content_id == NULL)
-			d->content_id = imap_quote(pool, value, value_len);
+		if (strcasecmp(name, "ID") == 0 && d->content_id == NULL) {
+			d->content_id =
+				imap_quote(pool, value, value_len, TRUE);
+		}
 		break;
 
 	case 'm':
 	case 'M':
-		if (strcasecmp(name, "MD5") == 0 && d->content_md5 == NULL)
-			d->content_md5 = imap_quote(pool, value, value_len);
+		if (strcasecmp(name, "MD5") == 0 && d->content_md5 == NULL) {
+			d->content_md5 =
+				imap_quote(pool, value, value_len, TRUE);
+		}
 		break;
 
 	case 't':
@@ -213,7 +217,7 @@ static void parse_content_header(struct 
 		else if (strcasecmp(name, "Location") == 0 &&
 			 d->content_location == NULL) {
 			d->content_location =
-				imap_quote(pool, value, value_len);
+				imap_quote(pool, value, value_len, TRUE);
 		}
 		break;
 
@@ -222,7 +226,7 @@ static void parse_content_header(struct 
 		if (strcasecmp(name, "Description") == 0 &&
 		    d->content_description == NULL) {
 			d->content_description =
-				imap_quote(pool, value, value_len);
+				imap_quote(pool, value, value_len, TRUE);
 		} else if (strcasecmp(name, "Disposition") == 0 &&
 			   d->content_disposition_params == NULL) {
 			parse_content_disposition(d, hdr);
diff -r 63b7223cce4b -r dad7264633a9 src/lib-imap/imap-envelope.c
--- a/src/lib-imap/imap-envelope.c	Fri Aug 28 17:01:41 2009 -0400
+++ b/src/lib-imap/imap-envelope.c	Fri Aug 28 17:27:08 2009 -0400
@@ -149,8 +149,10 @@ void imap_envelope_parse_header(pool_t p
 						(unsigned int)-1, TRUE);
 	}
 
-	if (str_p != NULL)
-		*str_p = imap_quote(pool, hdr->full_value, hdr->full_value_len);
+	if (str_p != NULL) {
+		*str_p = imap_quote(pool, hdr->full_value,
+				    hdr->full_value_len, TRUE);
+	}
 }
 
 static void imap_write_address(string_t *str, struct message_address *addr)
diff -r 63b7223cce4b -r dad7264633a9 src/lib-imap/imap-quote.c
--- a/src/lib-imap/imap-quote.c	Fri Aug 28 17:01:41 2009 -0400
+++ b/src/lib-imap/imap-quote.c	Fri Aug 28 17:27:08 2009 -0400
@@ -5,7 +5,7 @@
 #include "imap-quote.h"
 
 void imap_quote_append(string_t *str, const unsigned char *value,
-		       size_t value_len, bool compress_lwsp)
+		       size_t value_len, bool fix_text)
 {
 	size_t i, extra = 0;
 	bool last_lwsp = TRUE, literal = FALSE, modify = FALSE;
@@ -23,14 +23,14 @@ void imap_quote_append(string_t *str, co
 		case 0:
 			/* it's converted to 8bit char */
 			literal = TRUE;
+			last_lwsp = FALSE;
 			modify = TRUE;
-			last_lwsp = FALSE;
 			break;
 		case '\t':
 			modify = TRUE;
 			/* fall through */
 		case ' ':
-			if (last_lwsp && compress_lwsp) {
+			if (last_lwsp && fix_text) {
 				modify = TRUE;
 				extra++;
 			}
@@ -47,6 +47,11 @@ void imap_quote_append(string_t *str, co
 				literal = TRUE;
 			last_lwsp = FALSE;
 		}
+	}
+
+	if (!fix_text) {
+		extra = 0;
+		modify = FALSE;
 	}
 
 	if (!literal) {
@@ -69,7 +74,7 @@ void imap_quote_append(string_t *str, co
 				break;
 			case ' ':
 			case '\t':
-				if (!last_lwsp || !compress_lwsp)
+				if (!last_lwsp)
 					str_append_c(str, ' ');
 				last_lwsp = TRUE;
 				break;
@@ -89,7 +94,7 @@ void imap_quote_append(string_t *str, co
 }
 
 const char *imap_quote(pool_t pool, const unsigned char *value,
-		       size_t value_len)
+		       size_t value_len, bool fix_text)
 {
 	string_t *str;
 	char *ret;
@@ -101,7 +106,7 @@ const char *imap_quote(pool_t pool, cons
 		t_push();
 
 	str = t_str_new(value_len + MAX_INT_STRLEN + 5);
-	imap_quote_append(str, value, value_len, TRUE);
+	imap_quote_append(str, value, value_len, fix_text);
 	ret = p_strndup(pool, str_data(str), str_len(str));
 
 	if (!pool->datastack_pool)
diff -r 63b7223cce4b -r dad7264633a9 src/lib-imap/imap-quote.h
--- a/src/lib-imap/imap-quote.h	Fri Aug 28 17:01:41 2009 -0400
+++ b/src/lib-imap/imap-quote.h	Fri Aug 28 17:27:08 2009 -0400
@@ -1,19 +1,19 @@
 #ifndef IMAP_QUOTE_H
 #define IMAP_QUOTE_H
 
+/* Append to existing string. If fix_text=TRUE, it converts TABs to spaces,
+   multiple spaces into a single space and NULs to #128. */
+void imap_quote_append(string_t *str, const unsigned char *value,
+		       size_t value_len, bool fix_text);
+
+#define imap_quote_append_string(str, value, fix_text) \
+	imap_quote_append(str, (const unsigned char *)(value), \
+			  (size_t)-1, fix_text)
+
 /* Return value suitable for sending to client, either as quoted-string or
-   literal. Note that this also converts TABs into spaces, multiple spaces
-   into single space and NULs to #128. */
+   literal. */
 const char *imap_quote(pool_t pool, const unsigned char *value,
-		       size_t value_len);
-
-/* Append to existing string. */
-void imap_quote_append(string_t *str, const unsigned char *value,
-		       size_t value_len, bool compress_lwsp);
-
-#define imap_quote_append_string(str, value, compress_lwsp) \
-	imap_quote_append(str, (const unsigned char *)(value), \
-			  (size_t)-1, compress_lwsp)
+		       size_t value_len, bool fix_text);
 
 /* Append data to destination string quoted using "". */
 void imap_dquote_append(string_t *dest, const char *src);


More information about the dovecot-cvs mailing list