@dawnlit/outlook-bridge 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -6
- package/dist/errors.d.ts +17 -6
- package/dist/errors.js +16 -7
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/mac/accounts.d.ts +4 -0
- package/dist/mac/accounts.js +10 -0
- package/dist/mac/accounts.js.map +1 -1
- package/dist/mac/bounces.js +10 -19
- package/dist/mac/bounces.js.map +1 -1
- package/dist/mac/cleanup.d.ts +11 -3
- package/dist/mac/cleanup.js +26 -17
- package/dist/mac/cleanup.js.map +1 -1
- package/dist/mac/drafts.js +3 -16
- package/dist/mac/drafts.js.map +1 -1
- package/dist/mac/folders.d.ts +5 -0
- package/dist/mac/folders.js +14 -5
- package/dist/mac/folders.js.map +1 -1
- package/dist/mac/profile.d.ts +12 -0
- package/dist/mac/profile.js +75 -1
- package/dist/mac/profile.js.map +1 -1
- package/dist/mac/read.js +14 -26
- package/dist/mac/read.js.map +1 -1
- package/dist/mac/run.d.ts +0 -3
- package/dist/mac/run.js +8 -8
- package/dist/mac/run.js.map +1 -1
- package/dist/mac/scripts.d.ts +46 -0
- package/dist/mac/scripts.js +98 -10
- package/dist/mac/scripts.js.map +1 -1
- package/dist/mac/send.d.ts +2 -1
- package/dist/mac/send.js +9 -3
- package/dist/mac/send.js.map +1 -1
- package/dist/mac/templates.js +1 -4
- package/dist/mac/templates.js.map +1 -1
- package/dist/mail.d.ts +6 -0
- package/dist/mail.js +7 -1
- package/dist/mail.js.map +1 -1
- package/dist/types.d.ts +20 -4
- package/dist/types.js.map +1 -1
- package/dist/windows/accounts.js +1 -1
- package/dist/windows/accounts.js.map +1 -1
- package/dist/windows/attachments.js +2 -2
- package/dist/windows/attachments.js.map +1 -1
- package/dist/windows/bounces.js +3 -3
- package/dist/windows/bounces.js.map +1 -1
- package/dist/windows/cleanup.js +2 -4
- package/dist/windows/cleanup.js.map +1 -1
- package/dist/windows/drafts.js +2 -2
- package/dist/windows/drafts.js.map +1 -1
- package/dist/windows/folders.js +1 -1
- package/dist/windows/folders.js.map +1 -1
- package/dist/windows/json.js.map +1 -0
- package/dist/windows/read.js +17 -14
- package/dist/windows/read.js.map +1 -1
- package/dist/windows/scripts.d.ts +6 -0
- package/dist/windows/scripts.js +11 -2
- package/dist/windows/scripts.js.map +1 -1
- package/dist/windows/send.d.ts +5 -1
- package/dist/windows/send.js +14 -4
- package/dist/windows/send.js.map +1 -1
- package/dist/windows/templates.js +2 -2
- package/dist/windows/templates.js.map +1 -1
- package/package.json +1 -1
- package/dist/shared/json.js.map +0 -1
- /package/dist/{shared → windows}/json.d.ts +0 -0
- /package/dist/{shared → windows}/json.js +0 -0
package/dist/mac/read.js
CHANGED
|
@@ -63,27 +63,17 @@ end tell`, 'standard'))
|
|
|
63
63
|
if (chosen.length === 0)
|
|
64
64
|
return [];
|
|
65
65
|
// Pass 2 — the expensive reads, only for the messages kept.
|
|
66
|
-
const preview = request.previewChars > 0
|
|
67
|
-
? ` set bodyText to ""
|
|
68
|
-
try
|
|
69
|
-
set bodyText to (plain text content of theMsg) as string
|
|
70
|
-
end try
|
|
71
|
-
if (length of bodyText) > ${(0, run_1.asInt)(request.previewChars)} then set bodyText to text 1 thru ${(0, run_1.asInt)(request.previewChars)} of bodyText`
|
|
72
|
-
: ' set bodyText to ""';
|
|
73
66
|
const raw = await (0, run_1.runOsaScript)(`tell application "Microsoft Outlook"
|
|
74
67
|
set out to ""
|
|
75
68
|
repeat with theId in ${(0, run_1.asIdList)(chosen.map(c => c.id))}
|
|
76
|
-
|
|
77
|
-
try
|
|
78
|
-
set theMsg to message id theId
|
|
79
|
-
end try
|
|
69
|
+
${(0, scripts_1.messageByIdSnippet)(' ')}
|
|
80
70
|
if theMsg is not missing value then
|
|
81
71
|
set subj to ""
|
|
82
72
|
try
|
|
83
73
|
set subj to (subject of theMsg) as string
|
|
84
74
|
end try
|
|
85
75
|
${outgoing ? (0, scripts_1.firstRecipientSnippet)(' ') : (0, scripts_1.senderSnippet)(' ')}
|
|
86
|
-
${
|
|
76
|
+
${(0, scripts_1.bodyTextSnippet)(' ', request.previewChars)}
|
|
87
77
|
set attNames to {}
|
|
88
78
|
try
|
|
89
79
|
set attNames to name of every attachment of theMsg
|
|
@@ -145,11 +135,12 @@ async function searchInboxByFilter(request) {
|
|
|
145
135
|
const acct = await (0, scripts_1.resolveMacAccount)(request.account);
|
|
146
136
|
// AppleScript reaches a child folder by name, so a path entry narrows to its leaf.
|
|
147
137
|
const asNameList = (list) => `{${list.map(mail_1.folderLeafName).filter(Boolean).map(run_1.asString).join(', ')}}`;
|
|
148
|
-
const rootInScope = request.includeFolders.length === 0 ? 'true' : 'false';
|
|
149
138
|
// Sent, Drafts, Deleted and Junk hang UNDER the Inbox on an IMAP profile, so
|
|
150
139
|
// their ids are collected first and the walk never descends into them — by
|
|
151
140
|
// the profile's own id where it records one, through the account otherwise.
|
|
152
|
-
|
|
141
|
+
// The roots are the ones Windows cuts, from the one list both read.
|
|
142
|
+
const skipIds = mail_1.NON_INCOMING_ROOTS
|
|
143
|
+
.map(rootId => scripts_1.MAC_ROOT_TERMS[rootId])
|
|
153
144
|
.map(term => {
|
|
154
145
|
const id = acct.folderIds?.[term];
|
|
155
146
|
return id !== undefined
|
|
@@ -223,8 +214,14 @@ ${skipIds}
|
|
|
223
214
|
set skipNames to ${asNameList(request.excludeFolders)}
|
|
224
215
|
set onlyNames to ${asNameList(request.includeFolders)}
|
|
225
216
|
end tell
|
|
217
|
+
-- The root is read on the terms its children are: when no folder is named, or
|
|
218
|
+
-- when it is one of those named.
|
|
219
|
+
set rootScope to (count of onlyNames) is 0
|
|
220
|
+
try
|
|
221
|
+
if onlyNames contains rootName then set rootScope to true
|
|
222
|
+
end try
|
|
226
223
|
set cutoff to (current date) - (${(0, run_1.asInt)(request.daysBack)} * days)
|
|
227
|
-
return my scanFolder(rootInbox, rootName, cutoff, skipIds, skipNames, onlyNames,
|
|
224
|
+
return my scanFolder(rootInbox, rootName, cutoff, skipIds, skipNames, onlyNames, rootScope)`, 'scan'));
|
|
228
225
|
const subjectFiltered = !!(request.subjectLike || request.subjectPattern || request.excludeReplies);
|
|
229
226
|
const likeRe = request.subjectLike ? new RegExp((0, mail_1.subjectGlobSource)(request.subjectLike), 'i') : null;
|
|
230
227
|
// PowerShell's -match is case-insensitive, so this test is too, whatever the
|
|
@@ -259,26 +256,17 @@ return my scanFolder(rootInbox, rootName, cutoff, skipIds, skipNames, onlyNames,
|
|
|
259
256
|
if (candidates.length === 0)
|
|
260
257
|
return [];
|
|
261
258
|
// Pass 2 — senders, attachment names and (when asked) bodies, for the survivors only.
|
|
262
|
-
const body = request.includeBody
|
|
263
|
-
? ` set bodyText to ""
|
|
264
|
-
try
|
|
265
|
-
set bodyText to (plain text content of theMsg) as string
|
|
266
|
-
end try`
|
|
267
|
-
: ' set bodyText to ""';
|
|
268
259
|
const raw = await (0, run_1.runOsaScript)(`tell application "Microsoft Outlook"
|
|
269
260
|
set out to ""
|
|
270
261
|
repeat with theId in ${(0, run_1.asIdList)(candidates.map(c => c.id))}
|
|
271
|
-
|
|
272
|
-
try
|
|
273
|
-
set theMsg to message id theId
|
|
274
|
-
end try
|
|
262
|
+
${(0, scripts_1.messageByIdSnippet)(' ')}
|
|
275
263
|
if theMsg is not missing value then
|
|
276
264
|
${(0, scripts_1.senderSnippet)(' ')}
|
|
277
265
|
set attNames to {}
|
|
278
266
|
try
|
|
279
267
|
set attNames to name of every attachment of theMsg
|
|
280
268
|
end try
|
|
281
|
-
${
|
|
269
|
+
${(0, scripts_1.bodyTextSnippet)(' ', request.includeBody ? undefined : 0)}
|
|
282
270
|
set out to out & ${(0, run_1.asRow)(['(id of theMsg as string)', 'sndName', 'sndAddr', 'my sanitizePositionalList(attNames)', 'bodyText'])}
|
|
283
271
|
end if
|
|
284
272
|
end repeat
|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CAAC,CAAC,IAAA,uBAAa,EAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;KAC9F,CAAC;AACN,CAAC;AAED,sGAAsG;AACtG,KAAK,UAAU,mBAAmB,CAAC,MAAc;IAC7C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1B,OAAO,CAAC,MAAM,IAAA,6BAAmB,GAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,EAAE,YAAY,IAAI,EAAE,CAAC;AAC1G,CAAC;AAED,0DAA0D;AACnD,KAAK,UAAU,gBAAgB,CAAC,KAAmB;IACtD,MAAM,EAAE,GAAG,IAAA,sBAAY,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,IAAA,kBAAY,EAAC;;EAErB,IAAA,8BAAoB,EAAC,EAAE,CAAC;;;SAGjB,EAAE,OAAO,CAAC,CAAC;AACpB,CAAC","sourcesContent":["// Reading mail on macOS: one folder, one item, a whole Inbox tree, or whatever\n// is selected in the running Outlook.\n//\n// Every reader is two passes. Pass 1 indexes a folder with bulk property reads\n// (one Apple event each); pass 2 fetches the expensive fields — body,\n// attachments, sender — only for the messages that survived. Reading\n// per-message in a loop costs an event per property and is unusably slow on a\n// real mailbox, which is the whole reason for the shape.\nimport {\n AS_LIST_SEP,\n asIdList,\n asInt,\n asRow,\n asString,\n field,\n runOsaScript,\n splitFields,\n splitList,\n splitPositionalList,\n splitRecords,\n summaryFields,\n} from './run';\nimport { readProfileAccounts } from './profile';\nimport {\n accountLookupSnippet,\n dateProperty,\n firstRecipientSnippet,\n folderChainSnippet,\n macFolderPath,\n macMessageId,\n mailScopeSnippet,\n MessageDetail,\n messageDetailFields,\n messageDetailSnippet,\n messageLookupSnippet,\n resolveMacAccount,\n rootFolderSnippet,\n senderSnippet,\n} from './scripts';\nimport { failureTag, NotFoundError } from '../errors';\nimport { folderLeafName, isOutgoingRoot, REPLY_PREFIX, subjectGlobSource } from '../mail';\nimport type { RawEmail, ReadInboxRequest, SearchRequest } from '../backend';\nimport type { EmailLocator, InboxEmail, InboxSearchMatch, SelectedEmail } from '../types';\n\n/**\n * Recent mail from the Inbox root or one folder, newest first. Entry ids here\n * are Outlook for Mac's integer message ids, not Windows EntryIDs.\n */\nexport async function readInboxEmails(request: ReadInboxRequest): Promise<InboxEmail[]> {\n const acct = await resolveMacAccount(request.account);\n const folderPath = macFolderPath(request.account, request.folder.rootLabel, request.folder.segments);\n const outgoing = isOutgoingRoot(request.folder.rootId);\n\n // Pass 1 — index the folder. Its order isn't documented, so it is sorted here.\n const index = (await runOsaScript(`tell application \"Microsoft Outlook\"\n${accountLookupSnippet(acct)}\n${mailScopeSnippet(acct, request.folder, request.folderLabel)}\n set cutoff to (current date) - (${asInt(request.daysBack)} * days)\n set idList to id of every message of scopeFolder\n try\n set timeList to ${dateProperty(request.folder.rootId)} of every message of scopeFolder\n on error\n set timeList to {}\n end try\n set hasTimes to ((count of timeList) is (count of idList))\n set out to \"\"\n repeat with i from 1 to (count of idList)\n set d to missing value\n if hasTimes then set d to item i of timeList\n -- An item with no timestamp of its own (an unsent draft filed into a\n -- mail folder) is skipped, as the Windows date filter skips it.\n if d is not missing value and d is greater than or equal to cutoff then\n set out to out & (item i of idList as string) & tab & my isoDate(d) & linefeed\n end if\n end repeat\n return out\nend tell`, 'standard'))\n .split('\\n')\n .map(line => line.trim())\n .filter(Boolean)\n .map(line => {\n const [id, receivedTime] = line.split('\\t');\n return { id, receivedTime: receivedTime || '' };\n });\n // 'yyyy-MM-dd HH:mm' sorts correctly as a string.\n index.sort((a, b) => b.receivedTime.localeCompare(a.receivedTime));\n const chosen = index.slice(0, request.limit);\n if (chosen.length === 0) return [];\n\n // Pass 2 — the expensive reads, only for the messages kept.\n const preview = request.previewChars > 0\n ? ` set bodyText to \"\"\n try\n set bodyText to (plain text content of theMsg) as string\n end try\n if (length of bodyText) > ${asInt(request.previewChars)} then set bodyText to text 1 thru ${asInt(request.previewChars)} of bodyText`\n : ' set bodyText to \"\"';\n const raw = await runOsaScript(`tell application \"Microsoft Outlook\"\n set out to \"\"\n repeat with theId in ${asIdList(chosen.map(c => c.id))}\n set theMsg to missing value\n try\n set theMsg to message id theId\n end try\n if theMsg is not missing value then\n set subj to \"\"\n try\n set subj to (subject of theMsg) as string\n end try\n${outgoing ? firstRecipientSnippet(' ') : senderSnippet(' ')}\n${preview}\n set attNames to {}\n try\n set attNames to name of every attachment of theMsg\n end try\n set out to out & ${asRow(['(id of theMsg as string)', 'subj', 'sndName', 'sndAddr', 'bodyText', 'my sanitizePositionalList(attNames)'])}\n end if\n end repeat\n return out\nend tell`, 'standard');\n\n const receivedById = new Map(chosen.map(c => [c.id, c.receivedTime]));\n return splitRecords(raw).map(record => {\n const parts = splitFields(record);\n const id = field(parts, 0);\n const attachmentNames = splitPositionalList(field(parts, 5));\n return {\n entryId: id,\n storeId: '',\n subject: field(parts, 1).trim(),\n senderName: field(parts, 2),\n senderEmail: field(parts, 3),\n receivedTime: receivedById.get(id) || '',\n bodyPreview: field(parts, 4),\n attachmentNames,\n attachmentCount: attachmentNames.length,\n folderPath,\n };\n });\n}\n\n/**\n * One email's full plain-text body. `storeId` has no macOS meaning: `message id\n * N` resolves against the application, wherever the message sits.\n */\nexport async function readEmailBody(email: EmailLocator): Promise<RawEmail> {\n const id = macMessageId(email.entryId);\n const parts = summaryFields(await runOsaScript(`tell application \"Microsoft Outlook\"\n${messageLookupSnippet(id)}\n${messageDetailSnippet(true)}\n return ${asRow(messageDetailFields(true))}\nend tell`, 'quick'));\n return {\n entryId: field(parts, MessageDetail.id) || id,\n subject: field(parts, MessageDetail.subject).trim(),\n senderName: field(parts, MessageDetail.senderName),\n senderEmail: field(parts, MessageDetail.senderEmail),\n receivedTime: field(parts, MessageDetail.receivedTime),\n body: field(parts, MessageDetail.body),\n attachmentNames: splitPositionalList(field(parts, MessageDetail.attachmentNames)),\n };\n}\n\n/**\n * Walk every folder under the Inbox for the mail matching the request.\n *\n * The filtering happens here rather than in Outlook: there is no AppleScript\n * counterpart to COM's server-side `Items.Restrict`, so each folder is indexed in\n * bulk reads and the subject and date tests run on the index. The results match\n * Windows; the cost doesn't, and a wide window over a big tree is heavier here.\n */\nexport async function searchInboxByFilter(request: SearchRequest): Promise<InboxSearchMatch[]> {\n const acct = await resolveMacAccount(request.account);\n // AppleScript reaches a child folder by name, so a path entry narrows to its leaf.\n const asNameList = (list: readonly string[]) => `{${list.map(folderLeafName).filter(Boolean).map(asString).join(', ')}}`;\n const rootInScope = request.includeFolders.length === 0 ? 'true' : 'false';\n // Sent, Drafts, Deleted and Junk hang UNDER the Inbox on an IMAP profile, so\n // their ids are collected first and the walk never descends into them — by\n // the profile's own id where it records one, through the account otherwise.\n const skipIds = ['sent items', 'deleted items', 'drafts', 'junk mail']\n .map(term => {\n const id = acct.folderIds?.[term];\n return id !== undefined\n ? ` set end of skipIds to ${id}`\n : ` try\n set end of skipIds to (id of (${term} of targetAcct))\n end try`;\n })\n .join('\\n');\n\n // Pass 1 — index every folder under the Inbox: path, id, subject, received.\n const indexed = splitRecords(await runOsaScript(`on scanFolder(theFolder, prefix, cutoff, skipIds, skipNames, onlyNames, inScope)\n set out to \"\"\n set idList to {}\n set subjList to {}\n set timeList to {}\n -- A folder the walk only passes through is never read: the bulk reads are\n -- the expensive part.\n if inScope then\n tell application \"Microsoft Outlook\"\n set idList to id of every message of theFolder\n set subjList to subject of every message of theFolder\n try\n set timeList to time received of every message of theFolder\n on error\n set timeList to {}\n end try\n end tell\n end if\n tell application \"Microsoft Outlook\"\n set subs to mail folders of theFolder\n end tell\n set hasTimes to ((count of timeList) is (count of idList))\n repeat with i from 1 to (count of idList)\n set d to missing value\n if hasTimes then set d to item i of timeList\n -- An item with no readable receive time is kept whatever the window\n -- says; dropping it would make a folder of them look empty.\n if d is missing value or d is not less than cutoff then\n set out to out & ${asRow(['prefix', '(item i of idList as string)', '(item i of subjList)', 'my isoDate(d)'])}\n end if\n end repeat\n repeat with f in subs\n set skipThis to false\n try\n if skipIds contains (id of f) then set skipThis to true\n end try\n try\n if skipNames contains ((name of f) as string) then set skipThis to true\n end try\n if not skipThis then\n set childName to \"\"\n try\n set childName to (name of f) as string\n end try\n set childScope to (count of onlyNames) is 0\n try\n if onlyNames contains childName then set childScope to true\n end try\n set out to out & my scanFolder(f, prefix & ${AS_LIST_SEP} & childName, cutoff, skipIds, skipNames, onlyNames, childScope)\n end if\n end repeat\n return out\nend scanFolder\n\ntell application \"Microsoft Outlook\"\n${accountLookupSnippet(acct)}\n${rootFolderSnippet(acct, 'inbox', 'rootInbox')}\n set rootName to (name of rootInbox) as string\n set skipIds to {}\n${skipIds}\n set skipNames to ${asNameList(request.excludeFolders)}\n set onlyNames to ${asNameList(request.includeFolders)}\nend tell\nset cutoff to (current date) - (${asInt(request.daysBack)} * days)\nreturn my scanFolder(rootInbox, rootName, cutoff, skipIds, skipNames, onlyNames, ${rootInScope})`, 'scan'));\n\n const subjectFiltered = !!(request.subjectLike || request.subjectPattern || request.excludeReplies);\n const likeRe = request.subjectLike ? new RegExp(subjectGlobSource(request.subjectLike), 'i') : null;\n // PowerShell's -match is case-insensitive, so this test is too, whatever the\n // caller's flags. Only u and v are kept: they decide how the source parses,\n // and without u, /\\p{L}/u would match the literal text \"p{L}\". Keeping g or y\n // would carry lastIndex from one subject to the next.\n const patternRe = request.subjectPattern\n ? new RegExp(request.subjectPattern.source, 'i' + request.subjectPattern.flags.replace(/[^uv]/g, ''))\n : null;\n const candidates = indexed\n .map(record => {\n const parts = splitFields(record);\n const segments = splitList(field(parts, 0));\n return {\n folderPath: macFolderPath(request.account, segments[0] || 'Inbox', segments.slice(1)),\n id: field(parts, 1),\n subject: field(parts, 2).trim(),\n receivedTime: field(parts, 3),\n };\n })\n .filter(candidate => {\n if (subjectFiltered && !candidate.subject) return false;\n if (likeRe && !likeRe.test(candidate.subject)) return false;\n if (patternRe && !patternRe.test(candidate.subject)) return false;\n if (request.excludeReplies && REPLY_PREFIX.test(candidate.subject)) return false;\n return true;\n });\n if (candidates.length === 0) return [];\n\n // Pass 2 — senders, attachment names and (when asked) bodies, for the survivors only.\n const body = request.includeBody\n ? ` set bodyText to \"\"\n try\n set bodyText to (plain text content of theMsg) as string\n end try`\n : ' set bodyText to \"\"';\n const raw = await runOsaScript(`tell application \"Microsoft Outlook\"\n set out to \"\"\n repeat with theId in ${asIdList(candidates.map(c => c.id))}\n set theMsg to missing value\n try\n set theMsg to message id theId\n end try\n if theMsg is not missing value then\n${senderSnippet(' ')}\n set attNames to {}\n try\n set attNames to name of every attachment of theMsg\n end try\n${body}\n set out to out & ${asRow(['(id of theMsg as string)', 'sndName', 'sndAddr', 'my sanitizePositionalList(attNames)', 'bodyText'])}\n end if\n end repeat\n return out\nend tell`, 'scan');\n const details = new Map(splitRecords(raw).map(record => {\n const parts = splitFields(record);\n const detail = {\n senderName: field(parts, 1),\n senderEmail: field(parts, 2),\n attachmentNames: splitPositionalList(field(parts, 3)),\n body: field(parts, 4),\n };\n return [field(parts, 0), detail] as const;\n }));\n\n const matches: InboxSearchMatch[] = [];\n for (const candidate of candidates) {\n const detail = details.get(candidate.id);\n if (!detail) continue;\n // Attachment names only arrive with the details, so this test waits for them.\n if (request.requireAttachment && detail.attachmentNames.length === 0) continue;\n matches.push({\n entryId: candidate.id,\n storeId: '',\n subject: candidate.subject,\n senderName: detail.senderName,\n senderEmail: detail.senderEmail,\n receivedTime: candidate.receivedTime,\n body: detail.body,\n attachmentNames: detail.attachmentNames,\n folderPath: candidate.folderPath,\n });\n }\n return matches;\n}\n\n/**\n * The email currently selected — or open — in Outlook. `current messages`\n * covers both cases the Windows reader handles separately.\n *\n * Where it sits comes back as a second record, so the detail row keeps its body\n * last. A mailbox with no account object answers `account of` with missing\n * value; its root folder's id is then looked up in the profile database.\n */\nexport async function readSelectedEmail(): Promise<SelectedEmail> {\n const records = splitRecords(await runOsaScript(`tell application \"Microsoft Outlook\"\n set sel to {}\n try\n set sel to current messages\n end try\n if (count of sel) is 0 then error ${asString(`${failureTag('NOT_FOUND', 'email')}No email is selected in Outlook. Select or open an email, then try again.`)}\n set theMsg to item 1 of sel\n${messageDetailSnippet(true)}\n set acctAddr to \"\"\n try\n set rawAddr to email address of (account of theMsg)\n if rawAddr is not missing value then set acctAddr to rawAddr as string\n end try\n set chainNames to {}\n set rootId to \"\"\n set theFolder to missing value\n try\n set theFolder to folder of theMsg\n end try\n if theFolder is not missing value then\n${folderChainSnippet(' ')}\n try\n set rootId to (id of cur) as string\n end try\n end if\n return ${asRow(messageDetailFields(true))} & ${asRow(['acctAddr', 'my sanitizeList(chainNames)', 'rootId'])}\nend tell`, 'quick'));\n if (records.length === 0) throw new NotFoundError('email', 'Outlook reported no selected email.');\n const parts = splitFields(records[0]);\n const where = splitFields(records[1] ?? '');\n const chain = splitList(field(where, 1)).reverse();\n const account = field(where, 0) || (chain.length ? await accountByRootFolder(field(where, 2)) : '');\n return {\n entryId: field(parts, MessageDetail.id),\n storeId: '',\n subject: field(parts, MessageDetail.subject).trim(),\n senderName: field(parts, MessageDetail.senderName),\n senderEmail: field(parts, MessageDetail.senderEmail),\n receivedTime: field(parts, MessageDetail.receivedTime),\n body: field(parts, MessageDetail.body),\n attachmentNames: splitPositionalList(field(parts, MessageDetail.attachmentNames)),\n folderPath: account && chain.length ? macFolderPath(account, chain[0], chain.slice(1)) : '',\n };\n}\n\n/** The address of the account whose root folder has this id, per the profile database; '' if none. */\nasync function accountByRootFolder(rootId: string): Promise<string> {\n if (!/^\\d+$/.test(rootId)) return '';\n const id = Number(rootId);\n return (await readProfileAccounts()).find(a => a.folderIds['root folder'] === id)?.emailAccount ?? '';\n}\n\n/** Open an email in Outlook and bring Outlook forward. */\nexport async function openOutlookEmail(email: EmailLocator): Promise<void> {\n const id = macMessageId(email.entryId);\n await runOsaScript(`\ntell application \"Microsoft Outlook\"\n${messageLookupSnippet(id)}\n open theMsg\n activate\nend tell`, 'quick');\n}\n"]}
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/mac/read.ts"],"names":[],"mappings":";;AAmDA,0CAiFC;AAMD,sCAgBC;AAUD,kDAyKC;AAUD,8CA4CC;AAUD,4CAQC;AArZD,+EAA+E;AAC/E,sCAAsC;AACtC,EAAE;AACF,+EAA+E;AAC/E,sEAAsE;AACtE,qEAAqE;AACrE,8EAA8E;AAC9E,yDAAyD;AACzD,+BAae;AACf,uCAAgD;AAChD,uCAkBmB;AACnB,sCAAsD;AACtD,kCAA8G;AAI9G;;;GAGG;AACI,KAAK,UAAU,eAAe,CAAC,OAAyB;IAC3D,MAAM,IAAI,GAAG,MAAM,IAAA,2BAAiB,EAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACtD,MAAM,UAAU,GAAG,IAAA,uBAAa,EAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACrG,MAAM,QAAQ,GAAG,IAAA,qBAAc,EAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEvD,+EAA+E;IAC/E,MAAM,KAAK,GAAG,CAAC,MAAM,IAAA,kBAAY,EAAC;EACpC,IAAA,8BAAoB,EAAC,IAAI,CAAC;EAC1B,IAAA,0BAAgB,EAAC,IAAI,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,WAAW,CAAC;sCACvB,IAAA,WAAK,EAAC,OAAO,CAAC,QAAQ,CAAC;;;0BAGnC,IAAA,sBAAY,EAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;;;;;;;;;;;;;;;;SAgBpD,EAAE,UAAU,CAAC,CAAC;SACd,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AE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE;KAC9F,CAAC;AACN,CAAC;AAED,sGAAsG;AACtG,KAAK,UAAU,mBAAmB,CAAC,MAAc;IAC7C,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC;IAC1B,OAAO,CAAC,MAAM,IAAA,6BAAmB,GAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC,EAAE,YAAY,IAAI,EAAE,CAAC;AAC1G,CAAC;AAED,0DAA0D;AACnD,KAAK,UAAU,gBAAgB,CAAC,KAAmB;IACtD,MAAM,EAAE,GAAG,IAAA,sBAAY,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,IAAA,kBAAY,EAAC;;EAErB,IAAA,8BAAoB,EAAC,EAAE,CAAC;;;SAGjB,EAAE,OAAO,CAAC,CAAC;AACpB,CAAC","sourcesContent":["// Reading mail on macOS: one folder, one item, a whole Inbox tree, or whatever\n// is selected in the running Outlook.\n//\n// Every reader is two passes. Pass 1 indexes a folder with bulk property reads\n// (one Apple event each); pass 2 fetches the expensive fields — body,\n// attachments, sender — only for the messages that survived. Reading\n// per-message in a loop costs an event per property and is unusably slow on a\n// real mailbox, which is the whole reason for the shape.\nimport {\n AS_LIST_SEP,\n asIdList,\n asInt,\n asRow,\n asString,\n field,\n runOsaScript,\n splitFields,\n splitList,\n splitPositionalList,\n splitRecords,\n summaryFields,\n} from './run';\nimport { readProfileAccounts } from './profile';\nimport {\n accountLookupSnippet,\n bodyTextSnippet,\n dateProperty,\n firstRecipientSnippet,\n folderChainSnippet,\n MAC_ROOT_TERMS,\n macFolderPath,\n macMessageId,\n mailScopeSnippet,\n messageByIdSnippet,\n MessageDetail,\n messageDetailFields,\n messageDetailSnippet,\n messageLookupSnippet,\n resolveMacAccount,\n rootFolderSnippet,\n senderSnippet,\n} from './scripts';\nimport { failureTag, NotFoundError } from '../errors';\nimport { folderLeafName, isOutgoingRoot, NON_INCOMING_ROOTS, REPLY_PREFIX, subjectGlobSource } from '../mail';\nimport type { RawEmail, ReadInboxRequest, SearchRequest } from '../backend';\nimport type { EmailLocator, InboxEmail, InboxSearchMatch, SelectedEmail } from '../types';\n\n/**\n * Recent mail from the Inbox root or one folder, newest first. Entry ids here\n * are Outlook for Mac's integer message ids, not Windows EntryIDs.\n */\nexport async function readInboxEmails(request: ReadInboxRequest): Promise<InboxEmail[]> {\n const acct = await resolveMacAccount(request.account);\n const folderPath = macFolderPath(request.account, request.folder.rootLabel, request.folder.segments);\n const outgoing = isOutgoingRoot(request.folder.rootId);\n\n // Pass 1 — index the folder. Its order isn't documented, so it is sorted here.\n const index = (await runOsaScript(`tell application \"Microsoft Outlook\"\n${accountLookupSnippet(acct)}\n${mailScopeSnippet(acct, request.folder, request.folderLabel)}\n set cutoff to (current date) - (${asInt(request.daysBack)} * days)\n set idList to id of every message of scopeFolder\n try\n set timeList to ${dateProperty(request.folder.rootId)} of every message of scopeFolder\n on error\n set timeList to {}\n end try\n set hasTimes to ((count of timeList) is (count of idList))\n set out to \"\"\n repeat with i from 1 to (count of idList)\n set d to missing value\n if hasTimes then set d to item i of timeList\n -- An item with no timestamp of its own (an unsent draft filed into a\n -- mail folder) is skipped, as the Windows date filter skips it.\n if d is not missing value and d is greater than or equal to cutoff then\n set out to out & (item i of idList as string) & tab & my isoDate(d) & linefeed\n end if\n end repeat\n return out\nend tell`, 'standard'))\n .split('\\n')\n .map(line => line.trim())\n .filter(Boolean)\n .map(line => {\n const [id, receivedTime] = line.split('\\t');\n return { id, receivedTime: receivedTime || '' };\n });\n // 'yyyy-MM-dd HH:mm' sorts correctly as a string.\n index.sort((a, b) => b.receivedTime.localeCompare(a.receivedTime));\n const chosen = index.slice(0, request.limit);\n if (chosen.length === 0) return [];\n\n // Pass 2 — the expensive reads, only for the messages kept.\n const raw = await runOsaScript(`tell application \"Microsoft Outlook\"\n set out to \"\"\n repeat with theId in ${asIdList(chosen.map(c => c.id))}\n${messageByIdSnippet(' ')}\n if theMsg is not missing value then\n set subj to \"\"\n try\n set subj to (subject of theMsg) as string\n end try\n${outgoing ? firstRecipientSnippet(' ') : senderSnippet(' ')}\n${bodyTextSnippet(' ', request.previewChars)}\n set attNames to {}\n try\n set attNames to name of every attachment of theMsg\n end try\n set out to out & ${asRow(['(id of theMsg as string)', 'subj', 'sndName', 'sndAddr', 'bodyText', 'my sanitizePositionalList(attNames)'])}\n end if\n end repeat\n return out\nend tell`, 'standard');\n\n const receivedById = new Map(chosen.map(c => [c.id, c.receivedTime]));\n return splitRecords(raw).map(record => {\n const parts = splitFields(record);\n const id = field(parts, 0);\n const attachmentNames = splitPositionalList(field(parts, 5));\n return {\n entryId: id,\n storeId: '',\n subject: field(parts, 1).trim(),\n senderName: field(parts, 2),\n senderEmail: field(parts, 3),\n receivedTime: receivedById.get(id) || '',\n bodyPreview: field(parts, 4),\n attachmentNames,\n attachmentCount: attachmentNames.length,\n folderPath,\n };\n });\n}\n\n/**\n * One email's full plain-text body. `storeId` has no macOS meaning: `message id\n * N` resolves against the application, wherever the message sits.\n */\nexport async function readEmailBody(email: EmailLocator): Promise<RawEmail> {\n const id = macMessageId(email.entryId);\n const parts = summaryFields(await runOsaScript(`tell application \"Microsoft Outlook\"\n${messageLookupSnippet(id)}\n${messageDetailSnippet(true)}\n return ${asRow(messageDetailFields(true))}\nend tell`, 'quick'));\n return {\n entryId: field(parts, MessageDetail.id) || id,\n subject: field(parts, MessageDetail.subject).trim(),\n senderName: field(parts, MessageDetail.senderName),\n senderEmail: field(parts, MessageDetail.senderEmail),\n receivedTime: field(parts, MessageDetail.receivedTime),\n body: field(parts, MessageDetail.body),\n attachmentNames: splitPositionalList(field(parts, MessageDetail.attachmentNames)),\n };\n}\n\n/**\n * Walk every folder under the Inbox for the mail matching the request.\n *\n * The filtering happens here rather than in Outlook: there is no AppleScript\n * counterpart to COM's server-side `Items.Restrict`, so each folder is indexed in\n * bulk reads and the subject and date tests run on the index. The results match\n * Windows; the cost doesn't, and a wide window over a big tree is heavier here.\n */\nexport async function searchInboxByFilter(request: SearchRequest): Promise<InboxSearchMatch[]> {\n const acct = await resolveMacAccount(request.account);\n // AppleScript reaches a child folder by name, so a path entry narrows to its leaf.\n const asNameList = (list: readonly string[]) => `{${list.map(folderLeafName).filter(Boolean).map(asString).join(', ')}}`;\n // Sent, Drafts, Deleted and Junk hang UNDER the Inbox on an IMAP profile, so\n // their ids are collected first and the walk never descends into them — by\n // the profile's own id where it records one, through the account otherwise.\n // The roots are the ones Windows cuts, from the one list both read.\n const skipIds = NON_INCOMING_ROOTS\n .map(rootId => MAC_ROOT_TERMS[rootId])\n .map(term => {\n const id = acct.folderIds?.[term];\n return id !== undefined\n ? ` set end of skipIds to ${id}`\n : ` try\n set end of skipIds to (id of (${term} of targetAcct))\n end try`;\n })\n .join('\\n');\n\n // Pass 1 — index every folder under the Inbox: path, id, subject, received.\n const indexed = splitRecords(await runOsaScript(`on scanFolder(theFolder, prefix, cutoff, skipIds, skipNames, onlyNames, inScope)\n set out to \"\"\n set idList to {}\n set subjList to {}\n set timeList to {}\n -- A folder the walk only passes through is never read: the bulk reads are\n -- the expensive part.\n if inScope then\n tell application \"Microsoft Outlook\"\n set idList to id of every message of theFolder\n set subjList to subject of every message of theFolder\n try\n set timeList to time received of every message of theFolder\n on error\n set timeList to {}\n end try\n end tell\n end if\n tell application \"Microsoft Outlook\"\n set subs to mail folders of theFolder\n end tell\n set hasTimes to ((count of timeList) is (count of idList))\n repeat with i from 1 to (count of idList)\n set d to missing value\n if hasTimes then set d to item i of timeList\n -- An item with no readable receive time is kept whatever the window\n -- says; dropping it would make a folder of them look empty.\n if d is missing value or d is not less than cutoff then\n set out to out & ${asRow(['prefix', '(item i of idList as string)', '(item i of subjList)', 'my isoDate(d)'])}\n end if\n end repeat\n repeat with f in subs\n set skipThis to false\n try\n if skipIds contains (id of f) then set skipThis to true\n end try\n try\n if skipNames contains ((name of f) as string) then set skipThis to true\n end try\n if not skipThis then\n set childName to \"\"\n try\n set childName to (name of f) as string\n end try\n set childScope to (count of onlyNames) is 0\n try\n if onlyNames contains childName then set childScope to true\n end try\n set out to out & my scanFolder(f, prefix & ${AS_LIST_SEP} & childName, cutoff, skipIds, skipNames, onlyNames, childScope)\n end if\n end repeat\n return out\nend scanFolder\n\ntell application \"Microsoft Outlook\"\n${accountLookupSnippet(acct)}\n${rootFolderSnippet(acct, 'inbox', 'rootInbox')}\n set rootName to (name of rootInbox) as string\n set skipIds to {}\n${skipIds}\n set skipNames to ${asNameList(request.excludeFolders)}\n set onlyNames to ${asNameList(request.includeFolders)}\nend tell\n-- The root is read on the terms its children are: when no folder is named, or\n-- when it is one of those named.\nset rootScope to (count of onlyNames) is 0\ntry\n if onlyNames contains rootName then set rootScope to true\nend try\nset cutoff to (current date) - (${asInt(request.daysBack)} * days)\nreturn my scanFolder(rootInbox, rootName, cutoff, skipIds, skipNames, onlyNames, rootScope)`, 'scan'));\n\n const subjectFiltered = !!(request.subjectLike || request.subjectPattern || request.excludeReplies);\n const likeRe = request.subjectLike ? new RegExp(subjectGlobSource(request.subjectLike), 'i') : null;\n // PowerShell's -match is case-insensitive, so this test is too, whatever the\n // caller's flags. Only u and v are kept: they decide how the source parses,\n // and without u, /\\p{L}/u would match the literal text \"p{L}\". Keeping g or y\n // would carry lastIndex from one subject to the next.\n const patternRe = request.subjectPattern\n ? new RegExp(request.subjectPattern.source, 'i' + request.subjectPattern.flags.replace(/[^uv]/g, ''))\n : null;\n const candidates = indexed\n .map(record => {\n const parts = splitFields(record);\n const segments = splitList(field(parts, 0));\n return {\n folderPath: macFolderPath(request.account, segments[0] || 'Inbox', segments.slice(1)),\n id: field(parts, 1),\n subject: field(parts, 2).trim(),\n receivedTime: field(parts, 3),\n };\n })\n .filter(candidate => {\n if (subjectFiltered && !candidate.subject) return false;\n if (likeRe && !likeRe.test(candidate.subject)) return false;\n if (patternRe && !patternRe.test(candidate.subject)) return false;\n if (request.excludeReplies && REPLY_PREFIX.test(candidate.subject)) return false;\n return true;\n });\n if (candidates.length === 0) return [];\n\n // Pass 2 — senders, attachment names and (when asked) bodies, for the survivors only.\n const raw = await runOsaScript(`tell application \"Microsoft Outlook\"\n set out to \"\"\n repeat with theId in ${asIdList(candidates.map(c => c.id))}\n${messageByIdSnippet(' ')}\n if theMsg is not missing value then\n${senderSnippet(' ')}\n set attNames to {}\n try\n set attNames to name of every attachment of theMsg\n end try\n${bodyTextSnippet(' ', request.includeBody ? undefined : 0)}\n set out to out & ${asRow(['(id of theMsg as string)', 'sndName', 'sndAddr', 'my sanitizePositionalList(attNames)', 'bodyText'])}\n end if\n end repeat\n return out\nend tell`, 'scan');\n const details = new Map(splitRecords(raw).map(record => {\n const parts = splitFields(record);\n const detail = {\n senderName: field(parts, 1),\n senderEmail: field(parts, 2),\n attachmentNames: splitPositionalList(field(parts, 3)),\n body: field(parts, 4),\n };\n return [field(parts, 0), detail] as const;\n }));\n\n const matches: InboxSearchMatch[] = [];\n for (const candidate of candidates) {\n const detail = details.get(candidate.id);\n if (!detail) continue;\n // Attachment names only arrive with the details, so this test waits for them.\n if (request.requireAttachment && detail.attachmentNames.length === 0) continue;\n matches.push({\n entryId: candidate.id,\n storeId: '',\n subject: candidate.subject,\n senderName: detail.senderName,\n senderEmail: detail.senderEmail,\n receivedTime: candidate.receivedTime,\n body: detail.body,\n attachmentNames: detail.attachmentNames,\n folderPath: candidate.folderPath,\n });\n }\n return matches;\n}\n\n/**\n * The email currently selected — or open — in Outlook. `current messages`\n * covers both cases the Windows reader handles separately.\n *\n * Where it sits comes back as a second record, so the detail row keeps its body\n * last. A mailbox with no account object answers `account of` with missing\n * value; its root folder's id is then looked up in the profile database.\n */\nexport async function readSelectedEmail(): Promise<SelectedEmail> {\n const records = splitRecords(await runOsaScript(`tell application \"Microsoft Outlook\"\n set sel to {}\n try\n set sel to current messages\n end try\n if (count of sel) is 0 then error ${asString(`${failureTag('NOT_FOUND', 'email')}No email is selected in Outlook. Select or open an email, then try again.`)}\n set theMsg to item 1 of sel\n${messageDetailSnippet(true)}\n set acctAddr to \"\"\n try\n set rawAddr to email address of (account of theMsg)\n if rawAddr is not missing value then set acctAddr to rawAddr as string\n end try\n set chainNames to {}\n set rootId to \"\"\n set theFolder to missing value\n try\n set theFolder to folder of theMsg\n end try\n if theFolder is not missing value then\n${folderChainSnippet(' ')}\n try\n set rootId to (id of cur) as string\n end try\n end if\n return ${asRow(messageDetailFields(true))} & ${asRow(['acctAddr', 'my sanitizeList(chainNames)', 'rootId'])}\nend tell`, 'quick'));\n if (records.length === 0) throw new NotFoundError('email', 'Outlook reported no selected email.');\n const parts = splitFields(records[0]);\n const where = splitFields(records[1] ?? '');\n const chain = splitList(field(where, 1)).reverse();\n const account = field(where, 0) || (chain.length ? await accountByRootFolder(field(where, 2)) : '');\n return {\n entryId: field(parts, MessageDetail.id),\n storeId: '',\n subject: field(parts, MessageDetail.subject).trim(),\n senderName: field(parts, MessageDetail.senderName),\n senderEmail: field(parts, MessageDetail.senderEmail),\n receivedTime: field(parts, MessageDetail.receivedTime),\n body: field(parts, MessageDetail.body),\n attachmentNames: splitPositionalList(field(parts, MessageDetail.attachmentNames)),\n folderPath: account && chain.length ? macFolderPath(account, chain[0], chain.slice(1)) : '',\n };\n}\n\n/** The address of the account whose root folder has this id, per the profile database; '' if none. */\nasync function accountByRootFolder(rootId: string): Promise<string> {\n if (!/^\\d+$/.test(rootId)) return '';\n const id = Number(rootId);\n return (await readProfileAccounts()).find(a => a.folderIds['root folder'] === id)?.emailAccount ?? '';\n}\n\n/** Open an email in Outlook and bring Outlook forward. */\nexport async function openOutlookEmail(email: EmailLocator): Promise<void> {\n const id = macMessageId(email.entryId);\n await runOsaScript(`\ntell application \"Microsoft Outlook\"\n${messageLookupSnippet(id)}\n open theMsg\n activate\nend tell`, 'quick');\n}\n"]}
|
package/dist/mac/run.d.ts
CHANGED
|
@@ -26,9 +26,6 @@ export declare function asIdList(ids: readonly string[]): string;
|
|
|
26
26
|
export declare const FIELD_SEP = "\u001F";
|
|
27
27
|
export declare const RECORD_SEP = "\u001E";
|
|
28
28
|
export declare const LIST_SEP = "\u001D";
|
|
29
|
-
/** The same three, as AppleScript expressions. */
|
|
30
|
-
export declare const AS_FIELD_SEP = "(character id 31)";
|
|
31
|
-
export declare const AS_RECORD_SEP = "(character id 30)";
|
|
32
29
|
export declare const AS_LIST_SEP = "(character id 29)";
|
|
33
30
|
/**
|
|
34
31
|
* One record: the AppleScript expressions in `fields`, separated and terminated
|
package/dist/mac/run.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ITEM_FAILURE_ROW = exports.AS_HANDLERS = exports.AS_LIST_SEP = exports.
|
|
6
|
+
exports.ITEM_FAILURE_ROW = exports.AS_HANDLERS = exports.AS_LIST_SEP = exports.LIST_SEP = exports.RECORD_SEP = exports.FIELD_SEP = void 0;
|
|
7
7
|
exports.runOsaScript = runOsaScript;
|
|
8
8
|
exports.asEscape = asEscape;
|
|
9
9
|
exports.asString = asString;
|
|
@@ -108,12 +108,12 @@ function asIdList(ids) {
|
|
|
108
108
|
// bodies contain tabs, newlines and commas, but never these — and every emitted
|
|
109
109
|
// field passes through the `sanitize` handler, which makes the framing safe
|
|
110
110
|
// rather than merely unlikely to break.
|
|
111
|
-
exports.FIELD_SEP = '
|
|
112
|
-
exports.RECORD_SEP = '
|
|
113
|
-
exports.LIST_SEP = '
|
|
114
|
-
/** The same three, as AppleScript expressions. */
|
|
115
|
-
|
|
116
|
-
|
|
111
|
+
exports.FIELD_SEP = '\x1f';
|
|
112
|
+
exports.RECORD_SEP = '\x1e';
|
|
113
|
+
exports.LIST_SEP = '\x1d';
|
|
114
|
+
/** The same three, as AppleScript expressions. Only the list one is written outside this module. */
|
|
115
|
+
const AS_FIELD_SEP = '(character id 31)';
|
|
116
|
+
const AS_RECORD_SEP = '(character id 30)';
|
|
117
117
|
exports.AS_LIST_SEP = '(character id 29)';
|
|
118
118
|
/**
|
|
119
119
|
* One record: the AppleScript expressions in `fields`, separated and terminated
|
|
@@ -124,7 +124,7 @@ exports.AS_LIST_SEP = '(character id 29)';
|
|
|
124
124
|
function asRow(fields) {
|
|
125
125
|
return fields
|
|
126
126
|
.map(f => `my sanitize(${f})`)
|
|
127
|
-
.join(` & ${
|
|
127
|
+
.join(` & ${AS_FIELD_SEP} & `) + ` & ${AS_RECORD_SEP}`;
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
130
|
* The handlers every script relies on, called with `my` from inside a `tell`.
|
package/dist/mac/run.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/mac/run.ts"],"names":[],"mappings":";;;;;;AAmCA,oCAmBC;AAOD,4BAKC;AAGD,4BAEC;AAGD,wBAEC;AAGD,sBAKC;AAGD,4BAEC;AAuBD,sBAIC;AAsGD,oCAEC;AAGD,kCAEC;AAOD,8BAEC;AAMD,kDAEC;AAGD,sBAEC;AAGD,sCAEC;AAGD,4BAGC;AAGD,8BAEC;AAYD,gCASC;AA5RD,oEAAoE;AACpE,EAAE;AACF,0EAA0E;AAC1E,0DAA0D;AAC1D,4CAAoB;AACpB,wCAAsE;AACtE,yCAAkD;AAClD,sCAAgD;AAChD,mDAA0D;AAG1D,MAAM,MAAM,GAAG,WAAoB,CAAC;AAEpC;;;;;GAKG;AACH,SAAS,YAAY,CAAC,MAAc;IAChC,MAAM,OAAO,GAAG,MAAM;SACjB,OAAO,CAAC,2CAA2C,EAAE,EAAE,CAAC;SACxD,OAAO,CAAC,kBAAkB,EA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AClF,SAAgB,SAAS,CAAC,MAAyB,EAAE,KAAa;IAC9D,OAAO,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,KAAK,MAAM,CAAC;AAClD,CAAC;AAED,4EAA4E;AAC5E,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,gDAAgD;AAEhD,qGAAqG;AACxF,QAAA,gBAAgB,GAAG,KAAK,CAAC,CAAC,mBAAmB,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;AAEhF,uFAAuF;AACvF,SAAgB,UAAU,CAAC,GAAW;IAClC,MAAM,CAAC,OAAO,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IACtD,OAAO;QACH,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;QAC7B,MAAM,EAAE,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;YAC1B,MAAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;YAClC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;QAC1F,CAAC,CAAC;KACL,CAAC;AACN,CAAC","sourcesContent":["// Getting a generated AppleScript to osascript and its output back.\n//\n// The macOS counterpart of windows/run.ts: running a script, the escaping\n// rules, and the record framing every reader here shares.\nimport fs from 'fs';\nimport { removeTempFile, type RunBudget, tempFile } from '../runtime';\nimport { runScriptProcess } from '../shared/exec';\nimport { InvalidRequestError } from '../errors';\nimport { WORD_SECTION_ANCHOR } from '../shared/replyBody';\nimport type { ItemFailure } from '../types';\n\nconst RUNNER = 'osascript' as const;\n\n/**\n * osascript's report of a script error: \"<file>:<start>:<end>: execution error:\n * <message> (<number>)\". Only the message is worth showing — these reach people\n * in per-item failure lists — and -2700 is the number AppleScript gives every\n * `error \"…\"` a script raises itself.\n */\nfunction parseFailure(stderr: string): { message: string } {\n const message = stderr\n .replace(/^(?:.*?:)?\\d+:\\d+:\\s*execution error:\\s*/m, '')\n .replace(/\\s*\\(-2700\\)\\s*$/, '')\n .trim();\n return { message };\n}\n\n/**\n * Run a script from a temp file (no argument-length or quoting limits) and\n * return what it printed, minus the newline osascript appends.\n *\n * `AS_HANDLERS` is prepended here rather than by each caller: a script missing\n * a handler fails to compile as a WHOLE, with an error pointing nowhere near the\n * omission, so it can't be left to each script to remember.\n */\nexport async function runOsaScript(source: string, budget: RunBudget): Promise<string> {\n // The full text is what osascript compiles, so it is also what error offsets\n // refer to and what the debug hook and errors carry.\n const script = AS_HANDLERS + source;\n const file = tempFile('osa', 'applescript');\n fs.writeFileSync(file, script, 'utf8');\n try {\n const { stdout } = await runScriptProcess({\n runner: RUNNER,\n command: 'osascript',\n args: [file],\n script,\n budget,\n parseFailure,\n });\n return stdout.replace(/\\n$/, '');\n } finally {\n removeTempFile(file);\n }\n}\n\n/**\n * Escape text for the inside of an AppleScript double-quoted literal.\n * AppleScript strings never interpolate, so escaping the quote, the backslash\n * and line breaks is the whole job.\n */\nexport function asEscape(text: string): string {\n return text\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\r\\n|\\r|\\n/g, '\\\\n');\n}\n\n/** Text as an AppleScript string literal. */\nexport function asString(text: string): string {\n return `\"${asEscape(text)}\"`;\n}\n\n/** AppleScript's boolean literals. */\nexport function asBool(value: boolean): string {\n return value ? 'true' : 'false';\n}\n\n/** A whole number for a script; anything else is refused before it becomes code. */\nexport function asInt(value: number): string {\n if (!Number.isSafeInteger(value)) {\n throw new InvalidRequestError(`Expected a whole number, got ${String(value)}.`);\n }\n return String(value);\n}\n\n/** Message ids (already validated as integers) as an AppleScript list literal. */\nexport function asIdList(ids: readonly string[]): string {\n return `{${ids.map(id => asInt(Number(id))).join(', ')}}`;\n}\n\n// ── Record framing ───────────────────────────────────────────────────────\n//\n// Control characters separate fields, records and list items: subjects and\n// bodies contain tabs, newlines and commas, but never these — and every emitted\n// field passes through the `sanitize` handler, which makes the framing safe\n// rather than merely unlikely to break.\nexport const FIELD_SEP = '\u001f';\nexport const RECORD_SEP = '\u001e';\nexport const LIST_SEP = '\u001d';\n\n/** The same three, as AppleScript expressions. */\nexport const AS_FIELD_SEP = '(character id 31)';\nexport const AS_RECORD_SEP = '(character id 30)';\nexport const AS_LIST_SEP = '(character id 29)';\n\n/**\n * One record: the AppleScript expressions in `fields`, separated and terminated\n * so `splitRecords`/`splitFields` can take them apart again. A field holding a\n * LIST must be built with `my sanitizeList(...)`, which cleans the elements —\n * `sanitize` deliberately leaves the list separator alone.\n */\nexport function asRow(fields: readonly string[]): string {\n return fields\n .map(f => `my sanitize(${f})`)\n .join(` & ${AS_FIELD_SEP} & `) + ` & ${AS_RECORD_SEP}`;\n}\n\n/**\n * The handlers every script relies on, called with `my` from inside a `tell`.\n *\n * `isoDate` produces the zero-padded 'yyyy-MM-dd HH:mm' both platforms return;\n * `sanitize` strips the framing characters; `joinList` and `replaceText` are the\n * text-item-delimiter dance nobody should write twice.\n */\nexport const AS_HANDLERS = `\non pad2(n)\n set s to (n as integer) as string\n if (length of s) < 2 then set s to \"0\" & s\n return s\nend pad2\n\non isoDate(d)\n if d is missing value then return \"\"\n return (year of d as string) & \"-\" & pad2(month of d as integer) & \"-\" & pad2(day of d) & \" \" & pad2(hours of d) & \":\" & pad2(minutes of d)\nend isoDate\n\non joinList(lst, sep)\n set saved to AppleScript's text item delimiters\n set AppleScript's text item delimiters to sep\n set out to lst as string\n set AppleScript's text item delimiters to saved\n return out\nend joinList\n\non replaceText(t, findWhat, replaceWith)\n set saved to AppleScript's text item delimiters\n set AppleScript's text item delimiters to findWhat\n set parts to text items of t\n set AppleScript's text item delimiters to replaceWith\n set out to parts as string\n set AppleScript's text item delimiters to saved\n return out\nend replaceText\n\n-- Strips the FIELD and RECORD separators only. The LIST separator is left\n-- alone on purpose: a field may legitimately BE a list.\non sanitize(v)\n if v is missing value then return \"\"\n set t to v as string\n repeat with codePoint in {30, 31}\n set marker to (character id (codePoint as integer))\n if t contains marker then set t to my replaceText(t, marker, \" \")\n end repeat\n return t\nend sanitize\n\n-- A list field: each element loses all three separators, then they are joined\n-- with the LIST separator that splitList() takes them apart on.\non sanitizeList(lst)\n set cleaned to {}\n repeat with item_ in lst\n set t to my sanitize(item_)\n set marker to (character id 29)\n if t contains marker then set t to my replaceText(t, marker, \" \")\n set end of cleaned to t\n end repeat\n return my joinList(cleaned, (character id 29))\nend sanitizeList\n\n-- A list whose positions matter, like an email's attachments: every element is\n-- FOLLOWED by the LIST separator, so an empty element keeps its place and an\n-- empty list stays distinct from a list of one empty name. splitPositionalList()\n-- takes it apart.\non sanitizePositionalList(lst)\n if (count of lst) is 0 then return \"\"\n return my sanitizeList(lst) & (character id 29)\nend sanitizePositionalList\n\non insertAboveQuoted(c, ins)\n if c is missing value then return ins\n set c to c as string\n if (length of c) is 0 then return ins\n -- A reply's own empty paragraph sits inside WordSection1; inserting straight\n -- after that tag puts the new text where the cursor would be. Anything else\n -- falls back to just inside <body>. ('at' is a reserved parameter name, so\n -- the cut point can't be called that.)\n set cutPoint to my tagEnd(c, \"${WORD_SECTION_ANCHOR}\")\n if cutPoint is 0 then set cutPoint to my tagEnd(c, \"<body\")\n if cutPoint is 0 then return ins & c\n if cutPoint is (length of c) then return c & ins\n return (text 1 thru cutPoint of c) & ins & (text (cutPoint + 1) thru -1 of c)\nend insertAboveQuoted\n\n-- 'rest' is an AppleScript term, so the remainder can't be called that:\n-- assigning to it compiles and then fails at run time.\non tagEnd(c, marker)\n set ix to offset of marker in c\n if ix is 0 then return 0\n if marker ends with \">\" then return ix + (length of marker) - 1\n set tailText to text ix thru -1 of c\n set gt to offset of \">\" in tailText\n if gt is 0 then return 0\n return ix + gt - 1\nend tagEnd\n`;\n\n/** A script's output as records, without the trailing empty one. */\nexport function splitRecords(raw: string): string[] {\n return raw.split(RECORD_SEP).filter(record => record.trim() !== '');\n}\n\n/** One record's fields. */\nexport function splitFields(record: string): string[] {\n return record.split(FIELD_SEP);\n}\n\n/**\n * A field that carries a list. Empty elements are dropped, so where an index\n * into the list must match Outlook's, the field is written with\n * `sanitizePositionalList` and read with `splitPositionalList` instead.\n */\nexport function splitList(value: string | undefined): string[] {\n return (value || '').split(LIST_SEP).filter(Boolean);\n}\n\n/**\n * A field written by `sanitizePositionalList`: every element at its position,\n * empty ones included, so index N here is item N+1 of the AppleScript list.\n */\nexport function splitPositionalList(value: string | undefined): string[] {\n return value ? value.split(LIST_SEP).slice(0, -1) : [];\n}\n\n/** A field by position; a missing field reads as ''. */\nexport function field(fields: readonly string[], index: number): string {\n return fields[index] ?? '';\n}\n\n/** The fields of a script's first record — the summary a mutation returns ahead of any per-item rows. */\nexport function summaryFields(raw: string): string[] {\n return splitFields(splitRecords(raw)[0] ?? '');\n}\n\n/** A numeric field, `fallback` when absent or unparsable. */\nexport function intField(fields: readonly string[], index: number, fallback = 0): number {\n const parsed = Number.parseInt(field(fields, index), 10);\n return Number.isNaN(parsed) ? fallback : parsed;\n}\n\n/** A boolean field; AppleScript renders booleans as the bare words true/false. */\nexport function boolField(fields: readonly string[], index: number): boolean {\n return field(fields, index).trim() === 'true';\n}\n\n// ── Batches ──────────────────────────────────────────────────────────────\n//\n// A script acting on a list of ids returns one summary record, then one record\n// per id that failed. The failure row and its decoder sit together so the two\n// can't come to disagree about the field order.\n\n/** The record a batch script appends, inside `on error errText`, for the id `theId` it failed on. */\nexport const ITEM_FAILURE_ROW = asRow(['(theId as string)', 'subj', 'errText']);\n\n/** A batch script's output: the summary record's fields, and the items that failed. */\nexport function splitBatch(raw: string): { summary: string[]; failed: ItemFailure[] } {\n const [summary = '', ...failures] = splitRecords(raw);\n return {\n summary: splitFields(summary),\n failed: failures.map(record => {\n const parts = splitFields(record);\n return { entryId: field(parts, 0), subject: field(parts, 1), error: field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AAM,KAAK,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;YAClC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;QAC1F,CAAC,CAAC;KACL,CAAC;AACN,CAAC","sourcesContent":["// Getting a generated AppleScript to osascript and its output back.\n//\n// The macOS counterpart of windows/run.ts: running a script, the escaping\n// rules, and the record framing every reader here shares.\nimport fs from 'fs';\nimport { removeTempFile, type RunBudget, tempFile } from '../runtime';\nimport { runScriptProcess } from '../shared/exec';\nimport { InvalidRequestError } from '../errors';\nimport { WORD_SECTION_ANCHOR } from '../shared/replyBody';\nimport type { ItemFailure } from '../types';\n\nconst RUNNER = 'osascript' as const;\n\n/**\n * osascript's report of a script error: \"<file>:<start>:<end>: execution error:\n * <message> (<number>)\". Only the message is worth showing — these reach people\n * in per-item failure lists — and -2700 is the number AppleScript gives every\n * `error \"…\"` a script raises itself.\n */\nfunction parseFailure(stderr: string): { message: string } {\n const message = stderr\n .replace(/^(?:.*?:)?\\d+:\\d+:\\s*execution error:\\s*/m, '')\n .replace(/\\s*\\(-2700\\)\\s*$/, '')\n .trim();\n return { message };\n}\n\n/**\n * Run a script from a temp file (no argument-length or quoting limits) and\n * return what it printed, minus the newline osascript appends.\n *\n * `AS_HANDLERS` is prepended here rather than by each caller: a script missing\n * a handler fails to compile as a WHOLE, with an error pointing nowhere near the\n * omission, so it can't be left to each script to remember.\n */\nexport async function runOsaScript(source: string, budget: RunBudget): Promise<string> {\n // The full text is what osascript compiles, so it is also what error offsets\n // refer to and what the debug hook and errors carry.\n const script = AS_HANDLERS + source;\n const file = tempFile('osa', 'applescript');\n fs.writeFileSync(file, script, 'utf8');\n try {\n const { stdout } = await runScriptProcess({\n runner: RUNNER,\n command: 'osascript',\n args: [file],\n script,\n budget,\n parseFailure,\n });\n return stdout.replace(/\\n$/, '');\n } finally {\n removeTempFile(file);\n }\n}\n\n/**\n * Escape text for the inside of an AppleScript double-quoted literal.\n * AppleScript strings never interpolate, so escaping the quote, the backslash\n * and line breaks is the whole job.\n */\nexport function asEscape(text: string): string {\n return text\n .replace(/\\\\/g, '\\\\\\\\')\n .replace(/\"/g, '\\\\\"')\n .replace(/\\r\\n|\\r|\\n/g, '\\\\n');\n}\n\n/** Text as an AppleScript string literal. */\nexport function asString(text: string): string {\n return `\"${asEscape(text)}\"`;\n}\n\n/** AppleScript's boolean literals. */\nexport function asBool(value: boolean): string {\n return value ? 'true' : 'false';\n}\n\n/** A whole number for a script; anything else is refused before it becomes code. */\nexport function asInt(value: number): string {\n if (!Number.isSafeInteger(value)) {\n throw new InvalidRequestError(`Expected a whole number, got ${String(value)}.`);\n }\n return String(value);\n}\n\n/** Message ids (already validated as integers) as an AppleScript list literal. */\nexport function asIdList(ids: readonly string[]): string {\n return `{${ids.map(id => asInt(Number(id))).join(', ')}}`;\n}\n\n// ── Record framing ───────────────────────────────────────────────────────\n//\n// Control characters separate fields, records and list items: subjects and\n// bodies contain tabs, newlines and commas, but never these — and every emitted\n// field passes through the `sanitize` handler, which makes the framing safe\n// rather than merely unlikely to break.\nexport const FIELD_SEP = '\\x1f';\nexport const RECORD_SEP = '\\x1e';\nexport const LIST_SEP = '\\x1d';\n\n/** The same three, as AppleScript expressions. Only the list one is written outside this module. */\nconst AS_FIELD_SEP = '(character id 31)';\nconst AS_RECORD_SEP = '(character id 30)';\nexport const AS_LIST_SEP = '(character id 29)';\n\n/**\n * One record: the AppleScript expressions in `fields`, separated and terminated\n * so `splitRecords`/`splitFields` can take them apart again. A field holding a\n * LIST must be built with `my sanitizeList(...)`, which cleans the elements —\n * `sanitize` deliberately leaves the list separator alone.\n */\nexport function asRow(fields: readonly string[]): string {\n return fields\n .map(f => `my sanitize(${f})`)\n .join(` & ${AS_FIELD_SEP} & `) + ` & ${AS_RECORD_SEP}`;\n}\n\n/**\n * The handlers every script relies on, called with `my` from inside a `tell`.\n *\n * `isoDate` produces the zero-padded 'yyyy-MM-dd HH:mm' both platforms return;\n * `sanitize` strips the framing characters; `joinList` and `replaceText` are the\n * text-item-delimiter dance nobody should write twice.\n */\nexport const AS_HANDLERS = `\non pad2(n)\n set s to (n as integer) as string\n if (length of s) < 2 then set s to \"0\" & s\n return s\nend pad2\n\non isoDate(d)\n if d is missing value then return \"\"\n return (year of d as string) & \"-\" & pad2(month of d as integer) & \"-\" & pad2(day of d) & \" \" & pad2(hours of d) & \":\" & pad2(minutes of d)\nend isoDate\n\non joinList(lst, sep)\n set saved to AppleScript's text item delimiters\n set AppleScript's text item delimiters to sep\n set out to lst as string\n set AppleScript's text item delimiters to saved\n return out\nend joinList\n\non replaceText(t, findWhat, replaceWith)\n set saved to AppleScript's text item delimiters\n set AppleScript's text item delimiters to findWhat\n set parts to text items of t\n set AppleScript's text item delimiters to replaceWith\n set out to parts as string\n set AppleScript's text item delimiters to saved\n return out\nend replaceText\n\n-- Strips the FIELD and RECORD separators only. The LIST separator is left\n-- alone on purpose: a field may legitimately BE a list.\non sanitize(v)\n if v is missing value then return \"\"\n set t to v as string\n repeat with codePoint in {30, 31}\n set marker to (character id (codePoint as integer))\n if t contains marker then set t to my replaceText(t, marker, \" \")\n end repeat\n return t\nend sanitize\n\n-- A list field: each element loses all three separators, then they are joined\n-- with the LIST separator that splitList() takes them apart on.\non sanitizeList(lst)\n set cleaned to {}\n repeat with item_ in lst\n set t to my sanitize(item_)\n set marker to (character id 29)\n if t contains marker then set t to my replaceText(t, marker, \" \")\n set end of cleaned to t\n end repeat\n return my joinList(cleaned, (character id 29))\nend sanitizeList\n\n-- A list whose positions matter, like an email's attachments: every element is\n-- FOLLOWED by the LIST separator, so an empty element keeps its place and an\n-- empty list stays distinct from a list of one empty name. splitPositionalList()\n-- takes it apart.\non sanitizePositionalList(lst)\n if (count of lst) is 0 then return \"\"\n return my sanitizeList(lst) & (character id 29)\nend sanitizePositionalList\n\non insertAboveQuoted(c, ins)\n if c is missing value then return ins\n set c to c as string\n if (length of c) is 0 then return ins\n -- A reply's own empty paragraph sits inside WordSection1; inserting straight\n -- after that tag puts the new text where the cursor would be. Anything else\n -- falls back to just inside <body>. ('at' is a reserved parameter name, so\n -- the cut point can't be called that.)\n set cutPoint to my tagEnd(c, \"${WORD_SECTION_ANCHOR}\")\n if cutPoint is 0 then set cutPoint to my tagEnd(c, \"<body\")\n if cutPoint is 0 then return ins & c\n if cutPoint is (length of c) then return c & ins\n return (text 1 thru cutPoint of c) & ins & (text (cutPoint + 1) thru -1 of c)\nend insertAboveQuoted\n\n-- 'rest' is an AppleScript term, so the remainder can't be called that:\n-- assigning to it compiles and then fails at run time.\non tagEnd(c, marker)\n set ix to offset of marker in c\n if ix is 0 then return 0\n if marker ends with \">\" then return ix + (length of marker) - 1\n set tailText to text ix thru -1 of c\n set gt to offset of \">\" in tailText\n if gt is 0 then return 0\n return ix + gt - 1\nend tagEnd\n`;\n\n/** A script's output as records, without the trailing empty one. */\nexport function splitRecords(raw: string): string[] {\n return raw.split(RECORD_SEP).filter(record => record.trim() !== '');\n}\n\n/** One record's fields. */\nexport function splitFields(record: string): string[] {\n return record.split(FIELD_SEP);\n}\n\n/**\n * A field that carries a list. Empty elements are dropped, so where an index\n * into the list must match Outlook's, the field is written with\n * `sanitizePositionalList` and read with `splitPositionalList` instead.\n */\nexport function splitList(value: string | undefined): string[] {\n return (value || '').split(LIST_SEP).filter(Boolean);\n}\n\n/**\n * A field written by `sanitizePositionalList`: every element at its position,\n * empty ones included, so index N here is item N+1 of the AppleScript list.\n */\nexport function splitPositionalList(value: string | undefined): string[] {\n return value ? value.split(LIST_SEP).slice(0, -1) : [];\n}\n\n/** A field by position; a missing field reads as ''. */\nexport function field(fields: readonly string[], index: number): string {\n return fields[index] ?? '';\n}\n\n/** The fields of a script's first record — the summary a mutation returns ahead of any per-item rows. */\nexport function summaryFields(raw: string): string[] {\n return splitFields(splitRecords(raw)[0] ?? '');\n}\n\n/** A numeric field, `fallback` when absent or unparsable. */\nexport function intField(fields: readonly string[], index: number, fallback = 0): number {\n const parsed = Number.parseInt(field(fields, index), 10);\n return Number.isNaN(parsed) ? fallback : parsed;\n}\n\n/** A boolean field; AppleScript renders booleans as the bare words true/false. */\nexport function boolField(fields: readonly string[], index: number): boolean {\n return field(fields, index).trim() === 'true';\n}\n\n// ── Batches ──────────────────────────────────────────────────────────────\n//\n// A script acting on a list of ids returns one summary record, then one record\n// per id that failed. The failure row and its decoder sit together so the two\n// can't come to disagree about the field order.\n\n/** The record a batch script appends, inside `on error errText`, for the id `theId` it failed on. */\nexport const ITEM_FAILURE_ROW = asRow(['(theId as string)', 'subj', 'errText']);\n\n/** A batch script's output: the summary record's fields, and the items that failed. */\nexport function splitBatch(raw: string): { summary: string[]; failed: ItemFailure[] } {\n const [summary = '', ...failures] = splitRecords(raw);\n return {\n summary: splitFields(summary),\n failed: failures.map(record => {\n const parts = splitFields(record);\n return { entryId: field(parts, 0), subject: field(parts, 1), error: field(parts, 2) };\n }),\n };\n}\n"]}
|
package/dist/mac/scripts.d.ts
CHANGED
|
@@ -12,6 +12,12 @@ import type { ItemFailure, MailFolderRef } from '../types';
|
|
|
12
12
|
export interface MacAccount {
|
|
13
13
|
readonly emailAccount: string;
|
|
14
14
|
readonly folderIds?: Readonly<Record<string, number>>;
|
|
15
|
+
/**
|
|
16
|
+
* Set when the profile has no row for the address because macOS refused it:
|
|
17
|
+
* the sentence to fail with should AppleScript not find the account either,
|
|
18
|
+
* since the profile is where a mailbox AppleScript can't see would have been.
|
|
19
|
+
*/
|
|
20
|
+
readonly profileRefusal?: string;
|
|
15
21
|
}
|
|
16
22
|
/** Look an address up in Outlook's profile database, for the folder ids it can add. */
|
|
17
23
|
export declare function resolveMacAccount(emailAccount: string): Promise<MacAccount>;
|
|
@@ -62,6 +68,33 @@ export declare function macFolderPath(emailAccount: string, rootLabel: string, s
|
|
|
62
68
|
* is exact.
|
|
63
69
|
*/
|
|
64
70
|
export declare function folderChainSnippet(indent: string): string;
|
|
71
|
+
/**
|
|
72
|
+
* Bind `acctRootId` to the id of the account's root folder — the folder every
|
|
73
|
+
* one of its top-level folders sits in — through the account object when the
|
|
74
|
+
* probe found one, else from the profile database. Requires
|
|
75
|
+
* `accountLookupSnippet`.
|
|
76
|
+
*
|
|
77
|
+
* Never fails: an account neither names a root for leaves `acctRootId` as
|
|
78
|
+
* `missing value`, which `ownMailGuardSnippet` reads as a root nothing can be
|
|
79
|
+
* shown to sit under.
|
|
80
|
+
*/
|
|
81
|
+
export declare function accountRootIdSnippet(acct: MacAccount): string;
|
|
82
|
+
/**
|
|
83
|
+
* Fail unless `theMsg` is the account's own mail — the macOS counterpart of
|
|
84
|
+
* Windows resolving an id in the account's store. `message id N` resolves
|
|
85
|
+
* against the application, so an id alone says nothing about whose mailbox the
|
|
86
|
+
* message is in, and a stale or wrong one can name mail in another.
|
|
87
|
+
*
|
|
88
|
+
* Either of two signs is enough, because neither exists for every mailbox:
|
|
89
|
+
* - the message's folder chain ends at the account's root folder. Requires
|
|
90
|
+
* `folderChainSnippet` (for `cur`) and `accountRootIdSnippet`.
|
|
91
|
+
* - the message's own account carries the address. A mailbox the dictionary
|
|
92
|
+
* publishes no account object for answers this with `missing value` (see
|
|
93
|
+
* profile.ts), which is why the first sign has to be able to stand alone.
|
|
94
|
+
* An item neither vouches for is refused rather than given the benefit of the
|
|
95
|
+
* doubt: what follows moves or deletes it.
|
|
96
|
+
*/
|
|
97
|
+
export declare function ownMailGuardSnippet(emailAccount: string, verb: 'delete' | 'move', indent: string): string;
|
|
65
98
|
/**
|
|
66
99
|
* Resolve `scopeFolder` from `targetAcct`: a well-known root walked down through
|
|
67
100
|
* any further segments. Also binds `scopeCreated`.
|
|
@@ -93,6 +126,19 @@ export declare function partitionMessageIds(entryIds: readonly string[]): {
|
|
|
93
126
|
* against the application, so the message is found wherever it sits.
|
|
94
127
|
*/
|
|
95
128
|
export declare function messageLookupSnippet(id: string): string;
|
|
129
|
+
/**
|
|
130
|
+
* Bind `theMsg` to the id a batch loop holds in `theId`, leaving it `missing
|
|
131
|
+
* value` when the id no longer resolves — the per-item counterpart of
|
|
132
|
+
* `messageLookupSnippet`, for a loop that skips or reports a miss and goes on
|
|
133
|
+
* rather than failing the whole run.
|
|
134
|
+
*/
|
|
135
|
+
export declare function messageByIdSnippet(indent: string): string;
|
|
136
|
+
/**
|
|
137
|
+
* `theMsg`'s plain-text body as `bodyText`: whole, cut to `maxChars`, or — with
|
|
138
|
+
* a `maxChars` of 0 — not read at all, the body being the one expensive
|
|
139
|
+
* property of a message.
|
|
140
|
+
*/
|
|
141
|
+
export declare function bodyTextSnippet(indent: string, maxChars?: number): string;
|
|
96
142
|
/**
|
|
97
143
|
* `theMsg`'s sender as `sndName` / `sndAddr`. `sender` is a record, and
|
|
98
144
|
* `address of sender of m` doesn't coerce, so the record is bound first.
|
package/dist/mac/scripts.js
CHANGED
|
@@ -7,10 +7,14 @@ exports.rootFolderSnippet = rootFolderSnippet;
|
|
|
7
7
|
exports.dateProperty = dateProperty;
|
|
8
8
|
exports.macFolderPath = macFolderPath;
|
|
9
9
|
exports.folderChainSnippet = folderChainSnippet;
|
|
10
|
+
exports.accountRootIdSnippet = accountRootIdSnippet;
|
|
11
|
+
exports.ownMailGuardSnippet = ownMailGuardSnippet;
|
|
10
12
|
exports.mailScopeSnippet = mailScopeSnippet;
|
|
11
13
|
exports.macMessageId = macMessageId;
|
|
12
14
|
exports.partitionMessageIds = partitionMessageIds;
|
|
13
15
|
exports.messageLookupSnippet = messageLookupSnippet;
|
|
16
|
+
exports.messageByIdSnippet = messageByIdSnippet;
|
|
17
|
+
exports.bodyTextSnippet = bodyTextSnippet;
|
|
14
18
|
exports.senderSnippet = senderSnippet;
|
|
15
19
|
exports.messageDetailSnippet = messageDetailSnippet;
|
|
16
20
|
exports.messageDetailFields = messageDetailFields;
|
|
@@ -26,7 +30,12 @@ async function resolveMacAccount(emailAccount) {
|
|
|
26
30
|
const wanted = emailAccount.trim().toLowerCase();
|
|
27
31
|
const found = (await (0, profile_1.readProfileAccounts)())
|
|
28
32
|
.find(account => account.emailAccount.trim().toLowerCase() === wanted);
|
|
29
|
-
|
|
33
|
+
if (found)
|
|
34
|
+
return { emailAccount, folderIds: found.folderIds };
|
|
35
|
+
// Asked only for an address the profile did not give: the script still looks
|
|
36
|
+
// for an account object first, so a classic account works without access.
|
|
37
|
+
const refusal = await (0, profile_1.profileRefusal)();
|
|
38
|
+
return refusal ? { emailAccount, profileRefusal: refusal } : { emailAccount };
|
|
30
39
|
}
|
|
31
40
|
/**
|
|
32
41
|
* Resolve the account whose address matches into `targetAcct`, inside a
|
|
@@ -54,10 +63,18 @@ function accountLookupSnippet(acct, needsAccountObject = false) {
|
|
|
54
63
|
end try`;
|
|
55
64
|
if (acct.folderIds && !needsAccountObject)
|
|
56
65
|
return probe;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
let complaint;
|
|
67
|
+
if (acct.folderIds) {
|
|
68
|
+
complaint = `${(0, errors_1.failureTag)('INVALID_REQUEST')}Outlook publishes no account object for '${acct.emailAccount}', `
|
|
69
|
+
+ 'so the account a message is sent from cannot be set. Its folders can be read; mail cannot be composed from it.';
|
|
70
|
+
}
|
|
71
|
+
else if (acct.profileRefusal) {
|
|
72
|
+
complaint = `${(0, errors_1.failureTag)('PERMISSION_DENIED')}Account '${acct.emailAccount}' is not one Outlook's scripting `
|
|
73
|
+
+ `can see. ${acct.profileRefusal}`;
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
complaint = `${(0, errors_1.failureTag)('ACCOUNT_NOT_FOUND')}Account '${acct.emailAccount}' not found in Outlook.`;
|
|
77
|
+
}
|
|
61
78
|
return `${probe}
|
|
62
79
|
if targetAcct is missing value then error ${(0, run_1.asString)(complaint)}`;
|
|
63
80
|
}
|
|
@@ -145,6 +162,52 @@ ${indent} set cur to nextUp
|
|
|
145
162
|
${indent} set guard to guard + 1
|
|
146
163
|
${indent}end repeat`;
|
|
147
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Bind `acctRootId` to the id of the account's root folder — the folder every
|
|
167
|
+
* one of its top-level folders sits in — through the account object when the
|
|
168
|
+
* probe found one, else from the profile database. Requires
|
|
169
|
+
* `accountLookupSnippet`.
|
|
170
|
+
*
|
|
171
|
+
* Never fails: an account neither names a root for leaves `acctRootId` as
|
|
172
|
+
* `missing value`, which `ownMailGuardSnippet` reads as a root nothing can be
|
|
173
|
+
* shown to sit under.
|
|
174
|
+
*/
|
|
175
|
+
function accountRootIdSnippet(acct) {
|
|
176
|
+
const profiled = acct.folderIds?.['root folder'];
|
|
177
|
+
return ` set acctRootId to missing value
|
|
178
|
+
try
|
|
179
|
+
if targetAcct is not missing value then set acctRootId to id of (root folder of targetAcct)
|
|
180
|
+
end try` + (profiled === undefined ? '' : `
|
|
181
|
+
if acctRootId is missing value then set acctRootId to ${(0, run_1.asInt)(profiled)}`);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Fail unless `theMsg` is the account's own mail — the macOS counterpart of
|
|
185
|
+
* Windows resolving an id in the account's store. `message id N` resolves
|
|
186
|
+
* against the application, so an id alone says nothing about whose mailbox the
|
|
187
|
+
* message is in, and a stale or wrong one can name mail in another.
|
|
188
|
+
*
|
|
189
|
+
* Either of two signs is enough, because neither exists for every mailbox:
|
|
190
|
+
* - the message's folder chain ends at the account's root folder. Requires
|
|
191
|
+
* `folderChainSnippet` (for `cur`) and `accountRootIdSnippet`.
|
|
192
|
+
* - the message's own account carries the address. A mailbox the dictionary
|
|
193
|
+
* publishes no account object for answers this with `missing value` (see
|
|
194
|
+
* profile.ts), which is why the first sign has to be able to stand alone.
|
|
195
|
+
* An item neither vouches for is refused rather than given the benefit of the
|
|
196
|
+
* doubt: what follows moves or deletes it.
|
|
197
|
+
*/
|
|
198
|
+
function ownMailGuardSnippet(emailAccount, verb, indent) {
|
|
199
|
+
return `${indent}set inAccount to false
|
|
200
|
+
${indent}try
|
|
201
|
+
${indent} if acctRootId is not missing value and (id of cur) is acctRootId then set inAccount to true
|
|
202
|
+
${indent}end try
|
|
203
|
+
${indent}if not inAccount then
|
|
204
|
+
${indent} try
|
|
205
|
+
${indent} set ownerAddr to email address of (account of theMsg)
|
|
206
|
+
${indent} if ownerAddr is not missing value and (ownerAddr as string) is ${(0, run_1.asString)(emailAccount)} then set inAccount to true
|
|
207
|
+
${indent} end try
|
|
208
|
+
${indent}end if
|
|
209
|
+
${indent}if not inAccount then error "item is in another mailbox, not this account - refusing to ${verb}"`;
|
|
210
|
+
}
|
|
148
211
|
/** The dictionary term for a root, or NOT_IMPLEMENTED naming what was asked. */
|
|
149
212
|
function rootTerm(ref, folderLabel = '') {
|
|
150
213
|
const term = exports.MAC_ROOT_TERMS[ref.rootId];
|
|
@@ -231,6 +294,35 @@ function messageLookupSnippet(id) {
|
|
|
231
294
|
end try
|
|
232
295
|
if theMsg is missing value then error ${(0, run_1.asString)(complaint)}`;
|
|
233
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Bind `theMsg` to the id a batch loop holds in `theId`, leaving it `missing
|
|
299
|
+
* value` when the id no longer resolves — the per-item counterpart of
|
|
300
|
+
* `messageLookupSnippet`, for a loop that skips or reports a miss and goes on
|
|
301
|
+
* rather than failing the whole run.
|
|
302
|
+
*/
|
|
303
|
+
function messageByIdSnippet(indent) {
|
|
304
|
+
return `${indent}set theMsg to missing value
|
|
305
|
+
${indent}try
|
|
306
|
+
${indent} set theMsg to message id theId
|
|
307
|
+
${indent}end try`;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* `theMsg`'s plain-text body as `bodyText`: whole, cut to `maxChars`, or — with
|
|
311
|
+
* a `maxChars` of 0 — not read at all, the body being the one expensive
|
|
312
|
+
* property of a message.
|
|
313
|
+
*/
|
|
314
|
+
function bodyTextSnippet(indent, maxChars) {
|
|
315
|
+
if (maxChars === 0)
|
|
316
|
+
return `${indent}set bodyText to ""`;
|
|
317
|
+
const read = `${indent}set bodyText to ""
|
|
318
|
+
${indent}try
|
|
319
|
+
${indent} set bodyText to (plain text content of theMsg) as string
|
|
320
|
+
${indent}end try`;
|
|
321
|
+
if (maxChars === undefined)
|
|
322
|
+
return read;
|
|
323
|
+
return `${read}
|
|
324
|
+
${indent}if (length of bodyText) > ${(0, run_1.asInt)(maxChars)} then set bodyText to text 1 thru ${(0, run_1.asInt)(maxChars)} of bodyText`;
|
|
325
|
+
}
|
|
234
326
|
/**
|
|
235
327
|
* `theMsg`'s sender as `sndName` / `sndAddr`. `sender` is a record, and
|
|
236
328
|
* `address of sender of m` doesn't coerce, so the record is bound first.
|
|
@@ -271,11 +363,7 @@ ${indent}end try
|
|
|
271
363
|
${indent}set attNames to {}
|
|
272
364
|
${indent}try
|
|
273
365
|
${indent} set attNames to name of every attachment of theMsg
|
|
274
|
-
${indent}end try` + (withBody ? `
|
|
275
|
-
${indent}set bodyText to ""
|
|
276
|
-
${indent}try
|
|
277
|
-
${indent} set bodyText to (plain text content of theMsg) as string
|
|
278
|
-
${indent}end try` : '');
|
|
366
|
+
${indent}end try` + (withBody ? `\n${bodyTextSnippet(indent)}` : '');
|
|
279
367
|
}
|
|
280
368
|
/** The fields `messageDetailSnippet` fills, in row order — see `MessageDetail`. */
|
|
281
369
|
function messageDetailFields(withBody = false) {
|