@ever-works/ever-email-router-plugin 0.0.0-stage → 1.0.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 +66 -2
- package/dist/index.cjs +2168 -0
- package/dist/index.d.cts +66 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.js +2156 -0
- package/package.json +82 -5
package/README.md
CHANGED
|
@@ -1,3 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ever-works/ever-email-router-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Ever Email Router plugin for Ever Works — receive mail for `@ever.email` addresses from the shared Cloudflare Worker **ever-email-router**.
|
|
4
|
+
|
|
5
|
+
- **Category**: `email-provider`
|
|
6
|
+
- **Capabilities**: `email-inbound` (it sends nothing — pair it with an outbound provider to reply)
|
|
7
|
+
- **Webhook**: `POST /api/email/inbound/ever-email-router`, answered with counts (`inboundAck: 'counts'`)
|
|
8
|
+
|
|
9
|
+
## Settings
|
|
10
|
+
|
|
11
|
+
| Key | Secret | Admin-only | Env var | Required |
|
|
12
|
+
| ---------------------- | ------ | ---------- | -------------------------- | -------- |
|
|
13
|
+
| `inboundWebhookSecret` | yes | yes | `EVER_EMAIL_ROUTER_SECRET` | yes |
|
|
14
|
+
|
|
15
|
+
The plugin also reads `EVER_EMAIL_DOMAIN` (default `ever.email`): the only domain an address registered with it may use, declared through its `inboundAddressPolicy`.
|
|
16
|
+
|
|
17
|
+
## Contract
|
|
18
|
+
|
|
19
|
+
The router posts one request **per recipient**:
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
POST /api/email/inbound/ever-email-router
|
|
23
|
+
content-type: application/json
|
|
24
|
+
x-ever-email-signature: t=<unix seconds>,v1=<lowercase hex HMAC-SHA256(secret, "<t>.<exact raw request body>")>
|
|
25
|
+
|
|
26
|
+
{
|
|
27
|
+
"raw": "<base64 RFC 5322 message>",
|
|
28
|
+
"envelope": { "from": "<envelope sender>", "to": ["<one recipient>"] },
|
|
29
|
+
"authenticationResults": "<optional: Cloudflare's own Authentication-Results value>"
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Answers:
|
|
34
|
+
|
|
35
|
+
| Status | Body | Router reads it as |
|
|
36
|
+
| --------------------- | ---------------------------------------------------------- | ------------------------------------------------------------- |
|
|
37
|
+
| `202` | `{"accepted":1,"duplicates":0,"dropped":0}` | taken — delivered to the address's Agent |
|
|
38
|
+
| `202` | `{"accepted":0,"duplicates":1,"dropped":0}` | taken — already delivered (a retry) |
|
|
39
|
+
| `202` | `{"accepted":0,"duplicates":0,"dropped":1}` | not ours — no such address here (or none takes it) |
|
|
40
|
+
| `401` | `{"statusCode":401,"message":"Invalid webhook signature"}` | temporary (bad/missing signature, stale timestamp, no secret) |
|
|
41
|
+
| `413` | — | too large (`INBOUND_EMAIL_BODY_LIMIT`, default 25 MB) |
|
|
42
|
+
| `404` / `429` / `5xx` | — | temporary — retry later (the plugin not enabled here: `500`) |
|
|
43
|
+
|
|
44
|
+
`dropped` covers every delivery nothing took: no enabled inbound address registered with this plugin, an address with no inbound Agent assignment, or a disabled one.
|
|
45
|
+
|
|
46
|
+
## Security
|
|
47
|
+
|
|
48
|
+
- **Signature first.** `verifyWebhookSignature` recomputes `HMAC-SHA256(secret, "<t>." + raw body)` over the exact bytes received and compares it in constant time (`crypto.timingSafeEqual`). It refuses a missing or malformed header, a timestamp more than **300 s** from the API's clock (either way), and a mismatch. Several `v1=` values are accepted (one per secret during a rotation).
|
|
49
|
+
- **Fails closed.** No secret, or one shorter than **24 characters**, refuses every delivery. There is no unsigned opt-out (`EMAIL_INBOUND_ALLOW_UNSIGNED` does not apply).
|
|
50
|
+
- **The deployment's secret only.** The setting is `x-adminOnly`, so a tenant can never save their own secret; an unknown recipient is verified with the admin/env secret before anything is answered.
|
|
51
|
+
- **Counts only after verification.** The platform's other inbound webhooks answer `{"received":true}` whatever happened (EW-718: no routing leak). The counts are answered only once the signature passed — the caller has proven it holds the deployment's secret — and carry no id, Agent or mode.
|
|
52
|
+
- **Bound to the envelope.** The message is routed to the envelope recipient (inside the signed body), never to the sender-written `To` header.
|
|
53
|
+
- **Replays are harmless.** Inside the 300 s window a captured request can only re-deliver the same message to the same recipient, which the `(pluginId, providerMessageId)` unique index answers as a duplicate.
|
|
54
|
+
- **One owner per mailbox.** The plugin declares `inboundAddressPolicy: { domain: EVER_EMAIL_DOMAIN || 'ever.email', exclusive: true }`, and the API (which never names the plugin) enforces it: an address outside the domain is refused (`400`), and so is (`409`) a mailbox another account already holds for inbound mail — under any plugin, since the inbound binding picks the oldest such row. Re-enabling a disabled address is checked the same way, addresses are stored lower-cased, and if the plugin cannot be loaded when an address is registered the registration is refused (`503`) rather than left unchecked.
|
|
55
|
+
|
|
56
|
+
## Parsing
|
|
57
|
+
|
|
58
|
+
- The `raw` message is decoded with [`postal-mime`](https://github.com/postalsys/postal-mime): `from` (header `From`, else the envelope sender), `to` / `cc` (bare mailboxes; a Bcc'd delivery's `to` is the envelope recipient), subject, text and HTML bodies, every attachment (base64; the dispatcher's per-message limits apply), `Message-ID`, `In-Reply-To` and `References` for threading.
|
|
59
|
+
- `providerMessageId` is `sha256(Message-ID, else the raw message)` + `:` + the recipient, so the same message sent to two Ever Works addresses is two deliveries, not a duplicate (a recipient too long for the 200-character column is replaced by its own sha256).
|
|
60
|
+
- `authenticationResults` is mapped onto the metadata the trust module reads — `dmarc`, `spf` / `spfDomain` (from `smtp.mailfrom`), `dkim` / `dkimDomain` (from `header.d`; with several signatures a pass aligned with `From` wins) — and kept as the topmost `Authentication-Results` of `metadata.headers`. The message's own `Authentication-Results` headers are dropped (the sender could have written them). A deployment whose only inbound provider is the router may also set `INBOUND_EMAIL_AUTHSERV_ID=mx.cloudflare.net`.
|
|
61
|
+
|
|
62
|
+
## Setup
|
|
63
|
+
|
|
64
|
+
1. Generate a secret (at least 24 characters, e.g. `openssl rand -hex 32`) and give the **same value** to the Worker and to the API as `EVER_EMAIL_ROUTER_SECRET` (the deployment's secret store — never a tenant setting).
|
|
65
|
+
2. Point the Worker at `https://<api host>/api/email/inbound/ever-email-router`.
|
|
66
|
+
3. In Ever Works, add an address `name@ever.email` with direction **Inbound** and provider **Ever Email Router** (Settings → Email addresses).
|
|
67
|
+
4. Assign the address to an Agent (inbound). Mail to it now creates a Task, or joins the Agent's conversation, per the assignment's dispatch mode.
|