Add QOutlook copy recipients
This commit is contained in:
+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