better handle mhtml attachments

This commit is contained in:
Adam D. Ruppe 2025-05-20 09:59:35 -04:00
parent f907585145
commit 71e20933af
1 changed files with 21 additions and 2 deletions

23
email.d
View File

@ -745,15 +745,32 @@ class MimePart {
if(type == "multipart/mixed" && stuff.length == 1) if(type == "multipart/mixed" && stuff.length == 1)
return stuff[0].toMimeAttachment; return stuff[0].toMimeAttachment;
// just attach the preferred thing. i think this is never triggered since this is most likely handled by the text/html body scanner
if(type == "multipart/alternative" && stuff.length >= 1)
return stuff[0].toMimeAttachment;
MimeAttachment att; MimeAttachment att;
att.type = type; att.type = type;
att.id = id;
if(filename.length == 0 && name.length > 0 ) { if(filename.length == 0 && name.length > 0 ) {
att.filename = name; att.filename = name;
} else { } else {
att.filename = filename; att.filename = filename;
} }
att.id = id;
att.content = content; if(type == "multipart/related" && stuff.length >= 1) {
// super hack for embedded html for a special user; it is basically a mhtml attachment so we report the filename of the html part for the whole thing
// really, the code should understand the type itself but this is still better than nothing
if(att.filename.length == 0)
att.filename = stuff[0].filename;
if(att.filename.length == 0)
att.filename = stuff[0].name;
att.filename = att.filename.replace(".html", ".mhtml");
att.content = []; // FIXME: recreate the concat thing and put some headers on it to make a valid .mhtml file out of it
} else {
att.content = content;
}
return att; return att;
} }
@ -1666,6 +1683,8 @@ unittest {
assert(result.attachments.equal(mail.attachments)); assert(result.attachments.equal(mail.attachments));
} }
// FIXME: add unittest with a pdf in first multipart/mixed position
private bool hasAllPrintableAscii(in char[] s) { private bool hasAllPrintableAscii(in char[] s) {
foreach(ch; s) { foreach(ch; s) {
if(ch < 32) if(ch < 32)