[dovecot-cvs] dovecot/src/lib-imap imap-bodystructure.c,1.34,1.35

cras at procontrol.fi cras at procontrol.fi
Wed Jun 4 20:13:26 EEST 2003


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

Modified Files:
	imap-bodystructure.c 
Log Message:
Add charset/us-ascii into body/bodystructure replies if no charset is given
for text/* body parts.



Index: imap-bodystructure.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-imap/imap-bodystructure.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -d -r1.34 -r1.35
--- imap-bodystructure.c	1 Apr 2003 14:55:48 -0000	1.34
+++ imap-bodystructure.c	4 Jun 2003 16:13:23 -0000	1.35
@@ -12,8 +12,11 @@
 #include "imap-envelope.h"
 #include "imap-bodystructure.h"
 
+#define DEFAULT_CHARSET \
+	"\"charset\" \"us-ascii\""
+
 #define EMPTY_BODYSTRUCTURE \
-        "(\"text\" \"plain\" (\"charset\" \"us-ascii\") NIL NIL \"7bit\" 0 0)"
+        "(\"text\" \"plain\" ("DEFAULT_CHARSET") NIL NIL \"7bit\" 0 0)"
 
 struct message_part_body_data {
 	pool_t pool;
@@ -29,6 +32,8 @@
 	char *content_language;
 
 	struct message_part_envelope_data *envelope;
+
+	unsigned int charset_found:1;
 };
 
 static void part_write_bodystructure(struct message_part *part,
@@ -66,6 +71,9 @@
 	if (str_len(data->str) != 0)
 		str_append_c(data->str, ' ');
 
+	if (name_len == 7 && memcasecmp(name, "charset", 7) == 0)
+		data->charset_found = TRUE;
+
 	imap_quote_append(data->str, name, name_len);
 	str_append_c(data->str, ' ');
 	imap_quote_append(data->str, value, value_len);
@@ -182,6 +190,13 @@
 			message_content_parse_header(value, value_len,
 						     parse_content_type,
 						     parse_save_params_list, d);
+			if (!d->charset_found &&
+			    strncasecmp(d->content_type, "\"text\"", 6) == 0) {
+				/* set a default charset */
+				if (str_len(d->str) != 0)
+					str_append_c(d->str, ' ');
+				str_append(d->str, DEFAULT_CHARSET);
+			}
 			d->content_type_params =
 				p_strdup_empty(pool, str_c(d->str));
 		}
@@ -366,9 +381,13 @@
 
 	/* ("content type param key" "value" ...) */
 	str_append_c(str, ' ');
-	if (data->content_type_params == NULL)
-		str_append(str, "NIL");
-	else {
+	if (data->content_type_params == NULL) {
+		if (data->content_type != NULL &&
+		    strncasecmp(data->content_type, "\"text\"", 6) != 0)
+			str_append(str, "NIL");
+		else
+			str_append(str, "("DEFAULT_CHARSET")");
+	} else {
 		str_append_c(str, '(');
 		str_append(str, data->content_type_params);
 		str_append_c(str, ')');



More information about the dovecot-cvs mailing list