w
This commit is contained in:
+40
-20
@@ -1,10 +1,10 @@
|
||||
import { XMLParser } from "fast-xml-parser";
|
||||
import { promisify } from "node:util";
|
||||
import { createRequire } from "node:module";
|
||||
import https from "node:https";
|
||||
import fs from "node:fs";
|
||||
import https from "node:https";
|
||||
import { createRequire } from "node:module";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { promisify } from "node:util";
|
||||
import type { Email, Folder, LoginConfig } from "./models.ts";
|
||||
|
||||
const ntlm: any = createRequire(import.meta.url)("httpntlm");
|
||||
@@ -91,7 +91,7 @@ export class EwsClient {
|
||||
return this.config.domain ?? "corp";
|
||||
}
|
||||
|
||||
private async soapRequest(body: string, soapAction: string): Promise<any> {
|
||||
private async soapRequest(body: string, soapAction: string): Promise<any> {
|
||||
const res = await postAsync({
|
||||
url: this.ewsUrl,
|
||||
username: this.config.username,
|
||||
@@ -154,7 +154,7 @@ private async soapRequest(body: string, soapAction: string): Promise<any> {
|
||||
</m:FolderIds>
|
||||
</m:GetFolder>`);
|
||||
|
||||
const data = await this.soapRequest(
|
||||
const data = await this.soapRequest(
|
||||
soap,
|
||||
"http://schemas.microsoft.com/exchange/services/2006/messages/GetFolder",
|
||||
);
|
||||
@@ -238,7 +238,8 @@ ${restriction}
|
||||
);
|
||||
|
||||
for (const msg of this.extractResponseMessages(data)) {
|
||||
const items = msg?.RootFolder?.Items?.Message ?? msg?.RootFolder?.Items?.CalendarItem;
|
||||
const items = msg?.RootFolder?.Items?.Message
|
||||
?? msg?.RootFolder?.Items?.CalendarItem;
|
||||
if (!items) continue;
|
||||
return Array.isArray(items) ? items : [items];
|
||||
}
|
||||
@@ -268,7 +269,13 @@ ${restriction}
|
||||
if (!items) continue;
|
||||
|
||||
const itemKey = Object.keys(items).find((k) =>
|
||||
["Message", "CalendarItem", "MeetingRequest", "MeetingResponse", "MeetingCancellation"].includes(k)
|
||||
[
|
||||
"Message",
|
||||
"CalendarItem",
|
||||
"MeetingRequest",
|
||||
"MeetingResponse",
|
||||
"MeetingCancellation",
|
||||
].includes(k)
|
||||
);
|
||||
if (itemKey) {
|
||||
return items[itemKey];
|
||||
@@ -283,7 +290,8 @@ ${restriction}
|
||||
recursive: boolean = false,
|
||||
): Promise<Folder[]> {
|
||||
const traversal = recursive ? "Deep" : "Shallow";
|
||||
const isDistinguished = DISTINGUISHED_FOLDERS[parentFolderId.toLowerCase()] !== undefined
|
||||
const isDistinguished =
|
||||
DISTINGUISHED_FOLDERS[parentFolderId.toLowerCase()] !== undefined
|
||||
|| ["msgfolderroot"].includes(parentFolderId.toLowerCase());
|
||||
|
||||
const folderIdXml = isDistinguished
|
||||
@@ -329,7 +337,10 @@ ${restriction}
|
||||
|
||||
extractEmailSummary(item: any): Email {
|
||||
const itemType = item["@_xsi_type"] ?? item.__type ?? "";
|
||||
const isMeeting = /MeetingRequest|MeetingResponse|MeetingCancellation|CalendarItem/i.test(itemType);
|
||||
const isMeeting =
|
||||
/MeetingRequest|MeetingResponse|MeetingCancellation|CalendarItem/i.test(
|
||||
itemType,
|
||||
);
|
||||
|
||||
const fromMailbox = item.From?.Mailbox
|
||||
?? item.Organizer?.Mailbox
|
||||
@@ -340,9 +351,11 @@ ${restriction}
|
||||
subject: item.Subject ?? "(No subject)",
|
||||
from: fromMailbox.EmailAddress ?? "",
|
||||
fromName: fromMailbox.Name ?? "",
|
||||
date: item.DateTimeSent ?? item.DateTimeReceived ?? item.DateTimeCreated ?? "",
|
||||
date: item.DateTimeSent ?? item.DateTimeReceived ?? item.DateTimeCreated
|
||||
?? "",
|
||||
isRead: item.IsRead === "true" || item.IsRead === true,
|
||||
hasAttachments: item.HasAttachments === "true" || item.HasAttachments === true,
|
||||
hasAttachments: item.HasAttachments === "true"
|
||||
|| item.HasAttachments === true,
|
||||
hasLinks: false,
|
||||
itemId: item.ItemId?.["@_Id"] ?? "",
|
||||
size: item.Size ? Number(item.Size) : 0,
|
||||
@@ -357,15 +370,20 @@ ${restriction}
|
||||
};
|
||||
|
||||
if (item.DisplayTo) {
|
||||
email.to = item.DisplayTo.split(";").map((t: string) => t.trim()).filter(Boolean);
|
||||
email.to = item.DisplayTo.split(";").map((t: string) => t.trim()).filter(
|
||||
Boolean,
|
||||
);
|
||||
}
|
||||
if (item.DisplayCc) {
|
||||
email.cc = item.DisplayCc.split(";").map((c: string) => c.trim()).filter(Boolean);
|
||||
email.cc = item.DisplayCc.split(";").map((c: string) => c.trim()).filter(
|
||||
Boolean,
|
||||
);
|
||||
}
|
||||
|
||||
if (isMeeting) {
|
||||
email.location = item.Location ?? "";
|
||||
email.start = item.Start ?? item.StartWallClock ?? item.ReminderDueBy ?? "";
|
||||
email.start = item.Start ?? item.StartWallClock ?? item.ReminderDueBy
|
||||
?? "";
|
||||
email.end = item.End ?? item.EndWallClock ?? "";
|
||||
}
|
||||
|
||||
@@ -416,11 +434,13 @@ ${restriction}
|
||||
isInline: a.IsInline === "true" || a.IsInline === true,
|
||||
}));
|
||||
|
||||
const isMeeting = /MeetingRequest|MeetingResponse|MeetingCancellation|CalendarItem/i.test(
|
||||
item["@_xsi_type"] ?? "",
|
||||
);
|
||||
const isMeeting =
|
||||
/MeetingRequest|MeetingResponse|MeetingCancellation|CalendarItem/i.test(
|
||||
item["@_xsi_type"] ?? "",
|
||||
);
|
||||
if (isMeeting) {
|
||||
email.location = item.Location ?? item.EnhancedLocation?.DisplayName ?? "";
|
||||
email.location = item.Location ?? item.EnhancedLocation?.DisplayName
|
||||
?? "";
|
||||
email.start = item.Start ?? "";
|
||||
email.end = item.End ?? "";
|
||||
|
||||
@@ -462,10 +482,10 @@ ${restriction}
|
||||
text = text.replace(/&/g, "&");
|
||||
text = text.replace(/</g, "<");
|
||||
text = text.replace(/>/g, ">");
|
||||
text = text.replace(/"/g, '"');
|
||||
text = text.replace(/"/g, "\"");
|
||||
text = text.replace(/'/g, "'");
|
||||
text = text.replace(/\n\s*\n/g, "\n\n");
|
||||
text = text.replace(/[ \t]+/g, " ");
|
||||
return text.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user