imapkit 4.0.3 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +271 -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 +106 -133
  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 +33 -74
  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 +55 -12
  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,18 +1,13 @@
1
- 'use strict';
2
-
3
1
  // THREAD and UID THREAD (RFC 5256 section 3) and the ORDEREDSUBJECT and REFERENCES algorithms
4
-
5
- const { states } = require('./command-states');
6
- const { getMessageData } = require('./mimeparser');
7
- const { collationKey, baseSubject, sentTime, parseMessageIds, searchMessages } = require('./sorting');
8
-
2
+ import { states } from './command-states.js';
3
+ import { getMessageData } from './mimeparser.js';
4
+ import { collationKey, baseSubject, sentTime, parseMessageIds, searchMessages } from './sorting.js';
9
5
  /**
10
6
  * Creates a thread tree node. A node without a message is a dummy
11
7
  */
12
8
  function createNode(entry) {
13
9
  return { entry: entry || null, parent: null, children: [] };
14
10
  }
15
-
16
11
  // Sent date order with the sequence number as tie-breaker (RFC 5256 section 2.2). A dummy is
17
12
  // ordered by its first child
18
13
  function compareNodes(a, b) {
@@ -22,9 +17,9 @@ function compareNodes(a, b) {
22
17
  while (!b.entry && b.children.length) {
23
18
  b = b.children[0];
24
19
  }
20
+ // pruning leaves no dummy without children, so both have an entry here
25
21
  return a.entry.date - b.entry.date || a.entry.seq - b.entry.seq;
26
22
  }
27
-
28
23
  /**
29
24
  * Lists the nodes of trees in pre-order (parents before their children). Iterative, as message
30
25
  * references can make a thread as deep as the mailbox is large.
@@ -44,7 +39,6 @@ function preOrder(nodes) {
44
39
  }
45
40
  return list;
46
41
  }
47
-
48
42
  /**
49
43
  * Serializes thread nodes (RFC 5256 section 5): every thread is a thread-list, a node is followed by its
50
44
  * only child, or by one thread-list per child when it has more. A dummy has no number of its own.
@@ -57,7 +51,7 @@ function formatThreads(roots, isUid) {
57
51
  const output = [];
58
52
  // strings to write and nodes to expand, the next one is at the end
59
53
  const stack = [];
60
- const pushLists = nodes => {
54
+ const pushLists = (nodes) => {
61
55
  for (let i = nodes.length - 1; i >= 0; i--) {
62
56
  stack.push(')', nodes[i], '(');
63
57
  }
@@ -72,7 +66,8 @@ function formatThreads(roots, isUid) {
72
66
  const children = item.children;
73
67
  if (children.length === 1) {
74
68
  stack.push(children[0]);
75
- } else {
69
+ }
70
+ else {
76
71
  pushLists(children);
77
72
  }
78
73
  if (item.entry) {
@@ -84,7 +79,6 @@ function formatThreads(roots, isUid) {
84
79
  }
85
80
  return output.join('');
86
81
  }
87
-
88
82
  /**
89
83
  * ORDEREDSUBJECT (RFC 5256 section 3): messages grouped by base subject, every thread is its first
90
84
  * message with the others as children, threads ordered by the sent date of their first message
@@ -100,14 +94,14 @@ function orderedSubject(entries) {
100
94
  for (const entry of sorted) {
101
95
  if (current && current.entry.subject.id === entry.subject.id) {
102
96
  current.children.push(createNode(entry));
103
- } else {
97
+ }
98
+ else {
104
99
  current = createNode(entry);
105
100
  threads.push(current);
106
101
  }
107
102
  }
108
103
  return threads.sort(compareNodes);
109
104
  }
110
-
111
105
  /**
112
106
  * REFERENCES (RFC 5256 section 3), steps 1 to 6
113
107
  *
@@ -117,8 +111,7 @@ function orderedSubject(entries) {
117
111
  function references(entries) {
118
112
  const byId = new Map();
119
113
  const all = [];
120
-
121
- const getNode = id => {
114
+ const getNode = (id) => {
122
115
  if (!byId.has(id)) {
123
116
  const node = createNode();
124
117
  byId.set(id, node);
@@ -126,7 +119,6 @@ function references(entries) {
126
119
  }
127
120
  return byId.get(id);
128
121
  };
129
-
130
122
  const isDescendant = (node, ancestor) => {
131
123
  for (let current = node; current; current = current.parent) {
132
124
  if (current === ancestor) {
@@ -135,14 +127,12 @@ function references(entries) {
135
127
  }
136
128
  return false;
137
129
  };
138
-
139
- const unlink = node => {
130
+ const unlink = (node) => {
140
131
  if (node.parent) {
141
132
  node.parent.children.splice(node.parent.children.indexOf(node), 1);
142
133
  node.parent = null;
143
134
  }
144
135
  };
145
-
146
136
  // links a parent and a child, unless that would introduce a loop. Only a node with children can have
147
137
  // the parent as a descendant, so the walk up from the parent is skipped for the others
148
138
  const link = (parent, child) => {
@@ -151,11 +141,9 @@ function references(entries) {
151
141
  child.parent = parent;
152
142
  }
153
143
  };
154
-
155
144
  // (1) link the messages by their references
156
145
  for (const entry of entries) {
157
146
  const header = getMessageData(entry.message).tree.parsedHeader;
158
-
159
147
  // (1.A) a message without a valid Message-ID, or with one that an earlier message already has, gets a unique one
160
148
  const messageId = parseMessageIds(header['message-id'])[0];
161
149
  let node = messageId !== undefined && getNode(messageId);
@@ -164,13 +152,11 @@ function references(entries) {
164
152
  all.push(node);
165
153
  }
166
154
  node.entry = entry;
167
-
168
155
  // the References header, or else the first Message ID of In-Reply-To
169
156
  let refs = parseMessageIds(header.references);
170
157
  if (!refs.length) {
171
158
  refs = parseMessageIds(header['in-reply-to']).slice(0, 1);
172
159
  }
173
-
174
160
  // (1.A) each reference is the parent of the next one, existing links are kept
175
161
  const refNodes = refs.map(getNode);
176
162
  for (let i = 1; i < refNodes.length; i++) {
@@ -178,7 +164,6 @@ function references(entries) {
178
164
  link(refNodes[i - 1], refNodes[i]);
179
165
  }
180
166
  }
181
-
182
167
  // (1.B) the last reference is the parent of the message, replacing an existing link
183
168
  const parent = refNodes[refNodes.length - 1] || null;
184
169
  if (node.parent !== parent) {
@@ -188,10 +173,8 @@ function references(entries) {
188
173
  }
189
174
  }
190
175
  }
191
-
192
176
  // (2) messages without a parent are the top level
193
177
  const roots = all.filter(node => !node.parent);
194
-
195
178
  // (3) prune dummies: drop the ones without children, put the children of the others in their place,
196
179
  // but not at the top level if there is more than one child
197
180
  const replacement = (node, topLevel) => {
@@ -214,7 +197,6 @@ function references(entries) {
214
197
  top.forEach(node => {
215
198
  node.parent = null;
216
199
  });
217
-
218
200
  // (4) sort the top level by sent date, a dummy by its first child
219
201
  top.forEach(node => {
220
202
  if (!node.entry) {
@@ -222,12 +204,10 @@ function references(entries) {
222
204
  }
223
205
  });
224
206
  top.sort(compareNodes);
225
-
226
207
  // (5) gather threads with the same base subject, the subject of a dummy is the one of its first child
227
- const threadSubject = node => (node.entry ? node.entry.subject : node.children[0].entry.subject);
228
- const isReply = node => !!node.entry && node.entry.subject.isReply;
208
+ const threadSubject = (node) => (node.entry ? node.entry.subject : node.children[0].entry.subject);
209
+ const isReply = (node) => !!node.entry && node.entry.subject.isReply;
229
210
  const table = new Map();
230
-
231
211
  // (5.B) one message per base subject, a dummy or a message that is not a reply or forward is preferred
232
212
  for (const node of top) {
233
213
  const subject = threadSubject(node);
@@ -239,7 +219,6 @@ function references(entries) {
239
219
  table.set(subject.id, node);
240
220
  }
241
221
  }
242
-
243
222
  // (5.C) merge the other threads with the same subject into the one in the table
244
223
  const removed = new Set();
245
224
  for (const node of top) {
@@ -247,6 +226,7 @@ function references(entries) {
247
226
  if (!subject.id) {
248
227
  continue;
249
228
  }
229
+ // (5.B) put a node for every subject in the table
250
230
  const other = table.get(subject.id);
251
231
  if (other === node) {
252
232
  continue;
@@ -254,9 +234,11 @@ function references(entries) {
254
234
  removed.add(node);
255
235
  if (!other.entry && !node.entry) {
256
236
  node.children.forEach(child => link(other, child));
257
- } else if (!other.entry || (isReply(node) && !isReply(other))) {
237
+ }
238
+ else if (!other.entry || (isReply(node) && !isReply(other))) {
258
239
  link(other, node);
259
- } else {
240
+ }
241
+ else {
260
242
  // both become children of a new dummy that takes the place of the message in the table
261
243
  const dummy = createNode();
262
244
  top[top.indexOf(other)] = dummy;
@@ -266,7 +248,6 @@ function references(entries) {
266
248
  }
267
249
  }
268
250
  top = top.filter(node => !removed.has(node));
269
-
270
251
  // (6) sort all sets of siblings by sent date, the deepest ones first
271
252
  for (const node of preOrder(top).reverse()) {
272
253
  node.children.sort(compareNodes);
@@ -274,12 +255,10 @@ function references(entries) {
274
255
  top.sort(compareNodes);
275
256
  return top;
276
257
  }
277
-
278
258
  const ALGORITHMS = {
279
259
  ORDEREDSUBJECT: orderedSubject,
280
260
  REFERENCES: references
281
261
  };
282
-
283
262
  /**
284
263
  * Adds the THREAD and UID THREAD commands, unless another algorithm plugin did already, and the
285
264
  * THREAD=<algorithm> capability
@@ -289,38 +268,26 @@ const ALGORITHMS = {
289
268
  */
290
269
  function addThreadAlgorithm(server, algorithm) {
291
270
  server.registerCapability('THREAD=' + algorithm);
292
-
293
271
  if (server.threadAlgorithms) {
294
272
  server.threadAlgorithms[algorithm] = ALGORITHMS[algorithm];
295
273
  return;
296
274
  }
297
275
  server.threadAlgorithms = { [algorithm]: ALGORITHMS[algorithm] };
298
-
299
276
  const threadHandler = (isUid, connection, parsed, data, callback) => {
300
277
  const command = isUid ? 'UID THREAD' : 'THREAD';
301
278
  const attributes = parsed.attributes || [];
302
-
303
279
  // RFC 5256 section 5: thread-alg = "ORDEREDSUBJECT" / "REFERENCES" / thread-alg-ext, an atom
304
280
  const name = attributes[0] && attributes[0].type === 'ATOM' ? attributes[0].value.toUpperCase() : '';
305
281
  if (!Object.hasOwn(server.threadAlgorithms, name)) {
306
- connection.sendStatus(
307
- parsed,
308
- data,
309
- 'BAD',
310
- name ? 'Unsupported threading algorithm ' + name : command + ' expects a threading algorithm atom',
311
- false,
312
- command + ' FAILED'
313
- );
282
+ connection.sendStatus(parsed, data, 'BAD', name ? 'Unsupported threading algorithm ' + name : command + ' expects a threading algorithm atom', false, command + ' FAILED');
314
283
  return callback();
315
284
  }
316
-
317
285
  const result = searchMessages(connection, parsed, data, attributes.slice(1));
318
286
  if (!result) {
319
287
  return callback();
320
288
  }
321
-
322
289
  // base subjects are compared with the collation (RFC 5256 sections 3 and 7)
323
- const entries = result.list.map(message => {
290
+ const entries = result.list.map((message) => {
324
291
  const base = baseSubject(getMessageData(message).tree.parsedHeader.subject);
325
292
  return {
326
293
  message,
@@ -330,28 +297,20 @@ function addThreadAlgorithm(server, algorithm) {
330
297
  subject: { id: collationKey(base.subject).toString('binary'), isReply: base.isReply }
331
298
  };
332
299
  });
333
-
334
- connection.send(
335
- {
336
- tag: '*',
337
- command: 'THREAD',
338
- // thread-data has no SP between thread-lists, so it can not be built from nested arrays
339
- attributes: entries.length ? [{ type: 'TEXT', value: formatThreads(server.threadAlgorithms[name](entries), isUid) }] : []
340
- },
341
- command,
342
- parsed,
343
- data,
344
- // the search result, so CONDSTORE knows about a MODSEQ search key (RFC 7162 section 3.1.9)
345
- result
346
- );
300
+ connection.send({
301
+ tag: '*',
302
+ command: 'THREAD',
303
+ // thread-data has no SP between thread-lists, so it can not be built from nested arrays
304
+ attributes: entries.length ? [{ type: 'TEXT', value: formatThreads(server.threadAlgorithms[name](entries), isUid) }] : []
305
+ }, command, parsed, data,
306
+ // the search result, so CONDSTORE knows about a MODSEQ search key (RFC 7162 section 3.1.9)
307
+ result);
347
308
  connection.sendStatus(parsed, data, 'OK', command + ' completed', false, command);
348
309
  return callback();
349
310
  };
350
-
351
311
  // RFC 5256 section 3: EXPUNGE responses are not permitted while responding to THREAD, but are during UID THREAD.
352
312
  // The search criteria start after the algorithm and the charset
353
313
  server.setCommandHandler('THREAD', threadHandler.bind(null, false), { states: states.SELECTED, searchCriteria: 2, noExpunge: true });
354
314
  server.setCommandHandler('UID THREAD', threadHandler.bind(null, true), { states: states.SELECTED, searchCriteria: 2 });
355
315
  }
356
-
357
- module.exports = { addThreadAlgorithm };
316
+ export { addThreadAlgorithm };
@@ -0,0 +1,327 @@
1
+ import type { IMAPServer, IMAPConnection } from './server.js';
2
+ export type { IMAPServer, IMAPConnection };
3
+ /**
4
+ * A value of the parsed command or of a response, as imap-handler parses and compiles it: an
5
+ * `{ type, value, section?, partial? }` node, a list (array), a string, a number or null (NIL).
6
+ * Commands and plugins walk these trees freely, so the type is left open.
7
+ */
8
+ export type Attribute = any;
9
+ /** A parsed client command, see imap-handler. Plugins add their own properties (e.g. `searchReturn`) */
10
+ export interface ParsedCommand {
11
+ tag: string;
12
+ command: string;
13
+ attributes?: Attribute[] | undefined;
14
+ [key: string]: any;
15
+ }
16
+ /**
17
+ * The command a response answers, as `connection.send()` and `connection.sendStatus()` take it: a parsed
18
+ * command, or only the tag for input that could not be parsed (or `{ tag: '*' }` for an untagged response)
19
+ */
20
+ export type CommandContext = ParsedCommand | {
21
+ tag: string;
22
+ command?: undefined;
23
+ attributes?: undefined;
24
+ [key: string]: any;
25
+ };
26
+ /** A response written to the client through `connection.send()` */
27
+ export interface IMAPResponse {
28
+ tag: string;
29
+ command?: string | undefined;
30
+ attributes?: Attribute | Attribute[] | undefined;
31
+ /** set by an output handler to drop the response */
32
+ skipResponse?: boolean | undefined;
33
+ /** an unsolicited response from the notification queue, it does not flush the queue */
34
+ notification?: boolean | undefined;
35
+ [key: string]: any;
36
+ }
37
+ /**
38
+ * An untagged response distributed with `server.notify()`, queued per session in
39
+ * `connection.notificationQueue` until it can be sent
40
+ */
41
+ export interface Notification extends IMAPResponse {
42
+ /** the session whose command caused the change, null for changes from SMTP */
43
+ origin?: IMAPConnection | null | undefined;
44
+ /** the new message of an EXISTS, or the removed message of an EXPUNGE */
45
+ message?: Message | undefined;
46
+ /** the removed messages of a VANISHED response (QRESYNC) */
47
+ messages?: Message[] | undefined;
48
+ /** the message list as it was before an expunge, for sessions that were not told about it yet */
49
+ mailboxCopy?: Message[] | undefined;
50
+ /** messages whose flags changed, sent as unsolicited FETCH responses */
51
+ flagUpdate?: Message[] | undefined;
52
+ }
53
+ /** The `notify` event of the server, see `server.notify()` */
54
+ export interface NotifyEvent {
55
+ command: Notification;
56
+ /** the mailbox the change is about, false or null for changes that are not about the selected mailbox */
57
+ mailbox: Mailbox | string | false | null | undefined;
58
+ /** the session that does not get the notification */
59
+ ignoreConnection: IMAPConnection | false | null | undefined;
60
+ /** only connections for which it returns true get the notification */
61
+ filter: ((connection: IMAPConnection) => boolean) | false | null | undefined;
62
+ /** the session whose command caused the change, null for changes from outside (e.g. SMTP) */
63
+ origin: IMAPConnection | null;
64
+ [key: string]: any;
65
+ }
66
+ /** The `mailbox` event of the server, see `server.mailboxChanged()` */
67
+ export interface MailboxChangeEvent {
68
+ /** "create", "delete", "rename", "subscribe" or "unsubscribe" */
69
+ type: string;
70
+ path: string;
71
+ oldPath: string | null;
72
+ mailbox: Mailbox | null;
73
+ origin: IMAPConnection | null;
74
+ }
75
+ export type Callback = (err?: any, ...args: any[]) => void;
76
+ /** Handler of an IMAP command, it must send a tagged response and then call the callback */
77
+ export type CommandHandler = (connection: IMAPConnection, parsed: ParsedCommand, data: string, callback: Callback) => void;
78
+ /** Options of a command, see `server.setCommandHandler()` and command-states.ts */
79
+ export interface CommandOptions {
80
+ states?: string[] | string | false | undefined;
81
+ noArguments?: boolean | undefined;
82
+ mailboxArguments?: number[] | number | undefined;
83
+ astringArguments?: number[] | number | undefined;
84
+ searchCriteria?: number | false | undefined;
85
+ sequenceSet?: number | false | undefined;
86
+ noExpunge?: boolean | undefined;
87
+ /** also the name of the capability that allows literal8 (`'BINARY'`) */
88
+ literal8?: boolean | string | undefined;
89
+ noPipelining?: boolean | undefined;
90
+ appendMessage?: boolean | undefined;
91
+ }
92
+ /** A plugin, given as a function in `options.plugins` or built in */
93
+ export interface Plugin {
94
+ (server: IMAPServer): void;
95
+ /** plugins that are loaded before this one, by name */
96
+ requires?: string[] | undefined;
97
+ }
98
+ /** An error that carries the response a command fails with */
99
+ export interface IMAPError extends Error {
100
+ code?: string | undefined;
101
+ imapResponse?: string | undefined;
102
+ responseCode?: Attribute;
103
+ responseCodeArgs?: Attribute;
104
+ [key: string]: any;
105
+ }
106
+ /** Connection states of RFC 3501 section 3, "Logout" after LOGOUT or BYE */
107
+ export type ConnectionState = 'Not Authenticated' | 'Authenticated' | 'Selected' | 'Logout';
108
+ /** A message in a mailbox, plugins keep their own properties on it (MODSEQ, X-GM-LABELS ...) */
109
+ export interface Message {
110
+ uid: number;
111
+ flags: string[];
112
+ internaldate: string;
113
+ /** the message source as a binary string (one char per octet) */
114
+ raw: string;
115
+ recent?: boolean | undefined;
116
+ /** expunged by another session but not yet reported to this one */
117
+ ghost?: boolean | undefined;
118
+ [key: string]: any;
119
+ }
120
+ /** Resolved messages of a sequence set, `[sequence number, message]` pairs */
121
+ export type MessageRange = [number, Message][];
122
+ /** A mailbox, plugins keep their own properties on it (acl, metadata, HIGHESTMODSEQ ...) */
123
+ export interface Mailbox {
124
+ path: string;
125
+ namespace: string;
126
+ uid: number;
127
+ uidvalidity: number;
128
+ uidnext: number;
129
+ flags: string[];
130
+ permanentFlags: string[];
131
+ allowPermanentFlags: boolean;
132
+ messages: Message[];
133
+ /** flags that messages of the mailbox had, they stay in FLAGS and PERMANENTFLAGS, see server.rememberFlags() */
134
+ knownFlags?: string[] | undefined;
135
+ folders?: Record<string, Mailbox> | undefined;
136
+ separator?: string | undefined;
137
+ /** an accessor of `server.subscriptions`, see server.trackSubscription() */
138
+ subscribed?: boolean | undefined;
139
+ [key: string]: any;
140
+ }
141
+ /**
142
+ * A name that getSubscriptionTree() lists without a mailbox: a subscribed name that is not a mailbox, or a
143
+ * superior hierarchy level of a subscribed name
144
+ */
145
+ export interface SubscriptionStandIn {
146
+ path: string;
147
+ namespace: string | false;
148
+ flags: string[];
149
+ subscribed: boolean;
150
+ }
151
+ /** The fields of a mailbox (or a stand-in) that LIST pattern matching needs, see server.matchFolders() */
152
+ export interface ListedMailbox {
153
+ path: string;
154
+ namespace: string | false;
155
+ flags: string[];
156
+ }
157
+ /** A message as the storage option gives it, the server fills in the rest. A string is the message source */
158
+ export interface StorageMessage {
159
+ uid?: number | undefined;
160
+ /** a single flag can be given as a string */
161
+ flags?: string | string[] | undefined;
162
+ /** a Date or a date-time string, the current time if not set */
163
+ internaldate?: string | Date | false | undefined;
164
+ raw?: string | Uint8Array | undefined;
165
+ recent?: boolean | undefined;
166
+ [key: string]: any;
167
+ }
168
+ /** A mailbox as the storage option gives it, the server fills in the rest */
169
+ export interface StorageMailbox {
170
+ uid?: number | undefined;
171
+ uidvalidity?: number | undefined;
172
+ uidnext?: number | undefined;
173
+ flags?: string[] | undefined;
174
+ permanentFlags?: string[] | undefined;
175
+ allowPermanentFlags?: boolean | undefined;
176
+ subscribed?: boolean | undefined;
177
+ messages?: (StorageMessage | string)[] | undefined;
178
+ folders?: Record<string, StorageMailbox> | undefined;
179
+ separator?: string | undefined;
180
+ [key: string]: any;
181
+ }
182
+ export type NamespaceType = 'personal' | 'user' | 'shared';
183
+ /** A namespace of the storage option, keyed by its prefix (`"INBOX"`, `""`, `"INBOX."`, ...) */
184
+ export interface StorageNamespace extends StorageMailbox {
185
+ separator?: string | undefined;
186
+ type?: NamespaceType | undefined;
187
+ }
188
+ /** A namespace in `server.storage`, with every key set by the server */
189
+ export interface Namespace {
190
+ separator: string;
191
+ type: NamespaceType;
192
+ folders: Record<string, Mailbox>;
193
+ [key: string]: any;
194
+ }
195
+ /** `server.storage`: the namespaces by prefix, and INBOX, which is a mailbox of its own */
196
+ export type ServerStorage = {
197
+ INBOX: Mailbox;
198
+ } & Record<string, Namespace>;
199
+ /** Mailbox counters of `server.getStatus()` */
200
+ export interface MailboxStatus {
201
+ /** number of messages by flag */
202
+ flags: Record<string, number>;
203
+ seen: number;
204
+ unseen: number;
205
+ recent: number;
206
+ permanentFlags: string[];
207
+ }
208
+ export interface UserData {
209
+ password?: string | undefined;
210
+ xoauth2?: {
211
+ accessToken?: string | undefined;
212
+ sessionTimeout?: number | undefined;
213
+ } | undefined;
214
+ [key: string]: any;
215
+ }
216
+ /** Options of `imapkit(options)` */
217
+ export interface IMAPServerOptions {
218
+ /** the mailbox tree, keyed by namespace */
219
+ storage?: Record<string, StorageNamespace> | undefined;
220
+ /** plugin names (`"IDLE"`, `"LITERAL+"`, ...) or plugin functions */
221
+ plugins?: (string | Plugin)[] | string | Plugin | undefined;
222
+ users?: Record<string, UserData> | undefined;
223
+ secureConnection?: boolean | undefined;
224
+ credentials?: {
225
+ key: string | Buffer;
226
+ cert: string | Buffer;
227
+ } | undefined;
228
+ debug?: boolean | undefined;
229
+ systemFlags?: string[] | undefined;
230
+ /** largest literal accepted after login, in octets */
231
+ maxLiteralSize?: number | undefined;
232
+ [key: string]: any;
233
+ }
234
+ /**
235
+ * A layer between the socket and the IMAP protocol, such as COMPRESS=DEFLATE. It passes data on with
236
+ * `connection.writeRaw()` and `connection.onData()`
237
+ */
238
+ export interface Transport {
239
+ write(data: Buffer): void;
240
+ receive(chunk: Buffer): void;
241
+ end(callback: () => void): void;
242
+ destroy(): void;
243
+ }
244
+ /** A response code, or a list for a code with arguments (`['MESSAGELIMIT', 1000]`) */
245
+ export type ResponseCode = string | (string | number)[];
246
+ /** The refusal of a command or a literal, sent as a tagged `command [code] text` */
247
+ export interface Refusal {
248
+ command: string;
249
+ code?: string | undefined;
250
+ text: string;
251
+ }
252
+ /** A refusal of `server.commandChecks`, `command` defaults to BAD */
253
+ export interface CommandRefusal {
254
+ command?: string | undefined;
255
+ code?: ResponseCode | undefined;
256
+ text: string;
257
+ }
258
+ /** A result of `server.appendChecks` (or other checks reported with `connection.applyChecks()`) */
259
+ export interface CheckResult {
260
+ code?: ResponseCode | undefined;
261
+ text: string;
262
+ /** only a warning, sent as an untagged NO */
263
+ soft?: boolean | undefined;
264
+ }
265
+ /** A message that APPEND, REPLACE, COPY or MOVE is about to add to a mailbox */
266
+ export interface AppendMessage {
267
+ raw: string;
268
+ flags?: string[] | undefined;
269
+ internaldate?: string | Date | false | undefined;
270
+ [key: string]: any;
271
+ }
272
+ /** Options of `server.appendChecks`: `{ move, source }` for COPY and MOVE, `{ command, replaced }` for APPEND and REPLACE */
273
+ export interface AppendCheckOptions {
274
+ move?: boolean | undefined;
275
+ source?: Mailbox | false | undefined;
276
+ command?: string | undefined;
277
+ replaced?: Message | null | undefined;
278
+ [key: string]: any;
279
+ }
280
+ type BivariantCallback<T extends (...args: any[]) => any> = {
281
+ bivarianceHack(...args: Parameters<T>): ReturnType<T>;
282
+ }['bivarianceHack'];
283
+ /**
284
+ * `server.outputHandlers`: called with the arguments of every `connection.send()`, can change the response or set
285
+ * `skipResponse`. Handlers may declare narrower parameter types for the responses they act on
286
+ */
287
+ export type OutputHandler = BivariantCallback<(connection: IMAPConnection, response: IMAPResponse, description: string | undefined, parsed: CommandContext | null | undefined, data: string | null | undefined, ...extra: any[]) => void>;
288
+ /** `server.fetchHandlers`: the value of a FETCH item */
289
+ export interface FetchHandler {
290
+ (connection: IMAPConnection, message: Message, query?: Attribute, ...args: any[]): any;
291
+ /** fetching the item sets \Seen like BODY[] */
292
+ setsSeen?: boolean | undefined;
293
+ }
294
+ /** `server.searchHandlers`: checks a message against a search key, the arguments follow the index */
295
+ export interface SearchHandler {
296
+ (connection: IMAPConnection, message: Message, index: number, ...args: any[]): any;
297
+ /** decides the argument types of the key instead of one string per handler parameter */
298
+ argumentTypes?: ((list: Attribute[]) => any[]) | undefined;
299
+ }
300
+ /** `server.storeHandlers`: applies a STORE item to a message */
301
+ export interface StoreHandler {
302
+ (connection: IMAPConnection, message: Message, values: any, index: number, parsed: ParsedCommand, data: string): any;
303
+ /** the values are astrings (X-GM-LABELS), NIL atoms are kept and literals accepted */
304
+ astringValues?: boolean | undefined;
305
+ }
306
+ /** `server.statusHandlers`: the value of a STATUS item */
307
+ export type StatusHandler = (connection: IMAPConnection, mailbox: Mailbox, status: MailboxStatus) => any;
308
+ /** `server.fetchFilters` and `server.storeFilters`: false leaves a message out */
309
+ export type MessageFilter = (connection: IMAPConnection, message: Message, parsed: ParsedCommand, index: number) => unknown;
310
+ /** `server.appendDataHandlers`: parses an append-data extension and returns the function that builds the message source */
311
+ export type AppendDataHandler = (connection: IMAPConnection, value: Attribute) => () => string;
312
+ export type CapabilityCheck = (connection: IMAPConnection) => boolean;
313
+ export type ConnectionHandler = (connection: IMAPConnection) => void;
314
+ export type MessageHandler = (server: IMAPServer, message: Message, mailbox: Mailbox) => void;
315
+ export type MailboxHandler = (server: IMAPServer, mailbox: Mailbox) => void;
316
+ export type CopyHandler = (server: IMAPServer, source: Message, properties: Record<string, any>, mailbox: Mailbox) => void;
317
+ export type NotifyFilter = (connection: IMAPConnection, event: NotifyEvent) => boolean;
318
+ export type AppendCheck = (connection: IMAPConnection, mailbox: Mailbox, messages: AppendMessage[], options: AppendCheckOptions) => CheckResult | false | null | undefined | void;
319
+ export type LiteralFilter = (connection: IMAPConnection, command: string, line: string, size: number) => Refusal | false | null | undefined;
320
+ export type UrlAccessCheck = (connection: IMAPConnection, mailbox: Mailbox, url: any) => {
321
+ text: string;
322
+ } | false | null | undefined;
323
+ export type SearchAccessCheck = (connection: IMAPConnection, mailbox: Mailbox, named: boolean) => boolean;
324
+ export type CommandCheck = (connection: IMAPConnection, parsed: ParsedCommand) => CommandRefusal | false | null | undefined;
325
+ export type RangeLimit = (connection: IMAPConnection, parsed: ParsedCommand, range: MessageRange) => MessageRange | false | null | undefined;
326
+ export type SearchLimit = (connection: IMAPConnection, messages: Message[], query: any) => Message[] | false | null | undefined;
327
+ export type ClosedCheck = (connection: IMAPConnection) => boolean;
@@ -0,0 +1,2 @@
1
+ // Shared types of the server, the commands and the plugins
2
+ export {};
@@ -0,0 +1,17 @@
1
+ import type { IMAPConnection } from './types.js';
2
+ /**
3
+ * Sets the UTF-8 options of a session from the extensions it has enabled. Run it when the session starts,
4
+ * after ENABLE and after UNAUTHENTICATE (once the ENABLE plugin has cleared `connection.enabled`).
5
+ *
6
+ * - With the UTF8=ACCEPT plugin, quoted strings may hold UTF-8 even before ENABLE (RFC 9755 section 3) and
7
+ * modified UTF-7 names must decode to Net-Unicode. Without it, 8-bit quoted strings are a syntax error until
8
+ * ENABLE IMAP4rev2, like RFC 3501 says
9
+ * - ENABLE UTF8=ACCEPT or IMAP4rev2: mailbox names are UTF-8 in both directions and strings that are valid
10
+ * UTF-8 are sent quoted (RFC 9755 section 3, RFC 9051 sections 4.3 and 5.1)
11
+ * - ENABLE UTF8=ACCEPT: SEARCH strings are UTF-8 and CHARSET is refused (RFC 9755 section 3)
12
+ * - ENABLE IMAP4rev2: SEARCH strings are UTF-8 unless a CHARSET says otherwise (RFC 9051 section 6.4.4)
13
+ *
14
+ * @param {Object} connection IMAP connection
15
+ */
16
+ declare function updateSession(connection: IMAPConnection): void;
17
+ export { updateSession };