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.
Files changed (485) hide show
  1. package/README.md +32 -19
  2. package/bin/imapkit.js +12 -16
  3. package/dist/cjs/addressparser.d.ts +21 -0
  4. package/dist/cjs/addressparser.js +277 -0
  5. package/dist/cjs/arguments.d.ts +31 -0
  6. package/{lib → dist/cjs}/arguments.js +9 -21
  7. package/dist/cjs/bodystructure.d.ts +25 -0
  8. package/dist/cjs/bodystructure.js +150 -0
  9. package/dist/cjs/cert.d.ts +2 -0
  10. package/dist/cjs/cert.js +7 -0
  11. package/dist/cjs/command-states.d.ts +36 -0
  12. package/dist/cjs/command-states.js +102 -0
  13. package/dist/cjs/commands/append.d.ts +88 -0
  14. package/dist/cjs/commands/append.js +299 -0
  15. package/dist/cjs/commands/capability.d.ts +2 -0
  16. package/dist/cjs/commands/capability.js +44 -0
  17. package/dist/cjs/commands/check.d.ts +2 -0
  18. package/dist/cjs/commands/check.js +28 -0
  19. package/dist/cjs/commands/close.d.ts +2 -0
  20. package/dist/cjs/commands/close.js +35 -0
  21. package/dist/cjs/commands/copy.d.ts +30 -0
  22. package/dist/cjs/commands/copy.js +107 -0
  23. package/dist/cjs/commands/create.d.ts +2 -0
  24. package/dist/cjs/commands/create.js +53 -0
  25. package/dist/cjs/commands/delete.d.ts +2 -0
  26. package/dist/cjs/commands/delete.js +63 -0
  27. package/dist/cjs/commands/examine.d.ts +2 -0
  28. package/dist/cjs/commands/examine.js +19 -0
  29. package/dist/cjs/commands/expunge.d.ts +2 -0
  30. package/dist/cjs/commands/expunge.js +32 -0
  31. package/dist/cjs/commands/fetch.d.ts +23 -0
  32. package/dist/cjs/commands/fetch.js +208 -0
  33. package/dist/cjs/commands/handlers/fetch.d.ts +12 -0
  34. package/dist/cjs/commands/handlers/fetch.js +195 -0
  35. package/dist/cjs/commands/handlers/flags.d.ts +17 -0
  36. package/dist/cjs/commands/handlers/flags.js +39 -0
  37. package/dist/cjs/commands/handlers/search.d.ts +85 -0
  38. package/dist/cjs/commands/handlers/search.js +504 -0
  39. package/dist/cjs/commands/handlers/status.d.ts +34 -0
  40. package/dist/cjs/commands/handlers/status.js +81 -0
  41. package/dist/cjs/commands/handlers/store.d.ts +3 -0
  42. package/dist/cjs/commands/handlers/store.js +117 -0
  43. package/dist/cjs/commands/index.d.ts +2 -0
  44. package/dist/cjs/commands/index.js +61 -0
  45. package/dist/cjs/commands/list.d.ts +2 -0
  46. package/dist/cjs/commands/list.js +86 -0
  47. package/dist/cjs/commands/login.d.ts +2 -0
  48. package/dist/cjs/commands/login.js +62 -0
  49. package/dist/cjs/commands/logout.d.ts +2 -0
  50. package/dist/cjs/commands/logout.js +40 -0
  51. package/dist/cjs/commands/lsub.d.ts +2 -0
  52. package/dist/cjs/commands/lsub.js +79 -0
  53. package/dist/cjs/commands/noop.d.ts +2 -0
  54. package/dist/cjs/commands/noop.js +28 -0
  55. package/dist/cjs/commands/rename.d.ts +2 -0
  56. package/dist/cjs/commands/rename.js +98 -0
  57. package/dist/cjs/commands/search.d.ts +10 -0
  58. package/dist/cjs/commands/search.js +71 -0
  59. package/dist/cjs/commands/select.d.ts +19 -0
  60. package/dist/cjs/commands/select.js +230 -0
  61. package/dist/cjs/commands/status.d.ts +2 -0
  62. package/dist/cjs/commands/status.js +57 -0
  63. package/dist/cjs/commands/store.d.ts +10 -0
  64. package/dist/cjs/commands/store.js +134 -0
  65. package/dist/cjs/commands/subscribe.d.ts +2 -0
  66. package/dist/cjs/commands/subscribe.js +51 -0
  67. package/dist/cjs/commands/uid-copy.d.ts +2 -0
  68. package/dist/cjs/commands/uid-copy.js +19 -0
  69. package/dist/cjs/commands/uid-fetch.d.ts +3 -0
  70. package/dist/cjs/commands/uid-fetch.js +17 -0
  71. package/dist/cjs/commands/uid-search.d.ts +3 -0
  72. package/dist/cjs/commands/uid-search.js +17 -0
  73. package/dist/cjs/commands/uid-store.d.ts +3 -0
  74. package/dist/cjs/commands/uid-store.js +17 -0
  75. package/dist/cjs/commands/unsubscribe.d.ts +2 -0
  76. package/dist/cjs/commands/unsubscribe.js +50 -0
  77. package/dist/cjs/dates.d.ts +64 -0
  78. package/dist/cjs/dates.js +124 -0
  79. package/dist/cjs/deflate-layer.d.ts +83 -0
  80. package/dist/cjs/deflate-layer.js +232 -0
  81. package/dist/cjs/encoded-words.d.ts +15 -0
  82. package/dist/cjs/encoded-words.js +85 -0
  83. package/dist/cjs/envelope.d.ts +33 -0
  84. package/dist/cjs/envelope.js +86 -0
  85. package/dist/cjs/esearch.d.ts +96 -0
  86. package/dist/cjs/esearch.js +190 -0
  87. package/dist/cjs/framing.d.ts +66 -0
  88. package/{lib → dist/cjs}/framing.js +9 -26
  89. package/dist/cjs/index.d.ts +9 -0
  90. package/dist/cjs/index.js +56 -0
  91. package/dist/cjs/list-extensions.d.ts +50 -0
  92. package/dist/cjs/list-extensions.js +35 -0
  93. package/dist/cjs/load-plugins.d.ts +21 -0
  94. package/dist/cjs/load-plugins.js +89 -0
  95. package/dist/cjs/mailbox-name.d.ts +26 -0
  96. package/dist/cjs/mailbox-name.js +127 -0
  97. package/dist/cjs/mimeparser.d.ts +137 -0
  98. package/dist/cjs/mimeparser.js +727 -0
  99. package/dist/cjs/mock-client.d.ts +39 -0
  100. package/dist/cjs/mock-client.js +236 -0
  101. package/dist/cjs/numbers.d.ts +28 -0
  102. package/dist/cjs/numbers.js +52 -0
  103. package/dist/cjs/package.json +3 -0
  104. package/dist/cjs/plugins/acl.d.ts +2 -0
  105. package/dist/cjs/plugins/acl.js +888 -0
  106. package/dist/cjs/plugins/appendlimit.d.ts +16 -0
  107. package/dist/cjs/plugins/appendlimit.js +87 -0
  108. package/dist/cjs/plugins/auth-plain.d.ts +2 -0
  109. package/dist/cjs/plugins/auth-plain.js +89 -0
  110. package/dist/cjs/plugins/binary.d.ts +30 -0
  111. package/dist/cjs/plugins/binary.js +247 -0
  112. package/dist/cjs/plugins/catenate.d.ts +14 -0
  113. package/dist/cjs/plugins/catenate.js +250 -0
  114. package/dist/cjs/plugins/compress.d.ts +7 -0
  115. package/dist/cjs/plugins/compress.js +79 -0
  116. package/dist/cjs/plugins/condstore.d.ts +5 -0
  117. package/dist/cjs/plugins/condstore.js +492 -0
  118. package/dist/cjs/plugins/context-search.d.ts +8 -0
  119. package/dist/cjs/plugins/context-search.js +304 -0
  120. package/dist/cjs/plugins/context-sort.d.ts +6 -0
  121. package/dist/cjs/plugins/context-sort.js +32 -0
  122. package/dist/cjs/plugins/create-special-use.d.ts +7 -0
  123. package/dist/cjs/plugins/create-special-use.js +101 -0
  124. package/dist/cjs/plugins/enable.d.ts +23 -0
  125. package/dist/cjs/plugins/enable.js +127 -0
  126. package/dist/cjs/plugins/esearch.d.ts +6 -0
  127. package/dist/cjs/plugins/esearch.js +142 -0
  128. package/dist/cjs/plugins/esort.d.ts +6 -0
  129. package/dist/cjs/plugins/esort.js +60 -0
  130. package/dist/cjs/plugins/id.d.ts +5 -0
  131. package/dist/cjs/plugins/id.js +123 -0
  132. package/dist/cjs/plugins/idle.d.ts +5 -0
  133. package/dist/cjs/plugins/idle.js +85 -0
  134. package/dist/cjs/plugins/imap4rev2.d.ts +6 -0
  135. package/dist/cjs/plugins/imap4rev2.js +184 -0
  136. package/dist/cjs/plugins/index.d.ts +2 -0
  137. package/dist/cjs/plugins/index.js +119 -0
  138. package/dist/cjs/plugins/list-extended.d.ts +2 -0
  139. package/dist/cjs/plugins/list-extended.js +235 -0
  140. package/dist/cjs/plugins/list-status.d.ts +6 -0
  141. package/dist/cjs/plugins/list-status.js +42 -0
  142. package/dist/cjs/plugins/literalminus.d.ts +8 -0
  143. package/dist/cjs/plugins/literalminus.js +32 -0
  144. package/dist/cjs/plugins/literalplus.d.ts +6 -0
  145. package/dist/cjs/plugins/literalplus.js +30 -0
  146. package/dist/cjs/plugins/logindisabled.d.ts +5 -0
  147. package/dist/cjs/plugins/logindisabled.js +54 -0
  148. package/dist/cjs/plugins/messagelimit.d.ts +19 -0
  149. package/dist/cjs/plugins/messagelimit.js +227 -0
  150. package/dist/cjs/plugins/metadata-server.d.ts +7 -0
  151. package/dist/cjs/plugins/metadata-server.js +24 -0
  152. package/dist/cjs/plugins/metadata.d.ts +11 -0
  153. package/dist/cjs/plugins/metadata.js +436 -0
  154. package/dist/cjs/plugins/move.d.ts +11 -0
  155. package/dist/cjs/plugins/move.js +96 -0
  156. package/dist/cjs/plugins/multiappend.d.ts +12 -0
  157. package/dist/cjs/plugins/multiappend.js +38 -0
  158. package/dist/cjs/plugins/multisearch.d.ts +6 -0
  159. package/dist/cjs/plugins/multisearch.js +263 -0
  160. package/dist/cjs/plugins/namespace.d.ts +5 -0
  161. package/dist/cjs/plugins/namespace.js +57 -0
  162. package/dist/cjs/plugins/notify.d.ts +2 -0
  163. package/dist/cjs/plugins/notify.js +628 -0
  164. package/dist/cjs/plugins/oauthbearer.d.ts +32 -0
  165. package/dist/cjs/plugins/oauthbearer.js +202 -0
  166. package/dist/cjs/plugins/objectid.d.ts +23 -0
  167. package/dist/cjs/plugins/objectid.js +221 -0
  168. package/dist/cjs/plugins/partial.d.ts +6 -0
  169. package/dist/cjs/plugins/partial.js +78 -0
  170. package/dist/cjs/plugins/preview.d.ts +31 -0
  171. package/dist/cjs/plugins/preview.js +378 -0
  172. package/dist/cjs/plugins/qresync.d.ts +11 -0
  173. package/dist/cjs/plugins/qresync.js +473 -0
  174. package/dist/cjs/plugins/quota.d.ts +18 -0
  175. package/dist/cjs/plugins/quota.js +254 -0
  176. package/dist/cjs/plugins/replace.d.ts +14 -0
  177. package/dist/cjs/plugins/replace.js +130 -0
  178. package/dist/cjs/plugins/sasl-ir.d.ts +5 -0
  179. package/dist/cjs/plugins/sasl-ir.js +24 -0
  180. package/dist/cjs/plugins/savedate.d.ts +17 -0
  181. package/dist/cjs/plugins/savedate.js +64 -0
  182. package/dist/cjs/plugins/savelimit.d.ts +10 -0
  183. package/dist/cjs/plugins/savelimit.js +30 -0
  184. package/dist/cjs/plugins/searchres.d.ts +6 -0
  185. package/dist/cjs/plugins/searchres.js +91 -0
  186. package/dist/cjs/plugins/sort-display.d.ts +11 -0
  187. package/dist/cjs/plugins/sort-display.js +37 -0
  188. package/dist/cjs/plugins/sort.d.ts +11 -0
  189. package/dist/cjs/plugins/sort.js +125 -0
  190. package/dist/cjs/plugins/special-use.d.ts +10 -0
  191. package/dist/cjs/plugins/special-use.js +95 -0
  192. package/dist/cjs/plugins/starttls.d.ts +5 -0
  193. package/dist/cjs/plugins/starttls.js +55 -0
  194. package/dist/cjs/plugins/status-size.d.ts +7 -0
  195. package/dist/cjs/plugins/status-size.js +30 -0
  196. package/dist/cjs/plugins/thread-orderedsubject.d.ts +11 -0
  197. package/dist/cjs/plugins/thread-orderedsubject.js +28 -0
  198. package/dist/cjs/plugins/thread-references.d.ts +11 -0
  199. package/dist/cjs/plugins/thread-references.js +28 -0
  200. package/dist/cjs/plugins/uidonly.d.ts +15 -0
  201. package/dist/cjs/plugins/uidonly.js +126 -0
  202. package/dist/cjs/plugins/uidplus.d.ts +15 -0
  203. package/dist/cjs/plugins/uidplus.js +119 -0
  204. package/dist/cjs/plugins/unauthenticate.d.ts +7 -0
  205. package/dist/cjs/plugins/unauthenticate.js +32 -0
  206. package/dist/cjs/plugins/unselect.d.ts +5 -0
  207. package/dist/cjs/plugins/unselect.js +36 -0
  208. package/dist/cjs/plugins/utf8-accept.d.ts +6 -0
  209. package/dist/cjs/plugins/utf8-accept.js +72 -0
  210. package/dist/cjs/plugins/x-gm-ext-1.d.ts +26 -0
  211. package/dist/cjs/plugins/x-gm-ext-1.js +422 -0
  212. package/dist/cjs/plugins/xoauth2.d.ts +2 -0
  213. package/dist/cjs/plugins/xoauth2.js +155 -0
  214. package/dist/cjs/plugins/xtoybird.d.ts +2 -0
  215. package/dist/cjs/plugins/xtoybird.js +236 -0
  216. package/dist/cjs/server.d.ts +876 -0
  217. package/dist/cjs/server.js +2597 -0
  218. package/dist/cjs/smtp-listener.d.ts +13 -0
  219. package/dist/cjs/smtp-listener.js +47 -0
  220. package/dist/cjs/sorting.d.ts +77 -0
  221. package/dist/cjs/sorting.js +290 -0
  222. package/dist/cjs/threading.d.ts +30 -0
  223. package/dist/cjs/threading.js +318 -0
  224. package/dist/cjs/types.d.ts +327 -0
  225. package/dist/cjs/types.js +3 -0
  226. package/dist/cjs/utf8-session.d.ts +17 -0
  227. package/dist/cjs/utf8-session.js +148 -0
  228. package/dist/cjs/vanished.d.ts +21 -0
  229. package/dist/cjs/vanished.js +55 -0
  230. package/dist/esm/addressparser.d.ts +21 -0
  231. package/{lib → dist/esm}/addressparser.js +102 -123
  232. package/dist/esm/arguments.d.ts +31 -0
  233. package/dist/esm/arguments.js +96 -0
  234. package/dist/esm/bodystructure.d.ts +25 -0
  235. package/{lib → dist/esm}/bodystructure.js +17 -33
  236. package/dist/esm/cert.d.ts +2 -0
  237. package/dist/esm/cert.js +4 -0
  238. package/dist/esm/command-states.d.ts +36 -0
  239. package/{lib → dist/esm}/command-states.js +4 -16
  240. package/dist/esm/commands/append.d.ts +88 -0
  241. package/{lib → dist/esm}/commands/append.js +47 -85
  242. package/dist/esm/commands/capability.d.ts +2 -0
  243. package/dist/esm/commands/capability.js +29 -0
  244. package/dist/esm/commands/check.d.ts +2 -0
  245. package/dist/esm/commands/check.js +13 -0
  246. package/dist/esm/commands/close.d.ts +2 -0
  247. package/dist/esm/commands/close.js +20 -0
  248. package/dist/esm/commands/copy.d.ts +30 -0
  249. package/{lib → dist/esm}/commands/copy.js +31 -55
  250. package/dist/esm/commands/create.d.ts +2 -0
  251. package/{lib → dist/esm}/commands/create.js +25 -39
  252. package/dist/esm/commands/delete.d.ts +2 -0
  253. package/{lib → dist/esm}/commands/delete.js +25 -41
  254. package/dist/esm/commands/examine.d.ts +2 -0
  255. package/dist/esm/commands/examine.js +4 -0
  256. package/dist/esm/commands/expunge.d.ts +2 -0
  257. package/dist/esm/commands/expunge.js +17 -0
  258. package/dist/esm/commands/fetch.d.ts +23 -0
  259. package/{lib → dist/esm}/commands/fetch.js +34 -75
  260. package/dist/esm/commands/handlers/fetch.d.ts +12 -0
  261. package/{lib → dist/esm}/commands/handlers/fetch.js +11 -42
  262. package/dist/esm/commands/handlers/flags.d.ts +17 -0
  263. package/{lib → dist/esm}/commands/handlers/flags.js +3 -11
  264. package/dist/esm/commands/handlers/search.d.ts +85 -0
  265. package/{lib → dist/esm}/commands/handlers/search.js +33 -71
  266. package/dist/esm/commands/handlers/status.d.ts +34 -0
  267. package/{lib → dist/esm}/commands/handlers/status.js +1 -9
  268. package/dist/esm/commands/handlers/store.d.ts +3 -0
  269. package/{lib → dist/esm}/commands/handlers/store.js +20 -44
  270. package/dist/esm/commands/index.d.ts +2 -0
  271. package/dist/esm/commands/index.js +55 -0
  272. package/dist/esm/commands/list.d.ts +2 -0
  273. package/dist/esm/commands/list.js +71 -0
  274. package/dist/esm/commands/login.d.ts +2 -0
  275. package/{lib → dist/esm}/commands/login.js +24 -44
  276. package/dist/esm/commands/logout.d.ts +2 -0
  277. package/dist/esm/commands/logout.js +25 -0
  278. package/dist/esm/commands/lsub.d.ts +2 -0
  279. package/dist/esm/commands/lsub.js +64 -0
  280. package/dist/esm/commands/noop.d.ts +2 -0
  281. package/dist/esm/commands/noop.js +13 -0
  282. package/dist/esm/commands/rename.d.ts +2 -0
  283. package/{lib → dist/esm}/commands/rename.js +32 -51
  284. package/dist/esm/commands/search.d.ts +10 -0
  285. package/dist/esm/commands/search.js +54 -0
  286. package/dist/esm/commands/select.d.ts +19 -0
  287. package/dist/esm/commands/select.js +214 -0
  288. package/dist/esm/commands/status.d.ts +2 -0
  289. package/{lib → dist/esm}/commands/status.js +18 -39
  290. package/dist/esm/commands/store.d.ts +10 -0
  291. package/{lib → dist/esm}/commands/store.js +39 -73
  292. package/dist/esm/commands/subscribe.d.ts +2 -0
  293. package/{lib → dist/esm}/commands/subscribe.js +22 -39
  294. package/dist/esm/commands/uid-copy.d.ts +2 -0
  295. package/dist/esm/commands/uid-copy.js +4 -0
  296. package/dist/esm/commands/uid-fetch.d.ts +3 -0
  297. package/dist/esm/commands/uid-fetch.js +3 -0
  298. package/dist/esm/commands/uid-search.d.ts +3 -0
  299. package/dist/esm/commands/uid-search.js +3 -0
  300. package/dist/esm/commands/uid-store.d.ts +3 -0
  301. package/dist/esm/commands/uid-store.js +3 -0
  302. package/dist/esm/commands/unsubscribe.d.ts +2 -0
  303. package/{lib → dist/esm}/commands/unsubscribe.js +22 -37
  304. package/dist/esm/dates.d.ts +64 -0
  305. package/{lib → dist/esm}/dates.js +6 -14
  306. package/dist/esm/deflate-layer.d.ts +83 -0
  307. package/{lib → dist/esm}/deflate-layer.js +9 -26
  308. package/dist/esm/encoded-words.d.ts +15 -0
  309. package/{lib → dist/esm}/encoded-words.js +9 -25
  310. package/dist/esm/envelope.d.ts +33 -0
  311. package/{lib → dist/esm}/envelope.js +8 -19
  312. package/dist/esm/esearch.d.ts +96 -0
  313. package/{lib → dist/esm}/esearch.js +12 -39
  314. package/dist/esm/framing.d.ts +66 -0
  315. package/dist/esm/framing.js +82 -0
  316. package/dist/esm/index.d.ts +9 -0
  317. package/dist/esm/index.js +6 -0
  318. package/dist/esm/list-extensions.d.ts +50 -0
  319. package/{lib → dist/esm}/list-extensions.js +1 -4
  320. package/dist/esm/load-plugins.d.ts +21 -0
  321. package/{lib → dist/esm}/load-plugins.js +9 -43
  322. package/dist/esm/mailbox-name.d.ts +26 -0
  323. package/{lib → dist/esm}/mailbox-name.js +5 -26
  324. package/dist/esm/mimeparser.d.ts +137 -0
  325. package/{lib → dist/esm}/mimeparser.js +74 -152
  326. package/dist/esm/mock-client.d.ts +39 -0
  327. package/{lib → dist/esm}/mock-client.js +26 -40
  328. package/dist/esm/numbers.d.ts +28 -0
  329. package/{lib → dist/esm}/numbers.js +1 -8
  330. package/dist/esm/package.json +3 -0
  331. package/dist/esm/plugins/acl.d.ts +2 -0
  332. package/{lib → dist/esm}/plugins/acl.js +146 -240
  333. package/dist/esm/plugins/appendlimit.d.ts +16 -0
  334. package/{lib → dist/esm}/plugins/appendlimit.js +5 -16
  335. package/dist/esm/plugins/auth-plain.d.ts +2 -0
  336. package/{lib → dist/esm}/plugins/auth-plain.js +11 -31
  337. package/dist/esm/plugins/binary.d.ts +30 -0
  338. package/{lib → dist/esm}/plugins/binary.js +17 -43
  339. package/dist/esm/plugins/catenate.d.ts +14 -0
  340. package/{lib → dist/esm}/plugins/catenate.js +19 -40
  341. package/dist/esm/plugins/compress.d.ts +7 -0
  342. package/dist/esm/plugins/compress.js +61 -0
  343. package/dist/esm/plugins/condstore.d.ts +5 -0
  344. package/{lib → dist/esm}/plugins/condstore.js +66 -152
  345. package/dist/esm/plugins/context-search.d.ts +8 -0
  346. package/{lib → dist/esm}/plugins/context-search.js +53 -88
  347. package/dist/esm/plugins/context-sort.d.ts +6 -0
  348. package/{lib → dist/esm}/plugins/context-sort.js +4 -9
  349. package/dist/esm/plugins/create-special-use.d.ts +7 -0
  350. package/{lib → dist/esm}/plugins/create-special-use.js +33 -55
  351. package/dist/esm/plugins/enable.d.ts +23 -0
  352. package/dist/esm/plugins/enable.js +111 -0
  353. package/dist/esm/plugins/esearch.d.ts +6 -0
  354. package/{lib → dist/esm}/plugins/esearch.js +13 -42
  355. package/dist/esm/plugins/esort.d.ts +6 -0
  356. package/{lib → dist/esm}/plugins/esort.js +7 -25
  357. package/dist/esm/plugins/id.d.ts +5 -0
  358. package/dist/esm/plugins/id.js +108 -0
  359. package/dist/esm/plugins/idle.d.ts +5 -0
  360. package/dist/esm/plugins/idle.js +70 -0
  361. package/dist/esm/plugins/imap4rev2.d.ts +6 -0
  362. package/{lib → dist/esm}/plugins/imap4rev2.js +24 -60
  363. package/dist/esm/plugins/index.d.ts +2 -0
  364. package/dist/esm/plugins/index.js +113 -0
  365. package/dist/esm/plugins/list-extended.d.ts +2 -0
  366. package/{lib → dist/esm}/plugins/list-extended.js +28 -66
  367. package/dist/esm/plugins/list-status.d.ts +6 -0
  368. package/{lib → dist/esm}/plugins/list-status.js +5 -12
  369. package/dist/esm/plugins/literalminus.d.ts +8 -0
  370. package/{lib → dist/esm}/plugins/literalminus.js +2 -5
  371. package/dist/esm/plugins/literalplus.d.ts +6 -0
  372. package/{lib → dist/esm}/plugins/literalplus.js +2 -5
  373. package/dist/esm/plugins/logindisabled.d.ts +5 -0
  374. package/dist/esm/plugins/logindisabled.js +39 -0
  375. package/dist/esm/plugins/messagelimit.d.ts +19 -0
  376. package/{lib → dist/esm}/plugins/messagelimit.js +18 -41
  377. package/dist/esm/plugins/metadata-server.d.ts +7 -0
  378. package/{lib → dist/esm}/plugins/metadata-server.js +3 -7
  379. package/dist/esm/plugins/metadata.d.ts +11 -0
  380. package/dist/esm/plugins/metadata.js +421 -0
  381. package/dist/esm/plugins/move.d.ts +11 -0
  382. package/{lib → dist/esm}/plugins/move.js +37 -66
  383. package/dist/esm/plugins/multiappend.d.ts +12 -0
  384. package/{lib → dist/esm}/plugins/multiappend.js +2 -5
  385. package/dist/esm/plugins/multisearch.d.ts +6 -0
  386. package/{lib → dist/esm}/plugins/multisearch.js +24 -48
  387. package/dist/esm/plugins/namespace.d.ts +5 -0
  388. package/dist/esm/plugins/namespace.js +42 -0
  389. package/dist/esm/plugins/notify.d.ts +2 -0
  390. package/{lib → dist/esm}/plugins/notify.js +90 -134
  391. package/dist/esm/plugins/oauthbearer.d.ts +32 -0
  392. package/{lib → dist/esm}/plugins/oauthbearer.js +18 -48
  393. package/dist/esm/plugins/objectid.d.ts +23 -0
  394. package/{lib → dist/esm}/plugins/objectid.js +21 -58
  395. package/dist/esm/plugins/partial.d.ts +6 -0
  396. package/{lib → dist/esm}/plugins/partial.js +7 -15
  397. package/dist/esm/plugins/preview.d.ts +31 -0
  398. package/{lib → dist/esm}/plugins/preview.js +28 -66
  399. package/dist/esm/plugins/qresync.d.ts +11 -0
  400. package/{lib → dist/esm}/plugins/qresync.js +64 -134
  401. package/dist/esm/plugins/quota.d.ts +18 -0
  402. package/{lib → dist/esm}/plugins/quota.js +89 -135
  403. package/dist/esm/plugins/replace.d.ts +14 -0
  404. package/{lib → dist/esm}/plugins/replace.js +21 -51
  405. package/dist/esm/plugins/sasl-ir.d.ts +5 -0
  406. package/{lib → dist/esm}/plugins/sasl-ir.js +3 -6
  407. package/dist/esm/plugins/savedate.d.ts +17 -0
  408. package/{lib → dist/esm}/plugins/savedate.js +5 -15
  409. package/dist/esm/plugins/savelimit.d.ts +10 -0
  410. package/{lib → dist/esm}/plugins/savelimit.js +3 -6
  411. package/dist/esm/plugins/searchres.d.ts +6 -0
  412. package/{lib → dist/esm}/plugins/searchres.js +13 -22
  413. package/dist/esm/plugins/sort-display.d.ts +11 -0
  414. package/{lib → dist/esm}/plugins/sort-display.js +6 -10
  415. package/dist/esm/plugins/sort.d.ts +11 -0
  416. package/{lib → dist/esm}/plugins/sort.js +24 -46
  417. package/dist/esm/plugins/special-use.d.ts +10 -0
  418. package/{lib → dist/esm}/plugins/special-use.js +9 -24
  419. package/dist/esm/plugins/starttls.d.ts +5 -0
  420. package/{lib → dist/esm}/plugins/starttls.js +20 -37
  421. package/dist/esm/plugins/status-size.d.ts +7 -0
  422. package/{lib → dist/esm}/plugins/status-size.js +4 -11
  423. package/dist/esm/plugins/thread-orderedsubject.d.ts +11 -0
  424. package/{lib → dist/esm}/plugins/thread-orderedsubject.js +3 -6
  425. package/dist/esm/plugins/thread-references.d.ts +11 -0
  426. package/{lib → dist/esm}/plugins/thread-references.js +3 -6
  427. package/dist/esm/plugins/uidonly.d.ts +15 -0
  428. package/{lib → dist/esm}/plugins/uidonly.js +11 -35
  429. package/dist/esm/plugins/uidplus.d.ts +15 -0
  430. package/{lib → dist/esm}/plugins/uidplus.js +25 -45
  431. package/dist/esm/plugins/unauthenticate.d.ts +7 -0
  432. package/dist/esm/plugins/unauthenticate.js +17 -0
  433. package/dist/esm/plugins/unselect.d.ts +5 -0
  434. package/dist/esm/plugins/unselect.js +21 -0
  435. package/dist/esm/plugins/utf8-accept.d.ts +6 -0
  436. package/{lib → dist/esm}/plugins/utf8-accept.js +10 -21
  437. package/dist/esm/plugins/x-gm-ext-1.d.ts +26 -0
  438. package/{lib → dist/esm}/plugins/x-gm-ext-1.js +48 -100
  439. package/dist/esm/plugins/xoauth2.d.ts +2 -0
  440. package/dist/esm/plugins/xoauth2.js +140 -0
  441. package/dist/esm/plugins/xtoybird.d.ts +2 -0
  442. package/dist/esm/plugins/xtoybird.js +218 -0
  443. package/dist/esm/server.d.ts +876 -0
  444. package/dist/esm/server.js +2543 -0
  445. package/dist/esm/smtp-listener.d.ts +13 -0
  446. package/{lib → dist/esm}/smtp-listener.js +5 -12
  447. package/dist/esm/sorting.d.ts +77 -0
  448. package/{lib → dist/esm}/sorting.js +40 -53
  449. package/dist/esm/threading.d.ts +30 -0
  450. package/{lib → dist/esm}/threading.js +29 -70
  451. package/dist/esm/types.d.ts +327 -0
  452. package/dist/esm/types.js +2 -0
  453. package/dist/esm/utf8-session.d.ts +17 -0
  454. package/{lib → dist/esm}/utf8-session.js +15 -25
  455. package/dist/esm/vanished.d.ts +21 -0
  456. package/{lib → dist/esm}/vanished.js +16 -21
  457. package/dist/plugin-help.json +298 -0
  458. package/package.json +54 -11
  459. package/lib/commands/capability.js +0 -47
  460. package/lib/commands/check.js +0 -21
  461. package/lib/commands/close.js +0 -30
  462. package/lib/commands/examine.js +0 -7
  463. package/lib/commands/expunge.js +0 -27
  464. package/lib/commands/list.js +0 -100
  465. package/lib/commands/logout.js +0 -41
  466. package/lib/commands/lsub.js +0 -87
  467. package/lib/commands/noop.js +0 -21
  468. package/lib/commands/search.js +0 -76
  469. package/lib/commands/select.js +0 -289
  470. package/lib/commands/uid copy.js +0 -7
  471. package/lib/commands/uid fetch.js +0 -5
  472. package/lib/commands/uid search.js +0 -5
  473. package/lib/commands/uid store.js +0 -5
  474. package/lib/plugins/compress.js +0 -76
  475. package/lib/plugins/enable.js +0 -155
  476. package/lib/plugins/id.js +0 -138
  477. package/lib/plugins/idle.js +0 -105
  478. package/lib/plugins/logindisabled.js +0 -50
  479. package/lib/plugins/metadata.js +0 -475
  480. package/lib/plugins/namespace.js +0 -67
  481. package/lib/plugins/unauthenticate.js +0 -28
  482. package/lib/plugins/unselect.js +0 -36
  483. package/lib/plugins/xoauth2.js +0 -188
  484. package/lib/plugins/xtoybird.js +0 -282
  485. package/lib/server.js +0 -2880
