Preserve QOutlook inline EML attachments

This commit is contained in:
Курнат Андрей
2026-06-01 08:25:11 +03:00
parent 472288badf
commit 1df1b1114e
3 changed files with 44 additions and 3 deletions
+33
View File
@@ -137,6 +137,39 @@ describe("outlookMail helpers", () => {
await expect(attachmentToBlob(attachments[0]).text()).resolves.toBe("Привет");
});
it("извлекает inline MIME-вложения с Content-ID и не добавляет бинарную часть в тело", async () => {
const body = [
"--related",
"Content-Type: text/html; charset=utf-8",
"",
"<p>Logo</p><img src=\"cid:logo\">",
"--related",
"Content-Type: image/png",
"Content-Disposition: inline",
"Content-ID: <logo>",
"Content-Transfer-Encoding: base64",
"",
"SGVsbG8=",
"--related--"
].join("\r\n");
const headers = { "content-type": 'multipart/related; boundary="related"' };
const attachments = extractMessageAttachments(headers, body);
expect(extractMessageBody(headers, body)).toBe("Logo");
expect(attachments).toEqual([
{
id: "attachment-вложение-1-1",
fileName: "Вложение 1",
contentType: "image/png",
size: 5,
contentBase64: "SGVsbG8=",
disposition: "inline",
contentId: "logo"
}
]);
await expect(attachmentToBlob(attachments[0]).text()).resolves.toBe("Hello");
});
it("импортирует multipart EML как письмо QOutlook", async () => {
const eml = [
"From: sender@example.com",
+9 -1
View File
@@ -200,6 +200,7 @@ export function extractMessageBody(headers: MailHeaders, body: string): string {
const bodyParts = parseMultipartBody(body, boundary)
.filter((part) => !isAttachmentPart(part.headers))
.filter((part) => isMessageBodyPart(part.headers))
.map((part) => {
const partType = parseContentType(part.headers["content-type"]);
return {
@@ -718,13 +719,20 @@ function unquoteHeaderValue(value: string): string {
function isAttachmentPart(headers: MailHeaders): boolean {
const disposition = parseContentDisposition(headers["content-disposition"]);
const contentType = parseContentType(headers["content-type"]);
const dispositionValue = disposition.value.toLowerCase();
return (
disposition.value.toLowerCase() === "attachment" ||
dispositionValue === "attachment" ||
(dispositionValue === "inline" && Boolean(headers["content-id"])) ||
Boolean(decodeMimeParameter(disposition.parameters, "filename")) ||
Boolean(decodeMimeParameter(contentType.parameters, "name"))
);
}
function isMessageBodyPart(headers: MailHeaders): boolean {
const contentType = parseContentType(headers["content-type"]);
return contentType.mediaType.startsWith("multipart/") || contentType.mediaType === "text/plain" || contentType.mediaType === "text/html";
}
function decodeHtmlEntities(value: string): string {
const namedEntities: Record<string, string> = {
amp: "&",