mblaze

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

commit d75c446aff168a399f4d169a7e44220f1acec63e
parent 935f4bf5b92bb066f7c1aa9fbe41b685e7677180
Author: Leah Neukirchen <leah@vuxu.org>
Date:   Thu,  6 Apr 2017 20:54:01 +0200

mmime: use RFC2231 for Content-Disposition when needed

Diffstat:
mmime.c | 44+++++++++++++++++++++++++++++++++++++++++---
1 file changed, 41 insertions(+), 3 deletions(-)

diff --git a/mmime.c b/mmime.c @@ -113,7 +113,45 @@ basenam(const char *s) return r ? r + 1 : s; } -int gen_file(char *file, char *ct) +static void +gen_attachment(const char *filename) +{ + const char *s = filename; + + for (s = (char *) filename; *s; s++) + if (*s <= 32 || *s >= 127 || s - filename > 35) + goto rfc2231; + + printf("Content-Disposition: attachment; filename=\"%s\"\n", filename); + return; + +rfc2231: + + printf("Content-Disposition: attachment"); + int i = 0; + int d = 0; + + s = filename; + + while (*s) { + i = printf(";\n filename*%d*=", d); + if (d++ == 0) { + printf("UTF-8''"); + i += 7; + } + while (*s && i < 78 - 3) { + if (*s <= 32 || *s > 126) + i += printf("%%%02x", (uint8_t) *s++); + else + i += printf("%c", (uint8_t) *s++); + } + } + + printf("\n"); +} + +int +gen_file(char *file, char *ct) { uint8_t *content; off_t size; @@ -144,8 +182,8 @@ int gen_file(char *file, char *ct) bithigh++; } - printf("Content-Disposition: attachment; filename=\"%s\"\n", - basenam(file)); + gen_attachment(basenam(file)); + if (bitlow == 0 && bithigh == 0 && maxlinelen <= 78 && content[size-1] == '\n') { if (!ct)