@@ -1,50 +1,35 @@
1
- 'use strict';
2
-
3
- module.exports = function (connection, parsed, data, callback) {
1
+ export default function unsubscribeCommand(connection, parsed, data, callback) {
4
2
  if (!parsed.attributes || parsed.attributes.length !== 1 || !parsed.attributes[0] || ['STRING', 'LITERAL', 'ATOM'].indexOf(parsed.attributes[0].type) < 0) {
5
- connection.send(
6
- {
7
- tag: parsed.tag,
8
- command: 'BAD',
9
- attributes: [
10
- {
11
- type: 'TEXT',
12
- value: 'UNSUBSCRIBE expects mailbox name'
13
- }
14
- ]
15
- },
16
- 'INVALID COMMAND',
17
- parsed,
18
- data
19
- );
3
+ connection.send({
4
+ tag: parsed.tag,
5
+ command: 'BAD',
6
+ attributes: [
7
+ {
8
+ type: 'TEXT',
9
+ value: 'UNSUBSCRIBE expects mailbox name'
10
+ }
11
+ ]
12
+ }, 'INVALID COMMAND', parsed, data);
20
13
  return callback();
21
14
  }
22
-
23
15
  let path = parsed.attributes[0].value;
24
16
  if (path.toUpperCase() === 'INBOX') {
25
17
  path = 'INBOX';
26
18
  }
27
-
28
19
  // The subscription list holds names, so a name stays removable after its mailbox is deleted
29
20
  // (RFC 3501 section 6.3.6). Removing a name that is not subscribed is not an error (RFC 9051 section 6.3.8)
30
21
  if (connection.server.subscriptions.delete(path)) {
31
22
  connection.server.mailboxChanged('unsubscribe', path);
32
23
  }
33
-
34
- connection.send(
35
- {
36
- tag: parsed.tag,
37
- command: 'OK',
38
- attributes: [
39
- {
40
- type: 'TEXT',
41
- value: 'UNSUBSCRIBE completed'
42
- }
43
- ]
44
- },
45
- 'UNSUBSCRIBE',
46
- parsed,
47
- data
48
- );
24
+ connection.send({
25
+ tag: parsed.tag,
26
+ command: 'OK',
27
+ attributes: [
28
+ {
29
+ type: 'TEXT',
30
+ value: 'UNSUBSCRIBE completed'
31
+ }
32
+ ]
33
+ }, 'UNSUBSCRIBE', parsed, data);
49
34
  return callback();
50
- };
35
+ }
@@ -0,0 +1,64 @@
1
+ declare const MONTHS: string[];
2
+ /** Date and time parts of a parsed date, the time fields are undefined when the value has no time */
3
+ export interface DateParts {
4
+ day: number;
5
+ /** month index, 0 for January */
6
+ month: number;
7
+ year: number;
8
+ hours?: number | undefined;
9
+ minutes?: number | undefined;
10
+ seconds?: number | undefined;
11
+ /** `+hhmm` / `-hhmm` or a zone name */
12
+ zone?: string | undefined;
13
+ }
14
+ /**
15
+ * Returns the index of a month name, ignoring case like all ABNF strings
16
+ *
17
+ * @param {String} name Three letter month name, e.g. "jan"
18
+ * @return {Number} 0 for January to 11 for December, or -1 for an unknown name
19
+ */
20
+ declare function monthIndex(name: string | undefined): number;
21
+ /**
22
+ * Checks if day, month and year make a real date
23
+ *
24
+ * @param {Number|String} day Day of the month
25
+ * @param {Number} month Month index, 0 for January
26
+ * @param {Number|String} year Full year
27
+ * @return {Boolean} true if the date exists
28
+ */
29
+ declare function isRealDate(day: number | string | undefined, month: number, year: number | string | undefined): boolean;
30
+ /**
31
+ * Converts day, month and year to a comparable YYYY-MM-DD string
32
+ *
33
+ * @param {Number|String} day Day of the month
34
+ * @param {Number} month Month index, 0 for January
35
+ * @param {Number|String} year Full year
36
+ * @return {String|Boolean} the date, or false for an impossible date
37
+ */
38
+ declare function dateKey(day: number | string, month: number, year: number | string): string | false;
39
+ /**
40
+ * Parses a date-time value of the RFC 3501 section 9 form, like an INTERNALDATE ("14-Sep-2013 21:22:28 -0300").
41
+ * A value with only the date part is accepted as well, its time fields are left undefined
42
+ *
43
+ * @param {String} value Date-time value
44
+ * @return {Object|null} `{ day, month, year, hours, minutes, seconds, zone }` with the month index, or null
45
+ */
46
+ declare function parseDateTime(value: unknown): DateParts | null;
47
+ /**
48
+ * Parses the date-time of a Date header (RFC 5322 section 3.3, with the obsolete forms of section 4.3: comments,
49
+ * two and three digit years, zone names). SEARCH uses only the date as written (RFC 3501 section 6.4.4), SORT
50
+ * normalizes date and time to UTC with toTimestamp (RFC 5256 section 2.2), so both read the header with this
51
+ *
52
+ * @param {String} header Value of the Date header
53
+ * @return {Object|null} `{ day, month, year, hours, minutes, seconds, zone }` with the month index, or null if the
54
+ * header has no valid date. The time fields are undefined when the header has no time
55
+ */
56
+ declare function parseHeaderDate(header: string | undefined): DateParts | null;
57
+ /**
58
+ * Converts date and time parts to milliseconds since the epoch, adjusted by the time zone. An unknown zone is UTC
59
+ *
60
+ * @param {Object} date `{ day, month, year, hours, minutes, seconds, zone }`, see parseDateTime and parseHeaderDate
61
+ * @return {Number} timestamp
62
+ */
63
+ declare function toTimestamp(date: DateParts): number;
64
+ export { MONTHS, monthIndex, isRealDate, dateKey, parseDateTime, parseHeaderDate, toTimestamp };
@@ -1,8 +1,5 @@
1
- 'use strict';
2
-
3
1
  // Month names of the RFC 3501 section 9 date-month rule, in the case they are sent in
