imapflow 1.7.8 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +8 -2
- package/dist/cjs/charsets.d.ts +1 -0
- package/dist/cjs/charsets.js +294 -0
- package/dist/cjs/commands/append.d.ts +22 -0
- package/dist/cjs/commands/append.js +151 -0
- package/dist/cjs/commands/authenticate.d.ts +24 -0
- package/dist/cjs/commands/authenticate.js +223 -0
- package/dist/cjs/commands/capability.d.ts +8 -0
- package/dist/cjs/commands/capability.js +32 -0
- package/dist/cjs/commands/close.d.ts +8 -0
- package/dist/cjs/commands/close.js +39 -0
- package/dist/cjs/commands/compress.d.ts +8 -0
- package/dist/cjs/commands/compress.js +56 -0
- package/dist/cjs/commands/copy.d.ts +13 -0
- package/dist/cjs/commands/copy.js +44 -0
- package/dist/cjs/commands/copyuid-parser.d.ts +11 -0
- package/dist/cjs/commands/copyuid-parser.js +32 -0
- package/dist/cjs/commands/create.d.ts +11 -0
- package/dist/cjs/commands/create.js +80 -0
- package/dist/cjs/commands/delete.d.ts +11 -0
- package/dist/cjs/commands/delete.js +40 -0
- package/dist/cjs/commands/enable.d.ts +9 -0
- package/dist/cjs/commands/enable.js +61 -0
- package/dist/cjs/commands/esearch-parser.d.ts +17 -0
- package/dist/cjs/commands/esearch-parser.js +91 -0
- package/dist/cjs/commands/expunge.d.ts +12 -0
- package/dist/cjs/commands/expunge.js +60 -0
- package/dist/cjs/commands/fetch.d.ts +30 -0
- package/dist/cjs/commands/fetch.js +241 -0
- package/dist/cjs/commands/id.d.ts +10 -0
- package/dist/cjs/commands/id.js +80 -0
- package/dist/cjs/commands/idle.d.ts +9 -0
- package/dist/cjs/commands/idle.js +347 -0
- package/dist/cjs/commands/list.d.ts +16 -0
- package/dist/cjs/commands/list.js +518 -0
- package/dist/cjs/commands/login.d.ts +11 -0
- package/dist/cjs/commands/login.js +42 -0
- package/dist/cjs/commands/logout.d.ts +8 -0
- package/dist/cjs/commands/logout.js +47 -0
- package/dist/cjs/commands/move.d.ts +13 -0
- package/dist/cjs/commands/move.js +57 -0
- package/dist/cjs/commands/namespace.d.ts +25 -0
- package/dist/cjs/commands/namespace.js +139 -0
- package/dist/cjs/commands/noop.d.ts +8 -0
- package/dist/cjs/commands/noop.js +22 -0
- package/dist/cjs/commands/quota.d.ts +10 -0
- package/dist/cjs/commands/quota.js +119 -0
- package/dist/cjs/commands/rename.d.ts +12 -0
- package/dist/cjs/commands/rename.js +48 -0
- package/dist/cjs/commands/search.d.ts +15 -0
- package/dist/cjs/commands/search.js +228 -0
- package/dist/cjs/commands/select.d.ts +25 -0
- package/dist/cjs/commands/select.js +250 -0
- package/dist/cjs/commands/starttls.d.ts +8 -0
- package/dist/cjs/commands/starttls.js +30 -0
- package/dist/cjs/commands/status-fields.d.ts +14 -0
- package/dist/cjs/commands/status-fields.js +61 -0
- package/dist/cjs/commands/status.d.ts +12 -0
- package/dist/cjs/commands/status.js +108 -0
- package/dist/cjs/commands/store.d.ts +19 -0
- package/dist/cjs/commands/store.js +93 -0
- package/dist/cjs/commands/subscribe.d.ts +9 -0
- package/dist/cjs/commands/subscribe.js +31 -0
- package/dist/cjs/commands/unsubscribe.d.ts +9 -0
- package/dist/cjs/commands/unsubscribe.js +31 -0
- package/dist/cjs/connection-deadline.d.ts +49 -0
- package/dist/cjs/connection-deadline.js +91 -0
- package/dist/cjs/errors.d.ts +83 -0
- package/dist/cjs/errors.js +13 -0
- package/dist/cjs/handler/imap-compiler.d.ts +24 -0
- package/dist/cjs/handler/imap-compiler.js +285 -0
- package/dist/cjs/handler/imap-formal-syntax.d.ts +28 -0
- package/dist/cjs/handler/imap-formal-syntax.js +121 -0
- package/dist/cjs/handler/imap-handler.d.ts +9 -0
- package/dist/cjs/handler/imap-handler.js +10 -0
- package/dist/cjs/handler/imap-parser.d.ts +16 -0
- package/dist/cjs/handler/imap-parser.js +90 -0
- package/dist/cjs/handler/imap-stream.d.ts +181 -0
- package/dist/cjs/handler/imap-stream.js +446 -0
- package/dist/cjs/handler/limits.d.ts +25 -0
- package/dist/cjs/handler/limits.js +51 -0
- package/dist/cjs/handler/parser-instance.d.ts +68 -0
- package/dist/cjs/handler/parser-instance.js +223 -0
- package/dist/cjs/handler/token-parser.d.ts +91 -0
- package/dist/cjs/handler/token-parser.js +673 -0
- package/dist/cjs/handler/types.d.ts +91 -0
- package/dist/cjs/handler/types.js +4 -0
- package/dist/cjs/imap-commands.d.ts +16 -0
- package/dist/cjs/imap-commands.js +74 -0
- package/dist/cjs/imap-flow.d.ts +676 -0
- package/dist/cjs/imap-flow.js +3949 -0
- package/dist/cjs/jp-decoder.d.ts +12 -0
- package/dist/cjs/jp-decoder.js +79 -0
- package/dist/cjs/limited-passthrough.d.ts +25 -0
- package/dist/cjs/limited-passthrough.js +54 -0
- package/dist/cjs/logger.d.ts +3 -0
- package/dist/cjs/logger.js +11 -0
- package/dist/cjs/package-info.d.ts +3 -0
- package/dist/cjs/package-info.js +7 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/proxy-connection.d.ts +33 -0
- package/dist/cjs/proxy-connection.js +392 -0
- package/dist/cjs/search-compiler.d.ts +34 -0
- package/dist/cjs/search-compiler.js +476 -0
- package/dist/cjs/special-use.d.ts +22 -0
- package/dist/cjs/special-use.js +911 -0
- package/dist/cjs/tools.d.ts +427 -0
- package/dist/cjs/tools.js +1496 -0
- package/{lib/imap-flow.d.ts → dist/cjs/types.d.ts} +386 -516
- package/dist/cjs/types.js +5 -0
- package/dist/esm/charsets.d.ts +1 -0
- package/{lib → dist/esm}/charsets.js +1 -6
- package/dist/esm/commands/append.d.ts +22 -0
- package/{lib → dist/esm}/commands/append.js +22 -52
- package/dist/esm/commands/authenticate.d.ts +24 -0
- package/{lib → dist/esm}/commands/authenticate.js +62 -87
- package/dist/esm/commands/capability.d.ts +8 -0
- package/{lib → dist/esm}/commands/capability.js +6 -9
- package/dist/esm/commands/close.d.ts +8 -0
- package/{lib → dist/esm}/commands/close.js +6 -10
- package/dist/esm/commands/compress.d.ts +8 -0
- package/{lib → dist/esm}/commands/compress.js +7 -11
- package/dist/esm/commands/copy.d.ts +13 -0
- package/{lib → dist/esm}/commands/copy.js +12 -20
- package/dist/esm/commands/copyuid-parser.d.ts +11 -0
- package/{lib → dist/esm}/commands/copyuid-parser.js +9 -15
- package/dist/esm/commands/create.d.ts +11 -0
- package/{lib → dist/esm}/commands/create.js +13 -27
- package/dist/esm/commands/delete.d.ts +11 -0
- package/{lib → dist/esm}/commands/delete.js +9 -14
- package/dist/esm/commands/enable.d.ts +9 -0
- package/{lib → dist/esm}/commands/enable.js +23 -30
- package/dist/esm/commands/esearch-parser.d.ts +17 -0
- package/dist/esm/commands/esearch-parser.js +88 -0
- package/dist/esm/commands/expunge.d.ts +12 -0
- package/{lib → dist/esm}/commands/expunge.js +17 -22
- package/dist/esm/commands/fetch.d.ts +30 -0
- package/{lib → dist/esm}/commands/fetch.js +32 -64
- package/dist/esm/commands/id.d.ts +10 -0
- package/{lib → dist/esm}/commands/id.js +17 -23
- package/dist/esm/commands/idle.d.ts +9 -0
- package/{lib → dist/esm}/commands/idle.js +47 -81
- package/dist/esm/commands/list.d.ts +16 -0
- package/{lib → dist/esm}/commands/list.js +56 -121
- package/dist/esm/commands/login.d.ts +11 -0
- package/{lib → dist/esm}/commands/login.js +10 -15
- package/dist/esm/commands/logout.d.ts +8 -0
- package/{lib → dist/esm}/commands/logout.js +9 -11
- package/dist/esm/commands/move.d.ts +13 -0
- package/{lib → dist/esm}/commands/move.js +13 -21
- package/dist/esm/commands/namespace.d.ts +25 -0
- package/{lib → dist/esm}/commands/namespace.js +34 -44
- package/dist/esm/commands/noop.d.ts +8 -0
- package/{lib → dist/esm}/commands/noop.js +6 -7
- package/dist/esm/commands/quota.d.ts +10 -0
- package/{lib → dist/esm}/commands/quota.js +18 -36
- package/dist/esm/commands/rename.d.ts +12 -0
- package/{lib → dist/esm}/commands/rename.js +10 -15
- package/dist/esm/commands/search.d.ts +15 -0
- package/{lib → dist/esm}/commands/search.js +36 -135
- package/dist/esm/commands/select.d.ts +25 -0
- package/{lib → dist/esm}/commands/select.js +33 -64
- package/dist/esm/commands/starttls.d.ts +8 -0
- package/{lib → dist/esm}/commands/starttls.js +6 -8
- package/dist/esm/commands/status-fields.d.ts +14 -0
- package/{lib → dist/esm}/commands/status-fields.js +5 -16
- package/dist/esm/commands/status.d.ts +12 -0
- package/{lib → dist/esm}/commands/status.js +18 -29
- package/dist/esm/commands/store.d.ts +19 -0
- package/{lib → dist/esm}/commands/store.js +24 -37
- package/dist/esm/commands/subscribe.d.ts +9 -0
- package/{lib → dist/esm}/commands/subscribe.js +8 -12
- package/dist/esm/commands/unsubscribe.d.ts +9 -0
- package/{lib → dist/esm}/commands/unsubscribe.js +8 -12
- package/dist/esm/connection-deadline.d.ts +49 -0
- package/{lib → dist/esm}/connection-deadline.js +14 -25
- package/dist/esm/errors.d.ts +83 -0
- package/dist/esm/errors.js +9 -0
- package/dist/esm/handler/imap-compiler.d.ts +24 -0
- package/{lib → dist/esm}/handler/imap-compiler.js +22 -80
- package/dist/esm/handler/imap-formal-syntax.d.ts +28 -0
- package/dist/esm/handler/imap-formal-syntax.js +117 -0
- package/dist/esm/handler/imap-handler.d.ts +9 -0
- package/dist/esm/handler/imap-handler.js +9 -0
- package/dist/esm/handler/imap-parser.d.ts +16 -0
- package/{lib → dist/esm}/handler/imap-parser.js +31 -44
- package/dist/esm/handler/imap-stream.d.ts +181 -0
- package/{lib → dist/esm}/handler/imap-stream.js +29 -121
- package/dist/esm/handler/limits.d.ts +25 -0
- package/{lib → dist/esm}/handler/limits.js +13 -22
- package/dist/esm/handler/parser-instance.d.ts +68 -0
- package/{lib → dist/esm}/handler/parser-instance.js +19 -47
- package/dist/esm/handler/token-parser.d.ts +91 -0
- package/{lib → dist/esm}/handler/token-parser.js +71 -155
- package/dist/esm/handler/types.d.ts +91 -0
- package/dist/esm/handler/types.js +3 -0
- package/dist/esm/imap-commands.d.ts +16 -0
- package/dist/esm/imap-commands.js +67 -0
- package/dist/esm/imap-flow.d.ts +676 -0
- package/{lib → dist/esm}/imap-flow.js +761 -1789
- package/dist/esm/jp-decoder.d.ts +12 -0
- package/{lib → dist/esm}/jp-decoder.js +6 -21
- package/dist/esm/limited-passthrough.d.ts +25 -0
- package/{lib → dist/esm}/limited-passthrough.js +7 -20
- package/dist/esm/logger.d.ts +3 -0
- package/dist/esm/logger.js +4 -0
- package/dist/esm/package-info.d.ts +3 -0
- package/dist/esm/package-info.js +4 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/proxy-connection.d.ts +33 -0
- package/{lib → dist/esm}/proxy-connection.js +56 -127
- package/dist/esm/search-compiler.d.ts +34 -0
- package/{lib → dist/esm}/search-compiler.js +54 -110
- package/dist/esm/special-use.d.ts +22 -0
- package/dist/esm/special-use.js +907 -0
- package/dist/esm/tools.d.ts +427 -0
- package/dist/esm/tools.js +1446 -0
- package/dist/esm/types.d.ts +828 -0
- package/dist/esm/types.js +4 -0
- package/package.json +60 -20
- package/.gitattributes +0 -1
- package/.github/CODE_OF_CONDUCT.md +0 -76
- package/.github/FUNDING.yml +0 -4
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -19
- package/.github/contributing.md +0 -17
- package/.github/workflows/release.yaml +0 -36
- package/.github/workflows/stale.yml +0 -29
- package/.github/workflows/test.yml +0 -51
- package/.ncurc.js +0 -4
- package/.prettierignore +0 -4
- package/.prettierrc.js +0 -8
- package/.release-please-manifest.json +0 -3
- package/CLAUDE.md +0 -104
- package/Gruntfile.js +0 -23
- package/eslint.config.js +0 -45
- package/lib/handler/imap-formal-syntax.js +0 -189
- package/lib/handler/imap-handler.js +0 -17
- package/lib/imap-commands.js +0 -45
- package/lib/logger.js +0 -5
- package/lib/special-use.js +0 -923
- package/lib/tools.js +0 -1612
- package/release-please-config.json +0 -10
- package/test/authentication-test.js +0 -101
- package/test/auto-idle-test.js +0 -470
- package/test/bodystructure-test.js +0 -899
- package/test/charsets-test.js +0 -161
- package/test/commands-branches-test.js +0 -1095
- package/test/commands-integration-test.js +0 -11124
- package/test/commands-test.js +0 -73
- package/test/connection-edge-cases-test.js +0 -1828
- package/test/connection-test.js +0 -162
- package/test/copyuid-parser-test.js +0 -173
- package/test/fetch-generator-test.js +0 -218
- package/test/fixtures/fake-timers.js +0 -115
- package/test/fixtures/serialized-mimetorture.js +0 -2738
- package/test/fixtures/test-client.js +0 -101
- package/test/fixtures/test-tls.js +0 -8
- package/test/handler-branches-test.js +0 -310
- package/test/idle-polling-test.js +0 -518
- package/test/imap-compiler-test.js +0 -809
- package/test/imap-flow-compress-test.js +0 -166
- package/test/imap-flow-coverage-test.js +0 -612
- package/test/imap-flow-fetch-download-test.js +0 -909
- package/test/imap-flow-internals-test.js +0 -725
- package/test/imap-flow-methods-test.js +0 -889
- package/test/imap-flow-proxy-paths-test.js +0 -366
- package/test/imap-flow-secure-test.js +0 -573
- package/test/imap-flow-server-test.js +0 -1474
- package/test/imap-formal-syntax-test.js +0 -293
- package/test/imap-parser-test.js +0 -1474
- package/test/imap-stream-edge-cases-test.js +0 -666
- package/test/imap-stream-test.js +0 -177
- package/test/imapflow-test.js +0 -258
- package/test/integration/README.md +0 -52
- package/test/integration/dovecot-test.conf +0 -27
- package/test/integration/rev2-live-test.js +0 -431
- package/test/integration/run-rev2-tests.sh +0 -75
- package/test/integration-test.js +0 -83
- package/test/jp-decoder-test.js +0 -304
- package/test/limited-passthrough-test.js +0 -299
- package/test/memory-cleanup-test.js +0 -144
- package/test/memory-leak-test.js +0 -667
- package/test/parser-limits-test.js +0 -292
- package/test/proxy-connection-test.js +0 -738
- package/test/reliability-improvements-test.js +0 -548
- package/test/search-compiler-test.js +0 -1300
- package/test/search-test.js +0 -329
- package/test/special-use-test.js +0 -418
- package/test/starttls-injection-test.js +0 -181
- package/test/tag-correlation-test.js +0 -333
- package/test/timer-policy-test.js +0 -227
- package/test/token-parser-test.js +0 -456
- package/test/tools-test.js +0 -2013
- package/test/unhandled-rejection-test.js +0 -661
|
@@ -0,0 +1,427 @@
|
|
|
1
|
+
import type { Transform } from 'node:stream';
|
|
2
|
+
import type { ImapFlow } from './imap-flow.js';
|
|
3
|
+
import type { ConnectionErrorSite, ImapFlowError } from './errors.js';
|
|
4
|
+
import type { ImapAttributeList, ImapAttributeNode, ImapResponse } from './handler/types.js';
|
|
5
|
+
import type { FetchMessageObject, ListResponse, ListTreeResponse, MailboxObject, MessageEnvelopeObject, MessageStructureObject, StatusQuery } from './types.js';
|
|
6
|
+
export { AuthenticationFailure } from './errors.js';
|
|
7
|
+
export declare const EXPANDED_RANGE_LIMIT = 16777216;
|
|
8
|
+
export declare const MAX_UINT32_DIGITS = 10;
|
|
9
|
+
export declare const noop: () => void;
|
|
10
|
+
/**
|
|
11
|
+
* A stream decoder returned by getDecoder(). The Japanese decoder reports the `limited`
|
|
12
|
+
* flag once it has buffered all it will accept; a streaming iconv decoder never sets it.
|
|
13
|
+
*/
|
|
14
|
+
export type CharsetDecoder = Transform & {
|
|
15
|
+
limited?: boolean | undefined;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Builds an error describing a connection that is gone, stamped so it can be traced back to
|
|
19
|
+
* where it came from: the connection id always travels on it, and each site names itself
|
|
20
|
+
* through `meta` (`rejectedFrom`, plus the command or mailbox path it belongs to).
|
|
21
|
+
*
|
|
22
|
+
* A stack trace only records where an error was built, and close() hands a rejection to every
|
|
23
|
+
* pending request and every queued lock in the same tick, so without these an error that
|
|
24
|
+
* reaches a global unhandledRejection handler arrives with nothing that identifies the
|
|
25
|
+
* connection it came from, let alone which of the rejected promises carried it.
|
|
26
|
+
*
|
|
27
|
+
* Takes the connection id rather than the connection, so the stamping stays in one place
|
|
28
|
+
* without every caller having to be a full ImapFlow instance.
|
|
29
|
+
*
|
|
30
|
+
* @param cid - Connection id
|
|
31
|
+
* @param code - Error code, e.g. 'NoConnection'
|
|
32
|
+
* @param message - Error message
|
|
33
|
+
* @param meta - Fields to stamp on the error
|
|
34
|
+
* @returns The stamped error
|
|
35
|
+
*/
|
|
36
|
+
export declare function buildConnectionError(cid: string, code: string, message: string, meta?: ConnectionErrorSite | undefined): ImapFlowError;
|
|
37
|
+
/**
|
|
38
|
+
* Re-stamps an existing connection error for a different rejection site.
|
|
39
|
+
*
|
|
40
|
+
* The same failure can be handed to more than one promise - close() rejects the in-flight
|
|
41
|
+
* command, and runIdle() then rejects everything queued behind it - and each of those is a
|
|
42
|
+
* separate promise with a separate consumer. Sharing one error object reports whichever of
|
|
43
|
+
* them escapes under the first site's marker, which is the attribution these markers exist to
|
|
44
|
+
* give.
|
|
45
|
+
*
|
|
46
|
+
* Everything describing *what went wrong* is carried over, because a re-stamped error reaches
|
|
47
|
+
* user code through run() and callers branch on `responseStatus`, `serverResponseCode` and
|
|
48
|
+
* friends. Everything describing *where it was rejected* is dropped, because the new site owns
|
|
49
|
+
* those and a leftover `command` from the previous site is exactly as misleading as a leftover
|
|
50
|
+
* `rejectedFrom`. The original travels on as `cause`.
|
|
51
|
+
*
|
|
52
|
+
* @param err - The error being re-stamped
|
|
53
|
+
* @param meta - Fields for the new site, e.g. { rejectedFrom: 'preCheckWaiter' }
|
|
54
|
+
* @returns A separate error describing the same failure at the new site
|
|
55
|
+
*/
|
|
56
|
+
export declare function restampConnectionError(err: ImapFlowError, meta?: ConnectionErrorSite | undefined): ImapFlowError;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a promise whose rejection is observed as soon as it exists.
|
|
59
|
+
*
|
|
60
|
+
* close() rejects every promise it owns - the in-flight and queued commands, the pending
|
|
61
|
+
* connect(), the queued mailbox locks, the waiters for an IDLE break - synchronously, from a
|
|
62
|
+
* socket event. A consumer that only reaches its `await` a microtask later has not attached a
|
|
63
|
+
* handler yet at the moment Node decides whether the rejection was observed, and the whole
|
|
64
|
+
* worker dies on the resulting unhandledRejection. The pre-attached observer settles that
|
|
65
|
+
* question; the rejection still propagates normally to whoever awaits the returned promise.
|
|
66
|
+
*
|
|
67
|
+
* Creation and guarding are one call because splitting them is what actually goes wrong: the
|
|
68
|
+
* guard was hand-attached at three of the four sites and the fourth (the IDLE-break waiter)
|
|
69
|
+
* went unguarded, on exactly the path a server BYE takes.
|
|
70
|
+
*
|
|
71
|
+
* @param executor - Promise executor, (resolve, reject) => {}
|
|
72
|
+
* @returns The promise, with its rejection already observed
|
|
73
|
+
*/
|
|
74
|
+
export declare function guardedPromise<T>(executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void): Promise<T>;
|
|
75
|
+
/**
|
|
76
|
+
* The already-rejected form of guardedPromise(), for a call that has to hand back a rejected
|
|
77
|
+
* promise rather than throw.
|
|
78
|
+
*
|
|
79
|
+
* @param error - Rejection reason
|
|
80
|
+
* @returns Rejected promise, with its rejection already observed
|
|
81
|
+
*/
|
|
82
|
+
export declare function guardedReject(error: Error): Promise<never>;
|
|
83
|
+
/**
|
|
84
|
+
* Detaches a background timer from the event loop, so it cannot keep the process alive on its
|
|
85
|
+
* own. Applied to every background timer (auto-IDLE, IDLE restart, fallback polling, throttle
|
|
86
|
+
* back-off, held-lock diagnostics); connection and greeting deadlines are deliberately left
|
|
87
|
+
* attached, because a caller is waiting for connect() to settle.
|
|
88
|
+
*
|
|
89
|
+
* @param timer - Timer handle returned by setTimeout
|
|
90
|
+
* @returns The same timer handle
|
|
91
|
+
*/
|
|
92
|
+
/**
|
|
93
|
+
* Clears a timer that may already have been dropped. `clearTimeout()` accepts undefined but not
|
|
94
|
+
* null, and the connection nulls its timer fields once cleared, so every site clears through here.
|
|
95
|
+
*
|
|
96
|
+
* @param timer - Timer handle returned by setTimeout, or null/undefined when none is armed
|
|
97
|
+
*/
|
|
98
|
+
export declare function clearTimer(timer: NodeJS.Timeout | null | undefined): void;
|
|
99
|
+
export declare function unrefTimer<T extends NodeJS.Timeout | null | undefined>(timer: T): T;
|
|
100
|
+
/**
|
|
101
|
+
* Logs a failure from background connection work at the level its cause deserves.
|
|
102
|
+
*
|
|
103
|
+
* Background work (IDLE sessions, polling timers, auto-IDLE) is interrupted by every normal
|
|
104
|
+
* disconnect, so a rejection carrying one of the CONNECTION_GONE_CODES is expected rather
|
|
105
|
+
* than notable and goes to debug. The three codes describe the same situation reached
|
|
106
|
+
* through different guards: write() throws NoConnection or StateLogout, exec() rejects
|
|
107
|
+
* EConnectionClosed for the window where the socket is destroyed but close() has not run
|
|
108
|
+
* yet, and close() rejects pending requests with NoConnection.
|
|
109
|
+
*
|
|
110
|
+
* A connection error carrying `reason` is the exception. That field holds the server's
|
|
111
|
+
* untagged BYE text ("Too many simultaneous connections", "Account is disabled"), which
|
|
112
|
+
* serverBye() only records - this log call is the one place it becomes visible, and it is
|
|
113
|
+
* usually the answer to why a client is reconnecting in a loop. Those stay at warn.
|
|
114
|
+
*
|
|
115
|
+
* Shared so the classification cannot drift between the call sites that make this decision.
|
|
116
|
+
*
|
|
117
|
+
* @param connection - IMAP connection instance
|
|
118
|
+
* @param msg - What failed, so the entries stay distinguishable in the log
|
|
119
|
+
* @param err - The error to log
|
|
120
|
+
*/
|
|
121
|
+
export declare function logConnectionError(connection: ImapFlow, msg: string, err: ImapFlowError | null | undefined): void;
|
|
122
|
+
/**
|
|
123
|
+
* Checks whether IMAP4rev2 semantics are active for the connection: either the
|
|
124
|
+
* client enabled IMAP4rev2 explicitly, or the server is rev2-only (advertises
|
|
125
|
+
* IMAP4rev2 without IMAP4rev1), in which case rev2 is the base protocol without
|
|
126
|
+
* any ENABLE (RFC 9051 Appendix A). UTF-8 mailbox names apply in both cases.
|
|
127
|
+
*
|
|
128
|
+
* @param connection - IMAP connection instance
|
|
129
|
+
* @returns True if IMAP4rev2 semantics apply to this session
|
|
130
|
+
*/
|
|
131
|
+
export declare function isRev2Active(connection: ImapFlow): boolean;
|
|
132
|
+
/**
|
|
133
|
+
* Checks a capability, accounting for extensions that RFC 9051 folds into base
|
|
134
|
+
* IMAP4rev2. Falls back to the plain capability lookup on IMAP4rev1 sessions,
|
|
135
|
+
* so behavior against rev1 servers is unchanged.
|
|
136
|
+
*
|
|
137
|
+
* @param connection - IMAP connection instance
|
|
138
|
+
* @param capability - Capability name, e.g. 'UIDPLUS'
|
|
139
|
+
* @returns True if the capability (or its rev2-folded equivalent) is available
|
|
140
|
+
*/
|
|
141
|
+
export declare function hasCapability(connection: ImapFlow, capability: string): boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Builds the attribute list for a STATUS request - the standalone STATUS command
|
|
144
|
+
* or the LIST-STATUS return option - from a status query object. Items the current
|
|
145
|
+
* session cannot request (RECENT under IMAP4rev2, HIGHESTMODSEQ without CONDSTORE)
|
|
146
|
+
* are silently dropped.
|
|
147
|
+
*
|
|
148
|
+
* @param connection - IMAP connection instance
|
|
149
|
+
* @param statusQuery - Status data items to request, e.g. {messages: true}
|
|
150
|
+
* @returns Attribute token list for the command compiler
|
|
151
|
+
*/
|
|
152
|
+
export declare function buildStatusQueryAttributes(connection: ImapFlow, statusQuery: StatusQuery | undefined): ImapAttributeNode[];
|
|
153
|
+
/**
|
|
154
|
+
* Encodes a mailbox path to modified UTF-7 if the server does not support UTF8=ACCEPT.
|
|
155
|
+
*
|
|
156
|
+
* @param connection - IMAP connection instance
|
|
157
|
+
* @param path - Mailbox path to encode
|
|
158
|
+
* @returns Encoded mailbox path
|
|
159
|
+
*/
|
|
160
|
+
export declare function encodePath(connection: ImapFlow, path: string | undefined): string;
|
|
161
|
+
/**
|
|
162
|
+
* Decodes a mailbox path from modified UTF-7 if the server does not support UTF8=ACCEPT.
|
|
163
|
+
*
|
|
164
|
+
* @param connection - IMAP connection instance
|
|
165
|
+
* @param path - Mailbox path to decode
|
|
166
|
+
* @returns Decoded mailbox path
|
|
167
|
+
*/
|
|
168
|
+
export declare function decodePath(connection: ImapFlow, path: string | undefined): string;
|
|
169
|
+
/**
|
|
170
|
+
* Normalizes a mailbox path by joining array segments with the namespace delimiter,
|
|
171
|
+
* uppercasing INBOX, and prepending the namespace prefix if needed.
|
|
172
|
+
*
|
|
173
|
+
* @param connection - IMAP connection instance
|
|
174
|
+
* @param path - Mailbox path or array of path segments
|
|
175
|
+
* @param skipNamespace - If true, skips prepending the namespace prefix
|
|
176
|
+
* @returns Normalized mailbox path
|
|
177
|
+
*/
|
|
178
|
+
export declare function normalizePath(connection: ImapFlow, path: string | string[], skipNamespace?: boolean): string;
|
|
179
|
+
/**
|
|
180
|
+
* Compares two mailbox paths for equality after normalization.
|
|
181
|
+
*
|
|
182
|
+
* @param connection - IMAP connection instance
|
|
183
|
+
* @param a - First mailbox path
|
|
184
|
+
* @param b - Second mailbox path
|
|
185
|
+
* @returns True if the paths are equal after normalization
|
|
186
|
+
*/
|
|
187
|
+
export declare function comparePaths(connection: ImapFlow, a: string | undefined, b: string | undefined): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* Parses a capability response list into a Map of capability names to values.
|
|
190
|
+
*
|
|
191
|
+
* @param list - Array of capability objects from IMAP response
|
|
192
|
+
* @returns Map of capability names to `true` or numeric values
|
|
193
|
+
*/
|
|
194
|
+
export declare function updateCapabilities(list: ImapAttributeList | null | undefined): Map<string, boolean | number>;
|
|
195
|
+
/**
|
|
196
|
+
* Extracts the IMAP response status code (e.g. AUTHENTICATIONFAILED, NONEXISTENT)
|
|
197
|
+
* from a parsed server response.
|
|
198
|
+
*
|
|
199
|
+
* @param response - Parsed IMAP server response
|
|
200
|
+
* @returns Uppercase status code string, or false if not found
|
|
201
|
+
*/
|
|
202
|
+
export declare function getStatusCode(response: ImapResponse | string | false | undefined): string | false;
|
|
203
|
+
/**
|
|
204
|
+
* Compiles an IMAP response object back into a human-readable string.
|
|
205
|
+
*
|
|
206
|
+
* @param response - Parsed IMAP server response
|
|
207
|
+
* @returns Compiled response text, or false if no response
|
|
208
|
+
*/
|
|
209
|
+
export declare function getErrorText(response: ImapResponse | string | false | undefined): Promise<string | false>;
|
|
210
|
+
/**
|
|
211
|
+
* Enhances an IMAP command error with the server response code and text.
|
|
212
|
+
*
|
|
213
|
+
* @param err - Error object with a `response` property
|
|
214
|
+
* @returns The enhanced error with `serverResponseCode` and string `response`
|
|
215
|
+
*/
|
|
216
|
+
export declare function enhanceCommandError(err: ImapFlowError): Promise<ImapFlowError>;
|
|
217
|
+
/**
|
|
218
|
+
* Converts a flat list of mailbox folders into a tree structure.
|
|
219
|
+
*
|
|
220
|
+
* @param folders - Array of folder objects from LIST/LSUB response
|
|
221
|
+
* @returns Tree structure with a `root` flag and nested `folders` arrays
|
|
222
|
+
*/
|
|
223
|
+
export declare function getFolderTree(folders: ListResponse[]): ListTreeResponse;
|
|
224
|
+
/**
|
|
225
|
+
* Derives a flag color name from a message's flags Set using Apple Mail color flag rules.
|
|
226
|
+
*
|
|
227
|
+
* @param flags - Message flags Set
|
|
228
|
+
* @returns Color name (e.g. 'red', 'orange') or null if not flagged
|
|
229
|
+
*/
|
|
230
|
+
export declare function getFlagColor(flags: Set<string>): string | null;
|
|
231
|
+
/**
|
|
232
|
+
* Converts a color name to the corresponding flag add/remove operations for Apple Mail color flags.
|
|
233
|
+
*
|
|
234
|
+
* @param color - Color name (e.g. 'red', 'orange', 'yellow')
|
|
235
|
+
* @returns Object with `add` and `remove` arrays of flag strings, or null if invalid color
|
|
236
|
+
*/
|
|
237
|
+
export declare function getColorFlags(color: string | null | undefined): {
|
|
238
|
+
add: string[];
|
|
239
|
+
remove: string[];
|
|
240
|
+
} | null;
|
|
241
|
+
/**
|
|
242
|
+
* Formats a raw untagged FETCH response into a structured message object.
|
|
243
|
+
*
|
|
244
|
+
* @param untagged - Parsed untagged IMAP response
|
|
245
|
+
* @param mailbox - Current mailbox state object
|
|
246
|
+
* @returns Formatted message object with properties like seq, uid, flags, envelope, etc.
|
|
247
|
+
*/
|
|
248
|
+
export declare function formatMessageResponse(untagged: ImapResponse, mailbox: MailboxObject): Promise<FetchMessageObject>;
|
|
249
|
+
/**
|
|
250
|
+
* Strips surrounding double quotes from a name string.
|
|
251
|
+
*
|
|
252
|
+
* @param name - Raw name string potentially wrapped in quotes
|
|
253
|
+
* @returns Name with surrounding quotes removed
|
|
254
|
+
*/
|
|
255
|
+
export declare function processName(name: unknown): string;
|
|
256
|
+
/**
|
|
257
|
+
* Decodes an ENVELOPE text field for display: encoded words first, then the
|
|
258
|
+
* surrounding quotes some servers leave in place.
|
|
259
|
+
*
|
|
260
|
+
* @param value - Raw field value from an ENVELOPE response
|
|
261
|
+
* @returns Decoded, unquoted text
|
|
262
|
+
*/
|
|
263
|
+
export declare function decodeText(value: string): string;
|
|
264
|
+
/**
|
|
265
|
+
* Parses a raw IMAP ENVELOPE response into a structured envelope object.
|
|
266
|
+
*
|
|
267
|
+
* @param entry - Raw envelope data array from IMAP response
|
|
268
|
+
* @returns Parsed envelope with date, subject, from, to, cc, bcc, messageId, etc.
|
|
269
|
+
*/
|
|
270
|
+
export declare function parseEnvelope(entry: ImapAttributeList): MessageEnvelopeObject;
|
|
271
|
+
/**
|
|
272
|
+
* Parses structured MIME parameter arrays (including RFC 2231 continuations)
|
|
273
|
+
* into a flat key-value object.
|
|
274
|
+
*
|
|
275
|
+
* @param arr - Raw parameter array from BODYSTRUCTURE response
|
|
276
|
+
* @returns Key-value object of decoded parameters
|
|
277
|
+
*/
|
|
278
|
+
export declare function getStructuredParams(arr: ImapAttributeList | null | undefined): {
|
|
279
|
+
[key: string]: string;
|
|
280
|
+
};
|
|
281
|
+
/**
|
|
282
|
+
* Parses a raw IMAP BODYSTRUCTURE response into a structured tree of body parts.
|
|
283
|
+
*
|
|
284
|
+
* @param entry - Raw BODYSTRUCTURE data array from IMAP response
|
|
285
|
+
* @returns Parsed body structure tree with part numbers, types, parameters, and child nodes
|
|
286
|
+
*/
|
|
287
|
+
export declare function parseBodystructure(entry: ImapAttributeList): MessageStructureObject;
|
|
288
|
+
/**
|
|
289
|
+
* Checks if a value is a Date object.
|
|
290
|
+
*
|
|
291
|
+
* @param obj - Value to check
|
|
292
|
+
* @returns True if the value is a Date object
|
|
293
|
+
*/
|
|
294
|
+
export declare function isDate(obj: unknown): obj is Date;
|
|
295
|
+
/**
|
|
296
|
+
* Converts a value to a valid Date object, or returns null.
|
|
297
|
+
*
|
|
298
|
+
* @param value - Date object or date string to convert
|
|
299
|
+
* @returns Valid Date object, or null if conversion fails
|
|
300
|
+
*/
|
|
301
|
+
export declare function toValidDate(value: unknown): Date | null;
|
|
302
|
+
/**
|
|
303
|
+
* Formats a date value into IMAP date format (DD-Mon-YYYY).
|
|
304
|
+
*
|
|
305
|
+
* @param value - Date to format
|
|
306
|
+
* @returns Formatted date string, or undefined if invalid
|
|
307
|
+
*/
|
|
308
|
+
export declare function formatDate(value: Date | string | null | undefined): string | undefined;
|
|
309
|
+
/**
|
|
310
|
+
* Formats a date value into IMAP date-time format (DD-Mon-YYYY HH:MM:SS +0000).
|
|
311
|
+
*
|
|
312
|
+
* @param value - Date to format
|
|
313
|
+
* @returns Formatted date-time string, or undefined if invalid
|
|
314
|
+
*/
|
|
315
|
+
export declare function formatDateTime(value: Date | string | null | undefined): string | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* Normalizes a flag string. Returns false for non-settable flags (e.g. \Recent),
|
|
318
|
+
* and capitalizes system flags properly.
|
|
319
|
+
*
|
|
320
|
+
* @param flag - Flag string to normalize
|
|
321
|
+
* @returns Normalized flag string, or false if the flag cannot be set
|
|
322
|
+
*/
|
|
323
|
+
export declare function formatFlag(flag: string): string | false;
|
|
324
|
+
/**
|
|
325
|
+
* Checks if a flag can be used in the given mailbox based on permanent flags.
|
|
326
|
+
*
|
|
327
|
+
* @param mailbox - Mailbox object with permanentFlags
|
|
328
|
+
* @param flag - Flag to check
|
|
329
|
+
* @returns True if the flag is allowed
|
|
330
|
+
*/
|
|
331
|
+
export declare function canUseFlag(mailbox: MailboxObject | false | null | undefined, flag: string): boolean;
|
|
332
|
+
/**
|
|
333
|
+
* Checks that a value is a valid IMAP sequence number or UID: a non-zero
|
|
334
|
+
* 32-bit unsigned integer (nz-number in the RFC 9051 grammar). Guards range
|
|
335
|
+
* expansion against untrusted server input such as 'Infinity' or '0:*'.
|
|
336
|
+
*
|
|
337
|
+
* @param value - Value to check
|
|
338
|
+
* @returns True if the value is a valid sequence number/UID
|
|
339
|
+
*/
|
|
340
|
+
export declare function isValidSequenceValue(value: unknown): value is number;
|
|
341
|
+
/**
|
|
342
|
+
* Checks that an untrusted response value is a pure decimal digit run no longer than
|
|
343
|
+
* the given bound.
|
|
344
|
+
*
|
|
345
|
+
* `!isNaN(value)` is not usable for this: it also passes '1e5', ' 12 ', '0x10' and
|
|
346
|
+
* 'Infinity'. BigInt() throws on all of them and Number() silently returns a value the
|
|
347
|
+
* grammar never allowed, so both are wrong in a response handler that is only trying to
|
|
348
|
+
* read one field. The length bound is checked before the pattern so an arbitrarily long
|
|
349
|
+
* digit run is rejected without any conversion work.
|
|
350
|
+
*
|
|
351
|
+
* @param value - Raw value from the response.
|
|
352
|
+
* @param maxDigits - Maximum number of digits accepted.
|
|
353
|
+
* @returns True if the value is a decimal string within the bound.
|
|
354
|
+
*/
|
|
355
|
+
export declare function isDecimalString(value: unknown, maxDigits: number): value is string;
|
|
356
|
+
/**
|
|
357
|
+
* Checks whether a server-supplied string is unsafe to use as a key on a plain object.
|
|
358
|
+
* Assigning "__proto__" writes through the prototype setter instead of creating an own
|
|
359
|
+
* property, and reading "constructor" or "prototype" resolves to an inherited member.
|
|
360
|
+
*
|
|
361
|
+
* @param key - Candidate key from a server response.
|
|
362
|
+
* @returns True if the key must not be used.
|
|
363
|
+
*/
|
|
364
|
+
export declare function isUnsafeKey(key: unknown): boolean;
|
|
365
|
+
/**
|
|
366
|
+
* Reads a parsed attribute list of atoms or strings (a flag list, a capability list) into
|
|
367
|
+
* an array of strings. Any element can be a parsed NIL, and the list itself can be NIL,
|
|
368
|
+
* so both levels are guarded here rather than at each call site.
|
|
369
|
+
*
|
|
370
|
+
* @param list - Parsed attribute list from a response.
|
|
371
|
+
* @returns The string values, in order, with unusable entries dropped.
|
|
372
|
+
*/
|
|
373
|
+
export declare function getStringList(list: unknown): string[];
|
|
374
|
+
/**
|
|
375
|
+
* Parses an untrusted decimal value from a server response into a BigInt.
|
|
376
|
+
*
|
|
377
|
+
* @param value - Raw value from the response.
|
|
378
|
+
* @param maxDigits - Maximum number of digits accepted. Defaults to MAX_NUMBER64_DIGITS.
|
|
379
|
+
* @returns The parsed value, or false when it is not usable.
|
|
380
|
+
*/
|
|
381
|
+
export declare function parseBigIntValue(value: unknown, maxDigits?: number): bigint | false;
|
|
382
|
+
/**
|
|
383
|
+
* Parses an untrusted decimal value from a server response into a Number. Values beyond
|
|
384
|
+
* the safe integer range are rejected rather than rounded: a silently rounded count or
|
|
385
|
+
* UID corrupts every range computation derived from it.
|
|
386
|
+
*
|
|
387
|
+
* @param value - Raw value from the response.
|
|
388
|
+
* @param maxDigits - Maximum number of digits accepted. Defaults to MAX_NUMBER64_DIGITS.
|
|
389
|
+
* @returns The parsed value, or false when it is not usable.
|
|
390
|
+
*/
|
|
391
|
+
export declare function parseUintValue(value: unknown, maxDigits?: number): number | false;
|
|
392
|
+
/**
|
|
393
|
+
* Expands an IMAP sequence range string (e.g. "1:3,5,7:9") into an array of numbers.
|
|
394
|
+
*
|
|
395
|
+
* Entries with endpoints that are not valid nz-numbers are skipped - the input
|
|
396
|
+
* may come from an untrusted server, and 'Infinity' or similar garbage would
|
|
397
|
+
* otherwise loop without bound. The whole set is expanded to at most
|
|
398
|
+
* EXPANDED_RANGE_LIMIT entries in total: legitimate responses never reach the limit
|
|
399
|
+
* (the mailbox would need that many messages), while hostile input is cut off
|
|
400
|
+
* instead of exhausting memory. The total is capped, not just each range -
|
|
401
|
+
* otherwise "1:16777216,1:16777216,..." would multiply the per-range bound by an
|
|
402
|
+
* unbounded number of ranges.
|
|
403
|
+
*
|
|
404
|
+
* @param range - IMAP sequence range string
|
|
405
|
+
* @returns Array of expanded sequence numbers
|
|
406
|
+
*/
|
|
407
|
+
export declare function expandRange(range: unknown): number[];
|
|
408
|
+
/**
|
|
409
|
+
* Returns a stream decoder for the given charset. Uses a special Japanese
|
|
410
|
+
* charset decoder for JIS/ISO-2022-JP, otherwise delegates to iconv-lite.
|
|
411
|
+
*
|
|
412
|
+
* @param charset - Character set name. Defaults to 'ascii'.
|
|
413
|
+
* @param maxBytes - Bound for the bytes the decoder may buffer. Only
|
|
414
|
+
* relevant for the Japanese decoder, which must buffer its whole input before
|
|
415
|
+
* it can decode: without the bound a server could defeat a caller's maxBytes
|
|
416
|
+
* download limit simply by labelling the part with a Japanese charset.
|
|
417
|
+
* @returns A stream decoder (Transform stream) for the charset
|
|
418
|
+
*/
|
|
419
|
+
export declare function getDecoder(charset?: string | undefined, maxBytes?: number | undefined): CharsetDecoder;
|
|
420
|
+
/**
|
|
421
|
+
* Packs an array of message sequence numbers into a compact IMAP range string
|
|
422
|
+
* (e.g. [1,2,3,5,7,8] becomes "1:3,5,7:8").
|
|
423
|
+
*
|
|
424
|
+
* @param list - Sequence number or array of sequence numbers
|
|
425
|
+
* @returns Packed IMAP sequence range string
|
|
426
|
+
*/
|
|
427
|
+
export declare function packMessageRange(list: number | number[] | null | undefined): string;
|