Preserve QOutlook inline EML attachments
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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: "&",
|
||||
|
||||
Reference in New Issue
Block a user