diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-06-12 15:31:27 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-06-12 15:31:27 +0200 |
commit | 938b2c2d31617ce7ae1d674f82f520c070153198 (patch) | |
tree | 97caf6c28f08b0ab4c16c7d1e2a22bf3edd72afe /mmime.c | |
parent | f726c2127678c3febf82ee4c9574a035ee8404e8 (diff) | |
download | mblaze-938b2c2d31617ce7ae1d674f82f520c070153198.tar.gz mblaze-938b2c2d31617ce7ae1d674f82f520c070153198.tar.xz mblaze-938b2c2d31617ce7ae1d674f82f520c070153198.zip |
mmime: gen_attachment: try to generate filenames as atoms, use qp for double quotes
Diffstat (limited to 'mmime.c')
-rw-r--r-- | mmime.c | 15 |
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++); |