@wtfalch/email 0.20.0 → 0.24.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 +67 -30
- package/dist/mailbox/index.d.ts +6 -2
- package/dist/mailbox/index.js +3 -1
- package/dist/mailbox/principals.d.ts +48 -0
- package/dist/mailbox/principals.js +111 -0
- package/dist/mailbox/rules.d.ts +102 -0
- package/dist/mailbox/rules.js +318 -0
- package/dist/mailbox/submit.d.ts +20 -1
- package/dist/mailbox/submit.js +125 -0
- package/dist/mailbox/types.d.ts +19 -0
- package/dist/mailbox/vacation.d.ts +4 -0
- package/dist/mailbox/vacation.js +118 -10
- package/dist/postmaster/apply.d.ts +20 -0
- package/dist/postmaster/apply.js +48 -1
- package/dist/postmaster/audit.d.ts +3 -0
- package/dist/postmaster/audit.js +1 -0
- package/dist/postmaster/index.d.ts +3 -2
- package/dist/postmaster/index.js +3 -2
- package/dist/postmaster/mail-copy.d.ts +12 -1
- package/dist/postmaster/mail-copy.js +2 -2
- package/dist/postmaster/mail-takeout.d.ts +31 -0
- package/dist/postmaster/mail-takeout.js +113 -0
- package/dist/postmaster/org-mail-export.d.ts +2 -2
- package/dist/postmaster/writes.d.ts +14 -1
- package/dist/postmaster/writes.js +17 -1
- package/package.json +1 -5
- package/dist/mailbox/fake/index.d.ts +0 -34
- package/dist/mailbox/fake/index.js +0 -85
- package/dist/mailbox/fake/mailbox.d.ts +0 -79
- package/dist/mailbox/fake/mailbox.js +0 -1235
- package/dist/mailbox/fake/sample.d.ts +0 -2
- package/dist/mailbox/fake/sample.js +0 -322
|
@@ -105,6 +105,26 @@ export declare function revokeAppPassword(instance: Instance, input: {
|
|
|
105
105
|
domainId: string;
|
|
106
106
|
apex: string;
|
|
107
107
|
}, audit?: PostmasterAudit): Promise<Applied>;
|
|
108
|
+
/**
|
|
109
|
+
* Stop every app password on the account working at once, used when a
|
|
110
|
+
* person must be shut out of mail immediately — disabling their sign-in
|
|
111
|
+
* alone does not do this, because IMAP and SMTP never consult the issuer
|
|
112
|
+
* and an app password they minted keeps authenticating after it.
|
|
113
|
+
*
|
|
114
|
+
* Same self-protection as `revokeAppPassword`, for the same reason: an
|
|
115
|
+
* instance whose administrator credential is itself an app password (a
|
|
116
|
+
* laptop, or an instance provisioned before slice 3) must not be able to
|
|
117
|
+
* revoke its own way in from inside the panel.
|
|
118
|
+
*
|
|
119
|
+
* Secrets are never read, here or anywhere else: surviving credentials
|
|
120
|
+
* (the account `Password`, any `ApiKey`) go back exactly as the server sent
|
|
121
|
+
* them, which it reads as "leave this one alone".
|
|
122
|
+
*/
|
|
123
|
+
export declare function revokeAllAppPasswords(instance: Instance, input: {
|
|
124
|
+
accountId: string;
|
|
125
|
+
domainId: string;
|
|
126
|
+
apex: string;
|
|
127
|
+
}, audit?: PostmasterAudit): Promise<Applied>;
|
|
108
128
|
/**
|
|
109
129
|
* Stop one API key working. The secret is never read, here or anywhere
|
|
110
130
|
* else: the entry is identified by its id and the surviving entries go back
|
package/dist/postmaster/apply.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FUTURE_RELEASE } from './objects.js';
|
|
2
|
-
import { MailWriteRefused, membershipIds, newAccount, newGroup, withAlias, withMembership, withoutAlias, withoutApiKey, withoutAppPassword, withoutMembership, } from './writes.js';
|
|
2
|
+
import { MailWriteRefused, membershipIds, newAccount, newGroup, withAlias, withMembership, withoutAlias, withoutAllAppPasswords, withoutApiKey, withoutAppPassword, withoutMembership, } from './writes.js';
|
|
3
3
|
/**
|
|
4
4
|
* The four writes `/email` makes, each as one round trip against the mail
|
|
5
5
|
* instance's management API.
|
|
@@ -322,6 +322,53 @@ export async function revokeAppPassword(instance, input, audit) {
|
|
|
322
322
|
message: `That app password no longer works${description ? ` (${description})` : ''}. Any mail client using it will be asked to sign in again.${lost}`,
|
|
323
323
|
});
|
|
324
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* Stop every app password on the account working at once, used when a
|
|
327
|
+
* person must be shut out of mail immediately — disabling their sign-in
|
|
328
|
+
* alone does not do this, because IMAP and SMTP never consult the issuer
|
|
329
|
+
* and an app password they minted keeps authenticating after it.
|
|
330
|
+
*
|
|
331
|
+
* Same self-protection as `revokeAppPassword`, for the same reason: an
|
|
332
|
+
* instance whose administrator credential is itself an app password (a
|
|
333
|
+
* laptop, or an instance provisioned before slice 3) must not be able to
|
|
334
|
+
* revoke its own way in from inside the panel.
|
|
335
|
+
*
|
|
336
|
+
* Secrets are never read, here or anywhere else: surviving credentials
|
|
337
|
+
* (the account `Password`, any `ApiKey`) go back exactly as the server sent
|
|
338
|
+
* them, which it reads as "leave this one alone".
|
|
339
|
+
*/
|
|
340
|
+
export async function revokeAllAppPasswords(instance, input, audit) {
|
|
341
|
+
const account = await readAccount(instance, input.accountId, input.domainId);
|
|
342
|
+
if (isOurOwnAccount(instance, account, input.apex)) {
|
|
343
|
+
throw new MailWriteRefused(`${instance.user} is the account this management app signs in as, and one of its app passwords is serving this request. Manage its credentials in the web admin.`);
|
|
344
|
+
}
|
|
345
|
+
// The same filter that decides what `withoutAllAppPasswords` removes,
|
|
346
|
+
// so the audited and reported count can never disagree with what was
|
|
347
|
+
// actually revoked. `description`/`credentialId` are both optional on
|
|
348
|
+
// `Credential`, so an entry naming neither still counts — it is named
|
|
349
|
+
// '(unnamed)' rather than silently dropped, which would otherwise read
|
|
350
|
+
// as "nothing revoked" while the write still stripped it.
|
|
351
|
+
const before = Object.values(account.credentials ?? {}).filter((c) => c['@type'] === 'AppPassword');
|
|
352
|
+
const revoked = before.map((c) => typeof c.description === 'string'
|
|
353
|
+
? c.description
|
|
354
|
+
: typeof c.credentialId === 'string'
|
|
355
|
+
? c.credentialId
|
|
356
|
+
: '(unnamed)');
|
|
357
|
+
const credentials = withoutAllAppPasswords(account);
|
|
358
|
+
await instance.client.update('Account', account.id, { credentials });
|
|
359
|
+
const lost = missingSince(Object.values(credentials)
|
|
360
|
+
.map((c) => c.credentialId)
|
|
361
|
+
.filter((id) => typeof id === 'string'), await credentialIds(instance, account.id));
|
|
362
|
+
return recorded(audit, 'mail.app_passwords_revoked', {
|
|
363
|
+
targetType: 'mail_app_password',
|
|
364
|
+
targetId: `${account.name}@${input.apex}`,
|
|
365
|
+
before: { mailbox: `${account.name}@${input.apex}`, revoked },
|
|
366
|
+
after: null,
|
|
367
|
+
message: `${revoked.length === 0
|
|
368
|
+
? `${account.name}@${input.apex} had no app passwords to revoke.`
|
|
369
|
+
: `Every app password on ${account.name}@${input.apex} (${revoked.length}) no longer works. Any mail client using one will be asked to sign in again.`}${lost}`,
|
|
370
|
+
});
|
|
371
|
+
}
|
|
325
372
|
/**
|
|
326
373
|
* Stop one API key working. The secret is never read, here or anywhere
|
|
327
374
|
* else: the entry is identified by its id and the surviving entries go back
|
|
@@ -27,6 +27,9 @@ export declare const POSTMASTER_AUDIT_EVENTS: {
|
|
|
27
27
|
readonly 'mail.app_password_revoked': {
|
|
28
28
|
readonly tenantVisible: true;
|
|
29
29
|
};
|
|
30
|
+
readonly 'mail.app_passwords_revoked': {
|
|
31
|
+
readonly tenantVisible: true;
|
|
32
|
+
};
|
|
30
33
|
readonly 'mail.api_key_revoked': {
|
|
31
34
|
readonly tenantVisible: true;
|
|
32
35
|
};
|
package/dist/postmaster/audit.js
CHANGED
|
@@ -13,6 +13,7 @@ export const POSTMASTER_AUDIT_EVENTS = {
|
|
|
13
13
|
'mail.alias_added': { tenantVisible: true },
|
|
14
14
|
'mail.alias_removed': { tenantVisible: true },
|
|
15
15
|
'mail.app_password_revoked': { tenantVisible: true },
|
|
16
|
+
'mail.app_passwords_revoked': { tenantVisible: true },
|
|
16
17
|
'mail.api_key_revoked': { tenantVisible: true },
|
|
17
18
|
'mail.holding_enabled': { tenantVisible: true },
|
|
18
19
|
'mail.spam_settings_updated': { tenantVisible: true },
|
|
@@ -20,10 +20,11 @@ export { loadOverview } from './load.js';
|
|
|
20
20
|
export { FUTURE_RELEASE, applyObjects, mailObjects, platformMailSettingsObjects, ref, type MailObjectsInput, type PlannedObject, type PlatformMailSettingsInput, } from './objects.js';
|
|
21
21
|
export { planMailboxes, withPassword } from './mailboxes.js';
|
|
22
22
|
export { overview, pickDomain, type AccountView, type CredentialSummary, type DomainView, type Managed, type Overview, type OverviewInput, type PeopleView, type Person, type WireAccount, type WireAlias, type WireDomain, type WireSystemSettings, } from './overview.js';
|
|
23
|
-
export { MailWriteRefused, membershipIds, newAccount, newGroup, withAlias, withMembership, withoutAlias, withoutApiKey, withoutAppPassword, withoutMembership, } from './writes.js';
|
|
24
|
-
export { addAlias, addToGroup, createGroupMailbox, createMailbox, enableHolding, holdLimit, purgeQueuedMessage, removeAlias, removeFromGroup, retryQueuedMessage, revokeApiKey, revokeAppPassword, spamSettings, updateSpamSettings, type Applied, type SpamSettingsInput, type SpamSettingsView, } from './apply.js';
|
|
23
|
+
export { MailWriteRefused, membershipIds, newAccount, newGroup, withAlias, withMembership, withoutAlias, withoutAllAppPasswords, withoutApiKey, withoutAppPassword, withoutMembership, } from './writes.js';
|
|
24
|
+
export { addAlias, addToGroup, createGroupMailbox, createMailbox, enableHolding, holdLimit, purgeQueuedMessage, removeAlias, removeFromGroup, retryQueuedMessage, revokeAllAppPasswords, revokeApiKey, revokeAppPassword, spamSettings, updateSpamSettings, type Applied, type SpamSettingsInput, type SpamSettingsView, } from './apply.js';
|
|
25
25
|
export { loadQueue, queueMessageView, type QueueMessage, type QueueRecipient, type QueueRecipientState, } from './queue.js';
|
|
26
26
|
export { applyOrgMail, applyOrgRelay, dkimRecordsFromZoneFile, hasOrgRelay, parkOrgMail, removeOrgRelay, type OrgRelayInput, type OrgRelayOrg, type DnsRecordSpec, type OrgMailMode, type OrgMailOptions, type OrgMailOrg, type OrgMailResult, } from './org-mail.js';
|
|
27
27
|
export { POSTMASTER_AUDIT_EVENTS, type PostmasterAudit, type PostmasterAuditAction, type PostmasterAuditEvent, } from './audit.js';
|
|
28
28
|
export { MailCopyPlanRefused, mailCopyPlan, type MailCopyAccount, type MailCopyAccountPlan, type MailCopyEnv, type MailCopyOptions, type MailCopyPlan, type MailCopyProvider, } from './mail-copy.js';
|
|
29
|
+
export { TAKEOUT_MAX_BYTES, mailTakeoutPlan, type MailTakeoutOptions, type MailTakeoutPlan, } from './mail-takeout.js';
|
|
29
30
|
export { OrgMailExportRefused, accountsOnDomain, orgMailBackupPlan, orgMailRestorePlan, type OrgMailBackupAccountPlan, type OrgMailBackupOptions, type OrgMailBackupPlan, type OrgMailExportAccount, type OrgMailExportEnv, type OrgMailRestoreAccount, type OrgMailRestoreAccountPlan, type OrgMailRestoreOptions, type OrgMailRestorePlan, } from './org-mail-export.js';
|
package/dist/postmaster/index.js
CHANGED
|
@@ -20,10 +20,11 @@ export { loadOverview } from './load.js';
|
|
|
20
20
|
export { FUTURE_RELEASE, applyObjects, mailObjects, platformMailSettingsObjects, ref, } from './objects.js';
|
|
21
21
|
export { planMailboxes, withPassword } from './mailboxes.js';
|
|
22
22
|
export { overview, pickDomain, } from './overview.js';
|
|
23
|
-
export { MailWriteRefused, membershipIds, newAccount, newGroup, withAlias, withMembership, withoutAlias, withoutApiKey, withoutAppPassword, withoutMembership, } from './writes.js';
|
|
24
|
-
export { addAlias, addToGroup, createGroupMailbox, createMailbox, enableHolding, holdLimit, purgeQueuedMessage, removeAlias, removeFromGroup, retryQueuedMessage, revokeApiKey, revokeAppPassword, spamSettings, updateSpamSettings, } from './apply.js';
|
|
23
|
+
export { MailWriteRefused, membershipIds, newAccount, newGroup, withAlias, withMembership, withoutAlias, withoutAllAppPasswords, withoutApiKey, withoutAppPassword, withoutMembership, } from './writes.js';
|
|
24
|
+
export { addAlias, addToGroup, createGroupMailbox, createMailbox, enableHolding, holdLimit, purgeQueuedMessage, removeAlias, removeFromGroup, retryQueuedMessage, revokeAllAppPasswords, revokeApiKey, revokeAppPassword, spamSettings, updateSpamSettings, } from './apply.js';
|
|
25
25
|
export { loadQueue, queueMessageView, } from './queue.js';
|
|
26
26
|
export { applyOrgMail, applyOrgRelay, dkimRecordsFromZoneFile, hasOrgRelay, parkOrgMail, removeOrgRelay, } from './org-mail.js';
|
|
27
27
|
export { POSTMASTER_AUDIT_EVENTS, } from './audit.js';
|
|
28
28
|
export { MailCopyPlanRefused, mailCopyPlan, } from './mail-copy.js';
|
|
29
|
+
export { TAKEOUT_MAX_BYTES, mailTakeoutPlan, } from './mail-takeout.js';
|
|
29
30
|
export { OrgMailExportRefused, accountsOnDomain, orgMailBackupPlan, orgMailRestorePlan, } from './org-mail-export.js';
|
|
@@ -105,6 +105,10 @@
|
|
|
105
105
|
* `impersonate` rather than trying to pre-arrange per-account ACL shares.
|
|
106
106
|
*/
|
|
107
107
|
export type MailCopyProvider = 'google' | 'microsoft';
|
|
108
|
+
/** The env var name every bare `--auth-bearer` resolves (`src/secret.rs:12-30`).
|
|
109
|
+
* Named once so the import and export sides are visibly the same
|
|
110
|
+
* variable, not two names that happen to collide. */
|
|
111
|
+
export declare const VANDELAY_TOKEN = "VANDELAY_TOKEN";
|
|
108
112
|
export declare class MailCopyPlanRefused extends Error {
|
|
109
113
|
}
|
|
110
114
|
export interface MailCopyAccount {
|
|
@@ -121,7 +125,7 @@ export interface MailCopyOptions {
|
|
|
121
125
|
readonly provider: MailCopyProvider;
|
|
122
126
|
readonly accounts: readonly MailCopyAccount[];
|
|
123
127
|
/** The Stalwart JMAP base URL `export --url` writes to, e.g.
|
|
124
|
-
* `https://mail.
|
|
128
|
+
* `https://mail.companyincluded.com`. */
|
|
125
129
|
readonly stalwartUrl: string;
|
|
126
130
|
/** Directory holding one Vandelay SQLite archive per account. */
|
|
127
131
|
readonly archiveDir: string;
|
|
@@ -146,6 +150,13 @@ export interface MailCopyPlan {
|
|
|
146
150
|
readonly provider: MailCopyProvider;
|
|
147
151
|
readonly accounts: readonly MailCopyAccountPlan[];
|
|
148
152
|
}
|
|
153
|
+
/** `--account-id=<id>` or `--account-name=<name>`, refusing both or
|
|
154
|
+
* neither rather than silently preferring one — the same exactly-one rule
|
|
155
|
+
* Vandelay's own `export` enforces with an `ArgGroup` (`src/cli.rs:301`).
|
|
156
|
+
* The `=` form, rather than two argv elements, so a value starting with
|
|
157
|
+
* `-` (an id or name clap would otherwise mistake for another flag) still
|
|
158
|
+
* parses as this flag's value. */
|
|
159
|
+
export declare function accountSelectorArgv(account: MailCopyAccount): string;
|
|
149
160
|
/**
|
|
150
161
|
* The Vandelay commands foundry runs to copy every account of one org's old
|
|
151
162
|
* mail from `input.provider` into Stalwart: one `import imap` and one
|
|
@@ -119,7 +119,7 @@ const IMAP_URL = {
|
|
|
119
119
|
/** The env var name every bare `--auth-bearer` resolves (`src/secret.rs:12-30`).
|
|
120
120
|
* Named once so the import and export sides are visibly the same
|
|
121
121
|
* variable, not two names that happen to collide. */
|
|
122
|
-
const VANDELAY_TOKEN = 'VANDELAY_TOKEN';
|
|
122
|
+
export const VANDELAY_TOKEN = 'VANDELAY_TOKEN';
|
|
123
123
|
export class MailCopyPlanRefused extends Error {
|
|
124
124
|
}
|
|
125
125
|
/** A very small email shape check: exactly one `@`, something on both
|
|
@@ -159,7 +159,7 @@ function archiveFileName(source) {
|
|
|
159
159
|
* The `=` form, rather than two argv elements, so a value starting with
|
|
160
160
|
* `-` (an id or name clap would otherwise mistake for another flag) still
|
|
161
161
|
* parses as this flag's value. */
|
|
162
|
-
function accountSelectorArgv(account) {
|
|
162
|
+
export function accountSelectorArgv(account) {
|
|
163
163
|
const { targetAccountId, targetAccountName } = account;
|
|
164
164
|
if (targetAccountId && targetAccountName) {
|
|
165
165
|
throw new MailCopyPlanRefused(`${account.source} names both a target account id and a target account name; export takes exactly one`);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MailCopyEnv } from './mail-copy.js';
|
|
2
|
+
/** The largest archive accepted: 50 GiB. A Takeout over this is split by
|
|
3
|
+
* Google into several archives anyway. */
|
|
4
|
+
export declare const TAKEOUT_MAX_BYTES: number;
|
|
5
|
+
export interface MailTakeoutOptions {
|
|
6
|
+
/** Absolute path to the uploaded `.mbox`, under `uploadDir`, alone in its
|
|
7
|
+
* own directory. */
|
|
8
|
+
readonly mboxPath: string;
|
|
9
|
+
/** Its size in bytes, as the caller measured it. */
|
|
10
|
+
readonly sizeBytes: number;
|
|
11
|
+
/** The directory uploads live under. */
|
|
12
|
+
readonly uploadDir: string;
|
|
13
|
+
/** Directory holding the Vandelay SQLite archive. */
|
|
14
|
+
readonly archiveDir: string;
|
|
15
|
+
readonly stalwartUrl: string;
|
|
16
|
+
readonly targetAccountId?: string;
|
|
17
|
+
readonly targetAccountName?: string;
|
|
18
|
+
/** The export credential's value, when the caller has it in hand. Never
|
|
19
|
+
* placed in argv; only used to redact it from a refusal message and to
|
|
20
|
+
* refuse an input that contains it. */
|
|
21
|
+
readonly exportToken?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface MailTakeoutPlan {
|
|
24
|
+
readonly archive: string;
|
|
25
|
+
readonly importArgv: readonly string[];
|
|
26
|
+
/** Import needs no credential. */
|
|
27
|
+
readonly importEnv: readonly MailCopyEnv[];
|
|
28
|
+
readonly exportArgv: readonly string[];
|
|
29
|
+
readonly exportEnv: readonly MailCopyEnv[];
|
|
30
|
+
}
|
|
31
|
+
export declare function mailTakeoutPlan(input: MailTakeoutOptions): MailTakeoutPlan;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The exact Vandelay command lines foundry runs to import one uploaded
|
|
3
|
+
* Google Takeout mbox archive into one Stalwart account (`wtfalch/email#152`).
|
|
4
|
+
* Like `./mail-copy.ts` it only decides argv: it never spawns Vandelay,
|
|
5
|
+
* touches a network or reads a credential.
|
|
6
|
+
*
|
|
7
|
+
* **Source** (`stalwartlabs/vandelay` commit
|
|
8
|
+
* `42f7c879115cd2179eff067f01ac14cdc4fad0ec`): `import takeout [--noautomap]
|
|
9
|
+
* <PATH> <ARCHIVE>` (`src/cli.rs:662-686`). `PATH` is a *directory tree*
|
|
10
|
+
* scanned recursively for `.mbox`/`.ics`/`.vcf` files
|
|
11
|
+
* (`src/sync/import_takeout/walk.rs:56-130`); a file path is not read. So
|
|
12
|
+
* this plans `PATH` as the mbox's parent directory, and the caller must
|
|
13
|
+
* keep each upload in a directory of its own, or a neighbour's mbox would
|
|
14
|
+
* import into this account. Import then export, two launches, exactly as in
|
|
15
|
+
* `mailCopyPlan`; export is the same step with the same rules: the
|
|
16
|
+
* credential is only named in `exportEnv`, never in argv.
|
|
17
|
+
*
|
|
18
|
+
* **Labels.** Vandelay reads Gmail's `X-Gmail-Labels` header
|
|
19
|
+
* (`src/sync/import_takeout/labels.rs`): each label becomes a mailbox of
|
|
20
|
+
* that name (`Archived` becomes `Archive`); with automap on (the default,
|
|
21
|
+
* kept here) `Inbox`, `Sent`, `Drafts`, `Trash`, `Spam` and `Archive` get
|
|
22
|
+
* the Stalwart roles inbox/sent/drafts/trash/junk/archive; `Starred`,
|
|
23
|
+
* `Important` and `Opened` become the `$flagged`, `$important` and `$seen`
|
|
24
|
+
* keywords; `Category …` labels are dropped. The spike on #148 could not be
|
|
25
|
+
* read from here, so this follows the Vandelay source alone.
|
|
26
|
+
*/
|
|
27
|
+
import { MailCopyPlanRefused, VANDELAY_TOKEN, accountSelectorArgv } from './mail-copy.js';
|
|
28
|
+
/** The largest archive accepted: 50 GiB. A Takeout over this is split by
|
|
29
|
+
* Google into several archives anyway. */
|
|
30
|
+
export const TAKEOUT_MAX_BYTES = 50 * 1024 ** 3;
|
|
31
|
+
function cleanDir(value, what) {
|
|
32
|
+
const dir = value.trim().replace(/\/+$/, '');
|
|
33
|
+
if (!dir.startsWith('/'))
|
|
34
|
+
throw new MailCopyPlanRefused(`${what} must be an absolute path`);
|
|
35
|
+
return dir;
|
|
36
|
+
}
|
|
37
|
+
export function mailTakeoutPlan(input) {
|
|
38
|
+
const token = input.exportToken;
|
|
39
|
+
const redact = (text) => (token ? text.split(token).join('[redacted]') : text);
|
|
40
|
+
const refuse = (message) => {
|
|
41
|
+
throw new MailCopyPlanRefused(redact(message));
|
|
42
|
+
};
|
|
43
|
+
if (token) {
|
|
44
|
+
const fields = [
|
|
45
|
+
input.mboxPath,
|
|
46
|
+
input.uploadDir,
|
|
47
|
+
input.archiveDir,
|
|
48
|
+
input.stalwartUrl,
|
|
49
|
+
input.targetAccountId ?? '',
|
|
50
|
+
input.targetAccountName ?? '',
|
|
51
|
+
];
|
|
52
|
+
if (fields.some((field) => field.includes(token))) {
|
|
53
|
+
refuse('the export token appears in the input; it belongs only in the environment');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const uploadDir = cleanDir(input.uploadDir, 'the upload directory');
|
|
57
|
+
const archiveDir = cleanDir(input.archiveDir, 'the archive directory');
|
|
58
|
+
const path = input.mboxPath.trim();
|
|
59
|
+
if ([...path].some((char) => char.charCodeAt(0) < 0x20 || char.charCodeAt(0) === 0x7f))
|
|
60
|
+
refuse('the archive path holds a control character');
|
|
61
|
+
if (path.split('/').some((part) => part === '.' || part === '..')) {
|
|
62
|
+
refuse(`"${path}" must not contain "." or ".." segments`);
|
|
63
|
+
}
|
|
64
|
+
if (path.includes('//'))
|
|
65
|
+
refuse(`"${path}" must not contain empty path segments`);
|
|
66
|
+
if (!path.startsWith(`${uploadDir}/`) || !/\.mbox$/.test(path)) {
|
|
67
|
+
refuse(`"${path}" must be a .mbox file under ${uploadDir}`);
|
|
68
|
+
}
|
|
69
|
+
const dir = path.slice(0, path.lastIndexOf('/'));
|
|
70
|
+
if (dir === uploadDir) {
|
|
71
|
+
refuse(`"${path}" must sit in its own directory under ${uploadDir}, not in it`);
|
|
72
|
+
}
|
|
73
|
+
if (!Number.isSafeInteger(input.sizeBytes) || input.sizeBytes <= 0) {
|
|
74
|
+
refuse(`the archive size must be a positive whole number of bytes, got ${input.sizeBytes}`);
|
|
75
|
+
}
|
|
76
|
+
if (input.sizeBytes > TAKEOUT_MAX_BYTES) {
|
|
77
|
+
refuse(`the archive is ${input.sizeBytes} bytes; the limit is ${TAKEOUT_MAX_BYTES}`);
|
|
78
|
+
}
|
|
79
|
+
const stalwartUrl = input.stalwartUrl.trim().replace(/\/+$/, '');
|
|
80
|
+
if (!/^https:\/\//.test(stalwartUrl)) {
|
|
81
|
+
refuse(`the Stalwart URL must be https, got "${input.stalwartUrl}"`);
|
|
82
|
+
}
|
|
83
|
+
let parsed;
|
|
84
|
+
try {
|
|
85
|
+
parsed = new URL(stalwartUrl);
|
|
86
|
+
}
|
|
87
|
+
catch {
|
|
88
|
+
return refuse(`"${input.stalwartUrl}" is not a valid URL`);
|
|
89
|
+
}
|
|
90
|
+
if (parsed.username || parsed.password) {
|
|
91
|
+
refuse('the Stalwart URL must not carry embedded credentials; use --auth-bearer instead');
|
|
92
|
+
}
|
|
93
|
+
let accountFlag;
|
|
94
|
+
try {
|
|
95
|
+
accountFlag = accountSelectorArgv({
|
|
96
|
+
source: path,
|
|
97
|
+
targetAccountId: input.targetAccountId,
|
|
98
|
+
targetAccountName: input.targetAccountName,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return refuse(error instanceof Error ? error.message : String(error));
|
|
103
|
+
}
|
|
104
|
+
const target = input.targetAccountId ?? input.targetAccountName ?? '';
|
|
105
|
+
const archive = `${archiveDir}/takeout-${encodeURIComponent(target)}.sqlite`;
|
|
106
|
+
return {
|
|
107
|
+
archive,
|
|
108
|
+
importArgv: ['import', 'takeout', '--', dir, archive],
|
|
109
|
+
importEnv: [],
|
|
110
|
+
exportArgv: ['export', '--url', stalwartUrl, '--auth-bearer', accountFlag, '--', archive],
|
|
111
|
+
exportEnv: [{ name: VANDELAY_TOKEN, purpose: `the Stalwart account credential for ${target}` }],
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -108,7 +108,7 @@ export interface OrgMailExportEnv {
|
|
|
108
108
|
}
|
|
109
109
|
export interface OrgMailBackupOptions {
|
|
110
110
|
readonly accounts: readonly OrgMailExportAccount[];
|
|
111
|
-
/** The shared Stalwart instance being backed up, e.g. `https://mail.
|
|
111
|
+
/** The shared Stalwart instance being backed up, e.g. `https://mail.companyincluded.com`. */
|
|
112
112
|
readonly stalwartUrl: string;
|
|
113
113
|
/** Directory to hold one Vandelay SQLite archive per account. */
|
|
114
114
|
readonly archiveDir: string;
|
|
@@ -149,7 +149,7 @@ export interface OrgMailRestoreAccount {
|
|
|
149
149
|
export interface OrgMailRestoreOptions {
|
|
150
150
|
readonly accounts: readonly OrgMailRestoreAccount[];
|
|
151
151
|
/** The — possibly different — shared Stalwart instance being restored
|
|
152
|
-
* into, e.g. `https://mail.
|
|
152
|
+
* into, e.g. `https://mail.companyincluded.com`. */
|
|
153
153
|
readonly stalwartUrl: string;
|
|
154
154
|
/** The same directory `orgMailBackupPlan` wrote into: restore reads the
|
|
155
155
|
* archive a backup already produced, it never creates one. */
|
|
@@ -41,6 +41,19 @@ export declare function withoutAlias(account: Pick<WireAccount, 'aliases'>, name
|
|
|
41
41
|
* relies on.
|
|
42
42
|
*/
|
|
43
43
|
export declare function withoutAppPassword(account: Pick<WireAccount, 'credentials'>, credentialId: string): Record<string, Credential>;
|
|
44
|
+
/**
|
|
45
|
+
* The `credentials` list to send so that every app password on the account
|
|
46
|
+
* stops working at once, used when a person must be shut out of mail
|
|
47
|
+
* immediately: IMAP and SMTP never consult the issuer, so a revoked sign-in
|
|
48
|
+
* there does nothing while an app password it minted keeps authenticating.
|
|
49
|
+
*
|
|
50
|
+
* Same type guard as `withoutAppPassword`, applied to every entry rather
|
|
51
|
+
* than one: `Password` and `ApiKey` entries are never this action's to
|
|
52
|
+
* touch and survive untouched, masked secrets and all. An account with no
|
|
53
|
+
* app password at all is not refused — there is nothing to revoke, and the
|
|
54
|
+
* empty list it already has is exactly what gets sent back.
|
|
55
|
+
*/
|
|
56
|
+
export declare function withoutAllAppPasswords(account: Pick<WireAccount, 'credentials'>): Record<string, Credential>;
|
|
44
57
|
/**
|
|
45
58
|
* The `credentials` list to send so that one API key stops working and
|
|
46
59
|
* every other credential survives.
|
|
@@ -63,7 +76,7 @@ export declare function withoutApiKey(account: Pick<WireAccount, 'credentials'>,
|
|
|
63
76
|
* **No credential, ever.** On a domain the issuer holds (`directoryId` set,
|
|
64
77
|
* which is every domain `mail-configure --mail-audience` has touched) the
|
|
65
78
|
* server refuses one anyway and the person signs in through
|
|
66
|
-
* auth.
|
|
79
|
+
* auth.companyincluded.com. On a domain with the instance's own directory a new
|
|
67
80
|
* account needs a first password, which `mail:sync` prints once to a
|
|
68
81
|
* terminal — a web page is the wrong place to show a secret and a worse
|
|
69
82
|
* place to store one, so this refuses that case and says which tool does it.
|
|
@@ -94,6 +94,22 @@ export function withoutAppPassword(account, credentialId) {
|
|
|
94
94
|
}
|
|
95
95
|
return indexed(existing.filter((c) => c !== target));
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* The `credentials` list to send so that every app password on the account
|
|
99
|
+
* stops working at once, used when a person must be shut out of mail
|
|
100
|
+
* immediately: IMAP and SMTP never consult the issuer, so a revoked sign-in
|
|
101
|
+
* there does nothing while an app password it minted keeps authenticating.
|
|
102
|
+
*
|
|
103
|
+
* Same type guard as `withoutAppPassword`, applied to every entry rather
|
|
104
|
+
* than one: `Password` and `ApiKey` entries are never this action's to
|
|
105
|
+
* touch and survive untouched, masked secrets and all. An account with no
|
|
106
|
+
* app password at all is not refused — there is nothing to revoke, and the
|
|
107
|
+
* empty list it already has is exactly what gets sent back.
|
|
108
|
+
*/
|
|
109
|
+
export function withoutAllAppPasswords(account) {
|
|
110
|
+
const existing = entriesOf(account.credentials);
|
|
111
|
+
return indexed(existing.filter((c) => c['@type'] !== 'AppPassword'));
|
|
112
|
+
}
|
|
97
113
|
/**
|
|
98
114
|
* The `credentials` list to send so that one API key stops working and
|
|
99
115
|
* every other credential survives.
|
|
@@ -126,7 +142,7 @@ export function withoutApiKey(account, credentialId) {
|
|
|
126
142
|
* **No credential, ever.** On a domain the issuer holds (`directoryId` set,
|
|
127
143
|
* which is every domain `mail-configure --mail-audience` has touched) the
|
|
128
144
|
* server refuses one anyway and the person signs in through
|
|
129
|
-
* auth.
|
|
145
|
+
* auth.companyincluded.com. On a domain with the instance's own directory a new
|
|
130
146
|
* account needs a first password, which `mail:sync` prints once to a
|
|
131
147
|
* terminal — a web page is the wrong place to show a secret and a worse
|
|
132
148
|
* place to store one, so this refuses that case and says which tool does it.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wtfalch/email",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "The wtfalch estate: reading a mailbox over JMAP, administering the Stalwart server it lives on, and iTIP scheduling over iMIP. Three entries with no code in common.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,10 +17,6 @@
|
|
|
17
17
|
"types": "./dist/mailbox/react/index.d.ts",
|
|
18
18
|
"default": "./dist/mailbox/react/index.js"
|
|
19
19
|
},
|
|
20
|
-
"./mailbox/fake": {
|
|
21
|
-
"types": "./dist/mailbox/fake/index.d.ts",
|
|
22
|
-
"default": "./dist/mailbox/fake/index.js"
|
|
23
|
-
},
|
|
24
20
|
"./mailbox/mail.css": "./dist/mailbox/mail.css",
|
|
25
21
|
"./imip": {
|
|
26
22
|
"types": "./dist/imip/index.d.ts",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A mailbox in memory, for stories, for a development build with no server,
|
|
3
|
-
* and for tests that want to exercise this package rather than a stub.
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* import { fakeMail } from '@wtfalch/email/mailbox/fake'
|
|
7
|
-
*
|
|
8
|
-
* const { client, mailbox, dispose } = fakeMail()
|
|
9
|
-
* const tree = await mailboxes(client) // the real function
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
import { MailClient } from '../client.ts';
|
|
13
|
-
import { FakeMailbox, type FakeOptions, type SeedMessage, type SeedThread } from './mailbox.ts';
|
|
14
|
-
import { SAMPLE } from './sample.ts';
|
|
15
|
-
export { FakeMailbox };
|
|
16
|
-
export type { FakeOptions, SeedMessage, SeedThread };
|
|
17
|
-
export { SAMPLE };
|
|
18
|
-
export type FakeMail = {
|
|
19
|
-
/** A real `MailClient`. Everything this package exports works against it
|
|
20
|
-
* unchanged, through the real wire code. */
|
|
21
|
-
client: MailClient;
|
|
22
|
-
/** The mailbox behind it, to seed more mail or to assert on what was sent. */
|
|
23
|
-
mailbox: FakeMailbox;
|
|
24
|
-
/** Stop intercepting. Call it when a story or a test is done; leaving it
|
|
25
|
-
* installed leaves the fake answering for the rest of the process. */
|
|
26
|
-
dispose: () => void;
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* A client and the mailbox it talks to.
|
|
30
|
-
*
|
|
31
|
-
* Seeded with `SAMPLE` unless told otherwise, because a fake with an empty
|
|
32
|
-
* inbox demonstrates the empty state and nothing else.
|
|
33
|
-
*/
|
|
34
|
-
export declare function fakeMail(options?: FakeOptions): FakeMail;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A mailbox in memory, for stories, for a development build with no server,
|
|
3
|
-
* and for tests that want to exercise this package rather than a stub.
|
|
4
|
-
*
|
|
5
|
-
* ```ts
|
|
6
|
-
* import { fakeMail } from '@wtfalch/email/mailbox/fake'
|
|
7
|
-
*
|
|
8
|
-
* const { client, mailbox, dispose } = fakeMail()
|
|
9
|
-
* const tree = await mailboxes(client) // the real function
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
import { MailClient } from "../client.js";
|
|
13
|
-
import { FakeMailbox } from "./mailbox.js";
|
|
14
|
-
import { SAMPLE } from "./sample.js";
|
|
15
|
-
export { FakeMailbox };
|
|
16
|
-
export { SAMPLE };
|
|
17
|
-
const ORIGIN = 'https://email.example.com';
|
|
18
|
-
/**
|
|
19
|
-
* The interception, and why it is here rather than a `fetch` option on
|
|
20
|
-
* `MailClient`.
|
|
21
|
-
*
|
|
22
|
-
* `jmap-jam` calls the bare global `fetch`, and takes no way to pass another
|
|
23
|
-
* one. A `fetch` option would therefore have to swap the global around each
|
|
24
|
-
* call and put it back, which is wrong under any overlap: two calls in flight
|
|
25
|
-
* save each other's replacement as "the original" and one of them restores
|
|
26
|
-
* the fake permanently.
|
|
27
|
-
*
|
|
28
|
-
* So the global is replaced once, by a function that **delegates**: anything
|
|
29
|
-
* not addressed to the fake's origin goes to the real `fetch` untouched.
|
|
30
|
-
* Nothing else in the application changes behaviour, which is the property
|
|
31
|
-
* that makes replacing a global acceptable at all. A count keeps several
|
|
32
|
-
* fakes from uninstalling each other.
|
|
33
|
-
*/
|
|
34
|
-
let installed = null;
|
|
35
|
-
let live = 0;
|
|
36
|
-
function install(route) {
|
|
37
|
-
live += 1;
|
|
38
|
-
if (installed)
|
|
39
|
-
return;
|
|
40
|
-
const original = globalThis.fetch;
|
|
41
|
-
installed = original;
|
|
42
|
-
globalThis.fetch = ((input, init) => {
|
|
43
|
-
const answered = route(input, init);
|
|
44
|
-
return answered ?? original(input, init);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function uninstall() {
|
|
48
|
-
live -= 1;
|
|
49
|
-
if (live > 0 || !installed)
|
|
50
|
-
return;
|
|
51
|
-
globalThis.fetch = installed;
|
|
52
|
-
installed = null;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* A client and the mailbox it talks to.
|
|
56
|
-
*
|
|
57
|
-
* Seeded with `SAMPLE` unless told otherwise, because a fake with an empty
|
|
58
|
-
* inbox demonstrates the empty state and nothing else.
|
|
59
|
-
*/
|
|
60
|
-
export function fakeMail(options = {}) {
|
|
61
|
-
const mailbox = new FakeMailbox({ threads: SAMPLE, ...options });
|
|
62
|
-
install((input, init) => {
|
|
63
|
-
const url = String(typeof input === 'object' && input !== null && 'url' in input
|
|
64
|
-
? input.url
|
|
65
|
-
: input);
|
|
66
|
-
if (!url.startsWith(ORIGIN))
|
|
67
|
-
return null;
|
|
68
|
-
return mailbox.fetch(url, init);
|
|
69
|
-
});
|
|
70
|
-
const client = new MailClient({
|
|
71
|
-
sessionUrl: `${ORIGIN}/.well-known/jmap`,
|
|
72
|
-
bearerToken: 'fake',
|
|
73
|
-
});
|
|
74
|
-
let disposed = false;
|
|
75
|
-
return {
|
|
76
|
-
client,
|
|
77
|
-
mailbox,
|
|
78
|
-
dispose: () => {
|
|
79
|
-
if (disposed)
|
|
80
|
-
return;
|
|
81
|
-
disposed = true;
|
|
82
|
-
uninstall();
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A mailbox in memory, and the JMAP that answers questions about it.
|
|
3
|
-
*
|
|
4
|
-
* **A fake transport, not a fake API.** The obvious shortcut is to stub the
|
|
5
|
-
* exported functions -- `mailboxes()` returns three objects, `listThreads()`
|
|
6
|
-
* returns five rows -- and it is the wrong one: every story then exercises the
|
|
7
|
-
* stub, and the four-call chain, the result references, the body-value
|
|
8
|
-
* resolution and the null-handling that make up most of this package are
|
|
9
|
-
* never run. This answers JMAP instead, so a component drawn against the fake
|
|
10
|
-
* is drawn through exactly the code that will face a real server.
|
|
11
|
-
*
|
|
12
|
-
* It implements only the methods this package sends. Anything else answers
|
|
13
|
-
* `unknownMethod`, which is what a real server does and what the error path
|
|
14
|
-
* expects.
|
|
15
|
-
*/
|
|
16
|
-
import type { EmailAddress } from '../types.ts';
|
|
17
|
-
export type SeedMessage = {
|
|
18
|
-
from: EmailAddress;
|
|
19
|
-
to?: readonly EmailAddress[];
|
|
20
|
-
subject: string;
|
|
21
|
-
text: string;
|
|
22
|
-
html?: string;
|
|
23
|
-
/** Minutes before "now". Later numbers are older. */
|
|
24
|
-
agoMinutes: number;
|
|
25
|
-
seen?: boolean;
|
|
26
|
-
flagged?: boolean;
|
|
27
|
-
attachments?: {
|
|
28
|
-
name: string;
|
|
29
|
-
type: string;
|
|
30
|
-
size: number;
|
|
31
|
-
}[];
|
|
32
|
-
};
|
|
33
|
-
export type SeedThread = {
|
|
34
|
-
mailbox: string;
|
|
35
|
-
messages: SeedMessage[];
|
|
36
|
-
};
|
|
37
|
-
export type FakeOptions = {
|
|
38
|
-
/** The signed-in person. */
|
|
39
|
-
me?: EmailAddress;
|
|
40
|
-
threads?: SeedThread[];
|
|
41
|
-
/** Fixed "now", so a story's timestamps do not move between runs. */
|
|
42
|
-
now?: Date;
|
|
43
|
-
/** Milliseconds of delay on every request, for looking at a loading state. */
|
|
44
|
-
latency?: number;
|
|
45
|
-
/** The session's `maxSizeUpload`. Stalwart's own default when not given. */
|
|
46
|
-
maxSizeUpload?: number;
|
|
47
|
-
};
|
|
48
|
-
export declare class FakeMailbox {
|
|
49
|
-
#private;
|
|
50
|
-
readonly me: EmailAddress;
|
|
51
|
-
/** Everything `EmailSubmission/set` accepted, for a test that asserts a
|
|
52
|
-
* message was actually sent rather than only composed. */
|
|
53
|
-
readonly submissions: {
|
|
54
|
-
emailId: string;
|
|
55
|
-
identityId: string;
|
|
56
|
-
}[];
|
|
57
|
-
/** Every blob uploaded, for a test that asserts the bytes reached the
|
|
58
|
-
* server rather than only the composer. */
|
|
59
|
-
readonly uploads: {
|
|
60
|
-
blobId: string;
|
|
61
|
-
type: string;
|
|
62
|
-
size: number;
|
|
63
|
-
}[];
|
|
64
|
-
constructor(options?: FakeOptions);
|
|
65
|
-
/** Move the fake's clock forward by `ms` milliseconds. The only way `#now`
|
|
66
|
-
* changes after construction, so a test can hold a submission, advance
|
|
67
|
-
* past its `sendAt`, and see the cancel window close -- deterministically,
|
|
68
|
-
* with no real wait and no wall-clock read. */
|
|
69
|
-
advance(ms: number): void;
|
|
70
|
-
/** Put a thread in the mailbox. Returns its id. */
|
|
71
|
-
add(seed: SeedThread): string;
|
|
72
|
-
/** The session document, as Stalwart writes it. */
|
|
73
|
-
session(origin?: string): Record<string, unknown>;
|
|
74
|
-
/** Answer one method call. Exported for the transport, and for a test that
|
|
75
|
-
* wants to assert on a single call's arguments. */
|
|
76
|
-
call(method: string, args: Record<string, unknown>): Record<string, unknown>;
|
|
77
|
-
/** A `fetch` that answers this mailbox. Hand it to `MailClient`. */
|
|
78
|
-
fetch: (input: unknown, init?: RequestInit) => Promise<Response>;
|
|
79
|
-
}
|