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
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toSequenceSet = toSequenceSet;
4
+ exports.toOrderedSet = toOrderedSet;
5
+ exports.selectReturned = selectReturned;
6
+ exports.selectPartial = selectPartial;
7
+ exports.parsePartialRange = parsePartialRange;
8
+ exports.registerPartialOption = registerPartialOption;
9
+ exports.buildCorrelator = buildCorrelator;
10
+ exports.buildEsearchResponse = buildEsearchResponse;
11
+ const search_js_1 = require("./commands/handlers/search.js");
12
+ const numbers_js_1 = require("./numbers.js");
13
+ /**
14
+ * ESEARCH response helpers (RFC 4731, RFC 4466 section 2.6.2). Used by the ESEARCH, SEARCHRES, PARTIAL,
15
+ * CONTEXT=SEARCH and MULTISEARCH plugins, and meant to be reused where SEARCH always answers with ESEARCH (IMAP4rev2, RFC 9051).
16
+ */
17
+ /**
18
+ * Formats a list of numbers as a compact sequence-set, e.g. [1, 2, 3, 5] becomes "1:3,5"
19
+ *
20
+ * @param {Array} numbers List of nz-numbers, in any order
21
+ * @return {String} sequence-set, empty for an empty list
22
+ */
23
+ function toSequenceSet(numbers) {
24
+ return toOrderedSet(Array.from(new Set(numbers)).sort((a, b) => a - b));
25
+ }
26
+ /**
27
+ * Formats a list of numbers as a sequence-set that keeps their order, for SORT results (RFC 5267
28
+ * section 3.2): only runs of ascending consecutive numbers become ranges, e.g. [5, 3, 4, 2] becomes "5,3:4,2"
29
+ *
30
+ * @param {Array} numbers List of nz-numbers in the requested order
31
+ * @return {String} sequence-set, empty for an empty list
32
+ */
33
+ function toOrderedSet(numbers) {
34
+ const ranges = [];
35
+ numbers.forEach(nr => {
36
+ const last = ranges[ranges.length - 1];
37
+ if (last && last[1] + 1 === nr) {
38
+ last[1] = nr;
39
+ }
40
+ else {
41
+ ranges.push([nr, nr]);
42
+ }
43
+ });
44
+ return ranges.map(range => (range[0] === range[1] ? String(range[0]) : range[0] + ':' + range[1])).join(',');
45
+ }
46
+ /**
47
+ * Parses the argument of the PARTIAL search return option (RFC 5267 section 4.4, RFC 9394 section 4):
48
+ * partial-range-first = nz-number ":" nz-number, partial-range-last = "-" nz-number ":" "-" nz-number.
49
+ * "*" is not allowed, and 500:400 is the same as 400:500
50
+ *
51
+ * @param {Object} item Parsed argument
52
+ * @param {Boolean} allowLast If true, the partial-range-last form of RFC 9394 is accepted
53
+ * @return {Object} `{ range, from, to, fromEnd }`, `range` is the argument as the client sent it
54
+ */
55
+ function parsePartialRange(item, allowLast) {
56
+ const value = item && ['ATOM', 'SEQUENCE'].includes(item.type) ? String(item.value) : '';
57
+ const match = value.match(/^(-?)([1-9][0-9]*):(-?)([1-9][0-9]*)$/);
58
+ if (!match || match[1] !== match[3] || (match[1] && !allowLast)) {
59
+ throw (0, search_js_1.badError)('PARTIAL expects a range like 1:100' + (allowLast ? ' or -1:-100' : ''));
60
+ }
61
+ const first = Number(match[2]);
62
+ const last = Number(match[4]);
63
+ if (first > numbers_js_1.MAX_NUMBER || last > numbers_js_1.MAX_NUMBER) {
64
+ throw (0, search_js_1.badError)('PARTIAL range is out of bounds');
65
+ }
66
+ return { range: value, from: Math.min(first, last), to: Math.max(first, last), fromEnd: !!match[1] };
67
+ }
68
+ /**
69
+ * Picks the results that a PARTIAL range refers to. The first result is 1, and -1 is the last one
70
+ * (RFC 9394 section 3.1). Results outside the list are left out
71
+ *
72
+ * @param {Array} list Results in mailbox order
73
+ * @param {Object} partial Parsed range, see parsePartialRange
74
+ * @return {Array} results in the range, in mailbox order
75
+ */
76
+ function selectPartial(list, partial) {
77
+ if (!partial.fromEnd) {
78
+ return list.slice(partial.from - 1, partial.to);
79
+ }
80
+ return list.slice(Math.max(list.length - partial.to, 0), Math.max(list.length - partial.from + 1, 0));
81
+ }
82
+ /**
83
+ * Registers the PARTIAL search return option, shared by the PARTIAL and CONTEXT=SEARCH plugins. The
84
+ * partial-range-last form (-1:-100) is only valid with the PARTIAL capability (RFC 9394 section 4)
85
+ *
86
+ * @param {Object} server IMAP server, with the ESEARCH plugin loaded
87
+ */
88
+ function registerPartialOption(server) {
89
+ if (server.searchReturnOptions.has('PARTIAL')) {
90
+ return;
91
+ }
92
+ server.searchReturnOptions.set('PARTIAL', { data: true, once: true, parse: (item) => parsePartialRange(item, !!server.partialRangeLast) });
93
+ // RFC 5267 section 4.4 and RFC 9394 section 3.1: a command MUST NOT contain more than one PARTIAL or ALL
94
+ server.searchReturnOptions.set('ALL', Object.assign({}, server.searchReturnOptions.get('ALL'), { once: true }));
95
+ server.searchReturnChecks.push((options) => options.has('PARTIAL') && options.has('ALL') && 'PARTIAL and ALL can not be used together');
96
+ }
97
+ /**
98
+ * Picks the messages that the requested result options return. With COUNT or ALL, or without
99
+ * MIN, MAX and PARTIAL, these are all matching messages, otherwise the lowest and/or the highest
100
+ * matching message and the ones in the PARTIAL range. This is the set that the MODSEQ result
101
+ * option describes (RFC 4731 section 3.2) and that SAVE stores (RFC 5182 section 2.4, RFC 9394
102
+ * section 3.2)
103
+ *
104
+ * @param {Array} list Matching messages, in mailbox order
105
+ * @param {Map} options Upper case result option names to their arguments, an empty map stands for ALL
106
+ * @return {Array} returned messages, in mailbox order
107
+ */
108
+ function selectReturned(list, options) {
109
+ const partial = options.get('PARTIAL');
110
+ if (!list.length || options.has('ALL') || options.has('COUNT') || (!partial && !options.has('MIN') && !options.has('MAX'))) {
111
+ return list;
112
+ }
113
+ const returned = new Set(partial ? selectPartial(list, partial) : []);
114
+ if (options.has('MIN')) {
115
+ returned.add(list[0]);
116
+ }
117
+ if (options.has('MAX')) {
118
+ returned.add(list[list.length - 1]);
119
+ }
120
+ return list.filter(message => returned.has(message));
121
+ }
122
+ /**
123
+ * Builds the search correlator (RFC 4466 section 2.6.2), with the MAILBOX and UIDVALIDITY
124
+ * correlators of RFC 7377 section 4 if a mailbox is given
125
+ *
126
+ * @param {String} tag Tag of the command
127
+ * @param {Object} [mailbox] Mailbox the response is about
128
+ * @return {Array} correlator list
129
+ */
130
+ function buildCorrelator(tag, mailbox) {
131
+ const correlator = [
132
+ { type: 'ATOM', value: 'TAG' },
133
+ { type: 'STRING', value: tag }
134
+ ];
135
+ if (mailbox) {
136
+ correlator.push({ type: 'ATOM', value: 'MAILBOX' },
137
+ // send() puts in the form of the name that the session uses
138
+ { type: 'MAILBOX', value: mailbox.path }, { type: 'ATOM', value: 'UIDVALIDITY' }, mailbox.uidvalidity);
139
+ }
140
+ return correlator;
141
+ }
142
+ /**
143
+ * Builds an ESEARCH response (RFC 4466 section 2.6.2) with the RFC 4731 section 3.1 return data
144
+ * and PARTIAL (RFC 5267 section 4.4, RFC 9394 section 3.1)
145
+ *
146
+ * @param {String} tag Tag of the command, for the search correlator
147
+ * @param {Boolean} isUid If true, the response lists UIDs and has the UID indicator
148
+ * @param {Object} result Search result, `{ list, numbers }` (see src/commands/handlers/search.ts)
149
+ * @param {Map} options Upper case result option names to their arguments, an empty map stands for ALL (RFC 4731 section 3.1)
150
+ * @param {Object} [mailbox] Adds the MAILBOX and UIDVALIDITY correlators of RFC 7377 for this mailbox
151
+ * @param {Array} [sorted] The matching messages in sort order, for an extended SORT (RFC 5267 section 3.1): MIN and MAX are
152
+ * the first and the last sorted message, ALL and PARTIAL list the results in sort order
153
+ * @return {Object} response for connection.send()
154
+ */
155
+ function buildEsearchResponse(tag, isUid, result, options, mailbox, sorted) {
156
+ const values = (sorted || result.list).map((message) => (isUid ? message.uid : result.numbers[message.uid]));
157
+ if (!sorted) {
158
+ values.sort((a, b) => a - b);
159
+ }
160
+ const toSet = sorted ? toOrderedSet : toSequenceSet;
161
+ const attributes = [buildCorrelator(tag, mailbox)];
162
+ if (isUid) {
163
+ attributes.push({ type: 'ATOM', value: 'UID' });
164
+ }
165
+ const add = (name, value) => attributes.push({ type: 'ATOM', value: name }, value);
166
+ // MIN, MAX and ALL are left out when nothing matched, COUNT is always included (RFC 4731 section 3.1)
167
+ if (values.length && options.has('MIN')) {
168
+ add('MIN', values[0]);
169
+ }
170
+ if (values.length && options.has('MAX')) {
171
+ add('MAX', values[values.length - 1]);
172
+ }
173
+ if (values.length && (options.has('ALL') || !options.size)) {
174
+ add('ALL', { type: 'SEQUENCE', value: toSet(values) });
175
+ }
176
+ if (options.has('PARTIAL')) {
177
+ // the requested range, and NIL when no results fall in it (RFC 9394 section 3.1)
178
+ const partial = options.get('PARTIAL');
179
+ const selected = selectPartial(values, partial);
180
+ add('PARTIAL', [{ type: 'ATOM', value: partial.range }, selected.length ? { type: 'SEQUENCE', value: toSet(selected) } : null]);
181
+ }
182
+ if (options.has('COUNT')) {
183
+ add('COUNT', values.length);
184
+ }
185
+ return {
186
+ tag: '*',
187
+ command: 'ESEARCH',
188
+ attributes
189
+ };
190
+ }
@@ -0,0 +1,66 @@
1
+ /**
2
+ * IMAP framing helpers shared by the mock client, the test helpers and the compare tool.
3
+ * Both functions take a Buffer or a binary string (one character per octet).
4
+ */
5
+ /** A line of a response: `end` excludes the CR before the LF, `lf` is the offset of the LF */
6
+ export interface FrameLine {
7
+ start: number;
8
+ end: number;
9
+ lf: number;
10
+ }
11
+ /** The data of a literal in a response */
12
+ export interface FrameLiteral {
13
+ start: number;
14
+ end: number;
15
+ literal8: boolean;
16
+ }
17
+ /** A complete response, its lines and the literals between them */
18
+ export interface FramedResponse {
19
+ start: number;
20
+ end: number;
21
+ lines: FrameLine[];
22
+ literals: FrameLiteral[];
23
+ }
24
+ /** An unfinished response at the end of the data, see splitResponses() */
25
+ export interface FrameIncomplete {
26
+ reason: 'line' | 'literal' | 'response';
27
+ lines: FrameLine[];
28
+ /** size of the literal that is cut short */
29
+ size?: number;
30
+ /** octets of that literal that were received */
31
+ available?: number;
32
+ }
33
+ /** Result of splitResponses() */
34
+ export interface SplitResponses {
35
+ responses: FramedResponse[];
36
+ end: number;
37
+ incomplete: FrameIncomplete | false;
38
+ }
39
+ /**
40
+ * Splits received server data into responses. A response is one line, or a line that ends with a
41
+ * literal marker `{n}` or `~{n}` (RFC 3516 literal8), followed by n octets and the rest of the
42
+ * response. Lenient: lines end at LF, a CR before it is not required. Callers that need strict
43
+ * framing check the line ends themselves.
44
+ *
45
+ * @param {Buffer|String} data Received data, possibly ending with an incomplete response
46
+ * @return {Object} `{ responses, end, incomplete }`. Every response is `{ start, end, lines, literals }`,
47
+ * where `lines` lists `{ start, end, lf }` (end excludes the CR before the LF, `lf` is the
48
+ * offset of the LF) and `literals` lists `{ start, end, literal8 }`. `end` is the offset right
49
+ * after the last complete response. `incomplete` is false when all data was used, otherwise
50
+ * `{ reason, lines }` with the complete lines of the unfinished response, where reason is
51
+ * 'line' for a line without LF, 'literal' for literal data that is cut short (with `size`
52
+ * and `available`), or 'response' when the data ends right after literal data.
53
+ */
54
+ declare function splitResponses(data: Buffer | string): SplitResponses;
55
+ /**
56
+ * Splits an outgoing command after every synchronizing literal marker, as a client must wait for the
57
+ * continuation request before it sends the literal data (RFC 3501 section 4.3). The data of every
58
+ * literal, synchronizing or not ({n+}, RFC 7888), is skipped, so markers inside it are not matched.
59
+ *
60
+ * @param {Buffer|String} payload Command, as a Buffer or a binary string
61
+ * @return {Array} Chunks to send, of the same type as the payload
62
+ */
63
+ declare function splitAtLiterals(payload: Buffer): Buffer[];
64
+ declare function splitAtLiterals(payload: string): string[];
65
+ declare function splitAtLiterals(payload: Buffer | string): (Buffer | string)[];
66
+ export { splitResponses, splitAtLiterals };
@@ -1,13 +1,13 @@
1
- 'use strict';
2
-
1
+ "use strict";
3
2
  /**
4
3
  * IMAP framing helpers shared by the mock client, the test helpers and the compare tool.
5
4
  * Both functions take a Buffer or a binary string (one character per octet).
6
5
  */
