Add QOutlook copy recipients
This commit is contained in:
@@ -138,6 +138,8 @@ describe("outlookMail helpers", () => {
|
||||
const eml = [
|
||||
"From: sender@example.com",
|
||||
"To: reader@example.com",
|
||||
"Cc: copy@example.com",
|
||||
"Bcc: hidden@example.com",
|
||||
"Subject: =?UTF-8?B?0JzRg9C70YzRgtC40L/QsNGA0YI=?=",
|
||||
"Date: Mon, 01 Jun 2026 10:00:00 +0300",
|
||||
'Content-Type: multipart/alternative; boundary="alt"',
|
||||
@@ -160,6 +162,8 @@ describe("outlookMail helpers", () => {
|
||||
expect(imported.body).toBe("Привет, письмо");
|
||||
expect(imported.from).toBe("sender@example.com");
|
||||
expect(imported.to).toBe("reader@example.com");
|
||||
expect(imported.cc).toBe("copy@example.com");
|
||||
expect(imported.bcc).toBe("hidden@example.com");
|
||||
});
|
||||
|
||||
it("импортирует multipart/mixed EML с вложением", async () => {
|
||||
@@ -213,7 +217,8 @@ describe("outlookMail helpers", () => {
|
||||
messageDeliveryTime: "Mon, 01 Jun 2026 10:00:00 GMT",
|
||||
recipients: [
|
||||
{ smtpAddress: "reader@example.com", recipType: "to" },
|
||||
{ smtpAddress: "copy@example.com", recipType: "cc" }
|
||||
{ smtpAddress: "copy@example.com", recipType: "cc" },
|
||||
{ smtpAddress: "hidden@example.com", recipType: "bcc" }
|
||||
],
|
||||
attachments: [{ fileName: "report.txt", attachMimeTag: "text/plain", contentLength: 5 }]
|
||||
}
|
||||
@@ -223,6 +228,8 @@ describe("outlookMail helpers", () => {
|
||||
folder: "inbox",
|
||||
from: "sender@example.com",
|
||||
to: "reader@example.com",
|
||||
cc: "copy@example.com",
|
||||
bcc: "hidden@example.com",
|
||||
subject: "MSG отчет",
|
||||
body: "HTML текст",
|
||||
time: "Mon, 01 Jun 2026 10:00:00 GMT",
|
||||
@@ -249,6 +256,8 @@ describe("outlookMail helpers", () => {
|
||||
folder: "sent",
|
||||
from: "sender@example.com",
|
||||
to: "reader@example.com",
|
||||
cc: "copy@example.com",
|
||||
bcc: "hidden@example.com",
|
||||
subject: "Тема",
|
||||
body: "Текст",
|
||||
time: "Mon, 01 Jan 2024 10:00:00 +0000",
|
||||
@@ -259,6 +268,8 @@ describe("outlookMail helpers", () => {
|
||||
const eml = buildEmlSource(message);
|
||||
|
||||
expect(eml).toContain("From: sender@example.com");
|
||||
expect(eml).toContain("Cc: copy@example.com");
|
||||
expect(eml).toContain("Bcc: hidden@example.com");
|
||||
expect(eml).toContain("Subject: =?UTF-8?B?");
|
||||
expect(eml.endsWith("Текст")).toBe(true);
|
||||
});
|
||||
@@ -269,6 +280,8 @@ describe("outlookMail helpers", () => {
|
||||
folder: "sent",
|
||||
from: "sender@example.com",
|
||||
to: "reader@example.com",
|
||||
cc: "copy@example.com",
|
||||
bcc: "hidden@example.com",
|
||||
subject: "Тема",
|
||||
body: "Текст",
|
||||
time: "Mon, 01 Jan 2024 10:00:00 +0000",
|
||||
@@ -291,6 +304,8 @@ describe("outlookMail helpers", () => {
|
||||
const attachments = extractMessageAttachments(parsed.headers, parsed.body);
|
||||
|
||||
expect(eml).toContain("Content-Type: multipart/mixed");
|
||||
expect(eml).toContain("Cc: copy@example.com");
|
||||
expect(eml).toContain("Bcc: hidden@example.com");
|
||||
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({
|
||||
|
||||
+16
-1
@@ -87,6 +87,8 @@ export async function importEmlFile(file: File): Promise<ImportedMailMessage> {
|
||||
folder: "inbox",
|
||||
from: decodeMimeWords(parsed.headers.from || ""),
|
||||
to: decodeMimeWords(parsed.headers.to || ""),
|
||||
...(parsed.headers.cc ? { cc: decodeMimeWords(parsed.headers.cc) } : {}),
|
||||
...(parsed.headers.bcc ? { bcc: decodeMimeWords(parsed.headers.bcc) } : {}),
|
||||
subject: decodeMimeWords(parsed.headers.subject || "Без темы"),
|
||||
body: extractMessageBody(parsed.headers, parsed.body),
|
||||
time: parsed.headers.date || new Date().toLocaleString("ru-RU"),
|
||||
@@ -113,11 +115,15 @@ export async function importMsgFile(file: File): Promise<ImportedMailMessage> {
|
||||
|
||||
export function msgDataToMailMessage(reader: Pick<MsgReaderInstance, "getAttachment">, data: MsgFileData): MailMessage {
|
||||
const headerFields = data.headers ? parseEmlHeaders(data.headers) : {};
|
||||
const cc = msgRecipientList(data.recipients, "cc") || decodeMimeWords(headerFields.cc || "");
|
||||
const bcc = msgRecipientList(data.recipients, "bcc") || decodeMimeWords(headerFields.bcc || "");
|
||||
return {
|
||||
id: `msg-${Date.now()}`,
|
||||
folder: "inbox",
|
||||
from: firstText(data.senderSmtpAddress, data.senderEmail, data.senderName, decodeMimeWords(headerFields.from || "")),
|
||||
to: msgRecipientList(data.recipients, "to") || decodeMimeWords(headerFields.to || ""),
|
||||
...(cc ? { cc } : {}),
|
||||
...(bcc ? { bcc } : {}),
|
||||
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")),
|
||||
@@ -264,7 +270,7 @@ function msgCharset(data: MsgFileData) {
|
||||
|
||||
function msgRecipientList(recipients: MsgRecipient[] = [], type: MsgRecipient["recipType"] = "to") {
|
||||
return recipients
|
||||
.filter((recipient) => !recipient.recipType || recipient.recipType === type)
|
||||
.filter((recipient) => (type === "to" ? !recipient.recipType || recipient.recipType === "to" : recipient.recipType === type))
|
||||
.map((recipient) => firstText(recipient.smtpAddress, recipient.email, recipient.name))
|
||||
.filter(Boolean)
|
||||
.join(", ");
|
||||
@@ -408,6 +414,7 @@ export function buildEmlSource(message: MailMessage): string {
|
||||
const lines = [
|
||||
`From: ${sanitizeHeaderValue(message.from)}`,
|
||||
`To: ${sanitizeHeaderValue(message.to)}`,
|
||||
...optionalAddressHeaders(message),
|
||||
`Subject: ${encodeHeaderValue(message.subject || "Без темы")}`,
|
||||
`Date: ${sanitizeHeaderValue(message.time || new Date().toUTCString())}`,
|
||||
"MIME-Version: 1.0",
|
||||
@@ -429,6 +436,7 @@ export function buildEmlSource(message: MailMessage): string {
|
||||
const lines = [
|
||||
`From: ${sanitizeHeaderValue(message.from)}`,
|
||||
`To: ${sanitizeHeaderValue(message.to)}`,
|
||||
...optionalAddressHeaders(message),
|
||||
`Subject: ${encodeHeaderValue(message.subject || "Без темы")}`,
|
||||
`Date: ${sanitizeHeaderValue(message.time || new Date().toUTCString())}`,
|
||||
"MIME-Version: 1.0",
|
||||
@@ -441,6 +449,13 @@ export function buildEmlSource(message: MailMessage): string {
|
||||
return lines.join("\r\n");
|
||||
}
|
||||
|
||||
function optionalAddressHeaders(message: MailMessage): string[] {
|
||||
return [
|
||||
...(message.cc?.trim() ? [`Cc: ${sanitizeHeaderValue(message.cc)}`] : []),
|
||||
...(message.bcc?.trim() ? [`Bcc: ${sanitizeHeaderValue(message.bcc)}`] : [])
|
||||
];
|
||||
}
|
||||
|
||||
export function decodeMimeWords(value: string): string {
|
||||
return value.replace(/=\?([^?]+)\?([bqBQ])\?([^?]+)\?=/g, (_match, charset: string, encoding: string, encoded: string) => {
|
||||
const normalizedCharset = charset.toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user