@blamejs/core 0.11.27 → 0.11.28
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/CHANGELOG.md +2 -0
- package/lib/guard-imap-command.js +2 -0
- package/lib/mail-server-imap.js +309 -0
- package/lib/mail-server-registry.js +4 -0
- package/package.json +1 -1
- package/sbom.cdx.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,8 @@ upgrading across more than a few patches at a time.
|
|
|
8
8
|
|
|
9
9
|
## v0.11.x
|
|
10
10
|
|
|
11
|
+
- v0.11.28 (2026-05-21) — **IMAP opt-in extensions: NOTIFY (RFC 5465), METADATA (RFC 5464), CATENATE (RFC 4469).** Three IMAP extensions advertised in CAPABILITY and dispatched through the existing per-method registry. NOTIFY accepts a client subscription spec and hands it to the operator's `mailStore.subscribeNotify(actor, spec, emitFn)` hook — actual event emission stays operator-side. METADATA exposes GETMETADATA and SETMETADATA per-mailbox + server-wide annotations through `mailStore.getMetadata` / `setMetadata`. CATENATE extends APPEND to compose a message from existing parts (`TEXT {N}` literals + `URL "imap://..."`) via `mailStore.appendCatenate`. Each handler refuses gracefully (`NO ... backend not configured`) when the operator backend doesn't supply the hook. COMPRESS=DEFLATE (RFC 4978) intentionally NOT advertised — CRIME-class compression-oracle threat on the encrypted IMAP stream. **Added:** *CAPABILITY advertises `NOTIFY`, `METADATA`, `METADATA-SERVER`, `CATENATE`* — All four added unconditionally so capable clients can exercise the extension regardless of authentication state. Each handler is registered in the protocol verb catalogue (`b.mail.serverRegistry`) + the wire-level guard verb list (`b.guardImapCommand.KNOWN_VERBS`) so the existing dispatch + audit + ratelimit gates apply uniformly. · *`NOTIFY SET ...` / `NOTIFY NONE` — RFC 5465* — The handler parses `NOTIFY SET [STATUS] (<filter-set> (<event>...))*` and `NOTIFY NONE` and stores the filter-set verbatim on `state.notifySpec`. When the operator backend exposes `mailStore.subscribeNotify(actor, spec, emitFn)`, the listener wires an `emitFn` that translates backend events (`{ kind: 'STATUS' | 'LIST' | 'FETCH', payload, seq? }`) into untagged IMAP responses on the same connection — drop-silent if the socket has already closed. Without the backend hook, the wire command refuses with `NO NOTIFY backend not configured` rather than silently accepting subscriptions the server can't fulfil. · *`GETMETADATA` / `SETMETADATA` — RFC 5464* — Both verbs parse the per-mailbox + server-wide annotation forms. GETMETADATA accepts optional `(MAXSIZE N)` / `(DEPTH ...)` options before the mailbox + entry list, walks the entries through `mailStore.getMetadata(actor, mailbox, names, opts) → [{ entry, value }]`, and renders an untagged `* METADATA <mailbox> (<entry> <value>...)` response. SETMETADATA tokenises the entry/value pairs (quoted-strings + NIL for clearing), validates the mailbox name, and forwards to `mailStore.setMetadata(actor, mailbox, entries)`. Without the backend hooks, both return `NO ... backend not configured`. · *APPEND `CATENATE` modifier — RFC 4469* — `APPEND mailbox [flags] [date-time] CATENATE (...)` is recognised before the legacy literal-required APPEND path. The parts list mixes `TEXT {N}` literal-bytes parts (handed in via the literal-aware parser) and `URL "imap://..."` reference parts; the listener bundles them into `parts: [{ kind: 'TEXT', bytes } | { kind: 'URL', url }]` and forwards to `mailStore.appendCatenate(mailbox, parts, { actor, flags, internalDate }) → { uid, uidValidity }`. When the backend returns the APPENDUID metadata the response carries `OK [APPENDUID <validity> <uid>] APPEND completed` (RFC 4315). Without the backend hook, refuses with `NO CATENATE backend not configured`. **Security:** *COMPRESS=DEFLATE intentionally NOT advertised (CRIME-class)* — RFC 4978 IMAP COMPRESS=DEFLATE enables stream compression that interacts badly with TLS — the CRIME attack class (CVE-2012-4929, BREACH, et al.) recovers plaintext via chosen-plaintext compression-ratio analysis. The framework default is OFF; operators with explicit threat models accept the downgrade via `opts.compress = true` (no opt-in path landed in v1, intentionally — defer-with-condition: open when an operator surfaces a deployment that needs it AND can document the chosen-plaintext threat model is mitigated). · *Mailbox-name validation reused for both METADATA verbs* — Both GETMETADATA and SETMETADATA run `_validateMailboxName` on the parsed mailbox argument (except for the empty-string `""` server-wide-metadata special case per RFC 5464 §3.1). Operators with the existing `allowLegacyMUtf7` opt see the same mailbox-name policy as the rest of the listener; injection-shape mailbox names are refused identically. · *NOTIFY backend-missing returns NO (not silent accept)* — If the operator wired the listener without `mailStore.subscribeNotify`, `NOTIFY SET ...` returns `NO NOTIFY backend not configured` — never a silent `OK`. RFC 5465 §6 specifies NO as the correct refusal shape; silent acceptance would let a client believe events will arrive when the server cannot fulfil the subscription. **References:** [RFC 5465 (IMAP NOTIFY)](https://www.rfc-editor.org/rfc/rfc5465.html) · [RFC 5464 (IMAP METADATA)](https://www.rfc-editor.org/rfc/rfc5464.html) · [RFC 4469 (IMAP CATENATE)](https://www.rfc-editor.org/rfc/rfc4469.html) · [RFC 4315 (IMAP UIDPLUS — APPENDUID response)](https://www.rfc-editor.org/rfc/rfc4315.html) · [RFC 4978 (IMAP COMPRESS — NOT enabled; CRIME-class threat)](https://www.rfc-editor.org/rfc/rfc4978.html) · [CVE-2012-4929 (CRIME — compression-oracle attack on TLS)](https://nvd.nist.gov/vuln/detail/CVE-2012-4929)
|
|
12
|
+
|
|
11
13
|
- v0.11.27 (2026-05-20) — **IMAP CONDSTORE (RFC 7162) — modseq-aware FETCH + STORE on `b.mail.server.imap`.** The IMAP listener advertises and honours the CONDSTORE extension. Clients that issue `ENABLE CONDSTORE` get MODSEQ attributes in every untagged FETCH response; FETCH parses the `(CHANGEDSINCE <modseq>)` modifier and forwards it to the operator's backend so the backend can prune unchanged rows server-side; STORE parses the `(UNCHANGEDSINCE <modseq>)` conditional-update modifier and surfaces the backend's MODIFIED conflict set in the tagged OK response (`OK [MODIFIED <set>] STORE completed`). The backend interface picks up four new opts on the existing `fetchRange` / `storeFlags` calls: `changedSince`, `includeVanished`, `includeModseq`, `unchangedSince`. Backends MAY return modseq on each row; the listener injects `MODSEQ (<n>)` into the payload when present and CONDSTORE is enabled. QRESYNC (RFC 7162 §3.2) is deferred — accepted in ENABLE but no vanished-set surface is exposed yet. **Added:** *CAPABILITY advertises `CONDSTORE` unconditionally* — Per RFC 7162 §3 servers advertise CONDSTORE; clients ENABLE before relying on MODSEQ in untagged FETCH responses. The advertisement is unconditional (state-independent) so clients that issue CAPABILITY pre-LOGIN see CONDSTORE in the same untagged-response shape they'll see post-LOGIN. The old SELECT-side `HIGHESTMODSEQ` emission keeps working. · *`ENABLE CONDSTORE` handler flips `state.enabledCondStore`* — Replaces the no-op `OK ENABLED` shortcut with a real handler that parses the requested capability set, flips `state.enabledCondStore = true` on CONDSTORE, and replies with `ENABLED CONDSTORE` + `OK ENABLE completed`. Unknown extensions are silently ignored per RFC 5161 §3.1. QRESYNC is recognised but accepted only when a v1+ backend exposes the vanished-set surface. · *FETCH parses `(CHANGEDSINCE <modseq>)` + injects MODSEQ in responses* — When the FETCH args carry a trailing `(CHANGEDSINCE <n>)` modifier (RFC 7162 §3.1.4) the listener strips it from the fetch-att spec and forwards `opts.changedSince` to `mailStore.fetchRange`. The backend can prune unchanged messages server-side. When CONDSTORE is enabled (or the client explicitly requested MODSEQ as a fetch-att), each untagged FETCH response includes `MODSEQ (<n>)` — synthesised from `row.modseq` if the backend supplies it and the payload doesn't already contain it. Also recognises the QRESYNC `VANISHED` modifier (flag forwarded as `opts.includeVanished`); the vanished-set emission is the backend's responsibility for now. · *STORE parses `(UNCHANGEDSINCE <modseq>)` + emits `[MODIFIED <set>]` on conflict* — Per RFC 7162 §3.1.3 the conditional STORE refuses to update messages whose modseq advanced past `unchangedSince` since the client last fetched. The listener parses the modifier between the seq-set and the FLAGS op, forwards `opts.unchangedSince` to `mailStore.storeFlags`, and accepts either the legacy `rows: [...]` shape or a structured `{ rows, modified }` shape. When `modified` is non-empty, the tagged response carries `OK [MODIFIED <set>] STORE completed` so the client knows which messages need re-fetching before retry. Untagged FETCH responses also include `MODSEQ (<n>)` when STORE accepted updates under CONDSTORE. **Security:** *Modifier parsing is bounded + non-greedy* — The CHANGEDSINCE / UNCHANGEDSINCE matchers use `[^)]*` rather than `.*` so a malformed modifier can't consume the entire fetch-att spec. Both modifiers parse `\d+` only — non-integer / negative / Infinity values are silently dropped (the modifier becomes a no-op), so a client cannot ride the modifier to inject arbitrary fragments into the backend opts. · *Modseq attribute is opt-in* — MODSEQ injection into untagged FETCH responses ONLY happens when (a) CONDSTORE is enabled OR (b) the client's fetch-att spec contains the `MODSEQ` keyword. Pre-CONDSTORE clients see exactly the responses they saw before this release. The IMAP wire-format compatibility line is unchanged for the IMAP4rev1 / IMAP4rev2 cohorts that never issue `ENABLE CONDSTORE`. **References:** [RFC 7162 (IMAP4 CONDSTORE / QRESYNC)](https://www.rfc-editor.org/rfc/rfc7162.html) · [RFC 9051 (IMAP4rev2)](https://www.rfc-editor.org/rfc/rfc9051.html) · [RFC 5161 (IMAP ENABLE Extension)](https://www.rfc-editor.org/rfc/rfc5161.html) · [RFC 4315 (IMAP UIDPLUS Extension)](https://www.rfc-editor.org/rfc/rfc4315.html)
|
|
12
14
|
|
|
13
15
|
- v0.11.26 (2026-05-20) — **`b.mail.server.submission` — CHUNKING / BDAT (RFC 3030).** The outbound submission listener now advertises and accepts the RFC 3030 BDAT (binary data) command, the chunked-upload alternative to DATA. Operators with large outbound payloads (attachments, MIME multipart bodies, encoded HTML) no longer pay the dot-stuffing cost of DATA; clients can stream chunks of arbitrary size and finalise with a `BDAT 0 LAST` (or `BDAT N LAST` for the final chunk). Mixing DATA + BDAT within one transaction is refused per RFC 3030 §3. Same `agent.handoff` contract — the body bytes arrive at the agent layer in their canonical SMTP form, no dot-stuffing applied (BDAT payloads are opaque). **Added:** *EHLO advertises `CHUNKING` + new `BDAT <chunk-size> [LAST]` command* — The EHLO 250-line list now includes `CHUNKING` (RFC 3030 §2.1). A new `BDAT` command handler accepts `BDAT <chunk-size> [LAST]` after MAIL FROM + RCPT TO; the server reads exactly `<chunk-size>` bytes from the socket — no dot-stuffing, no end-of-data marker — and acknowledges with `250 2.0.0 <octets> octets received`. Multiple BDAT chunks accumulate into the message body; the final chunk carries the `LAST` keyword and triggers the same agent-handoff path as DATA. A `BDAT 0 LAST` finalises an empty trailer when the last chunk's byte count is unknown in advance. · *Cumulative size cap honoured up-front* — `BDAT <large-size>` is refused with `552 5.3.4 BDAT cumulative size <total> exceeds maxMessageBytes (<cap>)` BEFORE the server begins reading bytes off the wire. A misconfigured client that pipelines `BDAT 999999999 LAST` and 1 GB of body is rejected at the command line, not after the byte stream lands. The collector bound on the receive side enforces the same cap as a backstop. · *Mid-segment payload drainage* — When `BDAT N LAST\r\n<payload>` arrives in one TCP segment (typical for pipelined small messages), the line-loop drains the post-`\r\n` bytes from the command buffer straight into the BDAT collector before returning. Any tail bytes after the BDAT chunk completes get re-fed as the next command. Operators get pipelining + chunking with no extra round-trip cost. **Security:** *BDAT state cleared on every STARTTLS upgrade* — Same threat model as CVE-2021-38371 (Exim) / CVE-2021-33515 (Dovecot): pre-handshake bytes a malicious peer pipelined MUST NOT reach the post-TLS state machine. The STARTTLS handler clears `inBdatChunk` / `bdatRemaining` / `bdatCollector` / `bdatTotalBytes` alongside the existing line-buffer + DATA-collector reset, so a smuggled `BDAT <n>` + body that lands before the TLS upgrade can't bleed into the encrypted transaction. · *Refusal on BDAT outside transaction* — BDAT before MAIL FROM / with zero RCPT returns `503 5.5.1` and does not enter chunk-collection mode. A misbehaving client that issues BDAT eagerly cannot leak state into the next transaction; the RSET reset path also clears all BDAT-side state. · *Pipelining race gate mirrors DATA* — If the operator's `recipientPolicy` is async and not all RCPT verdicts have resolved, BDAT returns `451 4.5.0 RCPT TO verdicts pending; reissue BDAT after recipient replies` — same shape as the DATA pipelining-race gate. The transaction never commits with a partially-resolved recipient set. **References:** [RFC 3030 (SMTP Service Extensions — CHUNKING / BDAT / BINARYMIME)](https://www.rfc-editor.org/rfc/rfc3030.html) · [RFC 5321 (SMTP)](https://www.rfc-editor.org/rfc/rfc5321.html) · [RFC 6409 (Message Submission for Mail)](https://www.rfc-editor.org/rfc/rfc6409.html) · [RFC 8314 (Cleartext considered obsolete — submission ports)](https://www.rfc-editor.org/rfc/rfc8314.html) · [CVE-2021-38371 (Exim STARTTLS injection)](https://nvd.nist.gov/vuln/detail/CVE-2021-38371) · [CVE-2021-33515 (Dovecot STARTTLS pre-handshake state leak)](https://nvd.nist.gov/vuln/detail/CVE-2021-33515)
|
|
@@ -141,6 +141,8 @@ var KNOWN_VERBS = Object.freeze({
|
|
|
141
141
|
COPY: true, MOVE: true, UID: true,
|
|
142
142
|
GETQUOTA: true, SETQUOTA: true, GETQUOTAROOT: true,
|
|
143
143
|
ID: true,
|
|
144
|
+
// v0.11.28 — RFC 5465 NOTIFY + RFC 5464 METADATA.
|
|
145
|
+
NOTIFY: true, GETMETADATA: true, SETMETADATA: true,
|
|
144
146
|
});
|
|
145
147
|
|
|
146
148
|
var ZERO_ARG_VERBS = Object.freeze({
|
package/lib/mail-server-imap.js
CHANGED
|
@@ -557,6 +557,13 @@ function create(opts) {
|
|
|
557
557
|
maxHandlerBytes: LONG_B, maxHandlerMs: LONG_MS },
|
|
558
558
|
IDLE: { fn: function (s, so, p) { return _handleIdle(s, so, p.tag); },
|
|
559
559
|
maxHandlerBytes: SHORT_B, maxHandlerMs: LONG_MS },
|
|
560
|
+
// v0.11.28 — RFC 5465 NOTIFY / RFC 5464 METADATA / RFC 4469 CATENATE.
|
|
561
|
+
NOTIFY: { fn: function (s, so, p) { return _handleNotify(s, so, p.tag, p.args); },
|
|
562
|
+
maxHandlerBytes: MEDIUM_B, maxHandlerMs: MEDIUM_MS },
|
|
563
|
+
GETMETADATA: { fn: function (s, so, p) { return _handleGetMetadata(s, so, p.tag, p.args); },
|
|
564
|
+
maxHandlerBytes: MEDIUM_B, maxHandlerMs: MEDIUM_MS },
|
|
565
|
+
SETMETADATA: { fn: function (s, so, p, lit) { return _handleSetMetadata(s, so, p.tag, p.args, lit); },
|
|
566
|
+
maxHandlerBytes: LONG_B, maxHandlerMs: MEDIUM_MS },
|
|
560
567
|
DONE: { fn: function (s, so, p) { return _writeTagged(so, p.tag, "BAD DONE outside IDLE"); },
|
|
561
568
|
maxHandlerBytes: SHORT_B, maxHandlerMs: SHORT_MS },
|
|
562
569
|
// Defaults for the verbs the v0.9.49 listener didn't dispatch —
|
|
@@ -641,6 +648,17 @@ function create(opts) {
|
|
|
641
648
|
// RFC 7162 §3 — CONDSTORE is server-advertised; clients ENABLE
|
|
642
649
|
// before relying on MODSEQ in untagged FETCH responses.
|
|
643
650
|
caps.push("CONDSTORE");
|
|
651
|
+
// v0.11.28 — opt-in extensions (advertised so capable clients can
|
|
652
|
+
// exercise them; each handler refuses gracefully when the operator
|
|
653
|
+
// backend doesn't supply the corresponding hook).
|
|
654
|
+
caps.push("NOTIFY"); // RFC 5465
|
|
655
|
+
caps.push("METADATA"); // RFC 5464 — per-mailbox annotations // allow:raw-byte-literal — RFC number in comment
|
|
656
|
+
caps.push("METADATA-SERVER"); // RFC 5464 §3.1 — server-wide annotations // allow:raw-byte-literal — RFC number in comment
|
|
657
|
+
caps.push("CATENATE"); // RFC 4469 — APPEND from existing parts
|
|
658
|
+
// NB: COMPRESS=DEFLATE (RFC 4978) intentionally NOT advertised —
|
|
659
|
+
// CRIME-class compression-oracle attack on the encrypted IMAP
|
|
660
|
+
// stream. Operators who explicitly enable it via opts.compress
|
|
661
|
+
// get a documented downgrade; v1 default is off.
|
|
644
662
|
// Advertise AUTH=<mech> ONLY for mechanisms the operator wired
|
|
645
663
|
// in opts.auth.mechanisms. RFC 9051 §7.2 — clients pick from the
|
|
646
664
|
// advertised list; advertising AUTH=PLAIN when authConfig is null
|
|
@@ -681,6 +699,191 @@ function create(opts) {
|
|
|
681
699
|
_writeTagged(socket, tag, "OK ENABLE completed");
|
|
682
700
|
}
|
|
683
701
|
|
|
702
|
+
// RFC 5465 NOTIFY — `NOTIFY SET [STATUS] (<filter-set> (<event>...))*`
|
|
703
|
+
// / `NOTIFY NONE`. Subscribes the connection to mailbox / message
|
|
704
|
+
// events on a filter set. Actual event emission is operator-side
|
|
705
|
+
// (the backend's `subscribeNotify(actor, spec, emitFn)` hook); this
|
|
706
|
+
// handler stores the parsed subscription on `state.notifySpec` so
|
|
707
|
+
// the backend can read it on later mutations. NOTIFY NONE clears.
|
|
708
|
+
function _handleNotify(state, socket, tag, args) {
|
|
709
|
+
if (!_requireAuth(state, socket, tag)) return;
|
|
710
|
+
var raw = (args || "").trim();
|
|
711
|
+
if (/^NONE\b/i.test(raw)) {
|
|
712
|
+
state.notifySpec = null;
|
|
713
|
+
if (typeof mailStore.subscribeNotify === "function") {
|
|
714
|
+
try { mailStore.subscribeNotify(state.actor, null, null); }
|
|
715
|
+
catch (_e) { /* drop-silent — operator hook may refuse mid-life */ }
|
|
716
|
+
}
|
|
717
|
+
_writeTagged(socket, tag, "OK NOTIFY completed");
|
|
718
|
+
return;
|
|
719
|
+
}
|
|
720
|
+
var setMatch = raw.match(/^SET\s+(?:STATUS\s+)?(.+)$/i); // allow:regex-no-length-cap — args length already capped upstream
|
|
721
|
+
if (!setMatch) {
|
|
722
|
+
_writeTagged(socket, tag, "BAD NOTIFY syntax (RFC 5465 §6)");
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
// Store the spec verbatim; the backend parses the filter-set
|
|
726
|
+
// vocabulary (`SELECTED`, `SELECTED-DELAYED`, `INBOXES`,
|
|
727
|
+
// `PERSONAL`, `SUBSCRIBED`, `MAILBOXES <list>`, `SUBTREE <list>`)
|
|
728
|
+
// since the event semantics live there. The listener's job is to
|
|
729
|
+
// hand the wire string to the backend.
|
|
730
|
+
state.notifySpec = setMatch[1];
|
|
731
|
+
if (typeof mailStore.subscribeNotify === "function") {
|
|
732
|
+
Promise.resolve()
|
|
733
|
+
.then(function () {
|
|
734
|
+
return mailStore.subscribeNotify(state.actor, state.notifySpec, function (event) {
|
|
735
|
+
// Backend pushes events as { kind, mailbox, payload }; we
|
|
736
|
+
// emit them as untagged responses on the same connection.
|
|
737
|
+
if (!event || typeof event.kind !== "string") return;
|
|
738
|
+
try {
|
|
739
|
+
if (event.kind === "STATUS") {
|
|
740
|
+
_writeUntagged(socket, "STATUS " + event.payload);
|
|
741
|
+
} else if (event.kind === "LIST") {
|
|
742
|
+
_writeUntagged(socket, "LIST " + event.payload);
|
|
743
|
+
} else if (event.kind === "FETCH") {
|
|
744
|
+
_writeUntagged(socket, (event.seq || "") + " FETCH (" + (event.payload || "") + ")");
|
|
745
|
+
}
|
|
746
|
+
} catch (_e) { /* drop-silent — socket may already be closed */ }
|
|
747
|
+
});
|
|
748
|
+
})
|
|
749
|
+
.then(function () { _writeTagged(socket, tag, "OK NOTIFY completed"); })
|
|
750
|
+
.catch(function (err) {
|
|
751
|
+
_writeTagged(socket, tag, "NO " + ((err && err.message) || "NOTIFY refused").slice(0, ERR_CLAMP));
|
|
752
|
+
});
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
// Backend doesn't expose the subscribe hook — accept the wire
|
|
756
|
+
// command but emit no events. RFC 5465 §6 says NO is the right
|
|
757
|
+
// refusal shape when the server cannot fulfil the subscription.
|
|
758
|
+
_writeTagged(socket, tag, "NO NOTIFY backend not configured");
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// RFC 5464 §4.1 GETMETADATA — `GETMETADATA [opts] mailbox entries`.
|
|
762
|
+
// `mailbox` may be `""` for server-wide annotations (METADATA-SERVER).
|
|
763
|
+
// Entries are slash-prefixed names (`/private/foo` / `/shared/bar`).
|
|
764
|
+
// Backend hook: `mailStore.getMetadata(actor, mailbox, names) →
|
|
765
|
+
// [{ entry, value }]`.
|
|
766
|
+
function _handleGetMetadata(state, socket, tag, args) {
|
|
767
|
+
if (!_requireAuth(state, socket, tag)) return;
|
|
768
|
+
if (typeof mailStore.getMetadata !== "function") {
|
|
769
|
+
_writeTagged(socket, tag, "NO GETMETADATA backend not configured");
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
// Strip optional MAXSIZE / DEPTH opts: GETMETADATA (MAXSIZE 1024) "" ("/foo")
|
|
773
|
+
var rest = (args || "").trim();
|
|
774
|
+
var opts = {};
|
|
775
|
+
var optsMatch = rest.match(/^\(([^)]+)\)\s+(.+)$/); // allow:regex-no-length-cap — args length already capped upstream
|
|
776
|
+
if (optsMatch) {
|
|
777
|
+
var optBody = optsMatch[1];
|
|
778
|
+
var maxMatch = optBody.match(/MAXSIZE\s+(\d+)/i); // allow:regex-no-length-cap — optBody bounded by parens
|
|
779
|
+
if (maxMatch) opts.maxSize = parseInt(maxMatch[1], 10);
|
|
780
|
+
var depthMatch = optBody.match(/DEPTH\s+(\w+)/i); // allow:regex-no-length-cap — optBody bounded
|
|
781
|
+
if (depthMatch) opts.depth = depthMatch[1];
|
|
782
|
+
rest = optsMatch[2];
|
|
783
|
+
}
|
|
784
|
+
var partsMatch = rest.match(/^(\S+|"[^"]*")\s+(\(([^)]+)\)|(\/\S+))$/); // allow:regex-no-length-cap — args length already capped upstream
|
|
785
|
+
if (!partsMatch) {
|
|
786
|
+
_writeTagged(socket, tag, "BAD GETMETADATA syntax (RFC 5464 §4.1)");
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
var mailbox = _unquote(partsMatch[1]);
|
|
790
|
+
var entries = partsMatch[3]
|
|
791
|
+
? partsMatch[3].split(/\s+/).filter(Boolean)
|
|
792
|
+
: [partsMatch[4]];
|
|
793
|
+
if (mailbox !== "" && !_validateMailboxName(mailbox, { allowLegacyMUtf7: allowLegacyMUtf7 })) {
|
|
794
|
+
_writeTagged(socket, tag, "BAD Mailbox name refused");
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
Promise.resolve()
|
|
798
|
+
.then(function () { return mailStore.getMetadata(state.actor, mailbox, entries, opts); })
|
|
799
|
+
.then(function (rows) {
|
|
800
|
+
if (Array.isArray(rows) && rows.length > 0) {
|
|
801
|
+
var pairs = rows.map(function (r) {
|
|
802
|
+
var v = r.value === null || r.value === undefined ? "NIL" : '"' + String(r.value).replace(/\\/g, "\\\\").replace(/"/g, "\\\"") + '"';
|
|
803
|
+
return r.entry + " " + v;
|
|
804
|
+
}).join(" ");
|
|
805
|
+
_writeUntagged(socket, "METADATA " + (mailbox === "" ? '""' : mailbox) + " (" + pairs + ")");
|
|
806
|
+
}
|
|
807
|
+
_writeTagged(socket, tag, "OK GETMETADATA completed");
|
|
808
|
+
})
|
|
809
|
+
.catch(function (err) {
|
|
810
|
+
_writeTagged(socket, tag, "NO " + ((err && err.message) || "GETMETADATA failed").slice(0, ERR_CLAMP));
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// RFC 5464 §4.3 SETMETADATA — `SETMETADATA mailbox (entry value ...)`.
|
|
815
|
+
// Setting `value = NIL` clears the entry. Backend hook:
|
|
816
|
+
// `mailStore.setMetadata(actor, mailbox, entries)`. The wire format
|
|
817
|
+
// delivers each value as a quoted-string or NIL atom; the parser
|
|
818
|
+
// here handles the simple single-line shape (no literals across
|
|
819
|
+
// SETMETADATA — operators using >1 KiB metadata go through APPEND).
|
|
820
|
+
function _handleSetMetadata(state, socket, tag, args, _literalBody) {
|
|
821
|
+
if (!_requireAuth(state, socket, tag)) return;
|
|
822
|
+
if (typeof mailStore.setMetadata !== "function") {
|
|
823
|
+
_writeTagged(socket, tag, "NO SETMETADATA backend not configured");
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
var match = (args || "").trim().match(/^(\S+|"[^"]*")\s+\((.+)\)$/); // allow:regex-no-length-cap — args length already capped upstream
|
|
827
|
+
if (!match) {
|
|
828
|
+
_writeTagged(socket, tag, "BAD SETMETADATA syntax (RFC 5464 §4.3)");
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
var mailbox = _unquote(match[1]);
|
|
832
|
+
var body = match[2];
|
|
833
|
+
if (mailbox !== "" && !_validateMailboxName(mailbox, { allowLegacyMUtf7: allowLegacyMUtf7 })) {
|
|
834
|
+
_writeTagged(socket, tag, "BAD Mailbox name refused");
|
|
835
|
+
return;
|
|
836
|
+
}
|
|
837
|
+
// Tokenise `<entry> <value> <entry> <value> ...`. Values are
|
|
838
|
+
// `"..."` quoted-string OR `NIL`. Entries are `/private/...` /
|
|
839
|
+
// `/shared/...` slash-prefixed names.
|
|
840
|
+
var entries = [];
|
|
841
|
+
var i = 0;
|
|
842
|
+
while (i < body.length) {
|
|
843
|
+
while (i < body.length && /\s/.test(body[i])) i++;
|
|
844
|
+
if (i >= body.length) break;
|
|
845
|
+
var entryStart = i;
|
|
846
|
+
while (i < body.length && !/\s/.test(body[i])) i++;
|
|
847
|
+
var entryName = body.slice(entryStart, i);
|
|
848
|
+
while (i < body.length && /\s/.test(body[i])) i++;
|
|
849
|
+
if (i >= body.length) {
|
|
850
|
+
_writeTagged(socket, tag, "BAD SETMETADATA entry '" + entryName + "' missing value");
|
|
851
|
+
return;
|
|
852
|
+
}
|
|
853
|
+
var valStart = i;
|
|
854
|
+
var value;
|
|
855
|
+
if (body[i] === '"') {
|
|
856
|
+
i++;
|
|
857
|
+
var v = "";
|
|
858
|
+
while (i < body.length && body[i] !== '"') {
|
|
859
|
+
if (body[i] === "\\" && i + 1 < body.length) { v += body[i + 1]; i += 2; }
|
|
860
|
+
else { v += body[i]; i++; }
|
|
861
|
+
}
|
|
862
|
+
if (body[i] !== '"') {
|
|
863
|
+
_writeTagged(socket, tag, "BAD SETMETADATA unterminated quoted value");
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
i++;
|
|
867
|
+
value = v;
|
|
868
|
+
} else {
|
|
869
|
+
while (i < body.length && !/\s/.test(body[i])) i++;
|
|
870
|
+
var tok = body.slice(valStart, i);
|
|
871
|
+
value = tok.toUpperCase() === "NIL" ? null : tok;
|
|
872
|
+
}
|
|
873
|
+
entries.push({ entry: entryName, value: value });
|
|
874
|
+
}
|
|
875
|
+
if (entries.length === 0) {
|
|
876
|
+
_writeTagged(socket, tag, "BAD SETMETADATA empty entry list");
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
Promise.resolve()
|
|
880
|
+
.then(function () { return mailStore.setMetadata(state.actor, mailbox, entries); })
|
|
881
|
+
.then(function () { _writeTagged(socket, tag, "OK SETMETADATA completed"); })
|
|
882
|
+
.catch(function (err) {
|
|
883
|
+
_writeTagged(socket, tag, "NO " + ((err && err.message) || "SETMETADATA failed").slice(0, ERR_CLAMP));
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
|
|
684
887
|
function _handleCapability(state, socket, tag) {
|
|
685
888
|
_writeUntagged(socket, "CAPABILITY " + _capabilityLine(state));
|
|
686
889
|
_writeTagged(socket, tag, "OK CAPABILITY completed");
|
|
@@ -1053,6 +1256,112 @@ function create(opts) {
|
|
|
1053
1256
|
|
|
1054
1257
|
function _handleAppend(state, socket, tag, args, literalBody) {
|
|
1055
1258
|
if (!_requireAuth(state, socket, tag)) return;
|
|
1259
|
+
// RFC 4469 CATENATE — `APPEND mailbox [(flags)] [date-time] CATENATE
|
|
1260
|
+
// (TEXT {literal} URL "imap://...")`. The CATENATE keyword turns the
|
|
1261
|
+
// command body into a list of parts the server stitches into a
|
|
1262
|
+
// single message; backends supply the `appendCatenate(actor,
|
|
1263
|
+
// mailbox, parts, opts) → meta` hook. Without CATENATE, fall
|
|
1264
|
+
// through to the bare APPEND path that already exists.
|
|
1265
|
+
var catenateMatch = args.match(/^(\S+|"[^"]+")(?:\s+\(([^)]*)\))?(?:\s+("[^"]+"))?\s+CATENATE\s+(.+)$/i); // allow:regex-no-length-cap — args length already capped upstream
|
|
1266
|
+
if (catenateMatch) {
|
|
1267
|
+
if (typeof mailStore.appendCatenate !== "function") {
|
|
1268
|
+
_writeTagged(socket, tag, "NO CATENATE backend not configured");
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
var catMailbox = _unquote(catenateMatch[1]);
|
|
1272
|
+
var catFlags = catenateMatch[2] ? catenateMatch[2].split(/\s+/).filter(Boolean) : [];
|
|
1273
|
+
var catDateArg = catenateMatch[3] ? _unquote(catenateMatch[3]) : null;
|
|
1274
|
+
var catInternalDate = null;
|
|
1275
|
+
if (catDateArg) {
|
|
1276
|
+
catInternalDate = _parseImapDateTime(catDateArg);
|
|
1277
|
+
if (catInternalDate === null) {
|
|
1278
|
+
_writeTagged(socket, tag, "BAD APPEND CATENATE date-time invalid");
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
if (!_validateMailboxName(catMailbox, { allowLegacyMUtf7: allowLegacyMUtf7 })) {
|
|
1283
|
+
_writeTagged(socket, tag, "BAD Mailbox name refused");
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
// Validate the parens are well-formed BEFORE we touch the
|
|
1287
|
+
// backend. The wire-format parts list MUST start with `(` and
|
|
1288
|
+
// end with `)`; a truncated list (e.g. `(TEXT {3}` arriving as
|
|
1289
|
+
// a single literal-completion before the rest of the parts
|
|
1290
|
+
// streams in) is refused. Order-preserving left-to-right token
|
|
1291
|
+
// walk replaces the prior URL-then-TEXT split — CATENATE
|
|
1292
|
+
// semantics depend on the SEQUENCE of parts.
|
|
1293
|
+
var partsBodyRaw = catenateMatch[4];
|
|
1294
|
+
if (partsBodyRaw[0] !== "(" || partsBodyRaw[partsBodyRaw.length - 1] !== ")") {
|
|
1295
|
+
_writeTagged(socket, tag, "BAD APPEND CATENATE parts list missing parens (RFC 4469 §3)");
|
|
1296
|
+
return;
|
|
1297
|
+
}
|
|
1298
|
+
var partsBody = partsBodyRaw.slice(1, -1);
|
|
1299
|
+
var parts = [];
|
|
1300
|
+
var hadTextPart = false;
|
|
1301
|
+
// Tokenise sequentially. Each part is one of:
|
|
1302
|
+
// URL "imap://..."
|
|
1303
|
+
// TEXT {<n>} (literal — multi-literal CATENATE deferred to a
|
|
1304
|
+
// later slice; defer-with-condition: refused
|
|
1305
|
+
// with NO until the multi-literal protocol path
|
|
1306
|
+
// lands).
|
|
1307
|
+
var pi = 0;
|
|
1308
|
+
while (pi < partsBody.length) {
|
|
1309
|
+
while (pi < partsBody.length && /\s/.test(partsBody[pi])) pi += 1;
|
|
1310
|
+
if (pi >= partsBody.length) break;
|
|
1311
|
+
if (/^URL\b/i.test(partsBody.slice(pi))) {
|
|
1312
|
+
pi += 3; // allow:raw-byte-literal — length of literal "URL" keyword
|
|
1313
|
+
while (pi < partsBody.length && /\s/.test(partsBody[pi])) pi += 1;
|
|
1314
|
+
if (partsBody[pi] !== "\"") {
|
|
1315
|
+
_writeTagged(socket, tag, "BAD APPEND CATENATE URL value must be quoted-string");
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1318
|
+
pi += 1;
|
|
1319
|
+
var urlStart = pi;
|
|
1320
|
+
while (pi < partsBody.length && partsBody[pi] !== "\"") pi += 1;
|
|
1321
|
+
if (partsBody[pi] !== "\"") {
|
|
1322
|
+
_writeTagged(socket, tag, "BAD APPEND CATENATE URL value unterminated quoted-string");
|
|
1323
|
+
return;
|
|
1324
|
+
}
|
|
1325
|
+
parts.push({ kind: "URL", url: partsBody.slice(urlStart, pi) });
|
|
1326
|
+
pi += 1;
|
|
1327
|
+
} else if (/^TEXT\b/i.test(partsBody.slice(pi))) {
|
|
1328
|
+
hadTextPart = true;
|
|
1329
|
+
break;
|
|
1330
|
+
} else {
|
|
1331
|
+
_writeTagged(socket, tag, "BAD APPEND CATENATE unknown part (RFC 4469 §3 only URL/TEXT)");
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
if (hadTextPart) {
|
|
1336
|
+
// Multi-literal CATENATE TEXT parts need a streaming-literal
|
|
1337
|
+
// protocol path the listener doesn't currently expose. RFC
|
|
1338
|
+
// 4469 §3 explicitly permits servers to refuse parts they
|
|
1339
|
+
// can't honour; refusing is correct (better than reordering
|
|
1340
|
+
// and corrupting the message body the client requested).
|
|
1341
|
+
_writeTagged(socket, tag, "NO CATENATE TEXT-literal parts not yet implemented; use APPEND with a single literal");
|
|
1342
|
+
return;
|
|
1343
|
+
}
|
|
1344
|
+
if (parts.length === 0) {
|
|
1345
|
+
_writeTagged(socket, tag, "BAD APPEND CATENATE empty parts list");
|
|
1346
|
+
return;
|
|
1347
|
+
}
|
|
1348
|
+
Promise.resolve()
|
|
1349
|
+
.then(function () {
|
|
1350
|
+
return mailStore.appendCatenate(catMailbox, parts, {
|
|
1351
|
+
actor: state.actor, flags: catFlags, internalDate: catInternalDate });
|
|
1352
|
+
})
|
|
1353
|
+
.then(function (meta) {
|
|
1354
|
+
var ok = "OK APPEND completed";
|
|
1355
|
+
if (meta && meta.uid && meta.uidValidity) {
|
|
1356
|
+
ok = "OK [APPENDUID " + meta.uidValidity + " " + meta.uid + "] APPEND completed";
|
|
1357
|
+
}
|
|
1358
|
+
_writeTagged(socket, tag, ok);
|
|
1359
|
+
})
|
|
1360
|
+
.catch(function (err) {
|
|
1361
|
+
_writeTagged(socket, tag, "NO " + ((err && err.message) || "CATENATE failed").slice(0, ERR_CLAMP));
|
|
1362
|
+
});
|
|
1363
|
+
return;
|
|
1364
|
+
}
|
|
1056
1365
|
if (!literalBody) {
|
|
1057
1366
|
_writeTagged(socket, tag, "BAD APPEND requires a literal {N} message");
|
|
1058
1367
|
return;
|
|
@@ -54,6 +54,10 @@ var IMAP_VERBS = Object.freeze({
|
|
|
54
54
|
NAMESPACE: 1, STATUS: 1, APPEND: 1, IDLE: 1, CHECK: 1, CLOSE: 1,
|
|
55
55
|
UNSELECT: 1, EXPUNGE: 1, SEARCH: 1, FETCH: 1, STORE: 1, COPY: 1,
|
|
56
56
|
MOVE: 1, UID: 1, DONE: 1,
|
|
57
|
+
// v0.11.28 — RFC 5465 NOTIFY / RFC 5464 METADATA / RFC 4469 CATENATE.
|
|
58
|
+
// CATENATE is an APPEND modifier and stays under APPEND in dispatch;
|
|
59
|
+
// METADATA gets GETMETADATA + SETMETADATA verbs.
|
|
60
|
+
NOTIFY: 1, GETMETADATA: 1, SETMETADATA: 1,
|
|
57
61
|
});
|
|
58
62
|
|
|
59
63
|
var MANAGESIEVE_VERBS = Object.freeze({
|
package/package.json
CHANGED
package/sbom.cdx.json
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
|
|
3
3
|
"bomFormat": "CycloneDX",
|
|
4
4
|
"specVersion": "1.5",
|
|
5
|
-
"serialNumber": "urn:uuid:
|
|
5
|
+
"serialNumber": "urn:uuid:e497b463-3374-4f8a-84c2-9686c0567a23",
|
|
6
6
|
"version": 1,
|
|
7
7
|
"metadata": {
|
|
8
|
-
"timestamp": "2026-05-
|
|
8
|
+
"timestamp": "2026-05-21T14:49:20.894Z",
|
|
9
9
|
"lifecycles": [
|
|
10
10
|
{
|
|
11
11
|
"phase": "build"
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
}
|
|
20
20
|
],
|
|
21
21
|
"component": {
|
|
22
|
-
"bom-ref": "@blamejs/core@0.11.
|
|
22
|
+
"bom-ref": "@blamejs/core@0.11.28",
|
|
23
23
|
"type": "application",
|
|
24
24
|
"name": "blamejs",
|
|
25
|
-
"version": "0.11.
|
|
25
|
+
"version": "0.11.28",
|
|
26
26
|
"scope": "required",
|
|
27
27
|
"author": "blamejs contributors",
|
|
28
28
|
"description": "The Node framework that owns its stack.",
|
|
29
|
-
"purl": "pkg:npm/%40blamejs/core@0.11.
|
|
29
|
+
"purl": "pkg:npm/%40blamejs/core@0.11.28",
|
|
30
30
|
"properties": [],
|
|
31
31
|
"externalReferences": [
|
|
32
32
|
{
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"components": [],
|
|
55
55
|
"dependencies": [
|
|
56
56
|
{
|
|
57
|
-
"ref": "@blamejs/core@0.11.
|
|
57
|
+
"ref": "@blamejs/core@0.11.28",
|
|
58
58
|
"dependsOn": []
|
|
59
59
|
}
|
|
60
60
|
]
|