imapkit 4.0.2 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -19
- package/bin/imapkit.js +12 -16
- package/dist/cjs/addressparser.d.ts +21 -0
- package/dist/cjs/addressparser.js +277 -0
- package/dist/cjs/arguments.d.ts +31 -0
- package/{lib → dist/cjs}/arguments.js +9 -21
- package/dist/cjs/bodystructure.d.ts +25 -0
- package/dist/cjs/bodystructure.js +150 -0
- package/dist/cjs/cert.d.ts +2 -0
- package/dist/cjs/cert.js +7 -0
- package/dist/cjs/command-states.d.ts +36 -0
- package/dist/cjs/command-states.js +102 -0
- package/dist/cjs/commands/append.d.ts +88 -0
- package/dist/cjs/commands/append.js +299 -0
- package/dist/cjs/commands/capability.d.ts +2 -0
- package/dist/cjs/commands/capability.js +44 -0
- package/dist/cjs/commands/check.d.ts +2 -0
- package/dist/cjs/commands/check.js +28 -0
- package/dist/cjs/commands/close.d.ts +2 -0
- package/dist/cjs/commands/close.js +35 -0
- package/dist/cjs/commands/copy.d.ts +30 -0
- package/dist/cjs/commands/copy.js +107 -0
- package/dist/cjs/commands/create.d.ts +2 -0
- package/dist/cjs/commands/create.js +53 -0
- package/dist/cjs/commands/delete.d.ts +2 -0
- package/dist/cjs/commands/delete.js +63 -0
- package/dist/cjs/commands/examine.d.ts +2 -0
- package/dist/cjs/commands/examine.js +19 -0
- package/dist/cjs/commands/expunge.d.ts +2 -0
- package/dist/cjs/commands/expunge.js +32 -0
- package/dist/cjs/commands/fetch.d.ts +23 -0
- package/dist/cjs/commands/fetch.js +208 -0
- package/dist/cjs/commands/handlers/fetch.d.ts +12 -0
- package/dist/cjs/commands/handlers/fetch.js +195 -0
- package/dist/cjs/commands/handlers/flags.d.ts +17 -0
- package/dist/cjs/commands/handlers/flags.js +39 -0
- package/dist/cjs/commands/handlers/search.d.ts +85 -0
- package/dist/cjs/commands/handlers/search.js +504 -0
- package/dist/cjs/commands/handlers/status.d.ts +34 -0
- package/dist/cjs/commands/handlers/status.js +81 -0
- package/dist/cjs/commands/handlers/store.d.ts +3 -0
- package/dist/cjs/commands/handlers/store.js +117 -0
- package/dist/cjs/commands/index.d.ts +2 -0
- package/dist/cjs/commands/index.js +61 -0
- package/dist/cjs/commands/list.d.ts +2 -0
- package/dist/cjs/commands/list.js +86 -0
- package/dist/cjs/commands/login.d.ts +2 -0
- package/dist/cjs/commands/login.js +62 -0
- package/dist/cjs/commands/logout.d.ts +2 -0
- package/dist/cjs/commands/logout.js +40 -0
- package/dist/cjs/commands/lsub.d.ts +2 -0
- package/dist/cjs/commands/lsub.js +79 -0
- package/dist/cjs/commands/noop.d.ts +2 -0
- package/dist/cjs/commands/noop.js +28 -0
- package/dist/cjs/commands/rename.d.ts +2 -0
- package/dist/cjs/commands/rename.js +98 -0
- package/dist/cjs/commands/search.d.ts +10 -0
- package/dist/cjs/commands/search.js +71 -0
- package/dist/cjs/commands/select.d.ts +19 -0
- package/dist/cjs/commands/select.js +230 -0
- package/dist/cjs/commands/status.d.ts +2 -0
- package/dist/cjs/commands/status.js +57 -0
- package/dist/cjs/commands/store.d.ts +10 -0
- package/dist/cjs/commands/store.js +134 -0
- package/dist/cjs/commands/subscribe.d.ts +2 -0
- package/dist/cjs/commands/subscribe.js +51 -0
- package/dist/cjs/commands/uid-copy.d.ts +2 -0
- package/dist/cjs/commands/uid-copy.js +19 -0
- package/dist/cjs/commands/uid-fetch.d.ts +3 -0
- package/dist/cjs/commands/uid-fetch.js +17 -0
- package/dist/cjs/commands/uid-search.d.ts +3 -0
- package/dist/cjs/commands/uid-search.js +17 -0
- package/dist/cjs/commands/uid-store.d.ts +3 -0
- package/dist/cjs/commands/uid-store.js +17 -0
- package/dist/cjs/commands/unsubscribe.d.ts +2 -0
- package/dist/cjs/commands/unsubscribe.js +50 -0
- package/dist/cjs/dates.d.ts +64 -0
- package/dist/cjs/dates.js +124 -0
- package/dist/cjs/deflate-layer.d.ts +83 -0
- package/dist/cjs/deflate-layer.js +232 -0
- package/dist/cjs/encoded-words.d.ts +15 -0
- package/dist/cjs/encoded-words.js +85 -0
- package/dist/cjs/envelope.d.ts +33 -0
- package/dist/cjs/envelope.js +86 -0
- package/dist/cjs/esearch.d.ts +96 -0
- package/dist/cjs/esearch.js +190 -0
- package/dist/cjs/framing.d.ts +66 -0
- package/{lib → dist/cjs}/framing.js +9 -26
- package/dist/cjs/index.d.ts +9 -0
- package/dist/cjs/index.js +56 -0
- package/dist/cjs/list-extensions.d.ts +50 -0
- package/dist/cjs/list-extensions.js +35 -0
- package/dist/cjs/load-plugins.d.ts +21 -0
- package/dist/cjs/load-plugins.js +89 -0
- package/dist/cjs/mailbox-name.d.ts +26 -0
- package/dist/cjs/mailbox-name.js +127 -0
- package/dist/cjs/mimeparser.d.ts +137 -0
- package/dist/cjs/mimeparser.js +727 -0
- package/dist/cjs/mock-client.d.ts +39 -0
- package/dist/cjs/mock-client.js +236 -0
- package/dist/cjs/numbers.d.ts +28 -0
- package/dist/cjs/numbers.js +52 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/plugins/acl.d.ts +2 -0
- package/dist/cjs/plugins/acl.js +888 -0
- package/dist/cjs/plugins/appendlimit.d.ts +16 -0
- package/dist/cjs/plugins/appendlimit.js +87 -0
- package/dist/cjs/plugins/auth-plain.d.ts +2 -0
- package/dist/cjs/plugins/auth-plain.js +89 -0
- package/dist/cjs/plugins/binary.d.ts +30 -0
- package/dist/cjs/plugins/binary.js +247 -0
- package/dist/cjs/plugins/catenate.d.ts +14 -0
- package/dist/cjs/plugins/catenate.js +250 -0
- package/dist/cjs/plugins/compress.d.ts +7 -0
- package/dist/cjs/plugins/compress.js +79 -0
- package/dist/cjs/plugins/condstore.d.ts +5 -0
- package/dist/cjs/plugins/condstore.js +492 -0
- package/dist/cjs/plugins/context-search.d.ts +8 -0
- package/dist/cjs/plugins/context-search.js +304 -0
- package/dist/cjs/plugins/context-sort.d.ts +6 -0
- package/dist/cjs/plugins/context-sort.js +32 -0
- package/dist/cjs/plugins/create-special-use.d.ts +7 -0
- package/dist/cjs/plugins/create-special-use.js +101 -0
- package/dist/cjs/plugins/enable.d.ts +23 -0
- package/dist/cjs/plugins/enable.js +127 -0
- package/dist/cjs/plugins/esearch.d.ts +6 -0
- package/dist/cjs/plugins/esearch.js +142 -0
- package/dist/cjs/plugins/esort.d.ts +6 -0
- package/dist/cjs/plugins/esort.js +60 -0
- package/dist/cjs/plugins/id.d.ts +5 -0
- package/dist/cjs/plugins/id.js +123 -0
- package/dist/cjs/plugins/idle.d.ts +5 -0
- package/dist/cjs/plugins/idle.js +85 -0
- package/dist/cjs/plugins/imap4rev2.d.ts +6 -0
- package/dist/cjs/plugins/imap4rev2.js +184 -0
- package/dist/cjs/plugins/index.d.ts +2 -0
- package/dist/cjs/plugins/index.js +119 -0
- package/dist/cjs/plugins/list-extended.d.ts +2 -0
- package/dist/cjs/plugins/list-extended.js +235 -0
- package/dist/cjs/plugins/list-status.d.ts +6 -0
- package/dist/cjs/plugins/list-status.js +42 -0
- package/dist/cjs/plugins/literalminus.d.ts +8 -0
- package/dist/cjs/plugins/literalminus.js +32 -0
- package/dist/cjs/plugins/literalplus.d.ts +6 -0
- package/dist/cjs/plugins/literalplus.js +30 -0
- package/dist/cjs/plugins/logindisabled.d.ts +5 -0
- package/dist/cjs/plugins/logindisabled.js +54 -0
- package/dist/cjs/plugins/messagelimit.d.ts +19 -0
- package/dist/cjs/plugins/messagelimit.js +227 -0
- package/dist/cjs/plugins/metadata-server.d.ts +7 -0
- package/dist/cjs/plugins/metadata-server.js +24 -0
- package/dist/cjs/plugins/metadata.d.ts +11 -0
- package/dist/cjs/plugins/metadata.js +436 -0
- package/dist/cjs/plugins/move.d.ts +11 -0
- package/dist/cjs/plugins/move.js +96 -0
- package/dist/cjs/plugins/multiappend.d.ts +12 -0
- package/dist/cjs/plugins/multiappend.js +38 -0
- package/dist/cjs/plugins/multisearch.d.ts +6 -0
- package/dist/cjs/plugins/multisearch.js +263 -0
- package/dist/cjs/plugins/namespace.d.ts +5 -0
- package/dist/cjs/plugins/namespace.js +57 -0
- package/dist/cjs/plugins/notify.d.ts +2 -0
- package/dist/cjs/plugins/notify.js +628 -0
- package/dist/cjs/plugins/oauthbearer.d.ts +32 -0
- package/dist/cjs/plugins/oauthbearer.js +202 -0
- package/dist/cjs/plugins/objectid.d.ts +23 -0
- package/dist/cjs/plugins/objectid.js +221 -0
- package/dist/cjs/plugins/partial.d.ts +6 -0
- package/dist/cjs/plugins/partial.js +78 -0
- package/dist/cjs/plugins/preview.d.ts +31 -0
- package/dist/cjs/plugins/preview.js +378 -0
- package/dist/cjs/plugins/qresync.d.ts +11 -0
- package/dist/cjs/plugins/qresync.js +473 -0
- package/dist/cjs/plugins/quota.d.ts +18 -0
- package/dist/cjs/plugins/quota.js +254 -0
- package/dist/cjs/plugins/replace.d.ts +14 -0
- package/dist/cjs/plugins/replace.js +130 -0
- package/dist/cjs/plugins/sasl-ir.d.ts +5 -0
- package/dist/cjs/plugins/sasl-ir.js +24 -0
- package/dist/cjs/plugins/savedate.d.ts +17 -0
- package/dist/cjs/plugins/savedate.js +64 -0
- package/dist/cjs/plugins/savelimit.d.ts +10 -0
- package/dist/cjs/plugins/savelimit.js +30 -0
- package/dist/cjs/plugins/searchres.d.ts +6 -0
- package/dist/cjs/plugins/searchres.js +91 -0
- package/dist/cjs/plugins/sort-display.d.ts +11 -0
- package/dist/cjs/plugins/sort-display.js +37 -0
- package/dist/cjs/plugins/sort.d.ts +11 -0
- package/dist/cjs/plugins/sort.js +125 -0
- package/dist/cjs/plugins/special-use.d.ts +10 -0
- package/dist/cjs/plugins/special-use.js +95 -0
- package/dist/cjs/plugins/starttls.d.ts +5 -0
- package/dist/cjs/plugins/starttls.js +55 -0
- package/dist/cjs/plugins/status-size.d.ts +7 -0
- package/dist/cjs/plugins/status-size.js +30 -0
- package/dist/cjs/plugins/thread-orderedsubject.d.ts +11 -0
- package/dist/cjs/plugins/thread-orderedsubject.js +28 -0
- package/dist/cjs/plugins/thread-references.d.ts +11 -0
- package/dist/cjs/plugins/thread-references.js +28 -0
- package/dist/cjs/plugins/uidonly.d.ts +15 -0
- package/dist/cjs/plugins/uidonly.js +126 -0
- package/dist/cjs/plugins/uidplus.d.ts +15 -0
- package/dist/cjs/plugins/uidplus.js +119 -0
- package/dist/cjs/plugins/unauthenticate.d.ts +7 -0
- package/dist/cjs/plugins/unauthenticate.js +32 -0
- package/dist/cjs/plugins/unselect.d.ts +5 -0
- package/dist/cjs/plugins/unselect.js +36 -0
- package/dist/cjs/plugins/utf8-accept.d.ts +6 -0
- package/dist/cjs/plugins/utf8-accept.js +72 -0
- package/dist/cjs/plugins/x-gm-ext-1.d.ts +26 -0
- package/dist/cjs/plugins/x-gm-ext-1.js +422 -0
- package/dist/cjs/plugins/xoauth2.d.ts +2 -0
- package/dist/cjs/plugins/xoauth2.js +155 -0
- package/dist/cjs/plugins/xtoybird.d.ts +2 -0
- package/dist/cjs/plugins/xtoybird.js +236 -0
- package/dist/cjs/server.d.ts +876 -0
- package/dist/cjs/server.js +2597 -0
- package/dist/cjs/smtp-listener.d.ts +13 -0
- package/dist/cjs/smtp-listener.js +47 -0
- package/dist/cjs/sorting.d.ts +77 -0
- package/dist/cjs/sorting.js +290 -0
- package/dist/cjs/threading.d.ts +30 -0
- package/dist/cjs/threading.js +318 -0
- package/dist/cjs/types.d.ts +327 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/utf8-session.d.ts +17 -0
- package/dist/cjs/utf8-session.js +148 -0
- package/dist/cjs/vanished.d.ts +21 -0
- package/dist/cjs/vanished.js +55 -0
- package/dist/esm/addressparser.d.ts +21 -0
- package/{lib → dist/esm}/addressparser.js +102 -123
- package/dist/esm/arguments.d.ts +31 -0
- package/dist/esm/arguments.js +96 -0
- package/dist/esm/bodystructure.d.ts +25 -0
- package/{lib → dist/esm}/bodystructure.js +17 -33
- package/dist/esm/cert.d.ts +2 -0
- package/dist/esm/cert.js +4 -0
- package/dist/esm/command-states.d.ts +36 -0
- package/{lib → dist/esm}/command-states.js +4 -16
- package/dist/esm/commands/append.d.ts +88 -0
- package/{lib → dist/esm}/commands/append.js +47 -85
- package/dist/esm/commands/capability.d.ts +2 -0
- package/dist/esm/commands/capability.js +29 -0
- package/dist/esm/commands/check.d.ts +2 -0
- package/dist/esm/commands/check.js +13 -0
- package/dist/esm/commands/close.d.ts +2 -0
- package/dist/esm/commands/close.js +20 -0
- package/dist/esm/commands/copy.d.ts +30 -0
- package/{lib → dist/esm}/commands/copy.js +31 -55
- package/dist/esm/commands/create.d.ts +2 -0
- package/{lib → dist/esm}/commands/create.js +25 -39
- package/dist/esm/commands/delete.d.ts +2 -0
- package/{lib → dist/esm}/commands/delete.js +25 -41
- package/dist/esm/commands/examine.d.ts +2 -0
- package/dist/esm/commands/examine.js +4 -0
- package/dist/esm/commands/expunge.d.ts +2 -0
- package/dist/esm/commands/expunge.js +17 -0
- package/dist/esm/commands/fetch.d.ts +23 -0
- package/{lib → dist/esm}/commands/fetch.js +34 -75
- package/dist/esm/commands/handlers/fetch.d.ts +12 -0
- package/{lib → dist/esm}/commands/handlers/fetch.js +11 -42
- package/dist/esm/commands/handlers/flags.d.ts +17 -0
- package/{lib → dist/esm}/commands/handlers/flags.js +3 -11
- package/dist/esm/commands/handlers/search.d.ts +85 -0
- package/{lib → dist/esm}/commands/handlers/search.js +33 -71
- package/dist/esm/commands/handlers/status.d.ts +34 -0
- package/{lib → dist/esm}/commands/handlers/status.js +1 -9
- package/dist/esm/commands/handlers/store.d.ts +3 -0
- package/{lib → dist/esm}/commands/handlers/store.js +20 -44
- package/dist/esm/commands/index.d.ts +2 -0
- package/dist/esm/commands/index.js +55 -0
- package/dist/esm/commands/list.d.ts +2 -0
- package/dist/esm/commands/list.js +71 -0
- package/dist/esm/commands/login.d.ts +2 -0
- package/{lib → dist/esm}/commands/login.js +24 -44
- package/dist/esm/commands/logout.d.ts +2 -0
- package/dist/esm/commands/logout.js +25 -0
- package/dist/esm/commands/lsub.d.ts +2 -0
- package/dist/esm/commands/lsub.js +64 -0
- package/dist/esm/commands/noop.d.ts +2 -0
- package/dist/esm/commands/noop.js +13 -0
- package/dist/esm/commands/rename.d.ts +2 -0
- package/{lib → dist/esm}/commands/rename.js +32 -51
- package/dist/esm/commands/search.d.ts +10 -0
- package/dist/esm/commands/search.js +54 -0
- package/dist/esm/commands/select.d.ts +19 -0
- package/dist/esm/commands/select.js +214 -0
- package/dist/esm/commands/status.d.ts +2 -0
- package/{lib → dist/esm}/commands/status.js +18 -39
- package/dist/esm/commands/store.d.ts +10 -0
- package/{lib → dist/esm}/commands/store.js +39 -73
- package/dist/esm/commands/subscribe.d.ts +2 -0
- package/{lib → dist/esm}/commands/subscribe.js +22 -39
- package/dist/esm/commands/uid-copy.d.ts +2 -0
- package/dist/esm/commands/uid-copy.js +4 -0
- package/dist/esm/commands/uid-fetch.d.ts +3 -0
- package/dist/esm/commands/uid-fetch.js +3 -0
- package/dist/esm/commands/uid-search.d.ts +3 -0
- package/dist/esm/commands/uid-search.js +3 -0
- package/dist/esm/commands/uid-store.d.ts +3 -0
- package/dist/esm/commands/uid-store.js +3 -0
- package/dist/esm/commands/unsubscribe.d.ts +2 -0
- package/{lib → dist/esm}/commands/unsubscribe.js +22 -37
- package/dist/esm/dates.d.ts +64 -0
- package/{lib → dist/esm}/dates.js +6 -14
- package/dist/esm/deflate-layer.d.ts +83 -0
- package/{lib → dist/esm}/deflate-layer.js +9 -26
- package/dist/esm/encoded-words.d.ts +15 -0
- package/{lib → dist/esm}/encoded-words.js +9 -25
- package/dist/esm/envelope.d.ts +33 -0
- package/{lib → dist/esm}/envelope.js +8 -19
- package/dist/esm/esearch.d.ts +96 -0
- package/{lib → dist/esm}/esearch.js +12 -39
- package/dist/esm/framing.d.ts +66 -0
- package/dist/esm/framing.js +82 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/list-extensions.d.ts +50 -0
- package/{lib → dist/esm}/list-extensions.js +1 -4
- package/dist/esm/load-plugins.d.ts +21 -0
- package/{lib → dist/esm}/load-plugins.js +9 -43
- package/dist/esm/mailbox-name.d.ts +26 -0
- package/{lib → dist/esm}/mailbox-name.js +5 -26
- package/dist/esm/mimeparser.d.ts +137 -0
- package/{lib → dist/esm}/mimeparser.js +74 -152
- package/dist/esm/mock-client.d.ts +39 -0
- package/{lib → dist/esm}/mock-client.js +26 -40
- package/dist/esm/numbers.d.ts +28 -0
- package/{lib → dist/esm}/numbers.js +1 -8
- package/dist/esm/package.json +3 -0
- package/dist/esm/plugins/acl.d.ts +2 -0
- package/{lib → dist/esm}/plugins/acl.js +146 -240
- package/dist/esm/plugins/appendlimit.d.ts +16 -0
- package/{lib → dist/esm}/plugins/appendlimit.js +5 -16
- package/dist/esm/plugins/auth-plain.d.ts +2 -0
- package/{lib → dist/esm}/plugins/auth-plain.js +11 -31
- package/dist/esm/plugins/binary.d.ts +30 -0
- package/{lib → dist/esm}/plugins/binary.js +17 -43
- package/dist/esm/plugins/catenate.d.ts +14 -0
- package/{lib → dist/esm}/plugins/catenate.js +19 -40
- package/dist/esm/plugins/compress.d.ts +7 -0
- package/dist/esm/plugins/compress.js +61 -0
- package/dist/esm/plugins/condstore.d.ts +5 -0
- package/{lib → dist/esm}/plugins/condstore.js +66 -152
- package/dist/esm/plugins/context-search.d.ts +8 -0
- package/{lib → dist/esm}/plugins/context-search.js +53 -88
- package/dist/esm/plugins/context-sort.d.ts +6 -0
- package/{lib → dist/esm}/plugins/context-sort.js +4 -9
- package/dist/esm/plugins/create-special-use.d.ts +7 -0
- package/{lib → dist/esm}/plugins/create-special-use.js +33 -55
- package/dist/esm/plugins/enable.d.ts +23 -0
- package/dist/esm/plugins/enable.js +111 -0
- package/dist/esm/plugins/esearch.d.ts +6 -0
- package/{lib → dist/esm}/plugins/esearch.js +13 -42
- package/dist/esm/plugins/esort.d.ts +6 -0
- package/{lib → dist/esm}/plugins/esort.js +7 -25
- package/dist/esm/plugins/id.d.ts +5 -0
- package/dist/esm/plugins/id.js +108 -0
- package/dist/esm/plugins/idle.d.ts +5 -0
- package/dist/esm/plugins/idle.js +70 -0
- package/dist/esm/plugins/imap4rev2.d.ts +6 -0
- package/{lib → dist/esm}/plugins/imap4rev2.js +24 -60
- package/dist/esm/plugins/index.d.ts +2 -0
- package/dist/esm/plugins/index.js +113 -0
- package/dist/esm/plugins/list-extended.d.ts +2 -0
- package/{lib → dist/esm}/plugins/list-extended.js +28 -66
- package/dist/esm/plugins/list-status.d.ts +6 -0
- package/{lib → dist/esm}/plugins/list-status.js +5 -12
- package/dist/esm/plugins/literalminus.d.ts +8 -0
- package/{lib → dist/esm}/plugins/literalminus.js +2 -5
- package/dist/esm/plugins/literalplus.d.ts +6 -0
- package/{lib → dist/esm}/plugins/literalplus.js +2 -5
- package/dist/esm/plugins/logindisabled.d.ts +5 -0
- package/dist/esm/plugins/logindisabled.js +39 -0
- package/dist/esm/plugins/messagelimit.d.ts +19 -0
- package/{lib → dist/esm}/plugins/messagelimit.js +18 -41
- package/dist/esm/plugins/metadata-server.d.ts +7 -0
- package/{lib → dist/esm}/plugins/metadata-server.js +3 -7
- package/dist/esm/plugins/metadata.d.ts +11 -0
- package/dist/esm/plugins/metadata.js +421 -0
- package/dist/esm/plugins/move.d.ts +11 -0
- package/{lib → dist/esm}/plugins/move.js +37 -66
- package/dist/esm/plugins/multiappend.d.ts +12 -0
- package/{lib → dist/esm}/plugins/multiappend.js +2 -5
- package/dist/esm/plugins/multisearch.d.ts +6 -0
- package/{lib → dist/esm}/plugins/multisearch.js +24 -48
- package/dist/esm/plugins/namespace.d.ts +5 -0
- package/dist/esm/plugins/namespace.js +42 -0
- package/dist/esm/plugins/notify.d.ts +2 -0
- package/{lib → dist/esm}/plugins/notify.js +90 -134
- package/dist/esm/plugins/oauthbearer.d.ts +32 -0
- package/{lib → dist/esm}/plugins/oauthbearer.js +18 -48
- package/dist/esm/plugins/objectid.d.ts +23 -0
- package/{lib → dist/esm}/plugins/objectid.js +21 -58
- package/dist/esm/plugins/partial.d.ts +6 -0
- package/{lib → dist/esm}/plugins/partial.js +7 -15
- package/dist/esm/plugins/preview.d.ts +31 -0
- package/{lib → dist/esm}/plugins/preview.js +28 -66
- package/dist/esm/plugins/qresync.d.ts +11 -0
- package/{lib → dist/esm}/plugins/qresync.js +64 -134
- package/dist/esm/plugins/quota.d.ts +18 -0
- package/{lib → dist/esm}/plugins/quota.js +89 -135
- package/dist/esm/plugins/replace.d.ts +14 -0
- package/{lib → dist/esm}/plugins/replace.js +21 -51
- package/dist/esm/plugins/sasl-ir.d.ts +5 -0
- package/{lib → dist/esm}/plugins/sasl-ir.js +3 -6
- package/dist/esm/plugins/savedate.d.ts +17 -0
- package/{lib → dist/esm}/plugins/savedate.js +5 -15
- package/dist/esm/plugins/savelimit.d.ts +10 -0
- package/{lib → dist/esm}/plugins/savelimit.js +3 -6
- package/dist/esm/plugins/searchres.d.ts +6 -0
- package/{lib → dist/esm}/plugins/searchres.js +13 -22
- package/dist/esm/plugins/sort-display.d.ts +11 -0
- package/{lib → dist/esm}/plugins/sort-display.js +6 -10
- package/dist/esm/plugins/sort.d.ts +11 -0
- package/{lib → dist/esm}/plugins/sort.js +24 -46
- package/dist/esm/plugins/special-use.d.ts +10 -0
- package/{lib → dist/esm}/plugins/special-use.js +9 -24
- package/dist/esm/plugins/starttls.d.ts +5 -0
- package/{lib → dist/esm}/plugins/starttls.js +20 -37
- package/dist/esm/plugins/status-size.d.ts +7 -0
- package/{lib → dist/esm}/plugins/status-size.js +4 -11
- package/dist/esm/plugins/thread-orderedsubject.d.ts +11 -0
- package/{lib → dist/esm}/plugins/thread-orderedsubject.js +3 -6
- package/dist/esm/plugins/thread-references.d.ts +11 -0
- package/{lib → dist/esm}/plugins/thread-references.js +3 -6
- package/dist/esm/plugins/uidonly.d.ts +15 -0
- package/{lib → dist/esm}/plugins/uidonly.js +11 -35
- package/dist/esm/plugins/uidplus.d.ts +15 -0
- package/{lib → dist/esm}/plugins/uidplus.js +25 -45
- package/dist/esm/plugins/unauthenticate.d.ts +7 -0
- package/dist/esm/plugins/unauthenticate.js +17 -0
- package/dist/esm/plugins/unselect.d.ts +5 -0
- package/dist/esm/plugins/unselect.js +21 -0
- package/dist/esm/plugins/utf8-accept.d.ts +6 -0
- package/{lib → dist/esm}/plugins/utf8-accept.js +10 -21
- package/dist/esm/plugins/x-gm-ext-1.d.ts +26 -0
- package/{lib → dist/esm}/plugins/x-gm-ext-1.js +48 -100
- package/dist/esm/plugins/xoauth2.d.ts +2 -0
- package/dist/esm/plugins/xoauth2.js +140 -0
- package/dist/esm/plugins/xtoybird.d.ts +2 -0
- package/dist/esm/plugins/xtoybird.js +218 -0
- package/dist/esm/server.d.ts +876 -0
- package/dist/esm/server.js +2543 -0
- package/dist/esm/smtp-listener.d.ts +13 -0
- package/{lib → dist/esm}/smtp-listener.js +5 -12
- package/dist/esm/sorting.d.ts +77 -0
- package/{lib → dist/esm}/sorting.js +40 -53
- package/dist/esm/threading.d.ts +30 -0
- package/{lib → dist/esm}/threading.js +29 -70
- package/dist/esm/types.d.ts +327 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/utf8-session.d.ts +17 -0
- package/{lib → dist/esm}/utf8-session.js +15 -25
- package/dist/esm/vanished.d.ts +21 -0
- package/{lib → dist/esm}/vanished.js +16 -21
- package/dist/plugin-help.json +298 -0
- package/package.json +54 -11
- package/lib/commands/capability.js +0 -47
- package/lib/commands/check.js +0 -21
- package/lib/commands/close.js +0 -30
- package/lib/commands/examine.js +0 -7
- package/lib/commands/expunge.js +0 -27
- package/lib/commands/list.js +0 -100
- package/lib/commands/logout.js +0 -41
- package/lib/commands/lsub.js +0 -87
- package/lib/commands/noop.js +0 -21
- package/lib/commands/search.js +0 -76
- package/lib/commands/select.js +0 -289
- package/lib/commands/uid copy.js +0 -7
- package/lib/commands/uid fetch.js +0 -5
- package/lib/commands/uid search.js +0 -5
- package/lib/commands/uid store.js +0 -5
- package/lib/plugins/compress.js +0 -76
- package/lib/plugins/enable.js +0 -155
- package/lib/plugins/id.js +0 -138
- package/lib/plugins/idle.js +0 -105
- package/lib/plugins/logindisabled.js +0 -50
- package/lib/plugins/metadata.js +0 -475
- package/lib/plugins/namespace.js +0 -67
- package/lib/plugins/unauthenticate.js +0 -28
- package/lib/plugins/unselect.js +0 -36
- package/lib/plugins/xoauth2.js +0 -188
- package/lib/plugins/xtoybird.js +0 -282
- package/lib/server.js +0 -2880
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
1
|
// Parses a message into a MIME tree. Ported from WildDuck (imap-core/lib/indexer/parse-mime-tree.js and
|
|
4
2
|
// tree-walker.js), adapted to ImapKit, where message sources are binary strings (one char per octet).
|
|
5
3
|
//
|
|
@@ -11,19 +9,14 @@
|
|
|
11
9
|
//
|
|
12
10
|
// The CRLF after an entity belongs to the delimiter that follows it (RFC 2046 5.1.1), a part body never
|
|
13
11
|
// includes it.
|
|
14
|
-
|
|
15
|
-
const addressparser = require('./addressparser');
|
|
16
|
-
|
|
12
|
+
import addressparser from './addressparser.js';
|
|
17
13
|
// header field and parameter names that are kept in the parsed header, anything else is only available
|
|
18
14
|
// through the raw header lines
|
|
19
15
|
const FIELD_NAME = /^[a-zA-Z0-9\-*]{1,99}$/;
|
|
20
|
-
|
|
21
16
|
// content transfer encodings that leave the data as it is (RFC 2045 section 6.2)
|
|
22
17
|
const IDENTITY_ENCODINGS = ['7bit', '8bit', 'binary'];
|
|
23
|
-
|
|
24
18
|
// message/rfc822 parts nested deeper than this are not parsed, they are described as plain parts
|
|
25
19
|
const MAX_MESSAGE_DEPTH = 32;
|
|
26
|
-
|
|
27
20
|
/**
|
|
28
21
|
* Converts every line break of a message to CRLF. IMAP serves messages with CRLF line breaks, so sizes and
|
|
29
22
|
* contents are computed from this form
|
|
@@ -32,11 +25,10 @@ const MAX_MESSAGE_DEPTH = 32;
|
|
|
32
25
|
* @return {String} Message source with CRLF line breaks
|
|
33
26
|
*/
|
|
34
27
|
function normalizeLineBreaks(raw) {
|
|
35
|
-
const str = (raw
|
|
28
|
+
const str = Buffer.isBuffer(raw) ? raw.toString('binary') : raw || '';
|
|
36
29
|
// most messages already use CRLF, so only replace if there is a bare LF
|
|
37
30
|
return /(?:^|[^\r])\n/.test(str) ? str.replace(/\r?\n/g, '\r\n') : str;
|
|
38
31
|
}
|
|
39
|
-
|
|
40
32
|
/**
|
|
41
33
|
* Splits a structured header value (RFC 2045 5.1 Content-Type and friends) at a separator character,
|
|
42
34
|
* leaving quoted strings intact and dropping RFC 822 comments outside of them. With no separator the
|
|
@@ -51,50 +43,50 @@ function splitStructuredValue(value, separator) {
|
|
|
51
43
|
let current = '';
|
|
52
44
|
let quoted = false;
|
|
53
45
|
let depth = 0;
|
|
54
|
-
|
|
55
46
|
for (let i = 0; i < value.length; i++) {
|
|
56
47
|
const chr = value.charAt(i);
|
|
57
|
-
|
|
58
48
|
if (quoted) {
|
|
59
49
|
current += chr;
|
|
60
50
|
if (chr === '\\' && i + 1 < value.length) {
|
|
61
51
|
// quoted-pair, keep the escaped character for the value parser
|
|
62
52
|
current += value.charAt(++i);
|
|
63
|
-
}
|
|
53
|
+
}
|
|
54
|
+
else if (chr === '"') {
|
|
64
55
|
quoted = false;
|
|
65
56
|
}
|
|
66
57
|
continue;
|
|
67
58
|
}
|
|
68
|
-
|
|
69
59
|
if (depth) {
|
|
70
60
|
// inside a comment, which may nest and may hold quoted-pairs
|
|
71
61
|
if (chr === '\\') {
|
|
72
62
|
i++;
|
|
73
|
-
}
|
|
63
|
+
}
|
|
64
|
+
else if (chr === '(') {
|
|
74
65
|
depth++;
|
|
75
|
-
}
|
|
66
|
+
}
|
|
67
|
+
else if (chr === ')') {
|
|
76
68
|
depth--;
|
|
77
69
|
}
|
|
78
70
|
continue;
|
|
79
71
|
}
|
|
80
|
-
|
|
81
72
|
if (chr === '"') {
|
|
82
73
|
quoted = true;
|
|
83
74
|
current += chr;
|
|
84
|
-
}
|
|
75
|
+
}
|
|
76
|
+
else if (chr === '(') {
|
|
85
77
|
depth = 1;
|
|
86
|
-
}
|
|
78
|
+
}
|
|
79
|
+
else if (separator && chr === separator) {
|
|
87
80
|
parts.push(current);
|
|
88
81
|
current = '';
|
|
89
|
-
}
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
90
84
|
current += chr;
|
|
91
85
|
}
|
|
92
86
|
}
|
|
93
|
-
|
|
94
87
|
parts.push(current);
|
|
95
88
|
return parts;
|
|
96
89
|
}
|
|
97
|
-
|
|
98
90
|
/**
|
|
99
91
|
* Decodes an RFC 2231 extended parameter value (percent encoded octets in a charset). UTF-8 and US-ASCII
|
|
100
92
|
* values become the UTF-8 octets, ISO-8859-1 values are converted to UTF-8, other charsets are kept as
|
|
@@ -121,7 +113,6 @@ function decodeExtendedValue(charset, value) {
|
|
|
121
113
|
return '=?' + charset.toUpperCase() + '?Q?' + value.replace(/%/g, '=') + '?=';
|
|
122
114
|
}
|
|
123
115
|
}
|
|
124
|
-
|
|
125
116
|
class MIMEParser {
|
|
126
117
|
/**
|
|
127
118
|
* @param {String} rfc822 Message source as a binary string with CRLF line breaks
|
|
@@ -130,48 +121,43 @@ class MIMEParser {
|
|
|
130
121
|
constructor(rfc822, depth) {
|
|
131
122
|
this.rfc822 = rfc822 || '';
|
|
132
123
|
this.depth = depth || 0;
|
|
133
|
-
|
|
134
124
|
// the line break that ended the last line read, false once the input is used up
|
|
135
125
|
this._br = '';
|
|
136
126
|
this._pos = 0;
|
|
137
|
-
|
|
138
127
|
this.tree = {
|
|
139
128
|
childNodes: []
|
|
140
129
|
};
|
|
141
130
|
this._node = this.createNode(this.tree);
|
|
142
131
|
}
|
|
143
|
-
|
|
144
132
|
/**
|
|
145
133
|
* Parses the message, line by line
|
|
146
134
|
*/
|
|
147
135
|
parse() {
|
|
148
136
|
let line;
|
|
149
137
|
let prevBr = '';
|
|
150
|
-
|
|
151
138
|
// keep parsing until the last linebreak is not a string (no linebreaks anymore)
|
|
152
139
|
while (typeof this._br === 'string') {
|
|
153
140
|
line = this.readLine();
|
|
154
|
-
|
|
155
141
|
const delimiter = this.matchDelimiter(line);
|
|
156
142
|
if (delimiter) {
|
|
157
143
|
this.endPart(delimiter, prevBr);
|
|
158
|
-
}
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
159
146
|
switch (this._node.state) {
|
|
160
147
|
case 'header':
|
|
161
148
|
if (!line) {
|
|
162
149
|
// the blank line that separates the header from the body
|
|
163
150
|
this.endHeader();
|
|
164
|
-
}
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
165
153
|
this._node.header.push(line);
|
|
166
154
|
}
|
|
167
155
|
break;
|
|
168
|
-
|
|
169
156
|
case 'body':
|
|
170
157
|
// push the line with previous linebreak value, joined together the lines
|
|
171
158
|
// give the original body
|
|
172
159
|
this._node.body.push((this._node.body.length ? prevBr : '') + line);
|
|
173
160
|
break;
|
|
174
|
-
|
|
175
161
|
case 'epilogue':
|
|
176
162
|
// RFC 2046 5.1.1: everything after the close delimiter up to the next delimiter
|
|
177
163
|
// of the enclosing multipart (or the end of the message) is the epilogue. Every
|
|
@@ -182,18 +168,15 @@ class MIMEParser {
|
|
|
182
168
|
}
|
|
183
169
|
this._node.epilogue.push(prevBr + line);
|
|
184
170
|
break;
|
|
185
|
-
|
|
186
171
|
default:
|
|
187
172
|
// never should be reached
|
|
188
173
|
throw new Error('Unexpected state');
|
|
189
174
|
}
|
|
190
175
|
}
|
|
191
|
-
|
|
192
176
|
// store the linebreak for later usage
|
|
193
177
|
prevBr = this._br;
|
|
194
178
|
}
|
|
195
179
|
}
|
|
196
|
-
|
|
197
180
|
/**
|
|
198
181
|
* Reads a line from the message
|
|
199
182
|
*
|
|
@@ -208,18 +191,15 @@ class MIMEParser {
|
|
|
208
191
|
this._br = false;
|
|
209
192
|
return line;
|
|
210
193
|
}
|
|
211
|
-
|
|
212
194
|
let lineEnd = end;
|
|
213
195
|
if (lineEnd > this._pos && this.rfc822.charCodeAt(lineEnd - 1) === 0x0d) {
|
|
214
196
|
lineEnd--;
|
|
215
197
|
}
|
|
216
|
-
|
|
217
198
|
const line = this.rfc822.slice(this._pos, lineEnd);
|
|
218
199
|
this._br = this.rfc822.slice(lineEnd, end + 1);
|
|
219
200
|
this._pos = end + 1;
|
|
220
201
|
return line;
|
|
221
202
|
}
|
|
222
|
-
|
|
223
203
|
/**
|
|
224
204
|
* Ends the header of the current node: its blank line was read, or a delimiter took its place
|
|
225
205
|
*/
|
|
@@ -228,7 +208,6 @@ class MIMEParser {
|
|
|
228
208
|
this.processContentType();
|
|
229
209
|
this._node.state = 'body';
|
|
230
210
|
}
|
|
231
|
-
|
|
232
211
|
/**
|
|
233
212
|
* Checks whether a line is a delimiter of an open multipart: the current node while it collects its
|
|
234
213
|
* preamble or epilogue, the multipart the current node belongs to, or any multipart above that (a
|
|
@@ -244,7 +223,6 @@ class MIMEParser {
|
|
|
244
223
|
if (!line.startsWith('--')) {
|
|
245
224
|
return false;
|
|
246
225
|
}
|
|
247
|
-
|
|
248
226
|
const node = this._node;
|
|
249
227
|
// a boundary is only known once the header has ended
|
|
250
228
|
const innermost = node.boundary ? node : node.parentNode;
|
|
@@ -253,28 +231,22 @@ class MIMEParser {
|
|
|
253
231
|
if (!line.startsWith(delimiter)) {
|
|
254
232
|
continue;
|
|
255
233
|
}
|
|
256
|
-
|
|
257
234
|
let rest = line.slice(delimiter.length);
|
|
258
235
|
const close = rest.startsWith('--');
|
|
259
236
|
if (close) {
|
|
260
237
|
rest = rest.slice(2);
|
|
261
238
|
}
|
|
262
|
-
|
|
263
239
|
if (/[^ \t]/.test(rest)) {
|
|
264
240
|
// something other than padding after the boundary, so a different boundary or text
|
|
265
241
|
continue;
|
|
266
242
|
}
|
|
267
|
-
|
|
268
243
|
if (multipart.state === 'epilogue') {
|
|
269
244
|
return false;
|
|
270
245
|
}
|
|
271
|
-
|
|
272
246
|
return { multipart, close, pad: rest };
|
|
273
247
|
}
|
|
274
|
-
|
|
275
248
|
return false;
|
|
276
249
|
}
|
|
277
|
-
|
|
278
250
|
/**
|
|
279
251
|
* Ends whatever the current node was collecting at a delimiter line and moves on to the next
|
|
280
252
|
* part of that multipart, or to its epilogue
|
|
@@ -285,7 +257,6 @@ class MIMEParser {
|
|
|
285
257
|
endPart(delimiter, prevBr) {
|
|
286
258
|
const node = this._node;
|
|
287
259
|
const multipart = delimiter.multipart;
|
|
288
|
-
|
|
289
260
|
if (node !== multipart) {
|
|
290
261
|
// a part ends here
|
|
291
262
|
if (node.state === 'header') {
|
|
@@ -299,19 +270,20 @@ class MIMEParser {
|
|
|
299
270
|
open.bare = true;
|
|
300
271
|
}
|
|
301
272
|
}
|
|
302
|
-
}
|
|
273
|
+
}
|
|
274
|
+
else if (node.body.length) {
|
|
303
275
|
// the preamble ends here. The line break between the preamble and the delimiter belongs to
|
|
304
276
|
// the delimiter, but the preamble lines end with their own
|
|
305
277
|
node.body[node.body.length - 1] += prevBr;
|
|
306
278
|
}
|
|
307
|
-
|
|
308
279
|
if (!delimiter.close) {
|
|
309
280
|
const next = this.createNode(multipart);
|
|
310
281
|
if (delimiter.pad) {
|
|
311
282
|
next.pad = delimiter.pad;
|
|
312
283
|
}
|
|
313
284
|
this._node = next;
|
|
314
|
-
}
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
315
287
|
if (delimiter.pad) {
|
|
316
288
|
multipart.closePad = delimiter.pad;
|
|
317
289
|
}
|
|
@@ -320,7 +292,6 @@ class MIMEParser {
|
|
|
320
292
|
this._node = multipart;
|
|
321
293
|
}
|
|
322
294
|
}
|
|
323
|
-
|
|
324
295
|
/**
|
|
325
296
|
* Parses the body of a message/rfc822 node into `node.message`. RFC 2046 5.2.1 only allows the
|
|
326
297
|
* identity encodings for such a body, RFC 2045 5.1 and 6.1 make the type and encoding names case
|
|
@@ -339,7 +310,6 @@ class MIMEParser {
|
|
|
339
310
|
}
|
|
340
311
|
node[type === 'message/rfc822' ? 'message' : 'globalMessage'] = parseTree(node.body, this.depth + 1);
|
|
341
312
|
}
|
|
342
|
-
|
|
343
313
|
/**
|
|
344
314
|
* Joins body arrays into strings. Removes unnecessary fields from the tree
|
|
345
315
|
*/
|
|
@@ -351,43 +321,38 @@ class MIMEParser {
|
|
|
351
321
|
this._node.headerUnterminated = true;
|
|
352
322
|
}
|
|
353
323
|
}
|
|
354
|
-
|
|
355
324
|
// iterative, so that deeply nested multiparts do not exhaust the stack
|
|
356
|
-
const stack = [
|
|
325
|
+
const stack = [...this.tree.childNodes];
|
|
357
326
|
while (stack.length) {
|
|
358
|
-
const
|
|
359
|
-
|
|
327
|
+
const parsing = stack.pop();
|
|
328
|
+
// the same object, from here on with its lines joined
|
|
329
|
+
const node = parsing;
|
|
330
|
+
const lines = parsing.body;
|
|
360
331
|
// a body section holds lines, parts, or at least a close delimiter. A blank line followed by
|
|
361
332
|
// the end of the input leaves the trailing empty line in the body, one followed directly by
|
|
362
333
|
// a delimiter leaves nothing
|
|
363
334
|
const closed = node.boundary && !node.unterminated;
|
|
364
|
-
if (!(
|
|
335
|
+
if (!(lines.length || parsing.childNodes.length || closed)) {
|
|
365
336
|
node.hasBody = false;
|
|
366
337
|
}
|
|
367
|
-
|
|
368
338
|
// RFC 3501 7.4.2 body-fld-lines, counted like Dovecot does: the line breaks in the body
|
|
369
|
-
node.lineCount =
|
|
370
|
-
node.body =
|
|
339
|
+
node.lineCount = lines.length ? lines.length - 1 : 0;
|
|
340
|
+
node.body = lines.join('');
|
|
371
341
|
node.size = node.body.length;
|
|
372
|
-
|
|
373
342
|
// a message/rfc822 entity carries its parsed message
|
|
374
343
|
this.parseEmbeddedMessage(node);
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
node.epilogue = node.epilogue.join('');
|
|
344
|
+
if (parsing.epilogue) {
|
|
345
|
+
node.epilogue = parsing.epilogue.join('');
|
|
378
346
|
}
|
|
379
|
-
|
|
380
|
-
node.childNodes.forEach(child => stack.push(child));
|
|
381
|
-
|
|
347
|
+
parsing.childNodes.forEach(child => stack.push(child));
|
|
382
348
|
// remove unneeded properties
|
|
383
|
-
delete
|
|
384
|
-
delete
|
|
349
|
+
delete parsing.parentNode;
|
|
350
|
+
delete parsing.state;
|
|
385
351
|
if (!node.childNodes.length) {
|
|
386
352
|
delete node.childNodes;
|
|
387
353
|
}
|
|
388
354
|
}
|
|
389
355
|
}
|
|
390
|
-
|
|
391
356
|
/**
|
|
392
357
|
* Creates a new node with default values for the parse tree
|
|
393
358
|
*/
|
|
@@ -405,61 +370,58 @@ class MIMEParser {
|
|
|
405
370
|
parentNode.childNodes.push(node);
|
|
406
371
|
return node;
|
|
407
372
|
}
|
|
408
|
-
|
|
409
373
|
/**
|
|
410
374
|
* Processes header lines. Splits lines to key-value pairs
|
|
411
375
|
* and processes special values
|
|
412
376
|
*/
|
|
413
377
|
processNodeHeader() {
|
|
414
378
|
const node = this._node;
|
|
415
|
-
|
|
379
|
+
// the fields hold raw values until they are parsed below
|
|
380
|
+
const fields = node.parsedHeader;
|
|
416
381
|
// RFC 5322 2.2.3: a line that starts with whitespace continues the previous header field
|
|
417
382
|
const header = [];
|
|
418
383
|
for (const line of node.header) {
|
|
419
384
|
if (header.length && /^\s/.test(line)) {
|
|
420
385
|
header[header.length - 1] += '\r\n' + line;
|
|
421
|
-
}
|
|
386
|
+
}
|
|
387
|
+
else {
|
|
422
388
|
header.push(line);
|
|
423
389
|
}
|
|
424
390
|
}
|
|
425
391
|
node.header = header;
|
|
426
|
-
|
|
427
392
|
for (const line of header) {
|
|
428
|
-
|
|
429
|
-
const key = (
|
|
430
|
-
value =
|
|
431
|
-
|
|
393
|
+
const parts = line.split(':');
|
|
394
|
+
const key = (parts.shift() || '').trim().toLowerCase();
|
|
395
|
+
const value = parts.join(':').trim();
|
|
432
396
|
// Do not touch headers that have strange looking keys, keep these
|
|
433
397
|
// only in the unparsed array
|
|
434
398
|
if (!FIELD_NAME.test(key)) {
|
|
435
399
|
continue;
|
|
436
400
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
node.parsedHeader[key].push(value);
|
|
441
|
-
} else {
|
|
442
|
-
node.parsedHeader[key] = [node.parsedHeader[key], value];
|
|
401
|
+
if (key in fields) {
|
|
402
|
+
if (Array.isArray(fields[key])) {
|
|
403
|
+
fields[key].push(value);
|
|
443
404
|
}
|
|
444
|
-
|
|
445
|
-
|
|
405
|
+
else {
|
|
406
|
+
fields[key] = [fields[key], value];
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
fields[key] = value.replace(/\s*\r?\n\s*/g, ' ');
|
|
446
411
|
}
|
|
447
412
|
}
|
|
448
|
-
|
|
449
413
|
// always ensure the presence of Content-Type. RFC 2046 5.1.5: inside a digest the default
|
|
450
414
|
// is message/rfc822 instead of text/plain
|
|
451
|
-
if (!
|
|
415
|
+
if (!fields['content-type']) {
|
|
452
416
|
const parentSubtype = ((node.parentNode && node.parentNode.multipart) || '').toString().toLowerCase();
|
|
453
|
-
|
|
417
|
+
fields['content-type'] = parentSubtype === 'digest' ? 'message/rfc822' : 'text/plain';
|
|
454
418
|
}
|
|
455
|
-
|
|
456
419
|
// parse additional params for Content-Type and Content-Disposition, the last header wins
|
|
457
420
|
['content-type', 'content-disposition'].forEach(key => {
|
|
458
|
-
if (
|
|
459
|
-
|
|
421
|
+
if (fields[key]) {
|
|
422
|
+
fields[key] = this.parseValueParams([].concat(fields[key]).pop());
|
|
460
423
|
}
|
|
461
424
|
});
|
|
462
|
-
|
|
463
425
|
// ensure single value for selected fields, the last header wins
|
|
464
426
|
[
|
|
465
427
|
'subject',
|
|
@@ -473,24 +435,21 @@ class MIMEParser {
|
|
|
473
435
|
'content-md5',
|
|
474
436
|
'content-location'
|
|
475
437
|
].forEach(key => {
|
|
476
|
-
if (Array.isArray(
|
|
477
|
-
|
|
438
|
+
if (Array.isArray(fields[key])) {
|
|
439
|
+
fields[key] = fields[key].pop().replace(/\s*\r?\n\s*/g, ' ');
|
|
478
440
|
}
|
|
479
441
|
});
|
|
480
|
-
|
|
481
|
-
if (node.parsedHeader['content-transfer-encoding']) {
|
|
442
|
+
if (fields['content-transfer-encoding']) {
|
|
482
443
|
// RFC 2045 6.1: the mechanism token may be followed by a comment, which is not part of it
|
|
483
|
-
|
|
444
|
+
fields['content-transfer-encoding'] = splitStructuredValue(fields['content-transfer-encoding'])[0].trim();
|
|
484
445
|
}
|
|
485
|
-
|
|
486
446
|
// Parse address fields (join several fields with same key)
|
|
487
447
|
['from', 'sender', 'reply-to', 'to', 'cc', 'bcc'].forEach(key => {
|
|
488
|
-
if (
|
|
489
|
-
|
|
448
|
+
if (fields[key]) {
|
|
449
|
+
fields[key] = [].concat(fields[key]).flatMap(value => (value && addressparser(value.replace(/\s*\r?\n\s*/g, ' '))) || []);
|
|
490
450
|
}
|
|
491
451
|
});
|
|
492
452
|
}
|
|
493
|
-
|
|
494
453
|
/**
|
|
495
454
|
* Splits a value to an object.
|
|
496
455
|
* eg. 'text/plain; charset=utf-8' -> {value: 'text/plain', params:{charset: 'utf-8'}}
|
|
@@ -505,10 +464,8 @@ class MIMEParser {
|
|
|
505
464
|
subtype: '',
|
|
506
465
|
params: Object.create(null)
|
|
507
466
|
};
|
|
508
|
-
|
|
509
467
|
// RFC 2231 continuations and extended values, by parameter name
|
|
510
468
|
const continuations = Object.create(null);
|
|
511
|
-
|
|
512
469
|
splitStructuredValue(headerValue || '', ';').forEach((part, i) => {
|
|
513
470
|
if (!i) {
|
|
514
471
|
data.value = part.trim();
|
|
@@ -517,23 +474,21 @@ class MIMEParser {
|
|
|
517
474
|
data.subtype = subtype.join('/');
|
|
518
475
|
return;
|
|
519
476
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
value = value.join('=').trim();
|
|
477
|
+
const parts = part.split('=');
|
|
478
|
+
const key = (parts.shift() || '').trim().toLowerCase();
|
|
479
|
+
let value = parts.join('=').trim();
|
|
524
480
|
if (value.length >= 2 && value.startsWith('"') && value.endsWith('"')) {
|
|
525
481
|
// RFC 2045 5.1 quoted-string: the quotes are not part of the value and a backslash
|
|
526
482
|
// quotes the character after it (RFC 822 3.3)
|
|
527
483
|
value = value.slice(1, -1).replace(/\\([\s\S])/g, '$1');
|
|
528
|
-
}
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
529
486
|
value = value.replace(/^['"\s]*|['"\s]*$/g, '');
|
|
530
487
|
}
|
|
531
|
-
|
|
532
488
|
// Do not touch parameters that have strange looking keys
|
|
533
489
|
if (!FIELD_NAME.test(key)) {
|
|
534
490
|
return;
|
|
535
491
|
}
|
|
536
|
-
|
|
537
492
|
// RFC 2231 3 and 4: `name*N` is segment N of a continued value, a trailing asterisk marks
|
|
538
493
|
// a segment as extended (percent encoded, the first one prefixed with charset'language')
|
|
539
494
|
const match = key.match(/^([^*]+)(?:\*(\d{1,3}))?(\*)?$/);
|
|
@@ -543,17 +498,16 @@ class MIMEParser {
|
|
|
543
498
|
continuations[name] = [];
|
|
544
499
|
}
|
|
545
500
|
continuations[name][Number(match[2]) || 0] = { value, extended: !!match[3] };
|
|
546
|
-
}
|
|
501
|
+
}
|
|
502
|
+
else {
|
|
547
503
|
data.params[key] = value;
|
|
548
504
|
}
|
|
549
505
|
data.hasParams = true;
|
|
550
506
|
});
|
|
551
|
-
|
|
552
507
|
Object.keys(continuations).forEach(key => {
|
|
553
508
|
let charset = '';
|
|
554
509
|
let encoded = '';
|
|
555
510
|
let extended = false;
|
|
556
|
-
|
|
557
511
|
continuations[key].forEach((segment, i) => {
|
|
558
512
|
if (!segment) {
|
|
559
513
|
return;
|
|
@@ -570,18 +524,16 @@ class MIMEParser {
|
|
|
570
524
|
if (segment.extended) {
|
|
571
525
|
extended = true;
|
|
572
526
|
encoded += value;
|
|
573
|
-
}
|
|
527
|
+
}
|
|
528
|
+
else {
|
|
574
529
|
// a segment that is not extended is plain text, encode it like the rest
|
|
575
530
|
encoded += value.replace(/[^\x21-\x24\x26-\x7e]/g, chr => '%' + ('0' + chr.charCodeAt(0).toString(16)).substr(-2));
|
|
576
531
|
}
|
|
577
532
|
});
|
|
578
|
-
|
|
579
533
|
data.params[key] = extended ? decodeExtendedValue(charset, encoded) : decodeExtendedValue('', encoded);
|
|
580
534
|
});
|
|
581
|
-
|
|
582
535
|
return data;
|
|
583
536
|
}
|
|
584
|
-
|
|
585
537
|
/**
|
|
586
538
|
* Checks Content-Type value for the current tree node.
|
|
587
539
|
*/
|
|
@@ -589,7 +541,6 @@ class MIMEParser {
|
|
|
589
541
|
const node = this._node;
|
|
590
542
|
// processNodeHeader() always sets a Content-Type
|
|
591
543
|
const contentType = node.parsedHeader['content-type'];
|
|
592
|
-
|
|
593
544
|
if (contentType.type === 'multipart' && contentType.params.boundary) {
|
|
594
545
|
node.multipart = contentType.subtype;
|
|
595
546
|
node.boundary = contentType.params.boundary;
|
|
@@ -598,7 +549,6 @@ class MIMEParser {
|
|
|
598
549
|
}
|
|
599
550
|
}
|
|
600
551
|
}
|
|
601
|
-
|
|
602
552
|
/**
|
|
603
553
|
* Parses a message into a MIME tree
|
|
604
554
|
*
|
|
@@ -610,13 +560,12 @@ function parseTree(rfc822, depth) {
|
|
|
610
560
|
const parser = new MIMEParser(rfc822, depth);
|
|
611
561
|
parser.parse();
|
|
612
562
|
parser.finalizeTree();
|
|
563
|
+
// finalizeTree() turned the nodes into MimeNodes
|
|
613
564
|
return parser.tree.childNodes[0];
|
|
614
565
|
}
|
|
615
|
-
|
|
616
566
|
// RFC 3501 9: body-type-mpart = 1*body SP media-subtype. A multipart whose boundary never appeared has
|
|
617
567
|
// no parts, so this empty text part stands in for them
|
|
618
568
|
const PLACEHOLDER_PART = parseTree('Content-Type: text/plain\r\n\r\n');
|
|
619
|
-
|
|
620
569
|
/**
|
|
621
570
|
* The parts of a node as IMAP numbers them: the parts of a multipart (the placeholder when it has none),
|
|
622
571
|
* undefined for anything else
|
|
@@ -630,7 +579,6 @@ function partsOf(node) {
|
|
|
630
579
|
}
|
|
631
580
|
return node.boundary ? [PLACEHOLDER_PART] : undefined;
|
|
632
581
|
}
|
|
633
|
-
|
|
634
582
|
/**
|
|
635
583
|
* The message encapsulated in a node: the message of a message/rfc822 part, and with `global` also of a
|
|
636
584
|
* message/global part (RFC 9051 sections 6.4.5.1 and 7.5.2, IMAP4rev1 treats message/global as a basic part)
|
|
@@ -642,7 +590,6 @@ function partsOf(node) {
|
|
|
642
590
|
function embeddedMessage(node, global) {
|
|
643
591
|
return node.message || (global ? node.globalMessage : undefined);
|
|
644
592
|
}
|
|
645
|
-
|
|
646
593
|
/**
|
|
647
594
|
* Resolves a numeric part path to a node. RFC 3501 6.4.5: the parts of a multipart are numbered from 1,
|
|
648
595
|
* a non-multipart message has one part which is the message itself, and the parts of a message/rfc822
|
|
@@ -657,25 +604,20 @@ function resolveNode(tree, path, global) {
|
|
|
657
604
|
// the message whose parts the next number counts
|
|
658
605
|
let scope = tree;
|
|
659
606
|
let node = tree;
|
|
660
|
-
|
|
661
607
|
for (const number of (path || '').toString().split('.')) {
|
|
662
608
|
const index = Number(number) - 1;
|
|
663
609
|
if (!scope || !(index >= 0)) {
|
|
664
610
|
return false;
|
|
665
611
|
}
|
|
666
|
-
|
|
667
612
|
const parts = partsOf(scope);
|
|
668
613
|
node = parts ? parts[index] : index === 0 ? scope : undefined;
|
|
669
614
|
if (!node) {
|
|
670
615
|
return false;
|
|
671
616
|
}
|
|
672
|
-
|
|
673
617
|
scope = embeddedMessage(node, global) || (partsOf(node) ? node : false);
|
|
674
618
|
}
|
|
675
|
-
|
|
676
619
|
return node;
|
|
677
620
|
}
|
|
678
|
-
|
|
679
621
|
/**
|
|
680
622
|
* The header of a node as the HEADER and MIME sections return it, with the blank line that ends it
|
|
681
623
|
*
|
|
@@ -690,7 +632,6 @@ function headerSection(node) {
|
|
|
690
632
|
}
|
|
691
633
|
return header.length ? header.join('\r\n') + '\r\n\r\n' : '\r\n';
|
|
692
634
|
}
|
|
693
|
-
|
|
694
635
|
/**
|
|
695
636
|
* Renders a node of the tree back to the octets it was parsed from
|
|
696
637
|
*
|
|
@@ -700,7 +641,6 @@ function headerSection(node) {
|
|
|
700
641
|
*/
|
|
701
642
|
function render(node, textOnly) {
|
|
702
643
|
const output = [];
|
|
703
|
-
|
|
704
644
|
const walk = (node, withHeader) => {
|
|
705
645
|
if (withHeader) {
|
|
706
646
|
const header = node.header || [];
|
|
@@ -708,22 +648,17 @@ function render(node, textOnly) {
|
|
|
708
648
|
output.push(header.join('\r\n') + (node.headerUnterminated ? '' : '\r\n'));
|
|
709
649
|
}
|
|
710
650
|
}
|
|
711
|
-
|
|
712
651
|
if (node.hasBody === false) {
|
|
713
652
|
return;
|
|
714
653
|
}
|
|
715
|
-
|
|
716
654
|
if (withHeader) {
|
|
717
655
|
// the blank line between header and body
|
|
718
656
|
output.push('\r\n');
|
|
719
657
|
}
|
|
720
|
-
|
|
721
658
|
output.push(node.body || '');
|
|
722
|
-
|
|
723
659
|
if (!node.boundary) {
|
|
724
660
|
return;
|
|
725
661
|
}
|
|
726
|
-
|
|
727
662
|
const children = node.childNodes || [];
|
|
728
663
|
for (let i = 0; i < children.length; i++) {
|
|
729
664
|
const child = children[i];
|
|
@@ -734,20 +669,16 @@ function render(node, textOnly) {
|
|
|
734
669
|
output.push('\r\n');
|
|
735
670
|
}
|
|
736
671
|
}
|
|
737
|
-
|
|
738
672
|
if (!node.unterminated) {
|
|
739
673
|
output.push('--' + node.boundary + '--' + (node.closePad || ''));
|
|
740
674
|
output.push(node.epilogue || '');
|
|
741
675
|
}
|
|
742
676
|
};
|
|
743
|
-
|
|
744
677
|
walk(node, !textOnly);
|
|
745
678
|
return output.join('');
|
|
746
679
|
}
|
|
747
|
-
|
|
748
680
|
// Parsed data of messages, so a message is parsed only once and not again until its source changes
|
|
749
681
|
const cache = new WeakMap();
|
|
750
|
-
|
|
751
682
|
/**
|
|
752
683
|
* Returns the source with CRLF line breaks and the MIME tree of a message
|
|
753
684
|
*
|
|
@@ -763,16 +694,7 @@ function getMessageData(message) {
|
|
|
763
694
|
}
|
|
764
695
|
return cached;
|
|
765
696
|
}
|
|
766
|
-
|
|
767
|
-
module.exports = function (rfc822) {
|
|
697
|
+
export default function mimeparser(rfc822) {
|
|
768
698
|
return parseTree(normalizeLineBreaks(rfc822));
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
module.exports.IDENTITY_ENCODINGS = IDENTITY_ENCODINGS;
|
|
772
|
-
module.exports.getMessageData = getMessageData;
|
|
773
|
-
module.exports.normalizeLineBreaks = normalizeLineBreaks;
|
|
774
|
-
module.exports.partsOf = partsOf;
|
|
775
|
-
module.exports.resolveNode = resolveNode;
|
|
776
|
-
module.exports.embeddedMessage = embeddedMessage;
|
|
777
|
-
module.exports.headerSection = headerSection;
|
|
778
|
-
module.exports.render = render;
|
|
699
|
+
}
|
|
700
|
+
export { parseTree, IDENTITY_ENCODINGS, getMessageData, normalizeLineBreaks, partsOf, resolveNode, embeddedMessage, headerSection, render };
|