mblaze

Unix utilities to deal with Maildir - my mirror
git clone https://pi.duncano.de/git/mblaze.git
Log | Files | Refs | README | COPYING

commit 938b2c2d31617ce7ae1d674f82f520c070153198
parent f726c2127678c3febf82ee4c9574a035ee8404e8
Author: Leah Neukirchen <leah@vuxu.org>
Date:   Mon, 12 Jun 2017 15:31:27 +0200

mmime: gen_attachment: try to generate filenames as atoms, use qp for double quotes

Diffstat:
mmime.c | 15++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git 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++);