about summary refs log tree commit diff
path: root/mmime.c
diff options
context:
space:
mode:
Diffstat (limited to 'mmime.c')
-rw-r--r--mmime.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/mmime.c b/mmime.c
index 3bcbbd1..0dbadfb 100644
--- a/mmime.c
+++ b/mmime.c
@@ -118,16 +118,21 @@ static void
 gen_attachment(const char *filename)
 {
 	const char *s = filename;
+	int quote = 0;
 
-	for (s = (char *) filename; *s; s++)
-		if (*s <= 32 || *s >= 127 || s - filename > 35)
+	for (s = (char *) filename; *s; s++) {
+		if (*s < 32 || *s == '"' || *s >= 127 || s - filename > 35)
 			goto rfc2231;
+		if (strchr(" ()<>@,;:\\/[]?=", *s))
+			quote = 1;
+	}
 
-	printf("Content-Disposition: attachment; filename=\"%s\"\n", filename);
+	// filename SHOULD be an atom if possible
+	printf("Content-Disposition: attachment; filename=%s%s%s\n",
+	    quote ? "\"" : "", filename, quote ? "\"" : "");
 	return;
 
 rfc2231:
-
 	printf("Content-Disposition: attachment");
 	int i = 0;
 	int d = 0;
@@ -141,7 +146,7 @@ rfc2231:
 			i += 7;
 		}
 		while (*s && i < 78 - 3) {
-			if (*s <= 32 || *s > 126)
+			if (*s <= 32 || *s == '"' || *s > 126)
 				i += printf("%%%02x", (uint8_t) *s++);
 			else
 				i += printf("%c", (uint8_t) *s++);