4
2
  const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
5
-
6
3
  /**
7
4
  * Returns the index of a month name, ignoring case like all ABNF strings
8
5
  *
@@ -13,7 +10,6 @@ function monthIndex(name) {
13
10
  const value = String(name || '').toLowerCase();
14
11
  return MONTHS.findIndex(month => month.toLowerCase() === value);
15
12
  }
16
-
17
13
  /**
18
14
  * Checks if day, month and year make a real date
19
15
  *
@@ -30,7 +26,6 @@ function isRealDate(day, month, year) {
30
26
  }
31
27
  return day <= new Date(Date.UTC(year, month + 1, 0)).getUTCDate();
32
28
  }
33
-
34
29
  /**
35
30
  * Converts day, month and year to a comparable YYYY-MM-DD string
36
31
  *
@@ -45,7 +40,6 @@ function dateKey(day, month, year) {
45
40
  }
46
41
  return String(year).padStart(4, '0') + '-' + String(month + 1).padStart(2, '0') + '-' + String(day).padStart(2, '0');
47
42
  }
48
-
49
43
  /**
50
44
  * Parses a date-time value of the RFC 3501 section 9 form, like an INTERNALDATE ("14-Sep-2013 21:22:28 -0300").
51
45
  * A value with only the date part is accepted as well, its time fields are left undefined
@@ -54,14 +48,13 @@ function dateKey(day, month, year) {
54
48
  * @return {Object|null} `{ day, month, year, hours, minutes, seconds, zone }` with the month index, or null
55
49
  */
