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

pull/37/head
Leah Neukirchen 7 years ago
parent f726c21276
commit 938b2c2d31

@ -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++);

Loading…
Cancel
Save