@yaks/mail 0.0.0-stage → 0.2.36
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/LICENSE +202 -0
- package/README.md +676 -2
- package/_dist/addr.d.ts +40 -0
- package/_dist/addr.d.ts.map +1 -0
- package/_dist/answers.d.ts +18 -0
- package/_dist/answers.d.ts.map +1 -0
- package/_dist/arrive.d.ts +64 -0
- package/_dist/arrive.d.ts.map +1 -0
- package/_dist/capture.d.ts +22 -0
- package/_dist/capture.d.ts.map +1 -0
- package/_dist/comp.d.ts +27 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/effects.d.ts +9 -0
- package/_dist/effects.d.ts.map +1 -0
- package/_dist/gmail.d.ts +16 -0
- package/_dist/gmail.d.ts.map +1 -0
- package/_dist/graph.d.ts +9 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/inbound.d.ts +105 -0
- package/_dist/inbound.d.ts.map +1 -0
- package/_dist/invite.d.ts +69 -0
- package/_dist/invite.d.ts.map +1 -0
- package/_dist/md.d.ts +34 -0
- package/_dist/md.d.ts.map +1 -0
- package/_dist/mod.d.ts +109 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/options.d.ts +38 -0
- package/_dist/options.d.ts.map +1 -0
- package/_dist/plugin.d.ts +38 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/pull.d.ts +99 -0
- package/_dist/pull.d.ts.map +1 -0
- package/_dist/receipts.d.ts +8 -0
- package/_dist/receipts.d.ts.map +1 -0
- package/_dist/recipient.d.ts +24 -0
- package/_dist/recipient.d.ts.map +1 -0
- package/_dist/routes.d.ts +19 -0
- package/_dist/routes.d.ts.map +1 -0
- package/_dist/send.d.ts +80 -0
- package/_dist/send.d.ts.map +1 -0
- package/_dist/service.d.ts +14 -0
- package/_dist/service.d.ts.map +1 -0
- package/_dist/stash.d.ts +23 -0
- package/_dist/stash.d.ts.map +1 -0
- package/_dist/tools.d.ts +27 -0
- package/_dist/tools.d.ts.map +1 -0
- package/_dist/transport.d.ts +6 -0
- package/_dist/transport.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/addr.js +92 -0
- package/addr.js.map +1 -0
- package/addr.ts +106 -0
- package/answers.js +71 -0
- package/answers.js.map +1 -0
- package/answers.ts +95 -0
- package/arrive.js +122 -0
- package/arrive.js.map +1 -0
- package/arrive.ts +198 -0
- package/capture.js +21 -0
- package/capture.js.map +1 -0
- package/capture.ts +43 -0
- package/comp.js +76 -0
- package/comp.js.map +1 -0
- package/comp.ts +91 -0
- package/deno.json +1 -0
- package/effects.js +90 -0
- package/effects.js.map +1 -0
- package/effects.ts +90 -0
- package/gmail.js +262 -0
- package/gmail.js.map +1 -0
- package/gmail.ts +314 -0
- package/graph.js +26 -0
- package/graph.js.map +1 -0
- package/graph.ts +30 -0
- package/inbound.js +206 -0
- package/inbound.js.map +1 -0
- package/inbound.ts +238 -0
- package/invite.js +102 -0
- package/invite.js.map +1 -0
- package/invite.ts +143 -0
- package/md.js +188 -0
- package/md.js.map +1 -0
- package/md.ts +245 -0
- package/mod.js +109 -0
- package/mod.js.map +1 -0
- package/mod.ts +111 -0
- package/options.js +24 -0
- package/options.js.map +1 -0
- package/options.ts +83 -0
- package/package.json +66 -4
- package/plugin.js +97 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +88 -0
- package/pull.js +344 -0
- package/pull.js.map +1 -0
- package/pull.ts +443 -0
- package/readings.js +24 -0
- package/readings.js.map +1 -0
- package/readings.ts +34 -0
- package/receipts.js +45 -0
- package/receipts.js.map +1 -0
- package/receipts.ts +45 -0
- package/recipient.js +92 -0
- package/recipient.js.map +1 -0
- package/recipient.ts +89 -0
- package/routes.js +103 -0
- package/routes.js.map +1 -0
- package/routes.ts +125 -0
- package/send.js +284 -0
- package/send.js.map +1 -0
- package/send.ts +325 -0
- package/service.js +64 -0
- package/service.js.map +1 -0
- package/service.ts +75 -0
- package/stash.js +29 -0
- package/stash.js.map +1 -0
- package/stash.ts +49 -0
- package/tools.js +343 -0
- package/tools.js.map +1 -0
- package/tools.ts +416 -0
- package/transport.js +23 -0
- package/transport.js.map +1 -0
- package/transport.ts +24 -0
- package/vocab.js +14 -0
- package/vocab.js.map +1 -0
- package/vocab.json +415 -0
- package/vocab.ts +16 -0
- package/work.js +121 -0
- package/work.js.map +1 -0
- package/work.ts +134 -0
package/comp.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// The components this package declares, as one vocabulary document to load
|
|
2
|
+
// beside your own.
|
|
3
|
+
//
|
|
4
|
+
// mail{from, name, to, at, target, reply_to, message_id, verified,
|
|
5
|
+
// in_reply_to, reply_address} one letter's envelope
|
|
6
|
+
// email{address} an address, as an entity
|
|
7
|
+
// deliver{to} who it is for, as an entity
|
|
8
|
+
// delivered{at} it left
|
|
9
|
+
// bounced{at, reason, refused} it did not
|
|
10
|
+
// notified{at, by, via} they were told
|
|
11
|
+
//
|
|
12
|
+
// The subject and the body are not here. They are `doc{title, body}`, from
|
|
13
|
+
// {@link https://jsr.io/@yaks/doc | @yaks/doc}, which this package depends on
|
|
14
|
+
// (Jeff, 2026-09-05: "the mail package can't require the package that installs
|
|
15
|
+
// doc?"). A letter is an entity like any other, and the words a person reads
|
|
16
|
+
// belong in the one component every readable thing has — so a letter is
|
|
17
|
+
// searched, rendered and edited by whatever already handles a `doc`, instead of
|
|
18
|
+
// by a second copy of the same two properties. What is left on `mail` is the
|
|
19
|
+
// envelope: who it is from, where it went, when, what it is about, what it
|
|
20
|
+
// answers.
|
|
21
|
+
//
|
|
22
|
+
// `mail` does not declare `doc` — a vocabulary rejects a component declared
|
|
23
|
+
// twice, so composing it is the application's choice: `loadVocab([docDoc,
|
|
24
|
+
// mailDoc, ...mine])`, `plugins: [docs(), mailbox({...})]`. `target` is what
|
|
25
|
+
// makes this a graph's mail — the entity the letter is about, which may be any
|
|
26
|
+
// entity at all, so a reply about the potluck hangs off the potluck.
|
|
27
|
+
//
|
|
28
|
+
// Two ways to record who it is for, on purpose. `mail.to` is the To: line — an
|
|
29
|
+
// address, written by whoever composed the letter. `deliver.to` is a
|
|
30
|
+
// recipient: an entity in your graph, whose address is looked up when the
|
|
31
|
+
// letter goes out. Addressing a person rather than a string is what lets them
|
|
32
|
+
// change their address without rewriting the mail that has not left yet.
|
|
33
|
+
//
|
|
34
|
+
// `verified` is the receiving side's verdict on an arrival: whether the sending
|
|
35
|
+
// domain signed for the letter (DKIM). It is a property and not a gate — a
|
|
36
|
+
// letter nobody signed for is recorded with `verified: false` rather than
|
|
37
|
+
// dropped, because dropping it is silence and the reader is the one who decides
|
|
38
|
+
// what an unsigned letter is worth.
|
|
39
|
+
//
|
|
40
|
+
// `delivered` and `bounced` are the two ends of one outcome, and exactly one of
|
|
41
|
+
// them lands on a letter. Both are stamped: they are the sender's report of
|
|
42
|
+
// what happened, written by the effect, never by a client claiming its own mail
|
|
43
|
+
// arrived.
|
|
44
|
+
//
|
|
45
|
+
// The document itself is `./vocab.json` — plain JSON Schema, readable by
|
|
46
|
+
// anything that reads JSON. This file re-exports it under the name callers
|
|
47
|
+
// import and keeps the prose about why it is shaped the way it is.
|
|
48
|
+
|
|
49
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
50
|
+
import doc from './vocab.json' with { type: 'json' }
|
|
51
|
+
|
|
52
|
+
/** The component naming one letter. */
|
|
53
|
+
export let MAIL = 'mail'
|
|
54
|
+
|
|
55
|
+
/** The component naming an address as an entity of its own. */
|
|
56
|
+
export let EMAIL = 'email'
|
|
57
|
+
|
|
58
|
+
/** The component keeping an address only a letter names to those who may read
|
|
59
|
+
* the letters. */
|
|
60
|
+
export let RECIPIENT = 'recipient'
|
|
61
|
+
|
|
62
|
+
/** The component naming who a letter is for, as an entity. */
|
|
63
|
+
export let DELIVER = 'deliver'
|
|
64
|
+
|
|
65
|
+
/** The component stamped on a letter that left. */
|
|
66
|
+
export let DELIVERED = 'delivered'
|
|
67
|
+
|
|
68
|
+
/** The component stamped on a letter that did not. */
|
|
69
|
+
export let BOUNCED = 'bounced'
|
|
70
|
+
|
|
71
|
+
/** The component stamped when a recipient was told. */
|
|
72
|
+
export let NOTIFIED = 'notified'
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The mail vocabulary document, to load beside
|
|
76
|
+
* {@link https://jsr.io/@yaks/doc | @yaks/doc}'s and your own:
|
|
77
|
+
* `loadVocab([docDoc, mailDoc, ...mine])`. It declares nothing about what a
|
|
78
|
+
* person or a club is — those are plain entities in your own vocabulary — only
|
|
79
|
+
* the envelope of a letter, who it is for, and what became of it. The subject
|
|
80
|
+
* and the body are `doc.title` and `doc.body`.
|
|
81
|
+
*
|
|
82
|
+
* The `prefix` keywords are {@link https://jsr.io/@yaks/id | @yaks/id}'s: load
|
|
83
|
+
* that package's keywords and a letter reads back as `E-7`, an address as
|
|
84
|
+
* `A-3`. A loader that never registers them simply drops both.
|
|
85
|
+
*
|
|
86
|
+
* `mail` declares `before: ['doc']` — an entity carrying both is a letter,
|
|
87
|
+
* not the `doc` it also carries, so `mail` sorts first. The component it sorts
|
|
88
|
+
* against is @yaks/doc's, which is why this document is never loaded without
|
|
89
|
+
* it.
|
|
90
|
+
*/
|
|
91
|
+
export let mailDoc: VocabDoc = doc
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts","./testing.ts","./conform.ts","./workers.json"]},"name":"@yaks/mail","version":"0.2.36","license":"Apache-2.0","description":"Represents letters and their delivery outcomes as graph components, sends them through a sender the caller supplies, and converts arrivals to bundles.","exports":{".":"./mod.ts","./addr":"./addr.ts","./vocab":"./vocab.ts","./answers":"./answers.ts","./graph":"./graph.ts","./tools":"./tools.ts","./effects":"./effects.ts","./routes":"./routes.ts","./service":"./service.ts","./gmail":"./gmail.ts"},"imports":{"@yaks/mail":"./mod.ts","@yaks/mail/addr":"./addr.ts","@yaks/mail/vocab":"./vocab.ts","@yaks/mail/answers":"./answers.ts","@yaks/mail/graph":"./graph.ts","@yaks/mail/tools":"./tools.ts","@yaks/mail/effects":"./effects.ts","@yaks/mail/routes":"./routes.ts","@yaks/mail/service":"./service.ts","@yaks/mail/gmail":"./gmail.ts"}}
|
package/effects.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// What the server does about a letter: the `@yaks/mail/effects` entry point —
|
|
2
|
+
// the code behind `mail_post` (./vocab.json), which hands an outbound letter to
|
|
3
|
+
// a sender and writes `delivered` or `bounced` back onto it, and behind
|
|
4
|
+
// `mail_task` and `mail_answered` (./work.ts), which file a letter that reached
|
|
5
|
+
// a project as a task and complete it once it is answered.
|
|
6
|
+
//
|
|
7
|
+
// The sender is why this entry point takes OPTIONS. Handing a letter over
|
|
8
|
+
// needs a transport — an account, a token, an endpoint — and none of that is a
|
|
9
|
+
// fact about the graph, so the config names it beside the plugin (./options.ts)
|
|
10
|
+
// and the factory builds it here.
|
|
11
|
+
//
|
|
12
|
+
// A missing sender leaves a visible waiting reason without marking the letter
|
|
13
|
+
// tried. A pool keeps that run pending until the sender is configured; an
|
|
14
|
+
// inline caller receives the configuration error instead.
|
|
15
|
+
// Read transport options on every attempt: secrets can arrive after startup.
|
|
16
|
+
import { after } from "@yaks/fp";
|
|
17
|
+
import { Stale } from "@yaks/graph/errors";
|
|
18
|
+
import { token } from "@yaks/graph/sha256";
|
|
19
|
+
import { letterOf, owed, sending } from "./send.js";
|
|
20
|
+
import { stash } from "./stash.js";
|
|
21
|
+
import { post } from "./transport.js";
|
|
22
|
+
export { post } from "./transport.js";
|
|
23
|
+
import { work } from "./work.js";
|
|
24
|
+
/** Keep the request owed while its sender is unavailable. */ export let waiting = (reason)=>(event, tx, write, attempt)=>after(letterOf(tx, event.entity), async (letter)=>{
|
|
25
|
+
if (!owed(letter)) return;
|
|
26
|
+
let deliver = letter?.deliver;
|
|
27
|
+
if (deliver.waiting != reason) {
|
|
28
|
+
try {
|
|
29
|
+
await write([
|
|
30
|
+
{
|
|
31
|
+
entity: event.entity,
|
|
32
|
+
deliver: {
|
|
33
|
+
waiting: reason
|
|
34
|
+
},
|
|
35
|
+
$was: {
|
|
36
|
+
deliver: {
|
|
37
|
+
to: token(deliver.to)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
]);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
if (error instanceof Stale && error.eid == event.entity.eid && error.comp == 'deliver' && error.prop == 'to' && error.current == null) return;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (attempt?.defer) {
|
|
48
|
+
await attempt.defer(60_000, reason);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`@yaks/mail — ${reason}`);
|
|
52
|
+
});
|
|
53
|
+
/** The outbound half: `mail_post`, wherever a sender was named. Where the
|
|
54
|
+
* sender cannot be built, nothing is sent and the letters wait in the graph
|
|
55
|
+
* rather than the server refusing to start. */ export let effects = (host, options = {})=>{
|
|
56
|
+
let kept;
|
|
57
|
+
let transport = ()=>{
|
|
58
|
+
let said = options.sender;
|
|
59
|
+
if (!said) return {
|
|
60
|
+
waiting: 'waiting for a configured sender'
|
|
61
|
+
};
|
|
62
|
+
// The built-in stash keeps its receipts across attempts. A host's
|
|
63
|
+
// sender takes precedence and owns its own lifetime.
|
|
64
|
+
if (said.via == 'stash' && !Object.hasOwn(host?.senders ?? {}, said.via)) {
|
|
65
|
+
return {
|
|
66
|
+
sender: kept ??= stash()
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return post(said, host);
|
|
70
|
+
};
|
|
71
|
+
let mail_post = (event, tx, write, attempt)=>{
|
|
72
|
+
let { sender, waiting: reason } = transport();
|
|
73
|
+
let run = sender ? sending({
|
|
74
|
+
sender,
|
|
75
|
+
...options.local && options.domain ? {
|
|
76
|
+
local: options.domain
|
|
77
|
+
} : {},
|
|
78
|
+
...options.mentions ? {
|
|
79
|
+
mentions: options.mentions
|
|
80
|
+
} : {}
|
|
81
|
+
}) : waiting(reason);
|
|
82
|
+
return run(event, tx, write, attempt);
|
|
83
|
+
};
|
|
84
|
+
mail_post.waiting = ()=>transport().waiting;
|
|
85
|
+
return {
|
|
86
|
+
...work(host?.vocab),
|
|
87
|
+
mail_post
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=effects.js.map
|
package/effects.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effects.js","sources":["./effects.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gFAAgF;AAChF,wEAAwE;AACxE,gFAAgF;AAChF,2DAA2D;AAC3D,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,gFAAgF;AAChF,kCAAkC;AAClC,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,0DAA0D;AAC1D,6EAA6E;AAG7E,SAAS,KAAK,wBAA6B;AAE3C,SAAS,KAAK,kCAAuC;AACrD,SAAS,KAAK,kCAAuC;AAKrD,SAAS,QAAQ,EAAE,IAAI,EAAE,OAAO,oBAAmB;AACnD,SAAS,KAAK,qBAAoB;AAClC,SAAS,IAAI,yBAAwB;AACrC,SAAS,IAAI,yBAAwB;AACrC,SAAS,IAAI,oBAAmB;AAEhC,2DAA2D,GAC3D,OAAO,IAAI,UAAU,CAAC,SAA4B,CAAC,OAAO,IAAI,OAAO,UACnE,MAAM,SAAS,IAAI,MAAM,MAAM,GAAG,OAAO;MACvC,IAAI,CAAC,KAAK,SAAS;MACnB,IAAI,UAAU,QAAQ;MACtB,IAAI,QAAQ,OAAO,IAAI,QAAQ;QAC7B,IAAI;UACF,MAAM,MAAM;YAAC;cACX,QAAQ,MAAM,MAAM;cACpB,SAAS;gBAAE,SAAS;cAAO;cAC3B,MAAM;gBAAE,SAAS;kBAAE,IAAI,MAAM,QAAQ,EAAE;gBAAE;cAAE;YAC7C;WAAE;QACJ,EAAE,OA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1
|
+
// What the server does about a letter: the `@yaks/mail/effects` entry point —
|
|
2
|
+
// the code behind `mail_post` (./vocab.json), which hands an outbound letter to
|
|
3
|
+
// a sender and writes `delivered` or `bounced` back onto it, and behind
|
|
4
|
+
// `mail_task` and `mail_answered` (./work.ts), which file a letter that reached
|
|
5
|
+
// a project as a task and complete it once it is answered.
|
|
6
|
+
//
|
|
7
|
+
// The sender is why this entry point takes OPTIONS. Handing a letter over
|
|
8
|
+
// needs a transport — an account, a token, an endpoint — and none of that is a
|
|
9
|
+
// fact about the graph, so the config names it beside the plugin (./options.ts)
|
|
10
|
+
// and the factory builds it here.
|
|
11
|
+
//
|
|
12
|
+
// A missing sender leaves a visible waiting reason without marking the letter
|
|
13
|
+
// tried. A pool keeps that run pending until the sender is configured; an
|
|
14
|
+
// inline caller receives the configuration error instead.
|
|
15
|
+
// Read transport options on every attempt: secrets can arrive after startup.
|
|
16
|
+
|
|
17
|
+
import type { Handler, Handlers } from 'jsr:@yaks/effects@0.2.36'
|
|
18
|
+
import { after } from '@yaks/fp'
|
|
19
|
+
import type { Comp } from 'jsr:@yaks/graph@0.2.36'
|
|
20
|
+
import { Stale } from '@yaks/graph/errors'
|
|
21
|
+
import { token } from '@yaks/graph/sha256'
|
|
22
|
+
import type { Host } from 'jsr:@yaks/host@0.2.36'
|
|
23
|
+
import type { Built } from 'jsr:@yaks/host@0.2.36/senders'
|
|
24
|
+
import type { Options } from './options.ts'
|
|
25
|
+
import type { Sender } from './send.js'
|
|
26
|
+
import { letterOf, owed, sending } from './send.js'
|
|
27
|
+
import { stash } from './stash.js'
|
|
28
|
+
import { post } from './transport.js'
|
|
29
|
+
export { post } from './transport.js'
|
|
30
|
+
import { work } from './work.js'
|
|
31
|
+
|
|
32
|
+
/** Keep the request owed while its sender is unavailable. */
|
|
33
|
+
export let waiting = (reason: string): Handler => (event, tx, write, attempt) =>
|
|
34
|
+
after(letterOf(tx, event.entity), async (letter) => {
|
|
35
|
+
if (!owed(letter)) return
|
|
36
|
+
let deliver = letter?.deliver as Comp
|
|
37
|
+
if (deliver.waiting != reason) {
|
|
38
|
+
try {
|
|
39
|
+
await write([{
|
|
40
|
+
entity: event.entity,
|
|
41
|
+
deliver: { waiting: reason },
|
|
42
|
+
$was: { deliver: { to: token(deliver.to) } },
|
|
43
|
+
}])
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (
|
|
46
|
+
error instanceof Stale && error.eid == event.entity.eid &&
|
|
47
|
+
error.comp == 'deliver' && error.prop == 'to' && error.current == null
|
|
48
|
+
) return
|
|
49
|
+
throw error
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (attempt?.defer) {
|
|
53
|
+
await attempt.defer(60_000, reason)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
throw new Error(`@yaks/mail — ${reason}`)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
/** The outbound half: `mail_post`, wherever a sender was named. Where the
|
|
60
|
+
* sender cannot be built, nothing is sent and the letters wait in the graph
|
|
61
|
+
* rather than the server refusing to start. */
|
|
62
|
+
export let effects = (
|
|
63
|
+
host?: Pick<Host, 'senders'> & Partial<Pick<Host, 'vocab'>> | null,
|
|
64
|
+
options: Options = {},
|
|
65
|
+
): Handlers => {
|
|
66
|
+
let kept: Sender | undefined
|
|
67
|
+
let transport = (): Built => {
|
|
68
|
+
let said = options.sender
|
|
69
|
+
if (!said) return { waiting: 'waiting for a configured sender' }
|
|
70
|
+
// The built-in stash keeps its receipts across attempts. A host's
|
|
71
|
+
// sender takes precedence and owns its own lifetime.
|
|
72
|
+
if (said.via == 'stash' && !Object.hasOwn(host?.senders ?? {}, said.via)) {
|
|
73
|
+
return { sender: kept ??= stash() }
|
|
74
|
+
}
|
|
75
|
+
return post(said, host)
|
|
76
|
+
}
|
|
77
|
+
let mail_post: Handlers[string] = (event, tx, write, attempt) => {
|
|
78
|
+
let { sender, waiting: reason } = transport()
|
|
79
|
+
let run = sender
|
|
80
|
+
? sending({
|
|
81
|
+
sender,
|
|
82
|
+
...(options.local && options.domain ? { local: options.domain } : {}),
|
|
83
|
+
...(options.mentions ? { mentions: options.mentions } : {}),
|
|
84
|
+
})
|
|
85
|
+
: waiting(reason!)
|
|
86
|
+
return run(event, tx, write, attempt)
|
|
87
|
+
}
|
|
88
|
+
mail_post.waiting = () => transport().waiting
|
|
89
|
+
return { ...work(host?.vocab), mail_post }
|
|
90
|
+
}
|
package/gmail.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import PostalMime from "postal-mime";
|
|
2
|
+
import { fromBase64url, toBase64, toBase64url } from "@yaks/fp";
|
|
3
|
+
import { Undeliverable, Unsent } from "@yaks/host/senders";
|
|
4
|
+
export let GMAIL_MAILBOX = 'gmail-mailbox';
|
|
5
|
+
let API = 'https://gmail.googleapis.com/gmail/v1/users/me';
|
|
6
|
+
let utf8 = (text)=>new TextEncoder().encode(text);
|
|
7
|
+
let encoded = (text)=>toBase64(utf8(text));
|
|
8
|
+
let body = (text)=>encoded(text).replace(/.{76}/g, '$&\r\n');
|
|
9
|
+
let line = (text)=>text.replace(/[\r\n]+/g, ' ').trim();
|
|
10
|
+
let word = (text)=>/^[\x20-\x7e]*$/.test(text) ? text : `=?UTF-8?B?${encoded(text)}?=`;
|
|
11
|
+
let address = (text)=>text.trim().toLowerCase();
|
|
12
|
+
/** The raw MIME Gmail sends, including the headers used to thread replies. */ export let gmailLetter = (m, id)=>{
|
|
13
|
+
let boundary = 'yak-' + crypto.randomUUID();
|
|
14
|
+
let who = m.name ? `${word(line(m.name))} <${line(m.from)}>` : line(m.from);
|
|
15
|
+
if (m.name && /^[\x20-\x7e]*$/.test(line(m.name))) {
|
|
16
|
+
who = `"${line(m.name).replace(/["\\]/g, '\\$&')}" <${line(m.from)}>`;
|
|
17
|
+
}
|
|
18
|
+
let headers = [
|
|
19
|
+
`From: ${who}`,
|
|
20
|
+
`To: ${[
|
|
21
|
+
m.to
|
|
22
|
+
].flat().map(line).join(', ')}`,
|
|
23
|
+
...m.cc ? [
|
|
24
|
+
`Cc: ${line(m.cc)}`
|
|
25
|
+
] : [],
|
|
26
|
+
`Subject: ${word(line(m.subject))}`,
|
|
27
|
+
...id ? [
|
|
28
|
+
`Message-ID: <${id}>`
|
|
29
|
+
] : [],
|
|
30
|
+
...m.replyAddress ? [
|
|
31
|
+
`Reply-To: ${line(m.replyAddress)}`
|
|
32
|
+
] : [],
|
|
33
|
+
...m.replyTo ? [
|
|
34
|
+
`In-Reply-To: <${line(m.replyTo)}>`,
|
|
35
|
+
`References: <${line(m.replyTo)}>`
|
|
36
|
+
] : [],
|
|
37
|
+
'MIME-Version: 1.0',
|
|
38
|
+
`Content-Type: multipart/alternative; boundary="${boundary}"`
|
|
39
|
+
];
|
|
40
|
+
let part = (type, text)=>[
|
|
41
|
+
`--${boundary}`,
|
|
42
|
+
`Content-Type: text/${type}; charset=UTF-8`,
|
|
43
|
+
'Content-Transfer-Encoding: base64',
|
|
44
|
+
'',
|
|
45
|
+
body(text)
|
|
46
|
+
];
|
|
47
|
+
return toBase64url(utf8([
|
|
48
|
+
...headers,
|
|
49
|
+
'',
|
|
50
|
+
...part('plain', m.text),
|
|
51
|
+
...part('html', m.html),
|
|
52
|
+
`--${boundary}--`,
|
|
53
|
+
''
|
|
54
|
+
].join('\r\n')));
|
|
55
|
+
};
|
|
56
|
+
class GmailError extends Error {
|
|
57
|
+
operation;
|
|
58
|
+
status;
|
|
59
|
+
constructor(operation, status){
|
|
60
|
+
super(`Gmail ${operation} returned ${status}`), this.operation = operation, this.status = status;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
let ask = async (call, path, query = {}, data)=>{
|
|
64
|
+
let at = new URL(API + path);
|
|
65
|
+
at.search = new URLSearchParams(query).toString();
|
|
66
|
+
let res = await call(new Request(at, data ? {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: {
|
|
69
|
+
'content-type': 'application/json'
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify(data)
|
|
72
|
+
} : undefined));
|
|
73
|
+
if (!res.ok) {
|
|
74
|
+
await res.body?.cancel();
|
|
75
|
+
throw new GmailError(path.replace(/\/messages\/[^/]+$/, '/messages/:id'), res.status);
|
|
76
|
+
}
|
|
77
|
+
return await res.json();
|
|
78
|
+
};
|
|
79
|
+
let gone = (error)=>error instanceof GmailError && error.status == 404;
|
|
80
|
+
/** The mailbox identity and the Gmail history position from which new mail starts. */ export let gmailProfile = async (call, expected)=>{
|
|
81
|
+
let { emailAddress, historyId } = await ask(call, '/profile');
|
|
82
|
+
if (address(emailAddress ?? '') != address(expected) || !historyId) {
|
|
83
|
+
throw new Error('Gmail returned a different mailbox or no history position');
|
|
84
|
+
}
|
|
85
|
+
return historyId;
|
|
86
|
+
};
|
|
87
|
+
/** Gmail's accepted addresses, after checking that this is the selected account. */ export let gmailAddresses = async (call, expected)=>{
|
|
88
|
+
let { sendAs = [] } = await ask(call, '/settings/sendAs');
|
|
89
|
+
let primary = sendAs.find((one)=>one.isPrimary);
|
|
90
|
+
if (address(primary?.sendAsEmail ?? '') != address(expected)) {
|
|
91
|
+
throw new Error('Gmail returned a different sending account');
|
|
92
|
+
}
|
|
93
|
+
return new Set(sendAs.filter((one)=>one.isPrimary || one.verificationStatus == 'accepted').map((one)=>address(one.sendAsEmail)));
|
|
94
|
+
};
|
|
95
|
+
export let gmailSender = (call, expected)=>({
|
|
96
|
+
send: async (message)=>{
|
|
97
|
+
let from = address(message.from);
|
|
98
|
+
let allowed = await gmailAddresses(call, expected).catch((error)=>{
|
|
99
|
+
throw new Unsent(error instanceof Error ? error.message : 'Could not check Gmail aliases', 60_000);
|
|
100
|
+
});
|
|
101
|
+
if (!allowed.has(from)) {
|
|
102
|
+
throw new Undeliverable(`${from} is not a verified Gmail Send mail as address`);
|
|
103
|
+
}
|
|
104
|
+
let id = `${message.id ?? crypto.randomUUID()}@${expected.split('@')[1]}`;
|
|
105
|
+
try {
|
|
106
|
+
await ask(call, '/messages/send', {}, {
|
|
107
|
+
raw: gmailLetter(message, id)
|
|
108
|
+
});
|
|
109
|
+
} catch (error) {
|
|
110
|
+
if (error instanceof GmailError && error.status == 429) {
|
|
111
|
+
throw new Unsent('Gmail is limiting sends', 60_000);
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
id
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
let excluded = new Set([
|
|
121
|
+
'SENT',
|
|
122
|
+
'DRAFT',
|
|
123
|
+
'SPAM',
|
|
124
|
+
'TRASH',
|
|
125
|
+
'CHAT'
|
|
126
|
+
]);
|
|
127
|
+
let incoming = async (encoded, addresses, primary)=>{
|
|
128
|
+
let raw = fromBase64url(encoded);
|
|
129
|
+
let mail = await PostalMime.parse(raw);
|
|
130
|
+
if (!mail.from?.address) return;
|
|
131
|
+
let headers = new Map(mail.headers.map(({ key, value })=>[
|
|
132
|
+
key,
|
|
133
|
+
value
|
|
134
|
+
]));
|
|
135
|
+
let recipients = [
|
|
136
|
+
...mail.to ?? [],
|
|
137
|
+
...mail.cc ?? []
|
|
138
|
+
].flatMap((one)=>'group' in one ? one.group ?? [] : [
|
|
139
|
+
one
|
|
140
|
+
]);
|
|
141
|
+
let to = [
|
|
142
|
+
...recipients.map((one)=>one.address ?? ''),
|
|
143
|
+
headers.get('x-original-to') ?? '',
|
|
144
|
+
headers.get('delivered-to') ?? ''
|
|
145
|
+
].map(address).find((one)=>one != primary && addresses.has(one)) ?? primary;
|
|
146
|
+
if (mail.subject != null) headers.set('subject', mail.subject);
|
|
147
|
+
if (mail.messageId) headers.set('message-id', mail.messageId);
|
|
148
|
+
return {
|
|
149
|
+
from: mail.from.address,
|
|
150
|
+
name: mail.from.name,
|
|
151
|
+
to,
|
|
152
|
+
headers: {
|
|
153
|
+
get: (name)=>headers.get(name.toLowerCase()) ?? null,
|
|
154
|
+
entries: ()=>headers.entries()
|
|
155
|
+
},
|
|
156
|
+
text: mail.text ?? '',
|
|
157
|
+
html: mail.html,
|
|
158
|
+
attachments: mail.attachments.map((file)=>({
|
|
159
|
+
name: file.filename ?? '',
|
|
160
|
+
type: file.mimeType || 'application/octet-stream',
|
|
161
|
+
bytes: typeof file.content == 'string' ? utf8(file.content) : new Uint8Array(file.content)
|
|
162
|
+
})),
|
|
163
|
+
sources: [
|
|
164
|
+
{
|
|
165
|
+
name: 'message.eml',
|
|
166
|
+
type: 'message/rfc822',
|
|
167
|
+
bytes: new Uint8Array(raw)
|
|
168
|
+
}
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
export let gmailStart = async (call, primary, started)=>({
|
|
173
|
+
history: await gmailProfile(call, primary),
|
|
174
|
+
since: started,
|
|
175
|
+
through: started
|
|
176
|
+
});
|
|
177
|
+
/** A poll reads message content only after Gmail's delivery time and labels
|
|
178
|
+
* have been checked. Advance the cursor only once every arrival is filed. */ export let gmailPoll = async (call, primary, cursor, started, file)=>{
|
|
179
|
+
let seen = new Set();
|
|
180
|
+
let since = Date.parse(cursor.since);
|
|
181
|
+
let addresses;
|
|
182
|
+
let receive = async ({ id })=>{
|
|
183
|
+
if (seen.has(id)) return;
|
|
184
|
+
seen.add(id);
|
|
185
|
+
let path = '/messages/' + encodeURIComponent(id);
|
|
186
|
+
let get = (query)=>ask(call, path, query).catch((error)=>gone(error) ? undefined : Promise.reject(error));
|
|
187
|
+
let meta = await get({
|
|
188
|
+
format: 'full',
|
|
189
|
+
fields: 'internalDate,labelIds'
|
|
190
|
+
});
|
|
191
|
+
if (!meta || meta.labelIds?.some((label)=>excluded.has(label))) return;
|
|
192
|
+
let at = Number(meta.internalDate);
|
|
193
|
+
if (!meta.internalDate || !Number.isFinite(at)) {
|
|
194
|
+
throw new Error('Gmail returned no message delivery time');
|
|
195
|
+
}
|
|
196
|
+
if (at < since) return;
|
|
197
|
+
addresses ??= gmailAddresses(call, primary);
|
|
198
|
+
let verified = await addresses;
|
|
199
|
+
let full = await get({
|
|
200
|
+
format: 'raw',
|
|
201
|
+
fields: 'raw'
|
|
202
|
+
});
|
|
203
|
+
if (full && !full.raw) throw new Error('Gmail returned no message content');
|
|
204
|
+
let mail = full?.raw && await incoming(full.raw, verified, primary);
|
|
205
|
+
if (mail) await file(id, mail);
|
|
206
|
+
};
|
|
207
|
+
let page = '';
|
|
208
|
+
try {
|
|
209
|
+
do {
|
|
210
|
+
let history = await ask(call, '/history', {
|
|
211
|
+
startHistoryId: cursor.history,
|
|
212
|
+
historyTypes: 'messageAdded',
|
|
213
|
+
maxResults: '100',
|
|
214
|
+
...page ? {
|
|
215
|
+
pageToken: page
|
|
216
|
+
} : {}
|
|
217
|
+
});
|
|
218
|
+
for (let event of history.history ?? []){
|
|
219
|
+
for (let { message } of event.messagesAdded ?? []){
|
|
220
|
+
await receive(message);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
page = history.nextPageToken ?? '';
|
|
224
|
+
if (!page) {
|
|
225
|
+
if (!history.historyId) {
|
|
226
|
+
throw new Error('Gmail returned no history position');
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
...cursor,
|
|
230
|
+
history: history.historyId,
|
|
231
|
+
through: started
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}while (page)
|
|
235
|
+
} catch (error) {
|
|
236
|
+
if (!(gone(error) && error.operation == '/history')) {
|
|
237
|
+
throw error;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
// Capture the replacement position before the search, so a delivery during
|
|
241
|
+
// the search is considered by the next history poll.
|
|
242
|
+
let history = await gmailProfile(call, primary);
|
|
243
|
+
let after = Math.floor(Date.parse(cursor.through) / 1000) - 1;
|
|
244
|
+
page = '';
|
|
245
|
+
do {
|
|
246
|
+
let listing = await ask(call, '/messages', {
|
|
247
|
+
q: `after:${after}`,
|
|
248
|
+
maxResults: '100',
|
|
249
|
+
...page ? {
|
|
250
|
+
pageToken: page
|
|
251
|
+
} : {}
|
|
252
|
+
});
|
|
253
|
+
for (let message of listing.messages ?? [])await receive(message);
|
|
254
|
+
page = listing.nextPageToken ?? '';
|
|
255
|
+
}while (page)
|
|
256
|
+
return {
|
|
257
|
+
...cursor,
|
|
258
|
+
history,
|
|
259
|
+
through: started
|
|
260
|
+
};
|
|
261
|
+
};
|
|
262
|
+
//# sourceMappingURL=gmail.js.map
|
package/gmail.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gmail.js","sources":["./gmail.ts"],"names":[],"mappings":"AAAA,OAAO,8BAAuC;AAC9C,SAAS,aAAa,EAAE,QAAQ,EAAE,WAAW,wBAA6B;AAC1E,SAIE,aAAa,EACb,MAAM,kCAC8B;AAEtC,OAAO,IAAI,gBAAgB,gBAAe;AAE1C,IAAI,MAAM;AACV,IAAI,OAAO,CAAC,OAAiB,IAAI,cAAc,MAAM,CAAC;AACtD,IAAI,UAAU,CAAC,OAAiB,SAAS,KAAK;AAC9C,IAAI,OAAO,CAAC,OAAiB,QAAQ,MAAM,OAAO,CAAC,UAAU;AAC7D,IAAI,OAAO,CAAC,OAAiB,KAAK,OAAO,CAAC,YAAY,KAAK,IAAI;AAC/D,IAAI,OAAO,CAAC,OACV,iBAAiB,IAAI,CAAC,QAAQ,OAAO,CAAC,UAAU,EAAE,QAAQ,MAAM,EAAE,CAAC;AACrE,IAAI,UAAU,CAAC,OAAiB,KAAK,IAAI,GAAG,WAAW;AAEvD,4EAA4E,GAC5E,OAAO,IAAI,cAAc,CAAC,GAAY;EACpC,IAAI,WAAW,SAAS,OAAO,UAAU;EACzC,IAAI,MAAM,EAAE,IAAI,GAAG,GAAG,KAAK,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,KAAK,EAAE,IAAI;EAC1E,IAAI,EAAE,IAAI,IAAI,iBAAiB,IAAI,CAAC,KAAK,EAAE,IAAI,IAAI;IACjD,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,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