56
50
  function parseDateTime(value) {
57
- const match = (value || '').toString().match(/^\s*(\d{1,2})-([A-Za-z]{3})-(\d{4})(?: (\d{2}):(\d{2}):(\d{2}) ([+-]\d{4}))?/);
51
+ const match = String(value || '').match(/^\s*(\d{1,2})-([A-Za-z]{3})-(\d{4})(?: (\d{2}):(\d{2}):(\d{2}) ([+-]\d{4}))?/);
58
52
  if (!match || !isRealDate(match[1], monthIndex(match[2]), match[3])) {
59
53
  return null;
60
54
  }
61
55
  const time = match[4] === undefined ? {} : { hours: Number(match[4]), minutes: Number(match[5]), seconds: Number(match[6]), zone: match[7] };
62
56
  return Object.assign({ day: Number(match[1]), month: monthIndex(match[2]), year: Number(match[3]) }, time);
63
57
  }
64
-
65
58
  /**
66
59
  * Parses the date-time of a Date header (RFC 5322 section 3.3, with the obsolete forms of section 4.3: comments,
67
60
  * two and three digit years, zone names). SEARCH uses only the date as written (RFC 3501 section 6.4.4), SORT
@@ -83,7 +76,8 @@ function parseHeaderDate(header) {
83
76
  // RFC 5322 section 4.3: two digit years below 50 are 20xx, three digit years add 1900
84
77
  if (match[3].length === 2) {
85
78
  year += year < 50 ? 2000 : 1900;
86
- } else if (match[3].length === 3) {
79
+ }
80
+ else if (match[3].length === 3) {
87
81
  year += 1900;
88
82
  }
89
83
  const day = Number(match[1]);
@@ -94,10 +88,8 @@ function parseHeaderDate(header) {
94
88
  const time = match[4] === undefined ? {} : { hours: Number(match[4]), minutes: Number(match[5]), seconds: Number(match[6] || 0), zone: match[7] };
95
89
  return Object.assign({ day, month, year }, time);
96
90
  }
97
-
98
91
  // RFC 5322 section 4.3 obsolete zones, military zones are treated as "-0000"
99
92
  const ZONES = { UT: 0, GMT: 0, EST: -5, EDT: -4, CST: -6, CDT: -5, MST: -7, MDT: -6, PST: -8, PDT: -7 };
100
-
101
93
  /**
102
94
  * Converts date and time parts to milliseconds since the epoch, adjusted by the time zone. An unknown zone is UTC
103
95
  *
@@ -114,10 +106,10 @@ function toTimestamp(date) {
114
106
  if (zoneMinutes < 60) {
115
107
  offset = sign * (zoneHours * 60 + zoneMinutes);
116
108
  }
117
- } else if (Object.hasOwn(ZONES, zone.toUpperCase())) {
109
+ }
110
+ else if (Object.hasOwn(ZONES, zone.toUpperCase())) {
118
111
  offset = ZONES[zone.toUpperCase()] * 60;
119
112
  }
120
113
  return Date.UTC(date.year, date.month, date.day, date.hours || 0, date.minutes || 0, date.seconds || 0) - offset * 60 * 1000;
121
114
  }
122
-
123
- module.exports = { MONTHS, monthIndex, isRealDate, dateKey, parseDateTime, parseHeaderDate, toTimestamp };
115
+ export { MONTHS, monthIndex, isRealDate, dateKey, parseDateTime, parseHeaderDate, toTimestamp };
@@ -0,0 +1,83 @@
1
+ import zlib from 'node:zlib';
2
+ /** Options of a DeflateLayer */
3
+ export interface DeflateLayerOptions {
4
+ /** sends octets to the peer */
5
+ writeRaw: (data: Buffer | string) => void;
6
+ /** gets the input, decompressed while compression is active */
7
+ onData: (data: Buffer) => void;
8
+ /** called when the input is not valid DEFLATE data */
9
+ onError?: ((err: Error) => unknown) | undefined;
10
+ }
11
+ /**
12
+ * One end of a COMPRESS=DEFLATE layer (RFC 4978): raw DEFLATE (RFC 1951, no zlib header or
13
+ * checksum) in both directions. The server plugin uses it, and so do the clients of the tests and
14
+ * the compare tool.
15
+ *
16
+ * Either direction can be terminated, which UNAUTHENTICATE requires (RFC 8437 section 4.1). Output
17
+ * terminates with a final DEFLATE block, data written after that goes out uncompressed once the
18
+ * compressed data is out. Input terminates where the peer ended its compression: at the end of
19
+ * its DEFLATE stream if it sent a final block, otherwise at the end of the sync flush that
20
+ * carried the last compressed data. The input is split at sync flush markers to find that point.
21
+ */
22
+ declare class DeflateLayer {
23
+ writeRaw: (data: Buffer | string) => void;
24
+ onData: (data: Buffer) => void;
25
+ onError: (err: Error) => unknown;
26
+ active: boolean;
27
+ inputActive: boolean;
28
+ _deflate: zlib.DeflateRaw;
29
+ _held: (Buffer | string)[] | null;
30
+ _endCallbacks: (() => void)[];
31
+ _flushScheduled: boolean;
32
+ _inflate: zlib.InflateRaw;
33
+ _pieces: Buffer[];
34
+ _busy: boolean;
35
+ _fed: number;
36
+ _expectFinal: boolean;
37
+ _idleCallbacks: (() => void)[];
38
+ /**
39
+ * @param {Object} options
40
+ * @param {Function} options.writeRaw `(buffer)` sends octets to the peer
41
+ * @param {Function} options.onData `(buffer)` gets the input, decompressed while compression is active
42
+ * @param {Function} [options.onError] `(err)` called when the input is not valid DEFLATE data
43
+ */
44
+ constructor(options: DeflateLayerOptions);
45
+ /**
46
+ * Sends data to the peer, compressed while compression is active
47
+ *
48
+ * @param {Buffer} data Data to send
49
+ */
50
+ write(data: Buffer | string): void;
51
+ /**
52
+ * Terminates the outgoing compression with a final DEFLATE block. Later writes are sent
53
+ * uncompressed, after the compressed data.
54
+ *
55
+ * @param {Function} [callback] Called once the compressed data is written out
56
+ */
57
+ end(callback?: (() => void) | null): void;
58
+ _runCallbacks(key: '_endCallbacks' | '_idleCallbacks'): void;
59
+ /**
60
+ * Handles octets received from the peer
61
+ *
62
+ * @param {Buffer} chunk Received data
63
+ */
64
+ receive(chunk: Buffer): void;
65
+ /**
66
+ * Tells the layer that the peer terminates its compression after the data decompressed so far
67
+ * (RFC 8437 section 4.1). Call it from onData, the rest of the input is then passed on as is.
68
+ */
69
+ endInput(): void;
70
+ /**
71
+ * Calls back once all received data is passed on
72
+ *
73
+ * @param {Function} callback Function to call
74
+ */
75
+ whenIdle(callback: () => void): void;
76
+ _next(): void;
77
+ _receivePlain(chunk: Buffer): void;
78
+ /**
79
+ * Frees the compressor and the decompressor
80
+ */
81
+ destroy(): void;
82
+ }
83
+ export default DeflateLayer;
@@ -1,12 +1,8 @@
1
- 'use strict';
2
-
3
- const zlib = require('zlib');
4
-
1
+ import zlib from 'node:zlib';
5
2
  // Z_SYNC_FLUSH ends with an empty stored block, LEN 0 and NLEN 0xFFFF (RFC 1951 section 3.2.4)
