imapkit 5.0.0 → 5.0.1
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 +33 -29
- package/bin/help.txt +3 -2
- package/bin/imapkit.js +15 -5
- package/dist/cjs/commands/handlers/fetch.js +2 -1
- package/dist/cjs/commands/handlers/store.js +4 -4
- package/dist/cjs/commands/list.js +17 -3
- package/dist/cjs/control.d.ts +4 -9
- package/dist/cjs/control.js +1 -1
- package/dist/cjs/dates.d.ts +9 -1
- package/dist/cjs/dates.js +20 -0
- package/dist/cjs/envelope.d.ts +1 -1
- package/dist/cjs/envelope.js +26 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/load-plugins.d.ts +3 -1
- package/dist/cjs/load-plugins.js +25 -6
- package/dist/cjs/plugins/binary.js +2 -1
- package/dist/cjs/plugins/context-search.js +2 -2
- package/dist/cjs/plugins/create-special-use.d.ts +0 -5
- package/dist/cjs/plugins/create-special-use.js +11 -1
- package/dist/cjs/plugins/imap4rev2.js +5 -0
- package/dist/cjs/plugins/metadata-server.d.ts +6 -2
- package/dist/cjs/plugins/metadata-server.js +3 -1
- package/dist/cjs/plugins/metadata.d.ts +5 -1
- package/dist/cjs/plugins/metadata.js +3 -0
- package/dist/cjs/quirks.d.ts +2 -2
- package/dist/cjs/quirks.js +5 -4
- package/dist/cjs/rest.d.ts +7 -3
- package/dist/cjs/rest.js +11 -5
- package/dist/cjs/server.d.ts +54 -3
- package/dist/cjs/server.js +210 -88
- package/dist/cjs/storage-schema.js +12 -5
- package/dist/cjs/store-operations.d.ts +5 -2
- package/dist/cjs/store-operations.js +6 -3
- package/dist/cjs/types.d.ts +4 -0
- package/dist/esm/commands/handlers/fetch.js +2 -1
- package/dist/esm/commands/handlers/store.js +4 -4
- package/dist/esm/commands/list.js +17 -3
- package/dist/esm/control.d.ts +4 -9
- package/dist/esm/control.js +1 -1
- package/dist/esm/dates.d.ts +9 -1
- package/dist/esm/dates.js +20 -1
- package/dist/esm/envelope.d.ts +1 -1
- package/dist/esm/envelope.js +26 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/load-plugins.d.ts +3 -1
- package/dist/esm/load-plugins.js +25 -6
- package/dist/esm/plugins/binary.js +2 -1
- package/dist/esm/plugins/context-search.js +2 -2
- package/dist/esm/plugins/create-special-use.d.ts +0 -5
- package/dist/esm/plugins/create-special-use.js +8 -1
- package/dist/esm/plugins/imap4rev2.js +5 -0
- package/dist/esm/plugins/metadata-server.d.ts +6 -2
- package/dist/esm/plugins/metadata-server.js +3 -1
- package/dist/esm/plugins/metadata.d.ts +5 -1
- package/dist/esm/plugins/metadata.js +3 -0
- package/dist/esm/quirks.d.ts +2 -2
- package/dist/esm/quirks.js +5 -4
- package/dist/esm/rest.d.ts +7 -3
- package/dist/esm/rest.js +11 -5
- package/dist/esm/server.d.ts +54 -3
- package/dist/esm/server.js +212 -90
- package/dist/esm/storage-schema.js +12 -5
- package/dist/esm/store-operations.d.ts +5 -2
- package/dist/esm/store-operations.js +6 -3
- package/dist/esm/types.d.ts +4 -0
- package/dist/plugin-help.json +3 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -71,7 +71,7 @@ ImapKit is extendable: any command can be overridden and plugins can be added (s
|
|
|
71
71
|
|
|
72
72
|
ImapKit is meant for developing standards compliant IMAP clients, so it follows the RFCs strictly instead of accepting whatever clients send. Most production servers are lenient, which hides client bugs until the client meets a stricter server. ImapKit answers these with `BAD` (or `NO` where the RFC requires it):
|
|
73
73
|
|
|
74
|
-
- commands sent in the wrong state (RFC 3501 section 3), for example `FETCH` before `SELECT` or `LOGIN` after login
|
|
74
|
+
- commands sent in the wrong state (RFC 3501 section 3), for example `FETCH` before `SELECT` or `LOGIN` and `AUTHENTICATE` (with any mechanism, known or not) after login
|
|
75
75
|
- arguments to commands that take none (`NOOP x`, `CLOSE x`), missing or extra arguments, and values that break the RFC 3501 grammar
|
|
76
76
|
- command lines that end with a bare LF instead of CRLF
|
|
77
77
|
- literal data sent before the server's `+` continuation request (RFC 3501 section 4.3); `{n+}` is only accepted when LITERAL+ or LITERAL- is enabled, and with LITERAL- only up to 4096 octets, a larger one is answered with `BAD [TOOBIG]` (RFC 7888 section 5)
|
|
@@ -89,6 +89,7 @@ ImapKit is meant for developing standards compliant IMAP clients, so it follows
|
|
|
89
89
|
- the QRESYNC `SELECT` parameter or the `VANISHED` modifier without `ENABLE QRESYNC`, `VANISHED` with `FETCH` or without `CHANGEDSINCE`, and QRESYNC values that break the RFC 7162 grammar (UIDVALIDITY or mod-sequence `0`, `*` in the UID sets, sequence match sets that are not ascending or not of the same size)
|
|
90
90
|
- unknown `SEARCH RETURN` options or `RETURN` after `CHARSET` (RFC 4466 section 2.6.1), `$` combined with numbers, and `SEARCH MODSEQ` values or entry names that break the RFC 7162 grammar
|
|
91
91
|
- extended LIST commands (RFC 5258) with unknown options, `RECURSIVEMATCH` without a base option like `SUBSCRIBED` (also `(SPECIAL-USE RECURSIVEMATCH)`, RFC 6154 section 6), an empty pattern list, options with values they do not take, a repeated `STATUS` return option with different items, and invalid `STATUS` items (RFC 5819)
|
|
92
|
+
- `CREATE ... (USE (...))` (CREATE-SPECIAL-USE) with entries that are not an atom starting with a backslash, like `NIL`, quoted strings or `Sent` (RFC 6154 section 6: `use-attr-ext = "\" atom`); an attribute the server does not support gets `NO [USEATTR]` (section 3)
|
|
92
93
|
- METADATA entry names that break RFC 5464 section 3.2 (`//`, a trailing `/`, `*`, `%`, 8-bit or control characters, a scope other than `/private` or `/shared`), values that are atoms or use bare CR or LF as line ends, empty entry or option lists, and GETMETADATA options after the mailbox name (errata 2785)
|
|
93
94
|
- unknown or uppercase ACL rights, and empty identifiers or identifiers with control characters or invalid UTF-8 (RFC 4314 section 3)
|
|
94
95
|
- more than one message in `APPEND` without MULTIAPPEND, and with MULTIAPPEND a zero-length message literal cancels the whole `APPEND` with `NO` (RFC 3502)
|
|
@@ -101,7 +102,7 @@ ImapKit is meant for developing standards compliant IMAP clients, so it follows
|
|
|
101
102
|
- with NOTIFY (RFC 5465): MessageNew without MessageExpunge or the other way round, FlagChange without both (section 5), mailbox events or two selected filters with `selected`/`selected-delayed` (section 6.1), fetch attributes outside the selected filters, empty event or mailbox lists, `NOTIFY SET` without event groups; unknown events get `NO [BADEVENT (...)]` listing the supported ones (section 3.1)
|
|
102
103
|
- after `ENABLE IMAP4rev2` (RFC 9051): `CHECK`, `LSUB`, the `RFC822`, `RFC822.HEADER` and `RFC822.TEXT` FETCH items, the `NEW`, `OLD` and `RECENT` SEARCH keys and the `RECENT` STATUS item, none of which are in the RFC 9051 grammar (Appendix E), numbers above 63 bits in LARGER and SMALLER, and invalid UTF-8 or mailbox names that are not Net-Unicode (section 5.1); before it, 8-bit quoted strings (Appendix A) and partial ranges, LARGER and SMALLER values above 32 bits (RFC 3501 section 9 number)
|
|
103
104
|
|
|
104
|
-
Responses follow the grammar strictly too: strings that can not be quoted are sent as literals. Failures carry the RFC 5530 response codes that RFC 9051 section 7.1 lists, in both protocol revisions: `AUTHENTICATIONFAILED` and `AUTHORIZATIONFAILED` for logins, `ALREADYEXISTS`, `NONEXISTENT`, `CANNOT`, `HASCHILDREN` and `NOPERM` for mailbox operations, `TRYCREATE` when the target of APPEND, COPY or MOVE does not exist or is a `\Noselect` name, `CLIENTBUG` for `STATUS` on the selected mailbox and for `STORE`, `EXPUNGE`, `UID EXPUNGE`, `MOVE` and `REPLACE` in a mailbox selected read-only, and `EXPUNGEISSUED` when FETCH, STORE, SEARCH, SORT or THREAD completes while the EXPUNGE of another session can not be reported yet.
|
|
105
|
+
Responses follow the grammar strictly too: strings that can not be quoted are sent as literals. Failures carry the RFC 5530 response codes that RFC 9051 section 7.1 lists, in both protocol revisions: `AUTHENTICATIONFAILED` and `AUTHORIZATIONFAILED` for logins, `ALREADYEXISTS`, `NONEXISTENT`, `CANNOT`, `HASCHILDREN` and `NOPERM` for mailbox operations, `TRYCREATE` when the target of APPEND, COPY or MOVE does not exist or is a `\Noselect` name, `CLIENTBUG` for `STATUS` on the selected mailbox and for `STORE`, `EXPUNGE`, `UID EXPUNGE`, `MOVE` and `REPLACE` in a mailbox selected read-only, and `EXPUNGEISSUED` when FETCH, STORE, SEARCH, SORT or THREAD (or UID SEARCH, UID SORT or UID THREAD with message numbers in the criteria) completes while the EXPUNGE of another session can not be reported yet.
|
|
105
106
|
|
|
106
107
|
Some client side recommendations of RFC 2683 are checked too: `STATUS` on the selected mailbox gets `CLIENTBUG` (section 3.1.1), mailbox names must be valid modified UTF-7 (section 3.4.2), and EXPUNGE or STORE after EXAMINE, which answered `[READ-ONLY]`, get `NO` (section 3.3.2). Command lines are not limited to the 1000 octets that section 3.2.1.5 suggests for clients, the server accepts up to 1 MiB (the section asks servers for at least 8000 octets) and answers a longer line with `BAD`.
|
|
107
108
|
|
|
@@ -112,7 +113,9 @@ ImapKit follows these of the strategies that RFC 2180 (IMAP4 Multi-Accessed Mail
|
|
|
112
113
|
- a session that has not been told about the EXPUNGE of another session yet keeps its message numbers. FETCH still returns the expunged messages (section 4.1.1) and SEARCH still finds them (section 4.3), both end with `OK [EXPUNGEISSUED]`
|
|
113
114
|
- STORE does not change expunged messages: with `.SILENT` it ends with `OK` (section 4.2.1), otherwise the other messages are stored and get their FETCH responses, and the tagged response is `NO [EXPUNGEISSUED]` (sections 4.2.2 and 4.2.3; with CONDSTORE `NO [MODIFIED ...]` when that applies, RFC 7162 section 3.1.3)
|
|
114
115
|
- COPY and MOVE of a set that includes an expunged message copy nothing and return the pending EXPUNGE responses with `NO [EXPUNGEISSUED]` (section 4.4.1)
|
|
115
|
-
- UID commands report the pending EXPUNGE responses before they run (RFC 3501 section 7.4.1), the UIDs of the expunged messages then no longer exist and are ignored (RFC 3501 section 6.4.8). UID SEARCH with message numbers in its criteria still uses the old numbers
|
|
116
|
+
- UID commands report the pending EXPUNGE responses before they run (RFC 3501 section 7.4.1), the UIDs of the expunged messages then no longer exist and are ignored (RFC 3501 section 6.4.8). UID SEARCH (UID SORT, UID THREAD) with message numbers in its criteria still uses the old numbers and ends with `OK [EXPUNGEISSUED]`
|
|
117
|
+
- a command that refers to messages (FETCH, STORE, SEARCH, COPY, MOVE, SORT, THREAD and the UID commands) first reports the new messages (EXISTS) and flag changes of other sessions, so every message number in its responses is one the client was told about (RFC 3501 section 5.2: "A server MUST send mailbox size updates automatically if a mailbox size change is observed during the processing of a command"). While an EXPUNGE is pending, only what was queued before it goes out, a message that arrived after it is announced after the EXPUNGE, and until then its number is answered with BAD (RFC 3501 section 9, seq-number)
|
|
118
|
+
- the EXISTS responses of new messages are followed by `* n RECENT` with the number of `\Recent` messages of the session (RFC 3501 section 7.3.2), also for its own APPEND, COPY and MOVE into the selected mailbox, but not after `ENABLE IMAP4rev2`
|
|
116
119
|
- DELETE of a mailbox that other sessions have selected disconnects them with `* BYE` (section 3.3)
|
|
117
120
|
- RENAME keeps the messages of the mailbox under the new name, sessions that have it selected keep working, the old name no longer exists (section 3.4)
|
|
118
121
|
- a session that ends without LOGOUT or CLOSE does not expunge anything (RFC 2683 section 3.1.2), and there is no inactivity timeout
|
|
@@ -130,7 +133,8 @@ All RFC 3501 commands are supported. Some choices that the RFCs leave to the ser
|
|
|
130
133
|
- The subscription list holds names, not mailboxes (RFC 3501 section 6.3.6). DELETE does not unsubscribe, so LSUB and `LIST (SUBSCRIBED)` keep listing the name (as `\NonExistent` in extended LIST) until UNSUBSCRIBE, and a mailbox created again under that name is subscribed. RENAME leaves the subscription with the old name (RFC 9051 section 6.3.6). A mailbox from the storage object is subscribed unless it has `"subscribed": false`, a new mailbox is not. SUBSCRIBE refuses names that are not mailboxes, UNSUBSCRIBE accepts any name
|
|
131
134
|
- CREATE `a/b` also creates `a` as a normal mailbox if it does not exist (RFC 3501 section 6.3.3, Dovecot creates a `\Noselect` level instead). An existing `\Noselect` level stays `\Noselect`
|
|
132
135
|
- DELETE of a mailbox with children leaves a `\Noselect` level that keeps nothing but the children, CREATE of that name makes a new mailbox with a new UIDVALIDITY
|
|
133
|
-
- A keyword stays in the FLAGS and PERMANENTFLAGS of a mailbox once a message in it had the keyword, also after that message is expunged (RFC 3501 section 7.2.6, like Dovecot)
|
|
136
|
+
- A keyword stays in the FLAGS and PERMANENTFLAGS of a mailbox once a message in it had the keyword, also after that message is expunged (RFC 3501 section 7.2.6, like Dovecot). In a mailbox with `"allowPermanentFlags": false` STORE accepts exactly the flags PERMANENTFLAGS lists (`permanentFlags` and the flags its messages have or had) and ignores the others, APPEND and COPY leave them out (RFC 3501 section 7.1)
|
|
137
|
+
- An obsolete source route in an address (`<@route.example:a@b.c>`, RFC 5322 section 4.4) goes to the at-domain-list field of the ENVELOPE address (`(NIL "@route.example" "a" "b.c")`), the mailbox name is the local part only (RFC 9051 section 7.5.2), like Dovecot sends it
|
|
134
138
|
|
|
135
139
|
### Supported Plugins
|
|
136
140
|
|
|
@@ -162,13 +166,13 @@ An unknown plugin name throws an error, and a plugin listed more than once is lo
|
|
|
162
166
|
- **LITERALPLUS** Enables LITERAL+ [RFC7888] capability. Can not be loaded together with LITERALMINUS, but replaces the LITERAL- that IMAP4rev2 loads
|
|
163
167
|
- **LOGINDISABLED** Disables LOGIN support for unencrypted connections
|
|
164
168
|
- **MESSAGELIMIT** Adds MESSAGELIMIT [RFC9738] capability, advertised as `MESSAGELIMIT=<n>`, where the server option `messageLimit` sets n (default 1000, any positive number is accepted so that small test mailboxes can hit it). FETCH, STORE, SEARCH, MOVE, UID EXPUNGE and their UID variants only work on the n messages with the highest UIDs (UID EXPUNGE counts the `\Deleted` ones) and add `[MESSAGELIMIT n uid]` with the lowest processed UID to the tagged OK, or send it in an untagged `NO` when the tagged OK already has a response code (like `HIGHESTMODSEQ` or `MODIFIED`). SEARCH counts the searched messages, which its top level sequence set, `UID`, `UIDAFTER` and `UIDBEFORE` keys narrow down. COPY, APPEND (MULTIAPPEND), SORT and THREAD of more messages, and a FETCH `PARTIAL` range (PARTIAL plugin) of more messages, fail with `NO [MESSAGELIMIT ...]`. EXPUNGE, CLOSE and STATUS are not limited. Adds the `UIDAFTER` and `UIDBEFORE` search keys. Can not be loaded together with SAVELIMIT
|
|
165
|
-
- **METADATA** Adds METADATA [RFC5464] capability (GETMETADATA and SETMETADATA) for server and mailbox annotations. Values can be binary: SETMETADATA takes a literal8 (`~{n}`), and values with NUL are sent back as a literal8. Initial mailbox entries come from a `metadata` object on the mailbox in storage (`"INBOX": { "metadata": { "/private/comment": "My comment" } }`), server entries from the `metadata` option. Server options `metadataMaxSize` (largest value in octets, default 65536), `metadataMaxEntries` (entries per mailbox and for the server, default 100) and `metadataPrivate: false` (refuse `/private` entries with `[METADATA NOPRIVATE]`) let you test the client's error handling. `/shared/admin` on the server is read-only. Annotations move with RENAME (renaming INBOX copies them), DELETE removes them. After `ENABLE METADATA` (needs the ENABLE plugin), changes made by other sessions are announced with unsolicited `METADATA` responses. With SPECIAL-USE loaded, the read-only `/private/specialuse` entry shows the special-use attributes of a mailbox (RFC 6154 section 4)
|
|
169
|
+
- **METADATA** Adds METADATA [RFC5464] capability (GETMETADATA and SETMETADATA) for server and mailbox annotations, and loads ENABLE, which RFC 5464 section 4.1 requires for unsolicited METADATA responses. Values can be binary: SETMETADATA takes a literal8 (`~{n}`), and values with NUL are sent back as a literal8. Initial mailbox entries come from a `metadata` object on the mailbox in storage (`"INBOX": { "metadata": { "/private/comment": "My comment" } }`), server entries from the `metadata` option. Server options `metadataMaxSize` (largest value in octets, default 65536), `metadataMaxEntries` (entries per mailbox and for the server, default 100) and `metadataPrivate: false` (refuse `/private` entries with `[METADATA NOPRIVATE]`) let you test the client's error handling. `/shared/admin` on the server is read-only. Annotations move with RENAME (renaming INBOX copies them), DELETE removes them. After `ENABLE METADATA` (needs the ENABLE plugin), changes made by other sessions are announced with unsolicited `METADATA` responses. With SPECIAL-USE loaded, the read-only `/private/specialuse` entry shows the special-use attributes of a mailbox (RFC 6154 section 4)
|
|
166
170
|
- **MULTISEARCH** Adds MULTISEARCH [RFC7377] capability, also loads ESEARCH: the ESEARCH command, also in the authenticated state. `ESEARCH IN (mailboxes "a" subtree "b" subtree-one "c" personal subscribed inboxes selected) RETURN (...) criteria` sends one ESEARCH response with UIDs and the `TAG`, `MAILBOX` and `UIDVALIDITY` correlators for every mailbox with matches. Mailboxes that do not exist or are `\Noselect` are skipped (with ACL also those without the `r` right, and without `l` unless named under `mailboxes` or as a subtree root), a mailbox named twice is searched once, and `inboxes` is INBOX. `SAVE` is only allowed when the selected mailbox is the only one searched, `UPDATE` (with CONTEXT=SEARCH) only applies to the selected mailbox
|
|
167
|
-
- **METADATA-SERVER** Same as METADATA, but only for server annotations (mailbox name `""`)
|
|
171
|
+
- **METADATA-SERVER** Same as METADATA (also loads ENABLE), but only for server annotations (mailbox name `""`)
|
|
168
172
|
- **MOVE** Adds MOVE [RFC6851] capability (MOVE and UID MOVE commands)
|
|
169
173
|
- **MULTIAPPEND** Adds MULTIAPPEND [RFC3502] capability. APPEND takes several messages and appends all or none of them. With UIDPLUS, APPENDUID lists the UIDs as a UID set
|
|
170
174
|
- **NAMESPACE** Adds NAMESPACE [RFC2342] capability
|
|
171
|
-
- **NOTIFY** Adds NOTIFY [RFC5465] capability: `NOTIFY SET [STATUS] (filter events) ...` and `NOTIFY NONE` with the `selected`, `selected-delayed`, `inboxes` (same as `personal`), `personal`, `subscribed`, `subtree` and `mailboxes` filters and the MessageNew (with fetch attributes for the selected mailbox), MessageExpunge, FlagChange, MailboxName (LIST with `OLDNAME` for RENAME) and SubscriptionChange events, plus MailboxMetadataChange and ServerMetadataChange with METADATA. Events are sent as soon as they happen, also between commands,
|
|
175
|
+
- **NOTIFY** Adds NOTIFY [RFC5465] capability: `NOTIFY SET [STATUS] (filter events) ...` and `NOTIFY NONE` with the `selected`, `selected-delayed`, `inboxes` (same as `personal`), `personal`, `subscribed`, `subtree` and `mailboxes` filters and the MessageNew (with fetch attributes for the selected mailbox), MessageExpunge, FlagChange, MailboxName (LIST with `OLDNAME` for RENAME) and SubscriptionChange events, plus MailboxMetadataChange and ServerMetadataChange with METADATA. Events are sent as soon as they happen, also between commands, while a command runs they wait for its tagged response, and EXPUNGE (or VANISHED) waits longer with `selected-delayed` and during FETCH, STORE and SEARCH. For a new message in the selected mailbox an IMAP4rev1 session gets EXISTS, the requested FETCH and then RECENT. After the first NOTIFY a session only hears about the events it asked for, also for the selected mailbox; changes made by the session itself are not reported. Other mailboxes are reported with STATUS (UNSEEN when the `\Seen` count changed, HIGHESTMODSEQ when CONDSTORE is enabled), with ACL only mailboxes with the `l` and `r` rights, and granting or revoking `l` counts as MailboxName. Fetch attributes never set `\Seen`. `server.notifyOverflow([connection])` sends `* OK [NOTIFICATIONOVERFLOW]` and turns NOTIFY off. AnnotationChange (no ANNOTATE support) is refused with `NO [BADEVENT]`, the fetch attributes of the CONTEXT=SEARCH `UPDATE` option (RFC 5465 section 7) are not supported
|
|
172
176
|
- **OAUTHBEARER** Adds AUTH=OAUTHBEARER [RFC7628] capability, with or without SASL-IR. Uses the same credentials as XOAUTH2: access token `"testtoken"`, the authzid in the GS2 header (`n,a=testuser,`) is optional. A failed login gets the JSON error result as a continuation request (`invalid_token` or `invalid_request`), the client must answer it with `AQ==` (a single `%x01`)
|
|
173
177
|
- **OBJECTID** Adds OBJECTID [RFC8474] capability: `MAILBOXID` for CREATE, SELECT, EXAMINE and STATUS, `EMAILID` and `THREADID` for FETCH and SEARCH. Ids are generated (`F1`, `M1`, `T1`, ...) unless the storage sets a `MAILBOXID` for a mailbox or an `EMAILID` / `THREADID` for a message. COPY, MOVE and RENAME INBOX keep the EMAILID and THREADID of a message. Messages are threaded by their `Message-ID`, `In-Reply-To` and `References` headers across all mailboxes, a message joins the thread of the nearest known parent when it is added
|
|
174
178
|
- **PARTIAL** Adds PARTIAL [RFC9394] capability, also loads ESEARCH: the `PARTIAL` result option of SEARCH (`RETURN (PARTIAL 1:100)`, `RETURN (PARTIAL -1:-100)` counts from the last result) and of SORT with ESORT, and the `PARTIAL` modifier of FETCH and UID FETCH (`UID FETCH 1:* (FLAGS) (PARTIAL -1:-50)`), which combines with CHANGEDSINCE. With PARTIAL loaded a command takes only one PARTIAL or ALL result option
|
|
@@ -178,7 +182,7 @@ An unknown plugin name throws an error, and a plugin listed more than once is lo
|
|
|
178
182
|
- **SASL-IR** Enables SASL-IR [RFC4959] capability
|
|
179
183
|
- **QRESYNC** Adds QRESYNC [RFC7162] capability, also loads CONDSTORE and ENABLE. After `ENABLE QRESYNC`: `SELECT`/`EXAMINE` with `(QRESYNC (uidvalidity modseq [known-uids] [seq-match-data]))` reports `VANISHED (EARLIER)` and the changed flags, `UID FETCH ... (CHANGEDSINCE n VANISHED)` works, and expunges (EXPUNGE, UID EXPUNGE, MOVE, other sessions, IDLE) are reported with `VANISHED` instead of `EXPUNGE`. Expunged UIDs are remembered with their mod-sequence; UIDs missing from the initial storage count as expunged before the server started
|
|
180
184
|
- **SAVELIMIT** Adds SAVELIMIT [RFC9738] capability, advertised as `SAVELIMIT=<n>` (server option `messageLimit`, default 1000): only COPY and APPEND (MULTIAPPEND) of more messages fail with `NO [MESSAGELIMIT ...]`. Can not be loaded together with MESSAGELIMIT
|
|
181
|
-
- **SAVEDATE** Adds SAVEDATE [RFC8514] capability: the `SAVEDATE` FETCH item and the `SAVEDBEFORE`, `SAVEDON`, `SAVEDSINCE` and `SAVEDATESUPPORTED` SEARCH keys. APPEND, COPY and MOVE set the save date to the current time, messages in storage can set it with a `SAVEDATE` value (a date-time string or a Date) and get the time the
|
|
185
|
+
- **SAVEDATE** Adds SAVEDATE [RFC8514] capability: the `SAVEDATE` FETCH item and the `SAVEDBEFORE`, `SAVEDON`, `SAVEDSINCE` and `SAVEDATESUPPORTED` SEARCH keys. APPEND, COPY and MOVE set the save date to the current time, messages in storage can set it with a `SAVEDATE` value (a date-time string or a Date) and get the the time the storage was loaded otherwise (the current time, or the `now` option). A mailbox with `"SAVEDATE": false` in storage does not support save dates: FETCH returns NIL and the SEARCH keys use the internal date
|
|
182
186
|
- **SEARCHRES** Adds SEARCHRES [RFC5182] capability, also loads ESEARCH: `SEARCH RETURN (SAVE)` stores the result and `$` refers to it in FETCH, STORE, COPY, MOVE, UID EXPUNGE, SEARCH and their UID variants. `$` must be used alone, not combined with numbers like `1,$`
|
|
183
187
|
- **SORT** Adds SORT [RFC5256] capability (SORT and UID SORT with all RFC 5256 sort keys). Strings are compared with the i;unicode-casemap collation (RFC 5051), base subjects follow RFC 5256 section 2.1 and sent dates section 2.2. With CONDSTORE, a MODSEQ search key appends the highest mod-sequence (RFC 7162 section 3.1.9). I18NLEVEL=1 is not advertised, as SEARCH matches strings with ASCII case folding only
|
|
184
188
|
- **SORT=DISPLAY** Adds SORT=DISPLAY [RFC5957] capability (DISPLAYFROM and DISPLAYTO sort keys), also loads SORT
|
|
@@ -255,9 +259,8 @@ The XTOYBIRD commands map to the [control API](#control-api):
|
|
|
255
259
|
|
|
256
260
|
# Known issues
|
|
257
261
|
|
|
258
|
-
- **addr-adl** (at-domain-list) values are not supported, NIL is always used
|
|
259
262
|
- **anonymous namespaces** are not supported
|
|
260
|
-
- **LIST** does not insert a hierarchy delimiter between a reference without one and the mailbox name (RFC 2683 section 3.4.9 recommends it), the two are concatenated as RFC 9051 section 6.3.9 describes, like Dovecot does
|
|
263
|
+
- **LIST** does not insert a hierarchy delimiter between a reference without one and the mailbox name (RFC 2683 section 3.4.9 recommends it), the two are concatenated as RFC 9051 section 6.3.9 describes, like Dovecot does. A pattern that starts with the `#` break out character ignores the reference
|
|
261
264
|
- **CHARSET** values other than US-ASCII and UTF-8 are not supported
|
|
262
265
|
|
|
263
266
|
# Running tests
|
|
@@ -376,7 +379,7 @@ describe('IMAP tests', () => {
|
|
|
376
379
|
|
|
377
380
|
## Control API
|
|
378
381
|
|
|
379
|
-
`server.control` changes and inspects the server from your test, without an IMAP session. Every change reaches the connected sessions the way a change by another session would: a selected session gets `EXISTS` for a new message, `EXPUNGE` (or `VANISHED` after `ENABLE QRESYNC`) for a removed one, an unsolicited `FETCH` with the UID and the new flags (with `MODSEQ` after `ENABLE CONDSTORE`), and `BYE` when its mailbox is deleted. NOTIFY and CONTEXT=SEARCH sessions get their updates too. ACL does not apply to the control API, but every argument is checked.
|
|
382
|
+
`server.control` changes and inspects the server from your test, without an IMAP session. Every change reaches the connected sessions the way a change by another session would: a selected session gets `EXISTS` (and `RECENT` in IMAP4rev1) for a new message, `EXPUNGE` (or `VANISHED` after `ENABLE QRESYNC`) for a removed one, an unsolicited `FETCH` with the UID and the new flags (with `MODSEQ` after `ENABLE CONDSTORE`), and `BYE` when its mailbox is deleted. NOTIFY and CONTEXT=SEARCH sessions get their updates too. ACL does not apply to the control API, but every argument is checked.
|
|
380
383
|
|
|
381
384
|
```javascript
|
|
382
385
|
const server = imapkit({ plugins: ['IDLE', 'CONDSTORE'] });
|
|
@@ -405,10 +408,10 @@ Mailboxes are addressed by their storage name (modified UTF-7, the name a client
|
|
|
405
408
|
| `createMailbox(path, { subscribed })`, `deleteMailbox(path)`, `renameMailbox(path, newPath)` | Like CREATE, DELETE and RENAME |
|
|
406
409
|
| `resetUidValidity(path, { uidvalidity, uids, offset, seed })` | Gives the mailbox a new, greater UIDVALIDITY. `uids` is `keep` (default), `renumber` (1 to n), `shuffle` (1 to n in a random order, repeatable with `seed`, so an old UID points to another message) or `offset` (every UID moves above the old UIDNEXT, plus `offset`, so old UIDs find nothing). A UID must not change during a session (RFC 9051 section 2.3.1.1), so sessions that have the mailbox selected get `BYE`. Returns `{ uidvalidity, uidnext, uids: [{ uid, newUid }] }` |
|
|
407
410
|
| `subscribe(path)`, `unsubscribe(path)` | Return true if the subscription changed |
|
|
408
|
-
| `listUsers()`, `addUser(name, { password, xoauth2 })`, `updateUser(name, {...})`, `deleteUser(name)` | `xoauth2` is `{ accessToken, sessionTimeout }
|
|
411
|
+
| `listUsers()`, `addUser(name, { password, xoauth2 })`, `updateUser(name, {...})`, `deleteUser(name)` | `xoauth2` is `{ accessToken, sessionTimeout }`, `sessionTimeout` is deprecated and ignored (access tokens do not expire). Deleting a user disconnects its sessions, `{ disconnect: false }` keeps them. No credentials in `listUsers()` |
|
|
409
412
|
| `disconnect(session or { user }, { text, reset })` | Disconnects sessions with an untagged `BYE`, or resets the TCP connection |
|
|
410
413
|
| `inject(session, data)` | Writes bytes to a session as they are, e.g. `* OK [ALERT] ...` between commands |
|
|
411
|
-
| `reset()` | Restores the mailboxes and users of the server options and disconnects every session with `BYE`, so a long running server can be reused between tests. Script rules stay
|
|
414
|
+
| `reset()` | Restores the mailboxes and users of the server options and disconnects every session with `BYE`, so a long running server can be reused between tests. Script rules stay, with their `hits` counts |
|
|
412
415
|
| `shutdown({ graceful })` | Stops accepting connections and resolves once the last client is gone, `graceful: false` closes the sessions |
|
|
413
416
|
|
|
414
417
|
Plugins add operations for their own data, they exist only when the plugin is loaded:
|
|
@@ -430,9 +433,10 @@ A plugin of your own adds operations with `server.control.register(name, fn, rou
|
|
|
430
433
|
Tests can wait for events instead of polling:
|
|
431
434
|
|
|
432
435
|
- `session`: `{ type, session }`, `type` is `open`, `login`, `select` (also when the same mailbox is selected again), `unselect` (CLOSE, UNSELECT, a failed SELECT, BYE), `logout` (UNAUTHENTICATE), `waiting` (a command waits for client input, with `command`, e.g. `IDLE` after its continuation) or `close`, `session` is the session as `sessions()` describes it.
|
|
433
|
-
- `command`: `{ session, tag, command, status, user }` when the tagged response of a command goes out, `status` is `OK`, `NO` or `BAD`.
|
|
436
|
+
- `command`: `{ session, tag, command, status, user }` when the tagged response of a command goes out, `status` is `OK`, `NO` or `BAD`. A line that is refused before it runs (it does not parse, or it is pipelined ambiguously) and a command that a script rule answers have no `command` event.
|
|
434
437
|
- `mailbox`: `{ type, path, oldPath, mailbox, origin }` for CREATE, DELETE, RENAME, SUBSCRIBE and UNSUBSCRIBE, `origin` is null for the control API.
|
|
435
438
|
- `expunge`: `(mailbox, messages, origin)` before the sessions are told, and `flags`: `(mailbox, messages, origin)` for flag changes of the control API.
|
|
439
|
+
- `acl`: `(mailbox, previousAcl)` when the ACL of a mailbox changes (ACL plugin), `script`: `{ rule, event, session, tag, command }` when a script rule fires, `reset`: after `control.reset()`.
|
|
436
440
|
|
|
437
441
|
```javascript
|
|
438
442
|
const idling = new Promise(resolve => server.on('session', event => event.type === 'waiting' && event.command === 'IDLE' && resolve(event)));
|
|
@@ -454,7 +458,7 @@ curl -X POST http://127.0.0.1:8143/v1/mailboxes/INBOX/messages \
|
|
|
454
458
|
|
|
455
459
|
The REST API controls the whole server, including the mail of every user, so it is careful by default. It listens on `127.0.0.1` unless `host` (`--rest-host`) says otherwise, and any other address than a loopback one needs a bearer token (`token`, `--rest-token`, `IMAPKIT_REST_TOKEN`) that every request sends as `Authorization: Bearer <token>`. Without a token it only answers requests for a loopback host name. It sends no CORS headers and takes JSON bodies only (`Content-Type: application/json`, at most 64 MiB), so a web page can not call it. Do not expose it outside a test environment.
|
|
456
460
|
|
|
457
|
-
Requests and responses are JSON. Errors are `{ "error": { "code", "message" } }` with HTTP status 404 for `NONEXISTENT`, 409 for `ALREADYEXISTS` and the
|
|
461
|
+
Requests and responses are JSON, and every POST needs `Content-Type: application/json`, also without a body (HTTP 415 otherwise). Errors are `{ "error": { "code", "message" } }` with HTTP status 404 for `NONEXISTENT`, 409 for `ALREADYEXISTS` and the response codes of a failed mailbox operation (`CANNOT`, `HASCHILDREN` ...), 400 for `INVALID`, 401 for a missing or wrong token, 404 `NOTFOUND` and 405 `METHOD` for an unknown route or method, 413 `TOOBIG` for a body over 64 MiB (and `addMessage` checks refused by APPENDLIMIT), 500 for a server error. A mailbox is its storage name (modified UTF-7) in the URL, URL encoded with a `/` in the name as `%2F` (`/v1/mailboxes/Work%2FProjects`). Message sources are base64 in responses (`"encoding": "base64"`), a request sends `raw` as text or as base64 with `"encoding": "base64"`. `GET /v1/openapi.json` describes every endpoint.
|
|
458
462
|
|
|
459
463
|
`GET /v1/events` streams the [events](#events) as [Server-Sent Events](https://html.spec.whatwg.org/multipage/server-sent-events.html) (`event: <type>` with JSON `data`), so a test in another language can wait for "the client selected INBOX" or "a script rule fired" without polling. `?types=session,command` chooses the types (`session`, `command`, `mailbox`, `expunge`, `flags`, `acl`, `script`, `reset`), mailboxes are paths, messages UIDs and sessions numbers in the data:
|
|
460
464
|
|
|
@@ -543,19 +547,19 @@ The actions say what happens instead of the usual behavior. Strings are sent as
|
|
|
543
547
|
| --------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
544
548
|
| `send` | all | output events: bytes sent instead of the output. command and input: bytes sent instead of processing the line |
|
|
545
549
|
| `run` | command, input | process the line as usual after `send` (to add output before the real response) |
|
|
546
|
-
| `drop` | all
|
|
550
|
+
| `drop` | all but quiet | output events: send nothing. command and input: ignore the line, the client gets no answer |
|
|
547
551
|
| `mutate` | response, continuation | `(response, context)` gets a copy of the response object before it is compiled and changes it, or returns another one. Continuation requests have a response object only when a plugin sends them with `connection.send()` (the error challenges of XOAUTH2 and OAUTHBEARER), other events ignore `mutate`. A tagged response that does not compile then is sent as `NO [SERVERBUG]`, an untagged one is dropped. Use `send` for output that is not valid IMAP |
|
|
548
552
|
| `literals` | response | sends every string of the response that the grammar allows (string, nstring, astring) as a literal. The positions that take only a quoted string stay quoted: the hierarchy delimiter of LIST, LSUB and NAMESPACE, CHILDINFO values, INTERNALDATE and SAVEDATE, and the media types `"TEXT"` and `"MESSAGE" "RFC822"` in a body structure (RFC 9051 section 9, RFC 5258 section 6). Atoms, response codes and text stay as they are. Works together with `mutate`, after it |
|
|
549
553
|
| `defer` | response | holds an untagged response back: `'tagged'` sends it right after the tagged response of its command, `'next'` with the answer to the next command, before its first response. Needs `untagged: true`. `send`, `before` and `after` change the held output, `drop`, `delay`, `chunk`, `truncate` and `close` can not be combined with it. A response that does not belong to a command (one that arrives in IDLE belongs to IDLE) is held for the next tagged response or command. Held responses are dropped when the connection closes |
|
|
550
554
|
| `before`, `after` | output events | bytes sent before or after the output, e.g. an unsolicited response |
|
|
551
|
-
| `delay` | all but input
|
|
555
|
+
| `delay` | all but input, quiet | milliseconds to wait before the output goes out, all later output waits behind it. For a command, the wait before the rule acts or the command runs, later commands wait too |
|
|
552
556
|
| `chunk`, `chunkDelay` | all | write the bytes in pieces of `chunk` octets, `chunkDelay` milliseconds apart (default 10). `chunkDelay: 0` or `'tick'` sends each piece after the earlier one was handed to the system, on the next event loop turn, so the pieces leave as separate TCP segments without a wall clock delay (on Deno a zero timer, about 2 ms a piece) |
|
|
553
557
|
| `truncate` | all | send only this many octets of the bytes, then close the connection |
|
|
554
558
|
| `close` | all | close the connection after the bytes are sent, `'reset'` destroys the socket instead (a TCP RST where the runtime supports it), 20 ms after the bytes so that the RST does not overtake them. Input that arrives meanwhile is not processed |
|
|
555
559
|
|
|
556
560
|
A rule needs at least one action, and for command and input events `chunk` and `truncate` need `send`. A rule with only `delay` (and `run`) delays the line and then processes it as usual. Rules are checked when they are added: an unknown option, an option that does not apply to the event, or an invalid value throws a `TypeError`, so a typo can not turn into a rule that never fires.
|
|
557
561
|
|
|
558
|
-
The event context, which `when`, `mutate` and `send` functions get, has `event`, `connection`, `session`, `state`, `user`, `mailbox`, `tag`, `command`, `data` (the command line or the output bytes, as a binary string), and for responses `description` and `response`.
|
|
562
|
+
The event context, which `when`, `mutate` and `send` functions get, has `event`, `connection`, `session`, `state`, `user`, `mailbox`, `tag`, `command`, `data` (the command line or the output bytes, as a binary string), `quiet` (milliseconds without input or output, quiet events), and for responses `description` and `response`.
|
|
559
563
|
|
|
560
564
|
`server.script.add(rule)` returns a handle with `rule`, `matched` (events that matched the rule, also before `nth`), `hits` (events the rule handled) and `remove()`, `server.script.add([rules])` returns a list of handles. `server.script.rules` lists the handles in order, `server.script.clear()` removes every rule. The server emits a `script` event `{ rule, event, session, tag, command }` every time a rule fires.
|
|
561
565
|
|
|
@@ -574,13 +578,13 @@ Faults change only the output and the handling of the lines a rule matches, the
|
|
|
574
578
|
|
|
575
579
|
The `quirks` option (`--quirk` for the `imapkit` command) turns on named presets that make the server behave like a known real server, so a client test reproduces that server's bug in every run, without the server itself. A preset is a set of script rules, after the rules of the `script` option, and plugins it leaves out. The presets are exported as data (`import { quirks } from 'imapkit'`), copy one into your own script rules to adjust it.
|
|
576
580
|
|
|
577
|
-
| Quirk | Behavior
|
|
578
|
-
| ----------------------- |
|
|
579
|
-
| `james-fetchgroup` | Apache James FetchGroup: only the first section asked for a part in one FETCH is answered, later ones for the same part are empty (`BODY[2.MIME] BODY[2]` gives a zero-length body)
|
|
580
|
-
| `james-late-fetch` | Apache James: 1 in 4 FETCH responses come after the tagged OK of their command
|
|
581
|
-
| `yahoo-quoted-sections` | Yahoo: short body sections (up to 100 octets without line breaks) are quoted strings instead of literals
|
|
582
|
-
| `m365-throttle` | Microsoft 365: 1 in 10 commands (not LOGOUT) is refused with `BAD Request is throttled. Suggested Backoff Time: 1000 milliseconds`
|
|
583
|
-
| `no-uidplus`, `no-move` | servers without UIDPLUS or MOVE, the plugins are not loaded even when `plugins` lists them
|
|
581
|
+
| Quirk | Behavior |
|
|
582
|
+
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
583
|
+
| `james-fetchgroup` | Apache James FetchGroup: only the first section asked for a part in one FETCH is answered, later ones for the same part are empty (`BODY[2.MIME] BODY[2]` gives a zero-length body) |
|
|
584
|
+
| `james-late-fetch` | Apache James: 1 in 4 FETCH responses come after the tagged OK of their command |
|
|
585
|
+
| `yahoo-quoted-sections` | Yahoo: short body sections (up to 100 octets without line breaks) are quoted strings instead of literals |
|
|
586
|
+
| `m365-throttle` | Microsoft 365: 1 in 10 commands (not LOGOUT) is refused with `BAD Request is throttled. Suggested Backoff Time: 1000 milliseconds` |
|
|
587
|
+
| `no-uidplus`, `no-move` | servers without UIDPLUS or MOVE, the plugins are not loaded even when `plugins` lists them, and with IMAP4rev2 (which requires both, RFC 9051 Appendix E) the server constructor throws |
|
|
584
588
|
|
|
585
589
|
```javascript
|
|
586
590
|
const server = imapkit({ plugins: ['IDLE', 'MOVE'], quirks: ['james-fetchgroup', 'm365-throttle'], scriptSeed: 42 });
|
|
@@ -592,7 +596,7 @@ const server = imapkit({ plugins: ['IDLE', 'MOVE'], quirks: ['james-fetchgroup',
|
|
|
592
596
|
- `now`: the time the server uses for the dates it sets itself, the INTERNALDATE of a message without one and SAVEDATE: a Date, a timestamp, or a function that returns one. The dates are formatted in the time zone of the process.
|
|
593
597
|
- `resetUidValidity(path, { uids: 'shuffle', seed })` of the control API.
|
|
594
598
|
|
|
595
|
-
The `storage` option is checked when the server is built: a key that looks like a typo of a known one (`message` for `messages`, `uidValidity`) or a wrong type fails with the path of the problem, e.g. `Invalid storage at "INBOX".messages[2]: unknown key "flag", did you mean "flags"?`. Plugins keep their own data on mailboxes and messages, so other keys are allowed. The package exports the check as `validateStorage(storage)` and the shape as a JSON Schema, `storageSchema`, for editors and fixture tooling. `server.control.snapshot()` returns the same shape.
|
|
599
|
+
The `storage` option is checked when the server is built: a key that looks like a typo of a known one (`message` for `messages`, `uidValidity`) or a wrong type fails with the path of the problem, e.g. `Invalid storage at "INBOX".messages[2]: unknown key "flag", did you mean "flags"?`. A message `internaldate` (or `SAVEDATE`) must be an RFC 3501 date-time string like `"14-Sep-2013 21:22:28 -0300"` or a valid Date, a Date header value like `"Thu, 1 Jan 2026 10:00:00 +0000"` is refused. Plugins keep their own data on mailboxes and messages, so other keys are allowed. The package exports the check as `validateStorage(storage)` and the shape as a JSON Schema, `storageSchema`, for editors and fixture tooling. `server.control.snapshot()` returns the same shape.
|
|
596
600
|
|
|
597
601
|
## Creating custom plugins
|
|
598
602
|
|
|
@@ -693,7 +697,7 @@ Where
|
|
|
693
697
|
- **mailboxArguments** lists the positions of arguments that are mailbox names, these must be valid modified UTF-7 (RFC 3501 section 5.1.3)
|
|
694
698
|
- **astringArguments** lists the positions of other astring arguments (user names, identifiers). In these, in mailbox names and in search criteria an atom `NIL` reaches the handler as an atom, not as `null`
|
|
695
699
|
- **searchCriteria** is the position where SEARCH style criteria start, **sequenceSet** the position of an argument with message sequence numbers. Both are used for the RFC 3501 section 5.5 pipelining check
|
|
696
|
-
- **noExpunge** if true, EXPUNGE responses are held back while the command runs (like FETCH, STORE and SEARCH, RFC 3501 section 7.4.1)
|
|
700
|
+
- **noExpunge** if true, EXPUNGE responses are held back while the command runs (like FETCH, STORE and SEARCH, RFC 3501 section 7.4.1), the notifications queued before them are still sent
|
|
697
701
|
- **literal8** if true (or the name of the capability that allows it), the command accepts `~{n}` literals (RFC 3516)
|
|
698
702
|
- **noPipelining** if true, the command is refused with BAD when the client sent more input after it (STARTTLS, COMPRESS), and so are the commands sent with it
|
|
699
703
|
- **appendMessage** if true, the command takes a message after its mailbox argument like APPEND (REPLACE), so a message literal to a missing mailbox is refused with `NO [TRYCREATE]` before it is sent
|
|
@@ -705,7 +709,7 @@ Where
|
|
|
705
709
|
server.getCommandOptions(name) -> Object
|
|
706
710
|
server.getCommandStates(name) -> Array|false
|
|
707
711
|
|
|
708
|
-
`getCommandOptions` returns the options of a command (see above) with every key set, `getCommandStates` only the connection states it is valid in
|
|
712
|
+
`getCommandOptions` returns the options of a command (see above) with every key set, `getCommandStates` only the connection states it is valid in (`false` for a command of a plugin that did not limit them).
|
|
709
713
|
|
|
710
714
|
#### Run after every plugin is loaded
|
|
711
715
|
|
|
@@ -807,7 +811,7 @@ server.outputHandlers.push(function (connection, response, description) {
|
|
|
807
811
|
#### Other extension points
|
|
808
812
|
|
|
809
813
|
- `server.messageHandlers` and `server.mailboxHandlers` run on every message and mailbox when it is loaded from storage or created, `(server, message, mailbox)` and `(server, mailbox)`
|
|
810
|
-
- `server.statusHandlers[ITEM]` returns the value of a STATUS item that a plugin adds to `server.allowedStatus`, `(connection, mailbox)`
|
|
814
|
+
- `server.statusHandlers[ITEM]` returns the value of a STATUS item that a plugin adds to `server.allowedStatus`, `(connection, mailbox, status)` where `status` holds the counters of `server.getStatus()`
|
|
811
815
|
- `server.appendChecks` are consulted before APPEND, COPY and MOVE add messages to a mailbox, `(connection, mailbox, messages, options)`. A check returns nothing to allow it, or `{ code, text }` to fail the command with a tagged `NO [code] text` (`{ code, text, soft: true }` only sends an untagged `NO` warning)
|
|
812
816
|
- `server.closedChecks` are consulted when SELECT or EXAMINE closes the selected mailbox, `(connection)`. If any returns true, `* OK [CLOSED]` marks where the responses for the new mailbox start
|
|
813
817
|
- `server.copyHandlers` run when COPY, MOVE or RENAME INBOX copies a message, `(server, source, properties, mailbox)`. Properties set on `properties` are given to the copy before the message handlers run
|
package/bin/help.txt
CHANGED
|
@@ -72,7 +72,7 @@ Configuration file takes the following structure
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"id":{
|
|
75
|
-
"name": "
|
|
75
|
+
"name": "imapkit",
|
|
76
76
|
"version": "__VERSION__",
|
|
77
77
|
"key": "value"
|
|
78
78
|
}
|
|
@@ -82,7 +82,8 @@ Scripted faults
|
|
|
82
82
|
---------------
|
|
83
83
|
|
|
84
84
|
A script file holds a list of rules. Each rule watches one event
|
|
85
|
-
("greeting", "command", "input", "response"
|
|
85
|
+
("greeting", "command", "input", "response", "continuation" or
|
|
86
|
+
"quiet", no input and output for "quietFor" milliseconds) and
|
|
86
87
|
changes what the server does when its matchers fit. For example, this
|
|
87
88
|
script answers the first FETCH with a literal that is too short and
|
|
88
89
|
then drops the connection:
|
package/bin/imapkit.js
CHANGED
|
@@ -83,7 +83,9 @@ if (debug) {
|
|
|
83
83
|
config.debug = true;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
// secureConnection can also come from the --config file
|
|
87
|
+
const isSecure = secure || config.secureConnection === true;
|
|
88
|
+
const port = argv.port || process.env.IMAPKIT_PORT || config.port || (isSecure ? 993 : 143);
|
|
87
89
|
|
|
88
90
|
if (argv.help) {
|
|
89
91
|
const help = fs.readFileSync(path.join(__dirname, 'help.txt'), 'utf-8');
|
|
@@ -120,13 +122,21 @@ if (argv.help) {
|
|
|
120
122
|
// smtp-server is an optional dependency, start() loads it only when SMTP is enabled
|
|
121
123
|
config.smtp = { port: Number(smtpPort) };
|
|
122
124
|
}
|
|
123
|
-
|
|
125
|
+
let server;
|
|
126
|
+
try {
|
|
127
|
+
server = imapkit(config);
|
|
128
|
+
} catch (err) {
|
|
129
|
+
// an unknown plugin or quirk name, invalid storage ...
|
|
130
|
+
console.error('Failed to start ImapKit: %s', err.message);
|
|
131
|
+
process.exit(1);
|
|
132
|
+
}
|
|
124
133
|
console.log('Starting ImapKit ...');
|
|
125
134
|
server.start(Number(port)).then(
|
|
126
|
-
|
|
127
|
-
|
|
135
|
+
listening => {
|
|
136
|
+
// the actual port, also for -p 0
|
|
137
|
+
console.log('ImapKit successfully%s listening on port %s', isSecure ? ' and securely' : '', listening);
|
|
128
138
|
if (server.restServer) {
|
|
129
|
-
console.log('REST API listening on %s:%s',
|
|
139
|
+
console.log('REST API listening on %s:%s', (config.rest && config.rest.host) || '127.0.0.1', server.restServer.address().port);
|
|
130
140
|
}
|
|
131
141
|
if (server.smtpServer) {
|
|
132
142
|
console.log('Incoming SMTP server up and running on port %s', server.smtpServer.server.address().port);
|
|
@@ -85,7 +85,8 @@ function getSection(data, query, global) {
|
|
|
85
85
|
else if (query.section.length > 1) {
|
|
86
86
|
throw new Error((key || 'Part number') + ' does not take any arguments');
|
|
87
87
|
}
|
|
88
|
-
//
|
|
88
|
+
// a part that does not exist is returned as an empty string, like Dovecot does: RFC 3501 and RFC 9051 section
|
|
89
|
+
// 6.4.5 define no error for it, only an empty string for a partial range that starts beyond the end of the text
|
|
89
90
|
const node = path ? (0, mimeparser_js_1.resolveNode)(data.tree, path, global) : data.tree;
|
|
90
91
|
if (!node) {
|
|
91
92
|
return '';
|
|
@@ -10,8 +10,8 @@ function setFlags(connection, message, flags) {
|
|
|
10
10
|
[].concat(flags).forEach(flag => {
|
|
11
11
|
flag = (0, flags_js_1.normalizeSystemFlag)(typeof flag === 'string' ? flag : String(flag.value || ''));
|
|
12
12
|
(0, flags_js_1.checkSystemFlags)(connection.server, flag);
|
|
13
|
-
//
|
|
14
|
-
if (
|
|
13
|
+
// a flag that is not in PERMANENTFLAGS is ignored (RFC 3501 section 7.1, RFC 9051 section 7.1)
|
|
14
|
+
if (!connection.server.isPermanentFlag(mailbox, flag)) {
|
|
15
15
|
return;
|
|
16
16
|
}
|
|
17
17
|
if (messageFlags.indexOf(flag) < 0) {
|
|
@@ -26,8 +26,8 @@ function addFlags(connection, message, flags) {
|
|
|
26
26
|
[].concat(flags).forEach(flag => {
|
|
27
27
|
flag = (0, flags_js_1.normalizeSystemFlag)(typeof flag === 'string' ? flag : String(flag.value || ''));
|
|
28
28
|
(0, flags_js_1.checkSystemFlags)(connection.server, flag);
|
|
29
|
-
//
|
|
30
|
-
if (
|
|
29
|
+
// a flag that is not in PERMANENTFLAGS is ignored (RFC 3501 section 7.1, RFC 9051 section 7.1)
|
|
30
|
+
if (!connection.server.isPermanentFlag(mailbox, flag)) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
if (message.flags.indexOf(flag) < 0) {
|
|
@@ -22,8 +22,22 @@ function listCommand(connection, parsed, data, callback) {
|
|
|
22
22
|
return callback();
|
|
23
23
|
}
|
|
24
24
|
if (!parsed.attributes[1].value) {
|
|
25
|
-
// empty
|
|
26
|
-
|
|
25
|
+
// RFC 3501 section 6.3.8: "An empty ("" string) mailbox name argument is a special request to return the
|
|
26
|
+
// hierarchy delimiter and the root name of the name given in the reference. The value returned as the root
|
|
27
|
+
// MAY be the empty string if the reference is non-rooted or is an empty string."
|
|
28
|
+
const server = connection.server;
|
|
29
|
+
const reference = parsed.attributes[0].value || '';
|
|
30
|
+
// the namespace of the reference, the personal one for a reference that is not a valid name
|
|
31
|
+
let key = server.referenceNamespace;
|
|
32
|
+
try {
|
|
33
|
+
key = server.getNamespace(connection.importMailboxName(reference)) || key;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// not a mailbox name, so not in another namespace
|
|
37
|
+
}
|
|
38
|
+
const namespace = key !== false ? server.storage[key] : undefined;
|
|
39
|
+
// the root of a name in another namespace is the prefix of that namespace, like "#news." in the RFC example
|
|
40
|
+
const root = key !== false && key !== server.referenceNamespace ? connection.exportMailboxName(key) : '';
|
|
27
41
|
if (namespace) {
|
|
28
42
|
connection.send({
|
|
29
43
|
tag: '*',
|
|
@@ -36,7 +50,7 @@ function listCommand(connection, parsed, data, callback) {
|
|
|
36
50
|
}
|
|
37
51
|
],
|
|
38
52
|
namespace.separator,
|
|
39
|
-
|
|
53
|
+
root
|
|
40
54
|
]
|
|
41
55
|
}, 'LIST ITEM', parsed, data);
|
|
42
56
|
}
|
package/dist/cjs/control.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* unsolicited FETCH, BYE, NOTIFY events, CONDSTORE mod-sequences), with no session as its origin. The API is the
|
|
5
5
|
* operator: ACL does not apply, but every argument is checked. Mailboxes are addressed by their storage name
|
|
6
6
|
* (modified UTF-7), messages by mailbox and UID. Methods return plain data and throw an ImapKitError with a `code`:
|
|
7
|
-
* NONEXISTENT, ALREADYEXISTS, INVALID, or
|
|
7
|
+
* NONEXISTENT, ALREADYEXISTS, INVALID, or the response code of a failed mailbox operation (CANNOT, HASCHILDREN ...)
|
|
8
8
|
*/
|
|
9
9
|
import { ImapKitError } from './store-operations.js';
|
|
10
10
|
import type { FlagMode, UidValidityOptions } from './store-operations.js';
|
|
@@ -22,7 +22,7 @@ interface MailboxInfo {
|
|
|
22
22
|
unseen: number;
|
|
23
23
|
uidnext: number;
|
|
24
24
|
uidvalidity: number;
|
|
25
|
-
/** flags
|
|
25
|
+
/** the flags of the FLAGS response, SELECT adds \* to PERMANENTFLAGS when new keywords are allowed */
|
|
26
26
|
permanentFlags: string[];
|
|
27
27
|
/** only with CONDSTORE */
|
|
28
28
|
highestModseq?: number;
|
|
@@ -67,13 +67,8 @@ interface NewMessage {
|
|
|
67
67
|
/** a Date or a RFC 3501 date-time string, the current time if not set */
|
|
68
68
|
internaldate?: Date | string | undefined;
|
|
69
69
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
xoauth2?: {
|
|
73
|
-
accessToken?: string | undefined;
|
|
74
|
-
sessionTimeout?: number | undefined;
|
|
75
|
-
} | undefined;
|
|
76
|
-
}
|
|
70
|
+
/** The credentials of a user, see UserData */
|
|
71
|
+
type UserOptions = Pick<UserData, 'password' | 'xoauth2'>;
|
|
77
72
|
/** What a REST route handler gets, see src/rest.ts */
|
|
78
73
|
interface RouteRequest {
|
|
79
74
|
params: Record<string, string>;
|
package/dist/cjs/control.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* unsolicited FETCH, BYE, NOTIFY events, CONDSTORE mod-sequences), with no session as its origin. The API is the
|
|
6
6
|
* operator: ACL does not apply, but every argument is checked. Mailboxes are addressed by their storage name
|
|
7
7
|
* (modified UTF-7), messages by mailbox and UID. Methods return plain data and throw an ImapKitError with a `code`:
|
|
8
|
-
* NONEXISTENT, ALREADYEXISTS, INVALID, or
|
|
8
|
+
* NONEXISTENT, ALREADYEXISTS, INVALID, or the response code of a failed mailbox operation (CANNOT, HASCHILDREN ...)
|
|
9
9
|
*/
|
|
10
10
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
11
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
package/dist/cjs/dates.d.ts
CHANGED
|
@@ -36,6 +36,14 @@ declare function isRealDate(day: number | string | undefined, month: number, yea
|
|
|
36
36
|
* @return {String|Boolean} the date, or false for an impossible date
|
|
37
37
|
*/
|
|
38
38
|
declare function dateKey(day: number | string, month: number, year: number | string): string | false;
|
|
39
|
+
/**
|
|
40
|
+
* Checks a date-time string of RFC 3501 section 9, like an INTERNALDATE ("14-Sep-2013 21:22:28 -0300"):
|
|
41
|
+
* date-time = DQUOTE date-day-fixed "-" date-month "-" date-year SP time SP zone DQUOTE
|
|
42
|
+
*
|
|
43
|
+
* @param {String} value Value to check
|
|
44
|
+
* @return {Boolean} true if the value is a date-time string of a real date and time
|
|
45
|
+
*/
|
|
46
|
+
declare function isDateTime(value: unknown): boolean;
|
|
39
47
|
/**
|
|
40
48
|
* Parses a date-time value of the RFC 3501 section 9 form, like an INTERNALDATE ("14-Sep-2013 21:22:28 -0300").
|
|
41
49
|
* A value with only the date part is accepted as well, its time fields are left undefined
|
|
@@ -61,4 +69,4 @@ declare function parseHeaderDate(header: string | undefined): DateParts | null;
|
|
|
61
69
|
* @return {Number} timestamp
|
|
62
70
|
*/
|
|
63
71
|
declare function toTimestamp(date: DateParts): number;
|
|
64
|
-
export { MONTHS, monthIndex, isRealDate, dateKey, parseDateTime, parseHeaderDate, toTimestamp };
|
|
72
|
+
export { MONTHS, monthIndex, isRealDate, isDateTime, dateKey, parseDateTime, parseHeaderDate, toTimestamp };
|
package/dist/cjs/dates.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MONTHS = void 0;
|
|
4
4
|
exports.monthIndex = monthIndex;
|
|
5
5
|
exports.isRealDate = isRealDate;
|
|
6
|
+
exports.isDateTime = isDateTime;
|
|
6
7
|
exports.dateKey = dateKey;
|
|
7
8
|
exports.parseDateTime = parseDateTime;
|
|
8
9
|
exports.parseHeaderDate = parseHeaderDate;
|
|
@@ -50,6 +51,25 @@ function dateKey(day, month, year) {
|
|
|
50
51
|
}
|
|
51
52
|
return String(year).padStart(4, '0') + '-' + String(month + 1).padStart(2, '0') + '-' + String(day).padStart(2, '0');
|
|
52
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Checks a date-time string of RFC 3501 section 9, like an INTERNALDATE ("14-Sep-2013 21:22:28 -0300"):
|
|
56
|
+
* date-time = DQUOTE date-day-fixed "-" date-month "-" date-year SP time SP zone DQUOTE
|
|
57
|
+
*
|
|
58
|
+
* @param {String} value Value to check
|
|
59
|
+
* @return {Boolean} true if the value is a date-time string of a real date and time
|
|
60
|
+
*/
|
|
61
|
+
function isDateTime(value) {
|
|
62
|
+
if (!value || typeof value !== 'string') {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
// month names are case-insensitive like all ABNF strings
|
|
66
|
+
const match = value.match(/^( \d|\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{4}) (\d{2}):(\d{2}):(\d{2}) [-+](\d{2})(\d{2})$/i);
|
|
67
|
+
if (!match) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
// the values must also make a real date and time
|
|
71
|
+
return (isRealDate(match[1], monthIndex(match[2]), match[3]) && Number(match[4]) < 24 && Number(match[5]) < 60 && Number(match[6]) < 61 && Number(match[8]) < 60);
|
|
72
|
+
}
|
|
53
73
|
/**
|
|
54
74
|
* Parses a date-time value of the RFC 3501 section 9 form, like an INTERNALDATE ("14-Sep-2013 21:22:28 -0300").
|
|
55
75
|
* A value with only the date part is accepted as well, its time fields are left undefined
|
package/dist/cjs/envelope.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ParsedAddress } from './addressparser.js';
|
|
2
2
|
import type { ParsedHeader } from './mimeparser.js';
|
|
3
3
|
/** An address of the ENVELOPE (RFC 3501 section 9): name, source route, mailbox and host, all NIL for a group end */
|
|
4
|
-
export type EnvelopeAddress = [name: string | null, adl: null, mailbox: string | null, host: string | null];
|
|
4
|
+
export type EnvelopeAddress = [name: string | null, adl: string | null, mailbox: string | null, host: string | null];
|
|
5
5
|
/** The fields of the ENVELOPE (RFC 3501 section 7.4.2), in order */
|
|
6
6
|
export type Envelope = [
|
|
7
7
|
date: string | null,
|
package/dist/cjs/envelope.js
CHANGED
|
@@ -3,6 +3,29 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.default = envelope;
|
|
5
5
|
exports.processAddress = processAddress;
|
|
6
|
+
// RFC 5322 section 4.4: obs-angle-addr = [CFWS] "<" obs-route addr-spec ">" [CFWS], obs-route = obs-domain-list ":",
|
|
7
|
+
// obs-domain-list = *(CFWS / ",") "@" domain *("," [CFWS] ["@" domain]). A domain-literal can hold a colon
|
|
8
|
+
const OBS_ROUTE = /^[\s,]*(@(?:[^:[]|\[[^\]]*\])*):/;
|
|
9
|
+
/**
|
|
10
|
+
* Splits an obsolete source route from an address: the route goes to addr-adl, the rest is the addr-spec
|
|
11
|
+
* (RFC 9051 section 7.5.2: the at-domain-list is the "source route and obs-route ABNF production from [RFC5322]",
|
|
12
|
+
* the mailbox name the "local-part ABNF production"). The route is sent like Dovecot does, "@a,@b"
|
|
13
|
+
*
|
|
14
|
+
* @param {String} address Address from the angle brackets
|
|
15
|
+
* @return {Array} [route or null, addr-spec]
|
|
16
|
+
*/
|
|
17
|
+
function splitRoute(address) {
|
|
18
|
+
const match = address.match(OBS_ROUTE);
|
|
19
|
+
if (!match) {
|
|
20
|
+
return [null, address];
|
|
21
|
+
}
|
|
22
|
+
const route = match[1]
|
|
23
|
+
.split(',')
|
|
24
|
+
.map(domain => domain.trim())
|
|
25
|
+
.filter(domain => domain)
|
|
26
|
+
.join(',');
|
|
27
|
+
return [route, address.substr(match[0].length).trim()];
|
|
28
|
+
}
|
|
6
29
|
/**
|
|
7
30
|
* Convert a message object to an ENVELOPE object
|
|
8
31
|
*
|
|
@@ -61,12 +84,14 @@ function processAddress(arr, def) {
|
|
|
61
84
|
if (!address) {
|
|
62
85
|
return;
|
|
63
86
|
}
|
|
87
|
+
const [route, addrSpec] = splitRoute(address);
|
|
88
|
+
address = addrSpec;
|
|
64
89
|
const at = address.lastIndexOf('@');
|
|
65
90
|
const user = at >= 0 ? address.substr(0, at) : address;
|
|
66
91
|
// RFC 3501 7.4.2 reserves a NIL host for group markers, so an address without a domain gets
|
|
67
92
|
// the placeholder host that Dovecot uses for the same input
|
|
68
93
|
const domain = (at >= 0 ? address.substr(at + 1) : '') || 'MISSING_DOMAIN';
|
|
69
|
-
result.push([name,
|
|
94
|
+
result.push([name, route, user || null, domain]);
|
|
70
95
|
});
|
|
71
96
|
// env-from = "(" 1*address ")", there is no SP between the addresses (RFC 3501 section 9)
|
|
72
97
|
Object.defineProperty(result, 'adjacentLists', { value: true });
|
package/dist/cjs/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ export { TAG_REGEX, IMAPServer, IMAPConnection, ImapKitError, quirks, storageSch
|
|
|
6
6
|
export type { Attribute, ParsedCommand, IMAPResponse, Notification, Callback, CommandHandler, CommandOptions, Plugin, IMAPError, Message, Mailbox, StorageNamespace, UserData, IMAPServerOptions } from './types.js';
|
|
7
7
|
export type { ScriptRule, ScriptContext, ScriptEvent, ScriptBytes, ScriptHandle } from './script.js';
|
|
8
8
|
export type { Quirk } from './quirks.js';
|
|
9
|
-
export type { Control, MailboxInfo, MessageInfo, SessionInfo, NewMessage, UserOptions, SessionFilter } from './control.js';
|
|
9
|
+
export type { Control, MailboxInfo, MessageInfo, SessionInfo, NewMessage, UserOptions, SessionFilter, ControlRoute, RouteRequest } from './control.js';
|
|
10
|
+
export type { FlagMode, UidMode, UidValidityOptions } from './store-operations.js';
|
|
10
11
|
declare const imapkit: typeof createServer & {
|
|
11
12
|
TAG_REGEX: RegExp;
|
|
12
13
|
IMAPServer: typeof IMAPServer;
|
|
@@ -15,7 +15,9 @@ declare function listPlugins(): string[];
|
|
|
15
15
|
*
|
|
16
16
|
* @param {Object} server IMAPServer instance
|
|
17
17
|
* @param {Array|String|Function} plugins List of plugins to load
|
|
18
|
+
* @param {Map} [exclude] Plugins a quirk preset leaves out, plugin name to quirk name
|
|
19
|
+
* @throws {Error} when a loaded plugin requires an excluded one
|
|
18
20
|
*/
|
|
19
|
-
declare function loadPlugins(server: IMAPServer, plugins: (string | Plugin)[] | string | Plugin | null | undefined, exclude?: string
|
|
21
|
+
declare function loadPlugins(server: IMAPServer, plugins: (string | Plugin)[] | string | Plugin | null | undefined, exclude?: Map<string, string>): void;
|
|
20
22
|
export default loadPlugins;
|
|
21
23
|
export { listPlugins };
|