From 938b2c2d31617ce7ae1d674f82f520c070153198 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 12 Jun 2017 15:31:27 +0200 Subject: mmime: gen_attachment: try to generate filenames as atoms, use qp for double quotes --- mmime.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'mmime.c') 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++); -- cgit 1.4.1