6
3
  const SYNC_MARKER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
7
4
  // Z_FINISH right after a flush is an empty final block with fixed Huffman codes
8
5
  const EMPTY_FINAL_BLOCK = Buffer.from([0x03, 0x00]);
9
-
10
6
  /**
11
7
  * One end of a COMPRESS=DEFLATE layer (RFC 4978): raw DEFLATE (RFC 1951, no zlib header or
12
8
  * checksum) in both directions. The server plugin uses it, and so do the clients of the tests and
@@ -29,28 +25,25 @@ class DeflateLayer {
29
25
  this.writeRaw = options.writeRaw;
30
26
  this.onData = options.onData;
31
27
  this.onError = options.onError || (() => false);
32
-
33
28
  // outgoing data is compressed
34
29
  this.active = true;
35
30
  // incoming data is compressed
36
31
  this.inputActive = true;
37
-
38
32
  this._deflate = zlib.createDeflateRaw();
39
- this._deflate.on('data', chunk => this.writeRaw(chunk));
40
- this._deflate.on('error', err => this.onError(err));
33
+ this._deflate.on('data', (chunk) => this.writeRaw(chunk));
34
+ this._deflate.on('error', (err) => this.onError(err));
41
35
  // writes that wait for the final compressed data, null when nothing is waiting
42
36
  this._held = null;
43
37
  this._endCallbacks = [];
44
38
  this._flushScheduled = false;
45
-
46
39
  this._inflate = zlib.createInflateRaw({ flush: zlib.constants.Z_SYNC_FLUSH });
47
- this._inflate.on('data', chunk => {
40
+ this._inflate.on('data', (chunk) => {
48
41
  // anything the peer compressed after it ended its compression is dropped
49
42
  if (this.inputActive) {
50
43
  this.onData(chunk);
51
44
  }
52
45
  });
53
- this._inflate.on('error', err => {
46
+ this._inflate.on('error', (err) => {
54
47
  this.inputActive = false;
55
48
  this._pieces = [];
56
49
  this._busy = false;
@@ -67,7 +60,6 @@ class DeflateLayer {
67
60
  // called once the received data is processed
68
61
  this._idleCallbacks = [];
69
62
  }
70
-
71
63
  /**
72
64
  * Sends data to the peer, compressed while compression is active
73
65
  *
@@ -95,7 +87,6 @@ class DeflateLayer {
95
87
  });
96
88
  }
97
89
  }
98
-
99
90
  /**
100
91
  * Terminates the outgoing compression with a final DEFLATE block. Later writes are sent
101
92
  * uncompressed, after the compressed data.
@@ -115,21 +106,19 @@ class DeflateLayer {
115
106
  this.active = false;
116
107
  this._held = [];
117
108
  this._deflate.once('end', () => {
118
- const held = this._held;
109
+ const held = this._held || [];
119
110
  this._held = null;
120
111
  held.forEach(data => this.writeRaw(data));
121
112
  this._runCallbacks('_endCallbacks');
122
113
  });
123
114
  this._deflate.end();
124
115
  }
125
-
126
116
  // calls the callbacks of a list once, callbacks added meanwhile wait for the next run
127
117
  _runCallbacks(key) {
128
118
  const callbacks = this[key];
129
119
  this[key] = [];
130
120
  callbacks.forEach(callback => callback());
131
121
  }
132
-
133
122
  /**
134
123
  * Handles octets received from the peer
135
124
  *
@@ -151,7 +140,6 @@ class DeflateLayer {
151
140
  }
152
141
  this._next();
153
142
  }
154
-
155
143
  /**
156
144
  * Tells the layer that the peer terminates its compression after the data decompressed so far
157
145
  * (RFC 8437 section 4.1). Call it from onData, the rest of the input is then passed on as is.
@@ -159,7 +147,6 @@ class DeflateLayer {
159
147
  endInput() {
160
148
  this.inputActive = false;
161
149
  }
162
-
163
150
  /**
164
151
  * Calls back once all received data is passed on
165
152
  *
@@ -169,7 +156,6 @@ class DeflateLayer {
169
156
  this._idleCallbacks.push(callback);
170
157
  this._next();
171
158
  }
172
-
173
159
  _next() {
174
160
  if (this._busy) {
175
161
  return;
@@ -185,7 +171,6 @@ class DeflateLayer {
185
171
  this._next();
186
172
  return;
187
173
  }
188
-
189
174
  const piece = this._pieces.shift();
190
175
  this._busy = true;
191
176
  this._fed += piece.length;
@@ -198,14 +183,14 @@ class DeflateLayer {
198
183
  if (unused > 0) {
199
184
  this._pieces.unshift(piece.subarray(piece.length - unused));
200
185
  }
201
- } else if (!this.inputActive) {
186
+ }
187
+ else if (!this.inputActive) {
202
188
  // the input ended at a sync flush, the final block may still follow
203
189
  this._expectFinal = true;
204
190
  }
205
191
  this._next();
206
192
  });
207
193
  }
208
-
209
194
  _receivePlain(chunk) {
210
195
  if (this._expectFinal) {
211
196
  this._expectFinal = false;
@@ -217,7 +202,6 @@ class DeflateLayer {
217
202
  this.onData(chunk);
218
203
  }
219
204
  }
220
-
221
205
  /**
222
206
  * Frees the compressor and the decompressor
223
207
  */
