Preserve QOutlook priority headers in EML
This commit is contained in:
@@ -68,6 +68,9 @@ export function QOutlook({ mail, onChange, onFolderChange }: QOutlookProps) {
|
||||
message.messageId ?? "",
|
||||
message.inReplyTo ?? "",
|
||||
message.references ?? "",
|
||||
message.importance ?? "",
|
||||
message.xPriority ?? "",
|
||||
message.priority ?? "",
|
||||
message.subject,
|
||||
message.body,
|
||||
...(message.attachments ?? []).map((attachment) => attachment.fileName)
|
||||
@@ -329,6 +332,15 @@ export function QOutlook({ mail, onChange, onFolderChange }: QOutlookProps) {
|
||||
{activeMessage.references ? `References: ${activeMessage.references}` : ""}
|
||||
</p>
|
||||
) : null}
|
||||
{activeMessage.importance || activeMessage.xPriority || activeMessage.priority ? (
|
||||
<p className="muted">
|
||||
{activeMessage.importance ? `Importance: ${activeMessage.importance}` : ""}
|
||||
{activeMessage.importance && activeMessage.xPriority ? " · " : ""}
|
||||
{activeMessage.xPriority ? `X-Priority: ${activeMessage.xPriority}` : ""}
|
||||
{(activeMessage.importance || activeMessage.xPriority) && activeMessage.priority ? " · " : ""}
|
||||
{activeMessage.priority ? `Priority: ${activeMessage.priority}` : ""}
|
||||
</p>
|
||||
) : null}
|
||||
<p>{activeMessage.body}</p>
|
||||
{activeAttachments.length > 0 ? (
|
||||
<section className="attachments-panel" aria-label="Вложения письма">
|
||||
|
||||
@@ -180,6 +180,9 @@ describe("outlookMail helpers", () => {
|
||||
"Message-ID: <message-1@example.com>",
|
||||
"In-Reply-To: <parent@example.com>",
|
||||
"References: <root@example.com> <parent@example.com>",
|
||||
"Importance: high",
|
||||
"X-Priority: 1",
|
||||
"Priority: urgent",
|
||||
"Subject: =?UTF-8?B?0JzRg9C70YzRgtC40L/QsNGA0YI=?=",
|
||||
"Date: Mon, 01 Jun 2026 10:00:00 +0300",
|
||||
'Content-Type: multipart/alternative; boundary="alt"',
|
||||
@@ -208,6 +211,9 @@ describe("outlookMail helpers", () => {
|
||||
expect(imported.messageId).toBe("<message-1@example.com>");
|
||||
expect(imported.inReplyTo).toBe("<parent@example.com>");
|
||||
expect(imported.references).toBe("<root@example.com> <parent@example.com>");
|
||||
expect(imported.importance).toBe("high");
|
||||
expect(imported.xPriority).toBe("1");
|
||||
expect(imported.priority).toBe("urgent");
|
||||
});
|
||||
|
||||
it("импортирует multipart/mixed EML с вложением", async () => {
|
||||
@@ -262,6 +268,9 @@ describe("outlookMail helpers", () => {
|
||||
"Message-ID: <msg-1@example.com>",
|
||||
"In-Reply-To: <msg-parent@example.com>",
|
||||
"References: <msg-root@example.com> <msg-parent@example.com>",
|
||||
"Importance: low",
|
||||
"X-Priority: 5",
|
||||
"Priority: non-urgent",
|
||||
"From: sender@example.com"
|
||||
].join("\r\n"),
|
||||
bodyHtml: "<p>HTML текст</p>",
|
||||
@@ -285,6 +294,9 @@ describe("outlookMail helpers", () => {
|
||||
messageId: "<msg-1@example.com>",
|
||||
inReplyTo: "<msg-parent@example.com>",
|
||||
references: "<msg-root@example.com> <msg-parent@example.com>",
|
||||
importance: "low",
|
||||
xPriority: "5",
|
||||
priority: "non-urgent",
|
||||
subject: "MSG отчет",
|
||||
body: "HTML текст",
|
||||
time: "Mon, 01 Jun 2026 10:00:00 GMT",
|
||||
@@ -317,6 +329,9 @@ describe("outlookMail helpers", () => {
|
||||
messageId: "<message-1@example.com>",
|
||||
inReplyTo: "<parent@example.com>",
|
||||
references: "<root@example.com> <parent@example.com>",
|
||||
importance: "high",
|
||||
xPriority: "1",
|
||||
priority: "urgent",
|
||||
subject: "Тема",
|
||||
body: "Текст",
|
||||
time: "Mon, 01 Jan 2024 10:00:00 +0000",
|
||||
@@ -333,6 +348,9 @@ describe("outlookMail helpers", () => {
|
||||
expect(eml).toContain("Message-ID: <message-1@example.com>");
|
||||
expect(eml).toContain("In-Reply-To: <parent@example.com>");
|
||||
expect(eml).toContain("References: <root@example.com> <parent@example.com>");
|
||||
expect(eml).toContain("Importance: high");
|
||||
expect(eml).toContain("X-Priority: 1");
|
||||
expect(eml).toContain("Priority: urgent");
|
||||
expect(eml).toContain("Subject: =?UTF-8?B?");
|
||||
expect(eml.endsWith("Текст")).toBe(true);
|
||||
});
|
||||
@@ -349,6 +367,9 @@ describe("outlookMail helpers", () => {
|
||||
messageId: "<message-1@example.com>",
|
||||
inReplyTo: "<parent@example.com>",
|
||||
references: "<root@example.com> <parent@example.com>",
|
||||
importance: "high",
|
||||
xPriority: "1",
|
||||
priority: "urgent",
|
||||
subject: "Тема",
|
||||
body: "Текст",
|
||||
time: "Mon, 01 Jan 2024 10:00:00 +0000",
|
||||
@@ -377,6 +398,9 @@ describe("outlookMail helpers", () => {
|
||||
expect(eml).toContain("Message-ID: <message-1@example.com>");
|
||||
expect(eml).toContain("In-Reply-To: <parent@example.com>");
|
||||
expect(eml).toContain("References: <root@example.com> <parent@example.com>");
|
||||
expect(eml).toContain("Importance: high");
|
||||
expect(eml).toContain("X-Priority: 1");
|
||||
expect(eml).toContain("Priority: urgent");
|
||||
expect(eml).toContain("filename*=utf-8''%D0%BE%D1%82%D1%87%D0%B5%D1%82%2E%74%78%74");
|
||||
expect(extractMessageBody(parsed.headers, parsed.body)).toBe("Текст");
|
||||
expect(attachments[0]).toMatchObject({
|
||||
|
||||
@@ -91,6 +91,7 @@ export async function importEmlFile(file: File): Promise<ImportedMailMessage> {
|
||||
...(parsed.headers.bcc ? { bcc: decodeMimeWords(parsed.headers.bcc) } : {}),
|
||||
...(parsed.headers["reply-to"] ? { replyTo: decodeMimeWords(parsed.headers["reply-to"]) } : {}),
|
||||
...mailThreadHeaders(parsed.headers),
|
||||
...mailPriorityHeaders(parsed.headers),
|
||||
subject: decodeMimeWords(parsed.headers.subject || "Без темы"),
|
||||
body: extractMessageBody(parsed.headers, parsed.body),
|
||||
time: parsed.headers.date || new Date().toLocaleString("ru-RU"),
|
||||
@@ -129,6 +130,7 @@ export function msgDataToMailMessage(reader: Pick<MsgReaderInstance, "getAttachm
|
||||
...(bcc ? { bcc } : {}),
|
||||
...(replyTo ? { replyTo } : {}),
|
||||
...mailThreadHeaders(headerFields),
|
||||
...mailPriorityHeaders(headerFields),
|
||||
subject: firstText(data.subject, decodeMimeWords(headerFields.subject || ""), "Без темы"),
|
||||
body: msgBodyText(data),
|
||||
time: firstText(data.messageDeliveryTime, data.clientSubmitTime, data.creationTime, data.lastModificationTime, headerFields.date, new Date().toLocaleString("ru-RU")),
|
||||
@@ -424,6 +426,7 @@ export function buildEmlSource(message: MailMessage): string {
|
||||
`Subject: ${encodeHeaderValue(message.subject || "Без темы")}`,
|
||||
`Date: ${sanitizeHeaderValue(message.time || new Date().toUTCString())}`,
|
||||
...optionalThreadHeaders(message),
|
||||
...optionalPriorityHeaders(message),
|
||||
"MIME-Version: 1.0",
|
||||
`Content-Type: multipart/mixed; boundary="${boundary}"`,
|
||||
"",
|
||||
@@ -447,6 +450,7 @@ export function buildEmlSource(message: MailMessage): string {
|
||||
`Subject: ${encodeHeaderValue(message.subject || "Без темы")}`,
|
||||
`Date: ${sanitizeHeaderValue(message.time || new Date().toUTCString())}`,
|
||||
...optionalThreadHeaders(message),
|
||||
...optionalPriorityHeaders(message),
|
||||
"MIME-Version: 1.0",
|
||||
"Content-Type: text/plain; charset=utf-8",
|
||||
"Content-Transfer-Encoding: 8bit",
|
||||
@@ -485,6 +489,26 @@ function mailThreadHeaders(headers: MailHeaders): Pick<MailMessage, "messageId"
|
||||
};
|
||||
}
|
||||
|
||||
function optionalPriorityHeaders(message: MailMessage): string[] {
|
||||
return [
|
||||
...(message.importance?.trim() ? [`Importance: ${sanitizeHeaderValue(message.importance)}`] : []),
|
||||
...(message.xPriority?.trim() ? [`X-Priority: ${sanitizeHeaderValue(message.xPriority)}`] : []),
|
||||
...(message.priority?.trim() ? [`Priority: ${sanitizeHeaderValue(message.priority)}`] : [])
|
||||
];
|
||||
}
|
||||
|
||||
function mailPriorityHeaders(headers: MailHeaders): Pick<MailMessage, "importance" | "xPriority" | "priority"> {
|
||||
const importance = sanitizeHeaderValue(headers.importance || "");
|
||||
const xPriority = sanitizeHeaderValue(headers["x-priority"] || "");
|
||||
const priority = sanitizeHeaderValue(headers.priority || "");
|
||||
|
||||
return {
|
||||
...(importance ? { importance } : {}),
|
||||
...(xPriority ? { xPriority } : {}),
|
||||
...(priority ? { priority } : {})
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeMimeWords(value: string): string {
|
||||
return value
|
||||
.replace(/(=\?[^?]+\?[bqBQ]\?[^?]+\?=)\s+(?==\?[^?]+\?[bqBQ]\?[^?]+\?=)/g, "$1")
|
||||
|
||||
@@ -129,6 +129,9 @@ export interface MailMessage {
|
||||
messageId?: string;
|
||||
inReplyTo?: string;
|
||||
references?: string;
|
||||
importance?: string;
|
||||
xPriority?: string;
|
||||
priority?: string;
|
||||
subject: string;
|
||||
body: string;
|
||||
time: string;
|
||||
|
||||
Reference in New Issue
Block a user