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
package/README.md CHANGED
@@ -42,11 +42,21 @@ npm install imapkit
42
42
  Create and start an IMAP server
43
43
 
44
44
  ```javascript
45
- const imapkit = require('imapkit');
45
+ import imapkit from 'imapkit';
46
+ // or with CommonJS: const imapkit = require('imapkit');
47
+
46
48
  const server = imapkit(options);
47
49
  server.listen(1143);
48
50
  ```
49
51
 
52
+ ImapKit is written in TypeScript and ships both ES modules and CommonJS, each with type declarations. The package exports the `imapkit(options)` factory as its default export, the `IMAPServer` and `IMAPConnection` classes, and types such as `IMAPServerOptions`, `Plugin`, `CommandHandler`, `Mailbox` and `Message` for writing plugins:
53
+
54
+ ```typescript
55
+ import imapkit, { type IMAPServerOptions, type Plugin } from 'imapkit';
56
+ ```
57
+
58
+ ImapKit needs Node.js 20 or newer. It also runs on the latest [Bun](https://bun.sh/) and [Deno](https://deno.com/) releases (`npm:imapkit` in Deno), CI runs the whole test suite on both.
59
+
50
60
  See [complete.js](https://github.com/postalsys/imapkit/blob/master/examples/complete.js) for an example.
51
61
 
52
62
  ## Scope
@@ -55,7 +65,7 @@ ImapKit is a single user, multiple connection IMAP server. Changes made over IMA
55
65
 
56
66
  Several clients can connect to the server simultaneously but all the clients share the same user account, even if login credentials are different. The ACL plugin can limit what users other than the owner can do (see [ACL](#acl)).
57
67
 
58
- ImapKit is extendable: any command can be overridden and plugins can be added (see [Creating custom plugins](#creating-custom-plugins), and `lib/commands` and `lib/plugins` for the built-in commands and plugins).
68
+ ImapKit is extendable: any command can be overridden and plugins can be added (see [Creating custom plugins](#creating-custom-plugins), and `src/commands` and `src/plugins` for the built-in commands and plugins).
59
69
 
60
70
  ## Strict by design
61
71
 
@@ -273,14 +283,16 @@ S: A1 OK XTOYBIRD Completed
273
283
 
274
284
  # Running tests
275
285
 
276
- Tests use the built-in Node.js test runner, linting uses ESLint and formatting uses Prettier.
286
+ The source is TypeScript in `src/`, `npm run build` compiles it into `dist/esm` (ES modules) and `dist/cjs` (CommonJS). Tests use the built-in Node.js test runner (TypeScript test files run through [tsx](https://tsx.is/)), linting uses ESLint and the TypeScript compiler, and formatting uses Prettier.
277
287
 
278
288
  npm install
279
- npm test # lint + all tests
280
- npm run test:unit # tests only
281
- npm run test:coverage # tests with coverage (Node.js 22.8 or newer)
282
- node --test test/fetch.js # a single test file
283
- npm run format # apply Prettier formatting
289
+ npm test # lint, type check, build and all tests
290
+ npm run test:unit # tests only
291
+ npm run test:coverage # tests with coverage (Node.js 22.8 or newer)
292
+ npm run test:bun # tests under Bun
293
+ npm run test:deno # tests under Deno
294
+ node --import tsx --test test/fetch.test.ts # a single test file
295
+ npm run format # apply Prettier formatting
284
296
 
285
297
  `compare/` holds a development tool that replays the same IMAP commands against ImapKit and a Dovecot server running in Docker and shows where the responses differ (`npm run dovecot:start`, then `npm run compare -- compare/scenarios/fetch.txt`). See [CLAUDE.md](CLAUDE.md#comparing-with-dovecot) for details.
286
298
 
@@ -351,24 +363,25 @@ storage.json:
351
363
  Creating your tests in Node.js is a piece of cake, you do not even need to run the `imapkit` command. Here is a sample test using the built-in [Node.js test runner](https://nodejs.org/api/test.html).
352
364
 
353
365
  ```javascript
354
- const { describe, it, beforeEach, afterEach } = require('node:test');
355
- const imapkit = require('imapkit');
356
- const myIMAPClient = require('../my-imap-client');
366
+ import { describe, it, beforeEach, afterEach } from 'node:test';
367
+ import imapkit from 'imapkit';
368
+ import myIMAPClient from '../my-imap-client.js';
357
369
 
358
370
  describe('IMAP tests', () => {
359
371
  let server;
360
372
 
361
373
  // Executed before every test, creates a new blank IMAP server
362
374
  // on a random free port
363
- beforeEach((t, done) => {
364
- server = imapkit();
365
- server.listen(0, done);
366
- });
375
+ beforeEach(
376
+ () =>
377
+ new Promise(resolve => {
378
+ server = imapkit();
379
+ server.listen(0, resolve);
380
+ })
381
+ );
367
382
 
368
383
  // Executed after every test, closes the IMAP server created for the test
369
- afterEach((t, done) => {
370
- server.close(done);
371
- });
384
+ afterEach(() => new Promise(resolve => server.close(resolve)));
372
385
 
373
386
  // A new IMAP client is instantiated that tries to connect to the
374
387
  // IMAP server. If the client is connected the test is considered as passed.
@@ -558,7 +571,7 @@ connection.inputHandler = function(line){
558
571
  }
559
572
  ```
560
573
 
561
- See [idle.js](https://github.com/postalsys/imapkit/blob/master/lib/plugins/idle.js) for an example
574
+ See [idle.ts](https://github.com/postalsys/imapkit/blob/master/src/plugins/idle.ts) for an example
562
575
 
563
576
  Raw output, such as a `+` continuation request, goes through `connection.write(data)`, and `connection.end()` closes the connection once all output is written. Do not use `connection.socket` for this, a COMPRESS layer (`connection.transport`) sits between the protocol and the socket.
564
577
 
package/bin/imapkit.js CHANGED
@@ -1,11 +1,13 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';
3
2
 
4
- const fs = require('node:fs');
5
- const path = require('node:path');
6
- const { parseArgs } = require('node:util');
7
- const imapkit = require('../lib/server');
8
- const packageData = require('../package.json');
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { parseArgs } from 'node:util';
7
+ import imapkit from '../dist/esm/index.js';
8
+
9
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
+ const packageData = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'));
9
11
 
10
12
  // Non-strict so that boolean flags also accept an explicit value (`--secure=true`)
11
13
  const { values: argv } = parseArgs({
@@ -65,15 +67,9 @@ const port = argv.port || process.env.IMAPKIT_PORT || config.port || (secure ? 9
65
67
 
66
68
  if (argv.help) {
67
69
  const help = fs.readFileSync(path.join(__dirname, 'help.txt'), 'utf-8');
68
- const pluginsDir = path.join(__dirname, '..', 'lib', 'plugins');
69
-
70
- const plugins = fs.readdirSync(pluginsDir).map(fileName => {
71
- const file = fs.readFileSync(path.join(pluginsDir, fileName), 'utf-8');
72
- return {
73
- key: fileName.replace(/\.js$/i, '').toUpperCase(),
74
- value: Array.from(file.matchAll(/@help (.*)/gim), match => match[1])
75
- };
76
- });
70
+ // the @help lines of every plugin, collected by the build (scripts/build.js)
71
+ const pluginHelp = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'dist', 'plugin-help.json'), 'utf-8'));
72
+ const plugins = Object.keys(pluginHelp).map(key => ({ key, value: pluginHelp[key] }));
77
73
 
78
74
  const indent = Math.max(0, ...plugins.map(plugin => plugin.key.length)) + 2;
79
75
  const pluginText = plugins.flatMap(plugin => [
@@ -103,6 +99,6 @@ if (argv.help) {
103
99
 
104
100
  if (smtpPort) {
105
101
  // loaded on demand, smtp-server is only needed when SMTP is enabled
106
- require('../lib/smtp-listener').startSMTPServer(smtpPort, server);
102
+ import('../dist/esm/smtp-listener.js').then(({ startSMTPServer }) => startSMTPServer(smtpPort, server));
107
103
  }
108
104
  }
@@ -0,0 +1,21 @@
1
+ /** An address, or a group with its member addresses */
2
+ export interface ParsedAddress {
3
+ name: string;
4
+ address?: string;
5
+ group?: ParsedAddress[];
6
+ }
7
+ /**
8
+ * Parses structured e-mail addresses from an address field
9
+ *
10
+ * Example:
11
+ *
12
+ * "Name <address@domain>"
13
+ *
14
+ * will be converted to
15
+ *
16
+ * [{name: "Name", address: "address@domain"}]
17
+ *
18
+ * @param {String} str Address field
19
+ * @return {Array} An array of address objects
20
+ */
21
+ export default function parse(str: string, inGroup?: boolean): ParsedAddress[];
@@ -0,0 +1,271 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = parse;
4
+ /**
5
+ * Parses structured e-mail addresses from an address field
6
+ *
7
+ * Example:
8
+ *
9
+ * "Name <address@domain>"
10
+ *
11
+ * will be converted to
12
+ *
13
+ * [{name: "Name", address: "address@domain"}]
14
+ *
15
+ * @param {String} str Address field
16
+ * @return {Array} An array of address objects
17
+ */
18
+ function parse(str, inGroup) {
19
+ const tokenizer = new Tokenizer(str);
20
+ const tokens = tokenizer.tokenize();
21
+ const addresses = [];
22
+ let address = [];
23
+ let parsedAddresses = [];
24
+ tokens.forEach(token => {
25
+ if (token.type === 'operator' && (token.value === ',' || token.value === ';')) {
26
+ if (address.length) {
27
+ addresses.push(address);
28
+ }
29
+ address = [];
30
+ }
31
+ else {
32
+ address.push(token);
33
+ }
34
+ });
35
+ if (address.length) {
36
+ addresses.push(address);
37
+ }
38
+ addresses.forEach(address => {
39
+ const handled = _handleAddress(address, inGroup);
40
+ if (handled.length) {
41
+ parsedAddresses = parsedAddresses.concat(handled);
42
+ }
43
+ });
44
+ return parsedAddresses;
45
+ }
46
+ /**
47
+ * Converts tokens for a single address into an address object
48
+ *
49
+ * @param {Array} tokens Tokens object
50
+ * @param {Boolean} [inGroup] If true, the tokens are a member of a group. Groups do not nest
51
+ * (RFC 5322 3.4), so a colon is not a group separator here
52
+ * @return {Object} Address object
53
+ */
54
+ function _handleAddress(tokens, inGroup) {
55
+ let token;
56
+ let isGroup = false;
57
+ let state = 'text';
58
+ const addresses = [];
59
+ const data = {
60
+ address: [],
61
+ comment: [],
62
+ group: [],
63
+ text: []
64
+ };
65
+ let i;
66
+ let len;
67
+ // Filter out <addresses>, (comments) and regular text
68
+ for (i = 0, len = tokens.length; i < len; i++) {
69
+ token = tokens[i];
70
+ if (token.type === 'operator') {
71
+ switch (token.value) {
72
+ case '<':
73
+ state = 'address';
74
+ break;
75
+ case '(':
76
+ state = 'comment';
77
+ break;
78
+ case ':':
79
+ if (inGroup) {
80
+ state = 'text';
81
+ break;
82
+ }
83
+ state = 'group';
84
+ isGroup = true;
85
+ break;
86
+ default:
87
+ state = 'text';
88
+ }
89
+ }
90
+ else {
91
+ if (token.value) {
92
+ data[state].push(token.value);
93
+ }
94
+ }
95
+ }
96
+ // If there is no text but a comment, replace the two
97
+ if (!data.text.length && data.comment.length) {
98
+ data.text = data.comment;
99
+ data.comment = [];
100
+ }
101
+ if (isGroup) {
102
+ // http://tools.ietf.org/html/rfc2822#appendix-A.1.3
103
+ const text = data.text.join(' ');
104
+ addresses.push({
105
+ // RFC 5322 section 3.4 requires a display name, but a group like ":a@b;" still parses, with an empty name
106
+ name: text,
107
+ group: data.group.length ? parse(data.group.join(','), true) : []
108
+ });
109
+ }
110
+ else {
111
+ // If no address was found, try to detect one from regular text
112
+ if (!data.address.length && data.text.length) {
113
+ for (i = data.text.length - 1; i >= 0; i--) {
114
+ if (data.text[i].match(/^[^@\s]+@[^@\s]+$/)) {
115
+ data.address = data.text.splice(i, 1);
116
+ break;
117
+ }
118
+ }
119
+ const _regexHandler = function (address) {
120
+ if (!data.address.length) {
121
+ data.address = [address.trim()];
122
+ return ' ';
123
+ }
124
+ else {
125
+ return address;
126
+ }
127
+ };
128
+ // still no address
129
+ if (!data.address.length) {
130
+ for (i = data.text.length - 1; i >= 0; i--) {
131
+ data.text[i] = data.text[i].replace(/\s*\b[^@\s]+@[^@\s]+\b\s*/, _regexHandler).trim();
132
+ if (data.address.length) {
133
+ break;
134
+ }
135
+ }
136
+ }
137
+ }
138
+ // If there's still is no text but a comment exixts, replace the two
139
+ if (!data.text.length && data.comment.length) {
140
+ data.text = data.comment;
141
+ data.comment = [];
142
+ }
143
+ // Keep only the first address occurence, push others to regular text
144
+ if (data.address.length > 1) {
145
+ data.text = data.text.concat(data.address.splice(1));
146
+ }
147
+ // Join values with spaces
148
+ const text = data.text.join(' ');
149
+ const addressText = data.address.join(' ');
150
+ const address = {
151
+ address: addressText || text || '',
152
+ name: text || addressText || ''
153
+ };
154
+ if (address.address === address.name) {
155
+ if ((address.address || '').match(/@/)) {
156
+ address.name = '';
157
+ }
158
+ else {
159
+ address.address = '';
160
+ }
161
+ }
162
+ addresses.push(address);
163
+ }
164
+ return addresses;
165
+ }
166
+ /**
167
+ * Creates a Tokenizer object for tokenizing address field strings
168
+ *
169
+ * @constructor
170
+ * @param {String} str Address field string
171
+ */
172
+ class Tokenizer {
173
+ constructor(str) {
174
+ this.str = (str || '').toString();
175
+ this.operatorCurrent = '';
176
+ this.operatorExpecting = '';
177
+ this.node = null;
178
+ this.escaped = false;
179
+ this.list = [];
180
+ }
181
+ /**
182
+ * Tokenizes the original input string
183
+ *
184
+ * @return {Array} An array of operator|text tokens
185
+ */
186
+ tokenize() {
187
+ let chr;
188
+ const list = [];
189
+ for (let i = 0, len = this.str.length; i < len; i++) {
190
+ chr = this.str.charAt(i);
191
+ this.checkChar(chr);
192
+ }
193
+ this.list.forEach(node => {
194
+ node.value = (node.value || '').toString().trim();
195
+ if (node.value) {
196
+ list.push(node);
197
+ }
198
+ });
199
+ return list;
200
+ }
201
+ /**
202
+ * Checks if a character is an operator or text and acts accordingly
203
+ *
204
+ * @param {String} chr Character from the address field
205
+ */
206
+ checkChar(chr) {
207
+ if ((chr in this.operators || chr === '\\') && this.escaped) {
208
+ this.escaped = false;
209
+ }
210
+ else if (this.operatorExpecting && chr === this.operatorExpecting) {
211
+ this.node = {
212
+ type: 'operator',
213
+ value: chr
214
+ };
215
+ this.list.push(this.node);
216
+ this.node = null;
217
+ this.operatorExpecting = '';
218
+ this.escaped = false;
219
+ return;
220
+ }
221
+ else if (!this.operatorExpecting && chr in this.operators) {
222
+ this.node = {
223
+ type: 'operator',
224
+ value: chr
225
+ };
226
+ this.list.push(this.node);
227
+ this.node = null;
228
+ this.operatorExpecting = this.operators[chr];
229
+ this.escaped = false;
230
+ return;
231
+ }
232
+ if (!this.escaped && chr === '\\') {
233
+ this.escaped = true;
234
+ return;
235
+ }
236
+ if (!this.node) {
237
+ this.node = {
238
+ type: 'text',
239
+ value: ''
240
+ };
241
+ this.list.push(this.node);
242
+ }
243
+ if (this.escaped && chr !== '\\') {
244
+ this.node.value += '\\';
245
+ }
246
+ this.node.value += chr;
247
+ this.escaped = false;
248
+ }
249
+ }
250
+ /**
251
+ * Operator tokens and which tokens are expected to end the sequence
252
+ */
253
+ Tokenizer.prototype.operators = {
254
+ '"': '"',
255
+ '(': ')',
256
+ '<': '>',
257
+ ',': '',
258
+ ':': ';'
259
+ };
260
+ {
261
+ const defaultExport = exports.default;
262
+ if (defaultExport && (typeof defaultExport === 'function' || typeof defaultExport === 'object')) {
263
+ for (const key of Object.keys(exports)) {
264
+ if (key !== 'default' && !(key in defaultExport)) {
265
+ defaultExport[key] = exports[key];
266
+ }
267
+ }
268
+ Object.defineProperty(defaultExport, 'default', { value: defaultExport, enumerable: false, writable: true, configurable: true });
269
+ module.exports = defaultExport;
270
+ }
271
+ }
@@ -0,0 +1,31 @@
1
+ import type { Attribute, ParsedCommand } from './types.js';
2
+ /**
3
+ * Checks if a parsed argument is an atom, optionally a specific one
4
+ *
5
+ * @param {Object} value Parsed argument
6
+ * @param {String} [name] Upper case atom to match, the value is compared case-insensitively
7
+ * @return {Boolean} true for an atom (with that name)
8
+ */
9
+ declare function isAtom(value: Attribute, name?: string): boolean;
10
+ /**
11
+ * Checks if a parsed argument is an astring (RFC 3501 section 9): an atom, a quoted string or a literal. An
12
+ * atom the parser split into a section or partial range (like BODY[1]<0.5>) is not
13
+ *
14
+ * @param {Object} value Parsed argument
15
+ * @return {Boolean} true for an astring
16
+ */
17
+ declare function isAstring(value: Attribute): boolean;
18
+ /**
19
+ * The parser turns every NIL atom into null, as in an nstring. Where the grammar has an astring (mailbox names, user
20
+ * names, search strings, ...) NIL is an ordinary atom, so these nulls are turned back into atoms with the spelling
21
+ * the client used
22
+ *
23
+ * @param {Object} parsed Parsed command, changed in place
24
+ * @param {String} data Raw command line with its literals
25
+ * @param {Function} select `(path)` returns true for the nulls to restore, `path` lists the indexes from the
26
+ * top-level arguments down, e.g. [2, 0] for the first item of a list in the third argument
27
+ */
28
+ /** Indexes from the top-level arguments down to a nested value, `'section'` steps into the section of an atom */
29
+ export type ArgumentPath = (number | string)[];
30
+ declare function restoreNilAtoms(parsed: ParsedCommand, data: string, select: (path: ArgumentPath) => boolean): void;
31
+ export { isAtom, isAstring, restoreNilAtoms };
@@ -1,7 +1,9 @@
1
- 'use strict';
2
-
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAtom = isAtom;
4
+ exports.isAstring = isAstring;
5
+ exports.restoreNilAtoms = restoreNilAtoms;
3
6
  // Checks of parsed command arguments (imap-handler parser output)
4
-
5
7
  /**
6
8
  * Checks if a parsed argument is an atom, optionally a specific one
7
9
  *
@@ -12,7 +14,6 @@
12
14
  function isAtom(value, name) {
13
15
  return !!value && !Array.isArray(value) && value.type === 'ATOM' && (name === undefined || String(value.value).toUpperCase() === name);
14
16
  }
15
-
16
17
  /**
17
18
  * Checks if a parsed argument is an astring (RFC 3501 section 9): an atom, a quoted string or a literal. An
18
19
  * atom the parser split into a section or partial range (like BODY[1]<0.5>) is not
@@ -23,10 +24,8 @@ function isAtom(value, name) {
23
24
  function isAstring(value) {
24
25
  return !!value && !Array.isArray(value) && ['ATOM', 'STRING', 'LITERAL'].indexOf(value.type) >= 0 && !value.section && !value.partial;
25
26
  }
26
-
27
27
  // characters that end an atom in a command line (RFC 3501 section 9 atom-specials, and "[" "]" of sections)
28
28
  const ATOM_END = /[\s()[\]{"%*\\<]/;
29
-
30
29
  /**
31
30
  * Lists how the client spelled the NIL atoms of a command line, in order. Quoted strings and literals are skipped
32
31
  *
@@ -68,17 +67,6 @@ function nilSpellings(data) {
68
67
  }
69
68
  return result;
70
69
  }
71
-
72
- /**
73
- * The parser turns every NIL atom into null, as in an nstring. Where the grammar has an astring (mailbox names, user
74
- * names, search strings, ...) NIL is an ordinary atom, so these nulls are turned back into atoms with the spelling
75
- * the client used
76
- *
77
- * @param {Object} parsed Parsed command, changed in place
78
- * @param {String} data Raw command line with its literals
79
- * @param {Function} select `(path)` returns true for the nulls to restore, `path` lists the indexes from the
80
- * top-level arguments down, e.g. [2, 0] for the first item of a list in the third argument
81
- */
82
70
  function restoreNilAtoms(parsed, data, select) {
83
71
  if (!parsed.attributes || !/nil/i.test(data || '')) {
84
72
  return;
@@ -89,9 +77,11 @@ function restoreNilAtoms(parsed, data, select) {
89
77
  list.forEach((item, i) => {
90
78
  if (item === null) {
91
79
  nulls.push({ list, index: i, path: path.concat(i) });
92
- } else if (Array.isArray(item)) {
80
+ }
81
+ else if (Array.isArray(item)) {
93
82
  walk(item, path.concat(i));
94
- } else if (item && Array.isArray(item.section)) {
83
+ }
84
+ else if (item && Array.isArray(item.section)) {
95
85
  walk(item.section, path.concat(i, 'section'));
96
86
  }
97
87
  });
@@ -108,5 +98,3 @@ function restoreNilAtoms(parsed, data, select) {
108
98
  }
109
99
  });
110
100
  }
111
-
112
- module.exports = { isAtom, isAstring, restoreNilAtoms };
@@ -0,0 +1,25 @@
1
+ import type { MimeNode } from './mimeparser.js';
2
+ import type { Attribute } from './types.js';
3
+ /** Options of createBodystructure() */
4
+ export interface BodystructureOptions {
5
+ upperCaseKeys?: boolean | undefined;
6
+ skipContentLocation?: boolean | undefined;
7
+ body?: boolean | undefined;
8
+ messageGlobal?: boolean | undefined;
9
+ }
10
+ /** A BODY or BODYSTRUCTURE list, nested lists for the parts, compiled by imap-handler */
11
+ export type Bodystructure = Attribute[];
12
+ export default createBodystructure;
13
+ /**
14
+ * Generates an object out of parsed mime tree, that can be
15
+ * serialized into a BODYSTRUCTURE string
16
+ *
17
+ * @param {Object} tree Parsed mime tree (see mimeparser.ts for input)
18
+ * @param {Object} [options] Optional options object
19
+ * @param {Boolean} [options.upperCaseKeys] If true, use only upper case key names
20
+ * @param {Boolean} [options.skipContentLocation] If true, do not include Content-Location in the output
21
+ * @param {Boolean} [options.body] If true, skip extension fields (needed for BODY)
22
+ * @param {Boolean} [options.messageGlobal] If true, describe message/global like message/rfc822 (IMAP4rev2, RFC 9051 section 7.5.2)
23
+ * @return {Array} Object structure in the form of BODYSTRUCTURE
24
+ */
25
+ declare function createBodystructure(tree: MimeNode, options?: BodystructureOptions | null): Bodystructure;