@@ -228,5 +212,4 @@ class DeflateLayer {
228
212
  this._inflate.destroy();
229
213
  }
230
214
  }
231
-
232
- module.exports = DeflateLayer;
215
+ export default DeflateLayer;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Reads a binary string (one char per octet) as UTF-8, invalid sequences become U+FFFD
3
+ */
4
+ declare function decodeUtf8(value: string): string;
5
+ /**
6
+ * Decodes an RFC 2047 header value to a Unicode string. Text outside encoded words is read as UTF-8
7
+ * (invalid sequences become U+FFFD). Adjacent encoded words in the same charset are decoded together,
8
+ * so a multi-octet character may span them, and the white space between them is dropped (RFC 2047
9
+ * section 6.2). Encoded words in an unknown charset are kept as they are.
10
+ *
11
+ * @param {String} value Header value as a binary string
12
+ * @return {String} Decoded value
13
+ */
14
+ declare function decodeHeader(input: unknown): string;
15
+ export { decodeHeader, decodeUtf8 };
@@ -1,23 +1,16 @@
1
- 'use strict';
2
-
3
1
  // RFC 2047 encoded words in header values, decoded for SEARCH, SORT and THREAD
4
-
5
2
  // RFC 2047 section 2: encoded-word = "=?" charset "?" encoding "?" encoded-text "?=", RFC 2231 section 5
