[dovecot-cvs] dovecot/src/lib-imap imap-quote.c,1.7,1.8

cras at procontrol.fi cras at procontrol.fi
Thu Feb 13 23:07:47 EET 2003


Update of /home/cvs/dovecot/src/lib-imap
In directory danu:/tmp/cvs-serv32473/lib-imap

Modified Files:
	imap-quote.c 
Log Message:
Quoting didn't remove CR and LF characters, so it could have caused
corrupted ENVELOPE/BODY replies.



Index: imap-quote.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-quote.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- imap-quote.c	11 Feb 2003 12:31:10 -0000	1.7
+++ imap-quote.c	13 Feb 2003 21:07:44 -0000	1.8
@@ -7,7 +7,7 @@
 void imap_quote_append(string_t *str, const unsigned char *value,
 		       size_t value_len)
 {
-	size_t i;
+	size_t i, linefeeds = 0;
 	int literal = FALSE;
 
 	for (i = 0; i < value_len; i++) {
@@ -16,6 +16,9 @@
 			break;
 		}
 
+		if (value[i] == 13 || value[i] == 10)
+                        linefeeds++;
+
 		if ((value[i] & 0x80) != 0)
 			literal = TRUE;
 	}
@@ -23,13 +26,22 @@
 	if (!literal) {
 		/* no 8bit chars, return as "string" */
 		str_append_c(str, '"');
-		str_append_n(str, value, value_len);
-		str_append_c(str, '"');
 	} else {
 		/* return as literal */
-		str_printfa(str, "{%"PRIuSIZE_T"}\r\n", value_len);
+		str_printfa(str, "{%"PRIuSIZE_T"}\r\n", value_len - linefeeds);
+	}
+
+	if (linefeeds == 0)
 		str_append_n(str, value, value_len);
+	else {
+		for (i = 0; i < value_len; i++) {
+			if (value[i] != 13 && value[i] != 10)
+				str_append_c(str, value[i]);
+		}
 	}
+
+	if (!literal)
+		str_append_c(str, '"');
 }
 
 const char *imap_quote_str_nil(const char *value)




More information about the dovecot-cvs mailing list