imapflow 1.7.7 → 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 +27 -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 +785 -1802
- 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 -57
- 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 -873
- 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 -593
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.0.0](https://github.com/postalsys/imapflow/compare/v1.7.8...v2.0.0) (2026-09-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### ⚠ BREAKING CHANGES
|
|
7
|
+
|
|
8
|
+
* Node.js 20 or newer is required. The `lib/` directory is no longer published; use the package root or the `imapflow/lib/*` export map.
|
|
9
|
+
|
|
10
|
+
### Features
|
|
11
|
+
|
|
12
|
+
* migrate to TypeScript with ES module and CommonJS builds ([a2cde07](https://github.com/postalsys/imapflow/commit/a2cde0778f6d7cb8471ca8e4011534476442ae98))
|
|
13
|
+
* support Bun and Cloudflare Workers ([70fff15](https://github.com/postalsys/imapflow/commit/70fff15b4a3297d4b29c8da7b1faf703ebf00876))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* re-arm auto-IDLE after an IDLE or poll session ends on its own ([e6e5d27](https://github.com/postalsys/imapflow/commit/e6e5d27debf87748aae740b5a0a47b2afc2079b3))
|
|
19
|
+
* **types:** strip the internal members of ImapFlow from the declarations ([68b7258](https://github.com/postalsys/imapflow/commit/68b72587e07ebba52676df5b68631d60f55b08c0))
|
|
20
|
+
* **types:** type AuthenticationFailure.response as the string it always is ([5c3b3af](https://github.com/postalsys/imapflow/commit/5c3b3afd234bccf7d86fd999f4673e43ec131b6d))
|
|
21
|
+
* **types:** type the events without the generic EventEmitter of @types/node ([a4285b2](https://github.com/postalsys/imapflow/commit/a4285b26064115bd1740b7850b2b0a14e02d96b8))
|
|
22
|
+
|
|
23
|
+
## [1.7.8](https://github.com/postalsys/imapflow/compare/v1.7.7...v1.7.8) (2026-09-01)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Bug Fixes
|
|
27
|
+
|
|
28
|
+
* **download:** keep the pipeline error forwarder across a backpressure wait ([c6b2ed7](https://github.com/postalsys/imapflow/commit/c6b2ed7f2ffb598dad0d7a4beb915055c3cfbef6))
|
|
29
|
+
|
|
3
30
|
## [1.7.7](https://github.com/postalsys/imapflow/compare/v1.7.6...v1.7.7) (2026-08-31)
|
|
4
31
|
|
|
5
32
|
|
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@ ImapFlow provides a clean, promise-based API for working with IMAP, so you don't
|
|
|
13
13
|
- **Automatic IMAP extension handling** - CONDSTORE, QRESYNC, IDLE, COMPRESS, and [more](https://imapflow.com/docs/)
|
|
14
14
|
- **Message streaming** - async iterators for efficient processing
|
|
15
15
|
- **Mailbox locking** - built-in locking mechanism for safe concurrent access
|
|
16
|
-
- **TypeScript support** - type definitions included
|
|
16
|
+
- **TypeScript support** - written in TypeScript, type definitions included
|
|
17
|
+
- **ES modules and CommonJS** - `import { ImapFlow } from 'imapflow'` and `const { ImapFlow } = require('imapflow')` both work
|
|
17
18
|
- **Proxy support** - SOCKS and HTTP CONNECT proxies
|
|
18
19
|
- **Gmail support** - labels, raw search via X-GM-EXT-1
|
|
19
20
|
|
|
@@ -23,10 +24,15 @@ ImapFlow provides a clean, promise-based API for working with IMAP, so you don't
|
|
|
23
24
|
npm install imapflow
|
|
24
25
|
```
|
|
25
26
|
|
|
27
|
+
ImapFlow requires Node.js 20 or newer. The package ships both an ES module build and a CommonJS build with bundled type declarations, so no separate `@types` package is needed.
|
|
28
|
+
|
|
29
|
+
The ES module build also runs on [Bun](https://bun.sh/) (tested against the latest release) and on [Cloudflare Workers](https://developers.cloudflare.com/workers/) with the `nodejs_compat` compatibility flag. On Workers connect with implicit TLS (`secure: true`, usually port 993) or in cleartext: the runtime can not upgrade an already connected socket, so a STARTTLS negotiation fails with a TLS error, and it does not allow turning certificate validation off, so `tls: { rejectUnauthorized: false }` is rejected with `ERR_OPTION_NOT_IMPLEMENTED`. COMPRESS=DEFLATE, IDLE and the default pino logger work as on Node.js.
|
|
30
|
+
|
|
26
31
|
## Quick Example
|
|
27
32
|
|
|
28
33
|
```js
|
|
29
|
-
|
|
34
|
+
import { ImapFlow } from 'imapflow';
|
|
35
|
+
// or in CommonJS: const { ImapFlow } = require('imapflow');
|
|
30
36
|
|
|
31
37
|
const client = new ImapFlow({
|
|
32
38
|
host: 'imap.example.com',
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const resolveCharset: (charset: string) => string | null;
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveCharset = void 0;
|
|
4
|
+
// Subset of the IANA Character Sets registry (https://www.iana.org/assignments/character-sets/).
|
|
5
|
+
// Used to validate and resolve charset names found in MIME Content-Type parameters.
|
|
6
|
+
// This list covers the most commonly encountered charsets in email messages.
|
|
7
|
+
const CHARACTER_SETS = [
|
|
8
|
+
'US-ASCII',
|
|
9
|
+
'ISO-8859-1',
|
|
10
|
+
'ISO-8859-2',
|
|
11
|
+
'ISO-8859-3',
|
|
12
|
+
'ISO-8859-4',
|
|
13
|
+
'ISO-8859-5',
|
|
14
|
+
'ISO-8859-6',
|
|
15
|
+
'ISO-8859-7',
|
|
16
|
+
'ISO-8859-8',
|
|
17
|
+
'ISO-8859-9',
|
|
18
|
+
'ISO-8859-10',
|
|
19
|
+
'ISO_6937-2-add',
|
|
20
|
+
'JIS_X0201',
|
|
21
|
+
'JIS_Encoding',
|
|
22
|
+
'Shift_JIS',
|
|
23
|
+
'EUC-JP',
|
|
24
|
+
'Extended_UNIX_Code_Fixed_Width_for_Japanese',
|
|
25
|
+
'BS_4730',
|
|
26
|
+
'SEN_850200_C',
|
|
27
|
+
'IT',
|
|
28
|
+
'ES',
|
|
29
|
+
'DIN_66003',
|
|
30
|
+
'NS_4551-1',
|
|
31
|
+
'NF_Z_62-010',
|
|
32
|
+
'ISO-10646-UTF-1',
|
|
33
|
+
'ISO_646.basic:1983',
|
|
34
|
+
'INVARIANT',
|
|
35
|
+
'ISO_646.irv:1983',
|
|
36
|
+
'NATS-SEFI',
|
|
37
|
+
'NATS-SEFI-ADD',
|
|
38
|
+
'NATS-DANO',
|
|
39
|
+
'NATS-DANO-ADD',
|
|
40
|
+
'SEN_850200_B',
|
|
41
|
+
'KS_C_5601-1987',
|
|
42
|
+
'ISO-2022-KR',
|
|
43
|
+
'EUC-KR',
|
|
44
|
+
'ISO-2022-JP',
|
|
45
|
+
'ISO-2022-JP-2',
|
|
46
|
+
'JIS_C6220-1969-jp',
|
|
47
|
+
'JIS_C6220-1969-ro',
|
|
48
|
+
'PT',
|
|
49
|
+
'greek7-old',
|
|
50
|
+
'latin-greek',
|
|
51
|
+
'NF_Z_62-010_(1973)',
|
|
52
|
+
'Latin-greek-1',
|
|
53
|
+
'ISO_5427',
|
|
54
|
+
'JIS_C6226-1978',
|
|
55
|
+
'BS_viewdata',
|
|
56
|
+
'INIS',
|
|
57
|
+
'INIS-8',
|
|
58
|
+
'INIS-cyrillic',
|
|
59
|
+
'ISO_5427:1981',
|
|
60
|
+
'ISO_5428:1980',
|
|
61
|
+
'GB_1988-80',
|
|
62
|
+
'GB_2312-80',
|
|
63
|
+
'NS_4551-2',
|
|
64
|
+
'videotex-suppl',
|
|
65
|
+
'PT2',
|
|
66
|
+
'ES2',
|
|
67
|
+
'MSZ_7795.3',
|
|
68
|
+
'JIS_C6226-1983',
|
|
69
|
+
'greek7',
|
|
70
|
+
'ASMO_449',
|
|
71
|
+
'iso-ir-90',
|
|
72
|
+
'JIS_C6229-1984-a',
|
|
73
|
+
'JIS_C6229-1984-b',
|
|
74
|
+
'JIS_C6229-1984-b-add',
|
|
75
|
+
'JIS_C6229-1984-hand',
|
|
76
|
+
'JIS_C6229-1984-hand-add',
|
|
77
|
+
'JIS_C6229-1984-kana',
|
|
78
|
+
'ISO_2033-1983',
|
|
79
|
+
'ANSI_X3.110-1983',
|
|
80
|
+
'T.61-7bit',
|
|
81
|
+
'T.61-8bit',
|
|
82
|
+
'ECMA-cyrillic',
|
|
83
|
+
'CSA_Z243.4-1985-1',
|
|
84
|
+
'CSA_Z243.4-1985-2',
|
|
85
|
+
'CSA_Z243.4-1985-gr',
|
|
86
|
+
'ISO-8859-6-E',
|
|
87
|
+
'ISO-8859-6-I',
|
|
88
|
+
'T.101-G2',
|
|
89
|
+
'ISO-8859-8-E',
|
|
90
|
+
'ISO-8859-8-I',
|
|
91
|
+
'CSN_369103',
|
|
92
|
+
'JUS_I.B1.002',
|
|
93
|
+
'IEC_P27-1',
|
|
94
|
+
'JUS_I.B1.003-serb',
|
|
95
|
+
'JUS_I.B1.003-mac',
|
|
96
|
+
'greek-ccitt',
|
|
97
|
+
'NC_NC00-10:81',
|
|
98
|
+
'ISO_6937-2-25',
|
|
99
|
+
'GOST_19768-74',
|
|
100
|
+
'ISO_8859-supp',
|
|
101
|
+
'ISO_10367-box',
|
|
102
|
+
'latin-lap',
|
|
103
|
+
'JIS_X0212-1990',
|
|
104
|
+
'DS_2089',
|
|
105
|
+
'us-dk',
|
|
106
|
+
'dk-us',
|
|
107
|
+
'KSC5636',
|
|
108
|
+
'UNICODE-1-1-UTF-7',
|
|
109
|
+
'ISO-2022-CN',
|
|
110
|
+
'ISO-2022-CN-EXT',
|
|
111
|
+
'UTF-8',
|
|
112
|
+
'ISO-8859-13',
|
|
113
|
+
'ISO-8859-14',
|
|
114
|
+
'ISO-8859-15',
|
|
115
|
+
'ISO-8859-16',
|
|
116
|
+
'GBK',
|
|
117
|
+
'GB18030',
|
|
118
|
+
'OSD_EBCDIC_DF04_15',
|
|
119
|
+
'OSD_EBCDIC_DF03_IRV',
|
|
120
|
+
'OSD_EBCDIC_DF04_1',
|
|
121
|
+
'ISO-11548-1',
|
|
122
|
+
'KZ-1048',
|
|
123
|
+
'ISO-10646-UCS-2',
|
|
124
|
+
'ISO-10646-UCS-4',
|
|
125
|
+
'ISO-10646-UCS-Basic',
|
|
126
|
+
'ISO-10646-Unicode-Latin1',
|
|
127
|
+
'ISO-10646-J-1',
|
|
128
|
+
'ISO-Unicode-IBM-1261',
|
|
129
|
+
'ISO-Unicode-IBM-1268',
|
|
130
|
+
'ISO-Unicode-IBM-1276',
|
|
131
|
+
'ISO-Unicode-IBM-1264',
|
|
132
|
+
'ISO-Unicode-IBM-1265',
|
|
133
|
+
'UNICODE-1-1',
|
|
134
|
+
'SCSU',
|
|
135
|
+
'UTF-7',
|
|
136
|
+
'UTF-16BE',
|
|
137
|
+
'UTF-16LE',
|
|
138
|
+
'UTF-16',
|
|
139
|
+
'CESU-8',
|
|
140
|
+
'UTF-32',
|
|
141
|
+
'UTF-32BE',
|
|
142
|
+
'UTF-32LE',
|
|
143
|
+
'BOCU-1',
|
|
144
|
+
'ISO-8859-1-Windows-3.0-Latin-1',
|
|
145
|
+
'ISO-8859-1-Windows-3.1-Latin-1',
|
|
146
|
+
'ISO-8859-2-Windows-Latin-2',
|
|
147
|
+
'ISO-8859-9-Windows-Latin-5',
|
|
148
|
+
'hp-roman8',
|
|
149
|
+
'Adobe-Standard-Encoding',
|
|
150
|
+
'Ventura-US',
|
|
151
|
+
'Ventura-International',
|
|
152
|
+
'DEC-MCS',
|
|
153
|
+
'IBM850',
|
|
154
|
+
'PC8-Danish-Norwegian',
|
|
155
|
+
'IBM862',
|
|
156
|
+
'PC8-Turkish',
|
|
157
|
+
'IBM-Symbols',
|
|
158
|
+
'IBM-Thai',
|
|
159
|
+
'HP-Legal',
|
|
160
|
+
'HP-Pi-font',
|
|
161
|
+
'HP-Math8',
|
|
162
|
+
'Adobe-Symbol-Encoding',
|
|
163
|
+
'HP-DeskTop',
|
|
164
|
+
'Ventura-Math',
|
|
165
|
+
'Microsoft-Publishing',
|
|
166
|
+
'Windows-31J',
|
|
167
|
+
'GB2312',
|
|
168
|
+
'Big5',
|
|
169
|
+
'macintosh',
|
|
170
|
+
'IBM037',
|
|
171
|
+
'IBM038',
|
|
172
|
+
'IBM273',
|
|
173
|
+
'IBM274',
|
|
174
|
+
'IBM275',
|
|
175
|
+
'IBM277',
|
|
176
|
+
'IBM278',
|
|
177
|
+
'IBM280',
|
|
178
|
+
'IBM281',
|
|
179
|
+
'IBM284',
|
|
180
|
+
'IBM285',
|
|
181
|
+
'IBM290',
|
|
182
|
+
'IBM297',
|
|
183
|
+
'IBM420',
|
|
184
|
+
'IBM423',
|
|
185
|
+
'IBM424',
|
|
186
|
+
'IBM437',
|
|
187
|
+
'IBM500',
|
|
188
|
+
'IBM851',
|
|
189
|
+
'IBM852',
|
|
190
|
+
'IBM855',
|
|
191
|
+
'IBM857',
|
|
192
|
+
'IBM860',
|
|
193
|
+
'IBM861',
|
|
194
|
+
'IBM863',
|
|
195
|
+
'IBM864',
|
|
196
|
+
'IBM865',
|
|
197
|
+
'IBM868',
|
|
198
|
+
'IBM869',
|
|
199
|
+
'IBM870',
|
|
200
|
+
'IBM871',
|
|
201
|
+
'IBM880',
|
|
202
|
+
'IBM891',
|
|
203
|
+
'IBM903',
|
|
204
|
+
'IBM904',
|
|
205
|
+
'IBM905',
|
|
206
|
+
'IBM918',
|
|
207
|
+
'IBM1026',
|
|
208
|
+
'EBCDIC-AT-DE',
|
|
209
|
+
'EBCDIC-AT-DE-A',
|
|
210
|
+
'EBCDIC-CA-FR',
|
|
211
|
+
'EBCDIC-DK-NO',
|
|
212
|
+
'EBCDIC-DK-NO-A',
|
|
213
|
+
'EBCDIC-FI-SE',
|
|
214
|
+
'EBCDIC-FI-SE-A',
|
|
215
|
+
'EBCDIC-FR',
|
|
216
|
+
'EBCDIC-IT',
|
|
217
|
+
'EBCDIC-PT',
|
|
218
|
+
'EBCDIC-ES',
|
|
219
|
+
'EBCDIC-ES-A',
|
|
220
|
+
'EBCDIC-ES-S',
|
|
221
|
+
'EBCDIC-UK',
|
|
222
|
+
'EBCDIC-US',
|
|
223
|
+
'UNKNOWN-8BIT',
|
|
224
|
+
'MNEMONIC',
|
|
225
|
+
'MNEM',
|
|
226
|
+
'VISCII',
|
|
227
|
+
'VIQR',
|
|
228
|
+
'KOI8-R',
|
|
229
|
+
'HZ-GB-2312',
|
|
230
|
+
'IBM866',
|
|
231
|
+
'IBM775',
|
|
232
|
+
'KOI8-U',
|
|
233
|
+
'IBM00858',
|
|
234
|
+
'IBM00924',
|
|
235
|
+
'IBM01140',
|
|
236
|
+
'IBM01141',
|
|
237
|
+
'IBM01142',
|
|
238
|
+
'IBM01143',
|
|
239
|
+
'IBM01144',
|
|
240
|
+
'IBM01145',
|
|
241
|
+
'IBM01146',
|
|
242
|
+
'IBM01147',
|
|
243
|
+
'IBM01148',
|
|
244
|
+
'IBM01149',
|
|
245
|
+
'Big5-HKSCS',
|
|
246
|
+
'IBM1047',
|
|
247
|
+
'PTCP154',
|
|
248
|
+
'Amiga-1251',
|
|
249
|
+
'KOI7-switched',
|
|
250
|
+
'BRF',
|
|
251
|
+
'TSCII',
|
|
252
|
+
'CP51932',
|
|
253
|
+
'windows-874',
|
|
254
|
+
'windows-1250',
|
|
255
|
+
'windows-1251',
|
|
256
|
+
'windows-1252',
|
|
257
|
+
'windows-1253',
|
|
258
|
+
'windows-1254',
|
|
259
|
+
'windows-1255',
|
|
260
|
+
'windows-1256',
|
|
261
|
+
'windows-1257',
|
|
262
|
+
'windows-1258',
|
|
263
|
+
'TIS-620',
|
|
264
|
+
'CP50220'
|
|
265
|
+
];
|
|
266
|
+
const CHARSET_MAP = new Map();
|
|
267
|
+
// Build a lookup map with normalized keys for fuzzy charset resolution.
|
|
268
|
+
// Normalization strategy:
|
|
269
|
+
// 1. Strip all underscores, hyphens, and spaces, then lowercase (e.g., "ISO-8859-1" -> "iso88591")
|
|
270
|
+
// 2. Create additional aliases for common alternative prefixes:
|
|
271
|
+
// - "windows" -> "win" (e.g., "windows1252" also matches as "win1252")
|
|
272
|
+
// - "usascii" -> "ascii" (common shorthand)
|
|
273
|
+
// - "iso8859" -> "latin" (e.g., "iso88591" also matches as "latin1")
|
|
274
|
+
// This handles the many variant spellings found in real-world email headers.
|
|
275
|
+
CHARACTER_SETS.forEach(entry => {
|
|
276
|
+
let key = entry.replace(/[_-\s]/g, '').toLowerCase();
|
|
277
|
+
let modifiedKey = key
|
|
278
|
+
.replace(/^windows/, 'win')
|
|
279
|
+
.replace(/^usascii/, 'ascii')
|
|
280
|
+
.replace(/^iso8859/, 'latin');
|
|
281
|
+
CHARSET_MAP.set(key, entry);
|
|
282
|
+
if (!CHARSET_MAP.has(modifiedKey)) {
|
|
283
|
+
CHARSET_MAP.set(modifiedKey, entry);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
// Resolves a charset name to its canonical IANA form using case-insensitive,
|
|
287
|
+
// symbol-stripping normalization. For example, "WIN-1252", "windows_1252",
|
|
288
|
+
// and "WINDOWS-1252" all resolve to "windows-1252".
|
|
289
|
+
// Returns null if the charset is not recognized.
|
|
290
|
+
const resolveCharset = (charset) => {
|
|
291
|
+
let key = charset.replace(/[_-\s]/g, '').toLowerCase();
|
|
292
|
+
return CHARSET_MAP.get(key) ?? null;
|
|
293
|
+
};
|
|
294
|
+
exports.resolveCharset = resolveCharset;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ImapFlow } from '../imap-flow.js';
|
|
2
|
+
import type { AppendResponseObject } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Result of an APPEND: the destination, the selected mailbox path at the time of the append,
|
|
5
|
+
* and the UID information the server reported
|
|
6
|
+
*/
|
|
7
|
+
export interface AppendResult extends AppendResponseObject {
|
|
8
|
+
/** Path of the currently selected mailbox, if any */
|
|
9
|
+
path?: string | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Appends a message to a mailbox.
|
|
13
|
+
*
|
|
14
|
+
* @param connection - IMAP connection instance
|
|
15
|
+
* @param destination - Destination mailbox path
|
|
16
|
+
* @param content - Message content (RFC 822 format)
|
|
17
|
+
* @param flags - Message flags to set on the appended message
|
|
18
|
+
* @param idate - Internal date to set for the message
|
|
19
|
+
* @returns Append result with UID info if available, or undefined if preconditions not met
|
|
20
|
+
* @throws {Error} If the APPEND command fails or message exceeds APPENDLIMIT
|
|
21
|
+
*/
|
|
22
|
+
export default function append(connection: ImapFlow, destination: string | string[], content: Buffer | string, flags?: string | string[] | undefined, idate?: Date | string | false | undefined): Promise<AppendResult | undefined>;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = append;
|
|
4
|
+
const tools_js_1 = require("../tools.js");
|
|
5
|
+
/**
|
|
6
|
+
* Appends a message to a mailbox.
|
|
7
|
+
*
|
|
8
|
+
* @param connection - IMAP connection instance
|
|
9
|
+
* @param destination - Destination mailbox path
|
|
10
|
+
* @param content - Message content (RFC 822 format)
|
|
11
|
+
* @param flags - Message flags to set on the appended message
|
|
12
|
+
* @param idate - Internal date to set for the message
|
|
13
|
+
* @returns Append result with UID info if available, or undefined if preconditions not met
|
|
14
|
+
* @throws {Error} If the APPEND command fails or message exceeds APPENDLIMIT
|
|
15
|
+
*/
|
|
16
|
+
async function append(connection, destination, content, flags, idate) {
|
|
17
|
+
if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !destination) {
|
|
18
|
+
// nothing to do here
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (typeof content === 'string') {
|
|
22
|
+
content = Buffer.from(content);
|
|
23
|
+
}
|
|
24
|
+
// APPENDLIMIT capability (RFC 7889): server may advertise the maximum message
|
|
25
|
+
// size it accepts. Check before sending to avoid a wasted round-trip.
|
|
26
|
+
if (connection.capabilities.has('APPENDLIMIT')) {
|
|
27
|
+
let appendLimit = connection.capabilities.get('APPENDLIMIT');
|
|
28
|
+
if (typeof appendLimit === 'number' && appendLimit < content.length) {
|
|
29
|
+
let err = new Error('Message content too big for APPENDLIMIT=' + appendLimit);
|
|
30
|
+
err.serverResponseCode = 'APPENDLIMIT';
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
destination = (0, tools_js_1.normalizePath)(connection, destination);
|
|
35
|
+
// If appending to the currently selected mailbox, we can listen for the
|
|
36
|
+
// untagged EXISTS response to capture the new message's sequence number.
|
|
37
|
+
let expectExists = (0, tools_js_1.comparePaths)(connection, connection.mailbox.path, destination);
|
|
38
|
+
// Validate and format flags. Only flags allowed by the mailbox's permanentFlags are included.
|
|
39
|
+
flags = (Array.isArray(flags) ? flags : [].concat(flags || []))
|
|
40
|
+
.map(flag => flag && (0, tools_js_1.formatFlag)(flag.toString()))
|
|
41
|
+
.filter((flag) => !!flag && (0, tools_js_1.canUseFlag)(connection.mailbox, flag));
|
|
42
|
+
// APPEND command format: APPEND <mailbox> [<flags>] [<date-time>] <literal>
|
|
43
|
+
let attributes = [{ type: 'ATOM', value: (0, tools_js_1.encodePath)(connection, destination) }];
|
|
44
|
+
// Internal date: the date the server should record for this message.
|
|
45
|
+
// Must be quoted (STRING type) per the IMAP date-time grammar.
|
|
46
|
+
idate = idate ? (0, tools_js_1.formatDateTime)(idate) : false;
|
|
47
|
+
// Flags and date are optional; flags must come before date if both are present
|
|
48
|
+
if (flags.length || idate) {
|
|
49
|
+
attributes.push(flags.map(flag => ({ type: 'ATOM', value: flag })));
|
|
50
|
+
}
|
|
51
|
+
if (idate) {
|
|
52
|
+
attributes.push({ type: 'STRING', value: idate });
|
|
53
|
+
}
|
|
54
|
+
// BINARY extension (RFC 3516): if the message content contains NUL bytes,
|
|
55
|
+
// use literal8 syntax (~{size}\r\n) instead of regular literal ({size}\r\n).
|
|
56
|
+
// Regular literals cannot contain NUL bytes per the IMAP grammar.
|
|
57
|
+
let isLiteral8 = false;
|
|
58
|
+
if (connection.capabilities.has('BINARY') && !connection.disableBinary) {
|
|
59
|
+
isLiteral8 = content.indexOf(Buffer.from([0])) >= 0;
|
|
60
|
+
}
|
|
61
|
+
attributes.push({ type: 'LITERAL', value: content, isLiteral8 });
|
|
62
|
+
let map = { destination };
|
|
63
|
+
if (connection.mailbox && connection.mailbox.path) {
|
|
64
|
+
map.path = connection.mailbox.path;
|
|
65
|
+
}
|
|
66
|
+
// Handler for untagged EXISTS: captures the new message count which gives
|
|
67
|
+
// us the sequence number of the appended message (it's the latest message).
|
|
68
|
+
const handleExistsUpdate = (untagged) => {
|
|
69
|
+
// The count is written into the live mailbox state below, so it has to clear the
|
|
70
|
+
// same bar untaggedExists() applies: a digit run long enough to coerce to Infinity
|
|
71
|
+
// would make resolveRange('*') compile to the literal string "Infinity" and break
|
|
72
|
+
// every range-based command until the next SELECT.
|
|
73
|
+
let seq = (0, tools_js_1.parseUintValue)(untagged.command, tools_js_1.MAX_UINT32_DIGITS);
|
|
74
|
+
if (seq === false) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
map.seq = seq;
|
|
78
|
+
// Update the connection's mailbox state and emit 'exists' event if the
|
|
79
|
+
// count changed (notifies listeners about the new message).
|
|
80
|
+
if (expectExists) {
|
|
81
|
+
let mailbox = connection.mailbox;
|
|
82
|
+
let prevCount = mailbox.exists;
|
|
83
|
+
if (map.seq !== prevCount) {
|
|
84
|
+
mailbox.exists = map.seq;
|
|
85
|
+
connection.emit('exists', {
|
|
86
|
+
path: mailbox.path,
|
|
87
|
+
count: map.seq,
|
|
88
|
+
prevCount
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
let response;
|
|
94
|
+
try {
|
|
95
|
+
response = await connection.exec('APPEND', attributes, {
|
|
96
|
+
// Only listen for EXISTS if we're appending to the currently selected mailbox
|
|
97
|
+
untagged: expectExists ? { EXISTS: handleExistsUpdate } : false
|
|
98
|
+
});
|
|
99
|
+
// UIDPLUS (RFC 4315): the server may include APPENDUID response code in
|
|
100
|
+
// the tagged OK. Format: [APPENDUID <uidValidity> <uid>]
|
|
101
|
+
let section = response.response.attributes && response.response.attributes[0] && response.response.attributes[0].section;
|
|
102
|
+
if (section && section.length) {
|
|
103
|
+
let first = section[0];
|
|
104
|
+
let responseCode = first && typeof first.value === 'string' ? first.value : '';
|
|
105
|
+
if (responseCode.toUpperCase() === 'APPENDUID') {
|
|
106
|
+
// Bounded digit runs only: isNaN() also passes '1e5', which BigInt() rejects
|
|
107
|
+
// with a throw - and this catch rethrows, so the append would reject after the
|
|
108
|
+
// message was already stored and a retrying caller would duplicate it.
|
|
109
|
+
let uidValidity = (0, tools_js_1.parseBigIntValue)(section[1] && section[1].value, tools_js_1.MAX_UINT32_DIGITS);
|
|
110
|
+
let uid = (0, tools_js_1.parseUintValue)(section[2] && section[2].value, tools_js_1.MAX_UINT32_DIGITS);
|
|
111
|
+
if (uidValidity !== false) {
|
|
112
|
+
map.uidValidity = uidValidity;
|
|
113
|
+
}
|
|
114
|
+
if (uid) {
|
|
115
|
+
map.uid = uid;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
response.next();
|
|
120
|
+
// If we didn't get an EXISTS during APPEND (some servers don't send it
|
|
121
|
+
// until the next command), issue a NOOP to flush pending notifications.
|
|
122
|
+
if (expectExists && !map.seq) {
|
|
123
|
+
try {
|
|
124
|
+
response = await connection.exec('NOOP', false, {
|
|
125
|
+
untagged: { EXISTS: handleExistsUpdate },
|
|
126
|
+
comment: 'Sequence not found from APPEND output'
|
|
127
|
+
});
|
|
128
|
+
response.next();
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
connection.log.warn({ err, cid: connection.id });
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
// If we have a sequence number but no UID (server doesn't support UIDPLUS),
|
|
135
|
+
// look up the UID via SEARCH to provide a consistent result to the caller.
|
|
136
|
+
if (map.seq && !map.uid) {
|
|
137
|
+
let list = await connection.search({ seq: map.seq }, { uid: true });
|
|
138
|
+
if (Array.isArray(list) && list.length) {
|
|
139
|
+
map.uid = list[0];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return map;
|
|
143
|
+
}
|
|
144
|
+
catch (err) {
|
|
145
|
+
await (0, tools_js_1.enhanceCommandError)(err);
|
|
146
|
+
connection.log.warn({ err, cid: connection.id });
|
|
147
|
+
throw err;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
module.exports = exports.default;
|
|
151
|
+
Object.defineProperty(module.exports, 'default', { value: exports.default, enumerable: false, writable: true, configurable: true });
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { ImapFlow } from '../imap-flow.js';
|
|
2
|
+
/**
|
|
3
|
+
* Credentials for the AUTHENTICATE command
|
|
4
|
+
*/
|
|
5
|
+
export interface AuthenticateCredentials {
|
|
6
|
+
/** OAuth2 access token for OAUTHBEARER/XOAUTH2 authentication */
|
|
7
|
+
accessToken?: string | undefined;
|
|
8
|
+
/** Password for PLAIN or LOGIN authentication */
|
|
9
|
+
password?: string | undefined;
|
|
10
|
+
/** Force a specific login method (e.g., 'AUTH=PLAIN', 'AUTH=LOGIN') */
|
|
11
|
+
loginMethod?: string | undefined;
|
|
12
|
+
/** Authorization identity for PLAIN authentication */
|
|
13
|
+
authzid?: string | undefined;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Authenticates user using the best available method.
|
|
17
|
+
*
|
|
18
|
+
* @param connection - IMAP connection instance
|
|
19
|
+
* @param username - The username to authenticate with
|
|
20
|
+
* @param credentials - Authentication credentials
|
|
21
|
+
* @returns The authenticated username, or undefined if already authenticated
|
|
22
|
+
* @throws {Error} If no supported authentication mechanism is available or if authentication fails
|
|
23
|
+
*/
|
|
24
|
+
export default function authenticate(connection: ImapFlow, username: string, { accessToken, password, loginMethod, authzid }: AuthenticateCredentials): Promise<string | undefined>;
|