6
3
  // adds an optional "*" language suffix to the charset
7
4
  const ENCODED_WORD = /=\?([^?\s*]+)(?:\*[^?\s]*)?\?([BbQq])\?([^?\s]*)\?=/g;
8
-
9
5
  const utf8Decoder = new TextDecoder('utf-8');
10
-
11
6
  /**
12
7
  * Reads a binary string (one char per octet) as UTF-8, invalid sequences become U+FFFD
13
8
  */
14
9
  function decodeUtf8(value) {
15
10
  return utf8Decoder.decode(Buffer.from(value, 'binary'));
16
11
  }
17
-
18
12
  // decoders by lower case charset name, false for a charset that TextDecoder does not know
19
13
  const decoders = new Map();
20
-
21
14
  /**
22
15
  * Decodes the octets of an encoded word, or returns false if the charset is unknown
23
16
  */
@@ -27,15 +20,15 @@ function decodeCharset(charset, octets) {
27
20
  let decoder = false;
28
21
  try {
29
22
  decoder = new TextDecoder(charset);
30
- } catch {
23
+ }
24
+ catch {
31
25
  // unknown charset
32
26
  }
33
27
  decoders.set(charset, decoder);
34
28
  }
35
29
  const decoder = decoders.get(charset);
36
- return decoder && decoder.decode(octets);
30
+ return decoder ? decoder.decode(octets) : false;
37
31
  }