7
-
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.splitResponses = splitResponses;
8
+ exports.splitAtLiterals = splitAtLiterals;
8
9
  const LF = 0x0a;
9
10
  const CR = 0x0d;
10
-
11
11
  /**
12
12
  * Splits received server data into responses. A response is one line, or a line that ends with a
13
13
  * literal marker `{n}` or `~{n}` (RFC 3516 literal8), followed by n octets and the rest of the
@@ -26,20 +26,19 @@ const CR = 0x0d;
26
26
  function splitResponses(data) {
27
27
  const isBuffer = Buffer.isBuffer(data);
28
28
  const length = data.length;
29
- const charAt = isBuffer ? i => data[i] : i => data.charCodeAt(i);
30
- const slice = isBuffer ? (start, end) => data.toString('binary', start, end) : (start, end) => data.slice(start, end);
31
-
29
+ const charAt = isBuffer ? (i) => data[i] : (i) => data.charCodeAt(i);
30
+ const slice = isBuffer
31
+ ? (start, end) => data.toString('binary', start, end)
32
+ : (start, end) => data.slice(start, end);
32
33
  const responses = [];
33
34
  let pos = 0;
34
35
  let end = 0;
35
36
  let current = null;
36
-
37
37
  while (pos < length) {
38
- const lf = data.indexOf(isBuffer ? LF : '\n', pos);
38
+ const lf = isBuffer ? data.indexOf(LF, pos) : data.indexOf('\n', pos);
39
39
  if (lf < 0) {
40
40
  return { responses, end, incomplete: { reason: 'line', lines: current ? current.lines : [] } };
41
41
  }
42
-
43
42
  const lineStart = pos;
44
43
  const lineEnd = lf > pos && charAt(lf - 1) === CR ? lf - 1 : lf;
45
44
  if (!current) {
@@ -47,7 +46,6 @@ function splitResponses(data) {
47
46
  }
48
47
  current.lines.push({ start: lineStart, end: lineEnd, lf });
49
48
  pos = lf + 1;
50
-
51
49
  // only lines that end with "}" can carry a literal marker, so most lines are not sliced
52
50
  const marker = lineEnd > lineStart && charAt(lineEnd - 1) === 0x7d && slice(Math.max(lineEnd - 32, lineStart), lineEnd).match(/(~?)\{(\d+)\}$/);
53
51
  if (marker) {
@@ -59,24 +57,13 @@ function splitResponses(data) {
59
57
  pos += size;
60
58
  continue;
61
59
  }
62
-
63
60
  current.end = end = pos;
64
61
  responses.push(current);
65
62
  current = null;
66
63
  }
67
-
68
64
  // the data ended right after a literal, the rest of the response is missing
69
65
  return { responses, end, incomplete: current ? { reason: 'response', lines: current.lines } : false };
70
66
  }
71
-
72
- /**
73
- * Splits an outgoing command after every synchronizing literal marker, as a client must wait for the
74
- * continuation request before it sends the literal data (RFC 3501 section 4.3). The data of every
75
- * literal, synchronizing or not ({n+}, RFC 7888), is skipped, so markers inside it are not matched.
76
- *
77
- * @param {Buffer|String} payload Command, as a Buffer or a binary string
78
- * @return {Array} Chunks to send, of the same type as the payload
79
- */
80
67
  function splitAtLiterals(payload) {
81
68
  const isBuffer = Buffer.isBuffer(payload);
82
69
  const str = isBuffer ? payload.toString('binary') : String(payload);
@@ -85,7 +72,6 @@ function splitAtLiterals(payload) {
85
72
  const re = /~?\{(\d+)(\+?)\}\r\n/g;
86
73
  let start = 0;
87
74
  let match;
88
-
89
75
  while ((match = re.exec(str))) {
90
76
  const end = match.index + match[0].length;
91
77
  if (!match[2]) {
@@ -95,8 +81,5 @@ function splitAtLiterals(payload) {
95
81
  re.lastIndex = end + Number(match[1]);
96
82
  }
97
83
  chunks.push(cut(start));
98
-
99
84
  return chunks.filter(chunk => chunk.length);
100
85
  }
101
-
102
- module.exports = { splitResponses, splitAtLiterals };
@@ -0,0 +1,9 @@
1
+ import createServer, { TAG_REGEX, IMAPServer, IMAPConnection } from './server.js';
2
+ export { TAG_REGEX, IMAPServer, IMAPConnection };
3
+ export type { Attribute, ParsedCommand, IMAPResponse, Notification, Callback, CommandHandler, CommandOptions, Plugin, IMAPError, Message, Mailbox, StorageNamespace, UserData, IMAPServerOptions } from './types.js';
4
+ declare const imapkit: typeof createServer & {
5
+ TAG_REGEX: RegExp;
6
+ IMAPServer: typeof IMAPServer;
7
+ IMAPConnection: typeof IMAPConnection;
8
+ };
9
+ export default imapkit;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.IMAPConnection = exports.IMAPServer = exports.TAG_REGEX = void 0;
37
+ const server_js_1 = __importStar(require("./server.js"));
38
+ Object.defineProperty(exports, "TAG_REGEX", { enumerable: true, get: function () { return server_js_1.TAG_REGEX; } });
39
+ Object.defineProperty(exports, "IMAPServer", { enumerable: true, get: function () { return server_js_1.IMAPServer; } });
40
+ Object.defineProperty(exports, "IMAPConnection", { enumerable: true, get: function () { return server_js_1.IMAPConnection; } });
41
+ // `imapkit(options)` creates a server. TAG_REGEX was a property of the CommonJS export, it and the
42
+ // classes are properties of the factory with both module formats
43
+ const imapkit = Object.assign(server_js_1.default, { TAG_REGEX: server_js_1.TAG_REGEX, IMAPServer: server_js_1.IMAPServer, IMAPConnection: server_js_1.IMAPConnection });
44
+ exports.default = imapkit;
45
+ {
46
+ const defaultExport = exports.default;
47
+ if (defaultExport && (typeof defaultExport === 'function' || typeof defaultExport === 'object')) {
48
+ for (const key of Object.keys(exports)) {
49
+ if (key !== 'default' && !(key in defaultExport)) {
50
+ defaultExport[key] = exports[key];
51
+ }
52
+ }
53
+ Object.defineProperty(defaultExport, 'default', { value: defaultExport, enumerable: false, writable: true, configurable: true });
54
+ module.exports = defaultExport;
55
+ }
56
+ }
@@ -0,0 +1,50 @@
1
+ import type { Attribute, IMAPConnection, IMAPServer, Mailbox, ParsedCommand } from './types.js';
2
+ /** An extended LIST selection option, see getListExtensions() */
3
+ export interface ListSelectionOption {
4
+ type: 'base' | 'independent' | 'modifier';
5
+ returnOption?: string;
6
+ includeNonExistent?: boolean;
7
+ match?: (folder: Mailbox, connection: IMAPConnection) => boolean;
8
+ }
9
+ /** What onItem() of a return option learns about a listed mailbox */
10
+ export interface ListItemInfo {
11
+ /** the mailbox matched the selection criteria */
12
+ matched: boolean;
13
+ /** the mailbox is not \NonExistent */
14
+ exists: boolean;
15
+ }
16
+ /** An extended LIST return option, see getListExtensions() */
17
+ export interface ListReturnOption {
18
+ parse?: (list: Attribute, connection: IMAPConnection) => any;
19
+ onItem?: (connection: IMAPConnection, folder: Mailbox, value: any, info: ListItemInfo, parsed: ParsedCommand, data: string) => void;
20
+ }
21
+ /** The registry of extended LIST options */
22
+ export interface ListExtensions {
23
+ enabled: boolean;
24
+ selectionOptions: Record<string, ListSelectionOption>;
25
+ returnOptions: Record<string, ListReturnOption>;
26
+ }
27
+ /**
28
+ * Returns the registry of extended LIST options (RFC 5258 section 3), shared by the LIST-EXTENDED
29
+ * plugin and the plugins that add their own options (SPECIAL-USE, LIST-STATUS). These can be loaded
30
+ * in any order, so whichever comes first creates the registry. Options are only accepted when the
31
+ * LIST-EXTENDED plugin is loaded (`enabled`).
32
+ *
33
+ * Selection options: `{ type, returnOption, includeNonExistent, match(folder, connection) }`
34
+ * - `type` is "base", "independent" or "modifier" (list-select-base-opt, list-select-independent-opt
35
+ * and list-select-mod-opt in the RFC 5258 section 6 grammar)
36
+ * - `returnOption` is the return option the selection option implies
37
+ * - `match` is the filter the mailboxes must pass, `includeNonExistent` if it can select mailbox
38
+ * names that do not exist (like SUBSCRIBED)
39
+ *
40
+ * Return options: `{ parse(list, connection), onItem(connection, folder, value, info, parsed, data) }`
41
+ * - `parse` is set for options that take a value (option-value), it returns the parsed value or
42
+ * throws an Error with a message for the BAD response
43
+ * - `onItem` runs after the LIST response of every listed mailbox. `info.matched` is true if the
44
+ * mailbox matched the selection criteria, `info.exists` if it is not \NonExistent
45
+ *
46
+ * @param {Object} server IMAPServer instance
47
+ * @return {Object} `{ enabled, selectionOptions, returnOptions }`
48
+ */
49
+ declare function getListExtensions(server: IMAPServer): ListExtensions;
50
+ export { getListExtensions };
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getListExtensions = getListExtensions;
4
+ /**
5
+ * Returns the registry of extended LIST options (RFC 5258 section 3), shared by the LIST-EXTENDED
6
+ * plugin and the plugins that add their own options (SPECIAL-USE, LIST-STATUS). These can be loaded
7
+ * in any order, so whichever comes first creates the registry. Options are only accepted when the
8
+ * LIST-EXTENDED plugin is loaded (`enabled`).
9
+ *
10
+ * Selection options: `{ type, returnOption, includeNonExistent, match(folder, connection) }`
11
+ * - `type` is "base", "independent" or "modifier" (list-select-base-opt, list-select-independent-opt
12
+ * and list-select-mod-opt in the RFC 5258 section 6 grammar)
13
+ * - `returnOption` is the return option the selection option implies
14
+ * - `match` is the filter the mailboxes must pass, `includeNonExistent` if it can select mailbox
15
+ * names that do not exist (like SUBSCRIBED)
16
+ *
17
+ * Return options: `{ parse(list, connection), onItem(connection, folder, value, info, parsed, data) }`
18
+ * - `parse` is set for options that take a value (option-value), it returns the parsed value or
19
+ * throws an Error with a message for the BAD response
20
+ * - `onItem` runs after the LIST response of every listed mailbox. `info.matched` is true if the
21
+ * mailbox matched the selection criteria, `info.exists` if it is not \NonExistent
22
+ *
23
+ * @param {Object} server IMAPServer instance
24
+ * @return {Object} `{ enabled, selectionOptions, returnOptions }`
25
+ */
26
+ function getListExtensions(server) {
27
+ if (!server.listExtensions) {
28
+ server.listExtensions = {
29
+ enabled: false,
30
+ selectionOptions: Object.create(null),
31
+ returnOptions: Object.create(null)
32
+ };
33
+ }
34
+ return server.listExtensions;
35
+ }
@@ -0,0 +1,21 @@
1
+ import type { IMAPServer, Plugin } from './types.js';
2
+ /**
3
+ * Lists the names of the built-in plugins (file names without extension)
4
+ *
5
+ * @return {Array} plugin names
6
+ */
7
+ declare function listPlugins(): string[];
8
+ /**
9
+ * Loads plugins for a server instance. Built-in plugins are referenced by name,
10
+ * custom plugins are functions. Unknown names throw, repeated plugins are loaded only once.
11
+ * A plugin that needs another plugin lists its name in `plugin.requires`, the required
12
+ * plugin is then loaded first. Once every plugin is loaded, the server emits `pluginsLoaded`: a plugin
13
+ * that has to wrap what other plugins set up (commands, output handlers), whatever the load order,
14
+ * does that in a `server.once('pluginsLoaded', ...)` listener. Listeners run in plugin load order.
15
+ *
16
+ * @param {Object} server IMAPServer instance
17
+ * @param {Array|String|Function} plugins List of plugins to load
18
+ */
19
+ declare function loadPlugins(server: IMAPServer, plugins: (string | Plugin)[] | string | Plugin | null | undefined): void;
20
+ export default loadPlugins;
21
+ export { listPlugins };
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.listPlugins = listPlugins;
4
+ const index_js_1 = require("./plugins/index.js");
5
+ // Capability spellings that do not match a plugin file name
6
+ const ALIASES = {
7
+ 'literal+': 'literalplus',
8
+ 'literal-': 'literalminus',
9
+ 'compress=deflate': 'compress',
10
+ 'auth=plain': 'auth-plain',
11
+ 'auth=xoauth2': 'xoauth2',
12
+ 'status=size': 'status-size',
13
+ 'sort=display': 'sort-display',
14
+ 'thread=orderedsubject': 'thread-orderedsubject',
15
+ 'thread=references': 'thread-references',
16
+ 'auth=oauthbearer': 'oauthbearer',
17
+ 'utf8=accept': 'utf8-accept',
18
+ 'context=search': 'context-search',
19
+ 'context=sort': 'context-sort'
20
+ };
21
+ /**
22
+ * Lists the names of the built-in plugins (file names without extension)
23
+ *
24
+ * @return {Array} plugin names
25
+ */
26
+ function listPlugins() {
27
+ return Object.keys(index_js_1.plugins);
28
+ }
29
+ /**
30
+ * Resolves a plugin name, as given in options.plugins, to a built-in plugin
31
+ *
32
+ * @param {String} name Plugin name, eg. "IDLE" or "LITERAL+"
33
+ * @return {String|false} Resolved plugin name or false if no such plugin exists
34
+ */
35
+ function resolvePlugin(name) {
36
+ let key = String(name).trim().toLowerCase();
37
+ if (Object.hasOwn(ALIASES, key)) {
38
+ key = ALIASES[key];
39
+ }
40
+ return Object.hasOwn(index_js_1.plugins, key) ? key : false;
41
+ }
42
+ /**
43
+ * Loads plugins for a server instance. Built-in plugins are referenced by name,
44
+ * custom plugins are functions. Unknown names throw, repeated plugins are loaded only once.
45
+ * A plugin that needs another plugin lists its name in `plugin.requires`, the required
46
+ * plugin is then loaded first. Once every plugin is loaded, the server emits `pluginsLoaded`: a plugin
47
+ * that has to wrap what other plugins set up (commands, output handlers), whatever the load order,
48
+ * does that in a `server.once('pluginsLoaded', ...)` listener. Listeners run in plugin load order.
49
+ *
50
+ * @param {Object} server IMAPServer instance
51
+ * @param {Array|String|Function} plugins List of plugins to load
52
+ */
53
+ function loadPlugins(server, plugins) {
54
+ const loaded = new Set();
55
+ const load = (entry) => {
56
+ let plugin = entry;
57
+ if (typeof plugin === 'string') {
58
+ const name = resolvePlugin(plugin);
59
+ if (!name) {
60
+ throw new Error('Unknown plugin "' + plugin + '". Available plugins: ' + listPlugins().join(', '));
61
+ }
62
+ plugin = index_js_1.plugins[name];
63
+ }
64
+ if (typeof plugin !== 'function') {
65
+ throw new TypeError('Invalid plugin, expecting a plugin name or a function');
66
+ }
67
+ if (loaded.has(plugin)) {
68
+ return;
69
+ }
70
+ loaded.add(plugin);
71
+ [].concat(plugin.requires || []).forEach(load);
72
+ plugin(server);
73
+ };
74
+ [].concat(plugins || []).forEach(load);
75
+ server.emit('pluginsLoaded');
76
+ }
77
+ exports.default = loadPlugins;
78
+ {
79
+ const defaultExport = exports.default;
80
+ if (defaultExport && (typeof defaultExport === 'function' || typeof defaultExport === 'object')) {
81
+ for (const key of Object.keys(exports)) {
82
+ if (key !== 'default' && !(key in defaultExport)) {
83
+ defaultExport[key] = exports[key];
84
+ }
85
+ }
86
+ Object.defineProperty(defaultExport, 'default', { value: defaultExport, enumerable: false, writable: true, configurable: true });
87
+ module.exports = defaultExport;
88
+ }
89
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Checks a mailbox name against the modified UTF-7 rules of RFC 3501 section 5.1.3:
3
+ * printable US-ASCII represents itself, "&" is written as "&-", everything else
4
+ * is encoded in modified BASE64 between "&" and "-", without superfluous shifts
5
+ * and without encoding printable US-ASCII.
6
+ *
7
+ * @param {String} name Mailbox name as a binary string
8
+ * @return {String|Boolean} Description of the problem, or false if the name is valid
9
+ */
10
+ declare function validateMailboxName(name: unknown): string | false;
11
+ /**
12
+ * Encodes a mailbox name in modified UTF-7 (RFC 3501 section 5.1.3)
13
+ *
14
+ * @param {String} name Mailbox name as a unicode string
15
+ * @return {String} Modified UTF-7 name
16
+ */
17
+ declare function encodeMailboxName(name: string): string;
18
+ /**
19
+ * Decodes a modified UTF-7 mailbox name (RFC 3501 section 5.1.3)
20
+ *
21
+ * @param {String} name Mailbox name as a binary string
22
+ * @return {String|Boolean} Mailbox name as a unicode string, or false if the name is not valid modified UTF-7
23
+ */
24
+ declare function decodeMailboxName(name: string): string | false;
25
+ export default validateMailboxName;
26
+ export { encodeMailboxName as encode, decodeMailboxName as decode, encodeMailboxName };