38
-
39
32
  /**
40
33
  * Decodes an RFC 2047 header value to a Unicode string. Text outside encoded words is read as UTF-8
41
34
  * (invalid sequences become U+FFFD). Adjacent encoded words in the same charset are decoded together,
@@ -45,8 +38,8 @@ function decodeCharset(charset, octets) {
45
38
  * @param {String} value Header value as a binary string
46
39
  * @return {String} Decoded value
47
40
  */
48
- function decodeHeader(value) {
49
- value = (value || '').toString();
41
+ function decodeHeader(input) {
42
+ const value = String(input || '');
50
43
  if (value.indexOf('=?') < 0 && !/[\u0080-\u00ff]/.test(value)) {
51
44
  // nothing to decode
52
45
  return value;
@@ -54,7 +47,6 @@ function decodeHeader(value) {
54
47
  let result = '';
55
48
  let pending = null;
56
49
  let lastIndex = 0;
57
-
58
50
  const flush = () => {
59
51
  if (pending) {
60
52
  const decoded = decodeCharset(pending.charset, Buffer.concat(pending.octets));
@@ -62,7 +54,6 @@ function decodeHeader(value) {
62
54
  pending = null;
63
55
  }
64
56
  };
65
-
66
57
  ENCODED_WORD.lastIndex = 0;
67
58
  let match;
68
59
  while ((match = ENCODED_WORD.exec(value))) {
@@ -73,15 +64,9 @@ function decodeHeader(value) {
73
64
  result += decodeUtf8(between);
74
65
  }
75
66
  lastIndex = ENCODED_WORD.lastIndex;
76
-
77
- const octets =
78
- match[2].toUpperCase() === 'B'
79
- ? Buffer.from(match[3], 'base64')
80
- : Buffer.from(
81
- match[3].replace(/_/g, ' ').replace(/=([0-9a-fA-F]{2})/g, (m, hex) => String.fromCharCode(parseInt(hex, 16))),
82
- 'binary'
83
- );
84
-
67
+ const octets = match[2].toUpperCase() === 'B'
68
+ ? Buffer.from(match[3], 'base64')
69
+ : Buffer.from(match[3].replace(/_/g, ' ').replace(/=([0-9a-fA-F]{2})/g, (m, hex) => String.fromCharCode(parseInt(hex, 16))), 'binary');
85
70
  if (pending && pending.charset.toLowerCase() !== match[1].toLowerCase()) {
86
71
  flush();
87
72
  }
@@ -94,5 +79,4 @@ function decodeHeader(value) {
94
79
  flush();
95
80
  return result + decodeUtf8(value.substr(lastIndex));
96
81
  }
97
-
98
- module.exports = { decodeHeader, decodeUtf8 };
82
+ export { decodeHeader, decodeUtf8 };
@@ -0,0 +1,33 @@
1
+ import type { ParsedAddress } from './addressparser.js';
2
+ import type { ParsedHeader } from './mimeparser.js';
3
+ /** An address of the ENVELOPE (RFC 3501 section 9): name, source route, mailbox and host, all NIL for a group end */
4
+ export type EnvelopeAddress = [name: string | null, adl: null, mailbox: string | null, host: string | null];
5
+ /** The fields of the ENVELOPE (RFC 3501 section 7.4.2), in order */
6
+ export type Envelope = [
7
+ date: string | null,
8
+ subject: string | null,
9
+ from: EnvelopeAddress[] | null,
10
+ sender: EnvelopeAddress[] | null,
11
+ replyTo: EnvelopeAddress[] | null,
12
+ to: EnvelopeAddress[] | null,
13
+ cc: EnvelopeAddress[] | null,
14
+ bcc: EnvelopeAddress[] | null,
15
+ inReplyTo: string | null,
16
+ messageId: string | null
17
+ ];
18
+ /**
19
+ * Convert a message object to an ENVELOPE object
20
+ *
21
+ * @param {Object} header Parsed header of a mime tree node
22
+ * @return {Object} ENVELOPE compatible object
23
+ */
24
+ export default function envelope(header: ParsedHeader): Envelope;
25
+ /**
26
+ * Converts an address object to a list of arrays
27
+ * [{name: "User Name", addres:"user@example.com"}] -> [["User Name", null, "user", "example.com"]]
28
+ *
29
+ * @param {Array} arr An array of address objects
30
+ * @return {Array} A list of addresses
31
+ */
32
+ declare function processAddress(arr: ParsedAddress | ParsedAddress[] | undefined, def?: ParsedAddress | ParsedAddress[]): EnvelopeAddress[] | null;
33
+ export { processAddress };
@@ -1,14 +1,11 @@
1
- 'use strict';
2
-
3
1
  // This module converts message structure into an ENVELOPE object
4
-
5
2
  /**
6
3
  * Convert a message object to an ENVELOPE object
7
4
  *
8
5
  * @param {Object} header Parsed header of a mime tree node
9
6
  * @return {Object} ENVELOPE compatible object
10
7
  */
11
- module.exports = function (header) {
8
+ export default function envelope(header) {
12
9
  // RFC 3501 9: env-date and env-subject are nstring, NIL when the header is missing
13
10
  const subject = header.subject;
14
11
  return [
@@ -25,8 +22,7 @@ module.exports = function (header) {
25
22
  header['in-reply-to'] || null,
26
23
  header['message-id'] || null
27
24
  ];
28
- };
29
-
25
+ }
30
26
  /**
31
27
  * Converts an address object to a list of arrays
32
28
  * [{name: "User Name", addres:"user@example.com"}] -> [["User Name", null, "user", "example.com"]]
@@ -35,15 +31,15 @@ module.exports = function (header) {
35
31
  * @return {Array} A list of addresses
36
32
  */
37
33
  function processAddress(arr, def) {
38
- arr = [].concat(arr || []);
39
- if (!arr.length) {
40
- arr = [].concat(def || []);
34
+ let list = [].concat(arr || []);
35
+ if (!list.length) {
36
+ list = [].concat(def || []);
41
37
  }
42
- if (!arr.length) {
38
+ if (!list.length) {
43
39
  return null;
44
40
  }
45
41
  let result = [];
46
- arr.forEach(addr => {
42
+ list.forEach(addr => {
47
43
  if (addr.group) {
48
44
  // Handle group syntax
49
45
  result.push([null, null, addr.name || '', null]);
@@ -51,32 +47,25 @@ function processAddress(arr, def) {
51
47
  result.push([null, null, null, null]);
52
48
  return;
53
49
  }
54
-
55
50
  let name = addr.name || null;
56
51
  let address = addr.address || '';
57
-
58
52
  if (!address && name) {
59
53
  // a bare word ("To: localuser") is the mailbox, not the name
60
54
  address = name;
61
55
  name = null;
62
56
  }
63
-
64
57
  if (!address) {
65
58
  return;
66
59
  }
67
-
68
60
  const at = address.lastIndexOf('@');
69
61
  const user = at >= 0 ? address.substr(0, at) : address;
70
62
  // RFC 3501 7.4.2 reserves a NIL host for group markers, so an address without a domain gets
71
63
  // the placeholder host that Dovecot uses for the same input
72
64
  const domain = (at >= 0 ? address.substr(at + 1) : '') || 'MISSING_DOMAIN';
73
-
74
65
  result.push([name, null, user || null, domain]);
75
66
  });
76
-
77
67
  // env-from = "(" 1*address ")", there is no SP between the addresses (RFC 3501 section 9)
78
68
  Object.defineProperty(result, 'adjacentLists', { value: true });
79
69
  return result.length ? result : null;
80
70
  }
81
-
82
- module.exports.processAddress = processAddress;
71
+ export { processAddress };