imapkit 4.3.1 → 5.0.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 (121) hide show
  1. package/README.md +187 -67
  2. package/bin/help.txt +20 -5
  3. package/bin/imapkit.js +64 -24
  4. package/dist/cjs/commands/append.js +1 -1
  5. package/dist/cjs/commands/create.js +2 -2
  6. package/dist/cjs/commands/delete.js +2 -14
  7. package/dist/cjs/commands/handlers/fetch.js +2 -1
  8. package/dist/cjs/commands/handlers/flags.d.ts +3 -3
  9. package/dist/cjs/commands/handlers/flags.js +3 -3
  10. package/dist/cjs/commands/handlers/store.js +7 -7
  11. package/dist/cjs/commands/list.js +17 -3
  12. package/dist/cjs/commands/rename.js +6 -46
  13. package/dist/cjs/commands/select.js +1 -0
  14. package/dist/cjs/commands/subscribe.js +7 -8
  15. package/dist/cjs/commands/unsubscribe.js +3 -9
  16. package/dist/cjs/control.d.ts +425 -0
  17. package/dist/cjs/control.js +637 -0
  18. package/dist/cjs/dates.d.ts +9 -1
  19. package/dist/cjs/dates.js +20 -0
  20. package/dist/cjs/envelope.d.ts +1 -1
  21. package/dist/cjs/envelope.js +26 -1
  22. package/dist/cjs/index.d.ts +9 -1
  23. package/dist/cjs/index.js +9 -2
  24. package/dist/cjs/load-plugins.d.ts +3 -1
  25. package/dist/cjs/load-plugins.js +28 -4
  26. package/dist/cjs/plugins/acl.js +109 -42
  27. package/dist/cjs/plugins/binary.js +2 -1
  28. package/dist/cjs/plugins/condstore.js +7 -0
  29. package/dist/cjs/plugins/context-search.js +2 -2
  30. package/dist/cjs/plugins/create-special-use.d.ts +0 -5
  31. package/dist/cjs/plugins/create-special-use.js +11 -1
  32. package/dist/cjs/plugins/imap4rev2.js +5 -0
  33. package/dist/cjs/plugins/index.js +1 -3
  34. package/dist/cjs/plugins/metadata-server.d.ts +6 -2
  35. package/dist/cjs/plugins/metadata-server.js +3 -1
  36. package/dist/cjs/plugins/metadata.d.ts +5 -1
  37. package/dist/cjs/plugins/metadata.js +143 -57
  38. package/dist/cjs/plugins/objectid.js +10 -0
  39. package/dist/cjs/plugins/quota.js +50 -2
  40. package/dist/cjs/plugins/savedate.js +1 -1
  41. package/dist/cjs/plugins/special-use.d.ts +0 -8
  42. package/dist/cjs/plugins/special-use.js +23 -0
  43. package/dist/cjs/quirks.d.ts +28 -0
  44. package/dist/cjs/quirks.js +125 -0
  45. package/dist/cjs/random.d.ts +10 -0
  46. package/dist/cjs/random.js +22 -0
  47. package/dist/cjs/rest.d.ts +54 -0
  48. package/dist/cjs/rest.js +567 -0
  49. package/dist/cjs/script.d.ts +33 -4
  50. package/dist/cjs/script.js +64 -4
  51. package/dist/cjs/server.d.ts +199 -9
  52. package/dist/cjs/server.js +603 -227
  53. package/dist/cjs/smtp-listener.d.ts +3 -2
  54. package/dist/cjs/smtp-listener.js +10 -6
  55. package/dist/cjs/storage-schema.d.ts +139 -0
  56. package/dist/cjs/storage-schema.js +222 -0
  57. package/dist/cjs/store-operations.d.ts +171 -0
  58. package/dist/cjs/store-operations.js +425 -0
  59. package/dist/cjs/types.d.ts +26 -1
  60. package/dist/esm/commands/append.js +1 -1
  61. package/dist/esm/commands/create.js +2 -2
  62. package/dist/esm/commands/delete.js +2 -14
  63. package/dist/esm/commands/handlers/fetch.js +2 -1
  64. package/dist/esm/commands/handlers/flags.d.ts +3 -3
  65. package/dist/esm/commands/handlers/flags.js +3 -3
  66. package/dist/esm/commands/handlers/store.js +7 -7
  67. package/dist/esm/commands/list.js +17 -3
  68. package/dist/esm/commands/rename.js +6 -46
  69. package/dist/esm/commands/select.js +1 -0
  70. package/dist/esm/commands/subscribe.js +7 -8
  71. package/dist/esm/commands/unsubscribe.js +3 -9
  72. package/dist/esm/control.d.ts +425 -0
  73. package/dist/esm/control.js +630 -0
  74. package/dist/esm/dates.d.ts +9 -1
  75. package/dist/esm/dates.js +20 -1
  76. package/dist/esm/envelope.d.ts +1 -1
  77. package/dist/esm/envelope.js +26 -1
  78. package/dist/esm/index.d.ts +9 -1
  79. package/dist/esm/index.js +5 -2
  80. package/dist/esm/load-plugins.d.ts +3 -1
  81. package/dist/esm/load-plugins.js +28 -4
  82. package/dist/esm/plugins/acl.js +109 -42
  83. package/dist/esm/plugins/binary.js +2 -1
  84. package/dist/esm/plugins/condstore.js +7 -0
  85. package/dist/esm/plugins/context-search.js +2 -2
  86. package/dist/esm/plugins/create-special-use.d.ts +0 -5
  87. package/dist/esm/plugins/create-special-use.js +8 -1
  88. package/dist/esm/plugins/imap4rev2.js +5 -0
  89. package/dist/esm/plugins/index.js +1 -3
  90. package/dist/esm/plugins/metadata-server.d.ts +6 -2
  91. package/dist/esm/plugins/metadata-server.js +3 -1
  92. package/dist/esm/plugins/metadata.d.ts +5 -1
  93. package/dist/esm/plugins/metadata.js +143 -57
  94. package/dist/esm/plugins/objectid.js +10 -0
  95. package/dist/esm/plugins/quota.js +50 -2
  96. package/dist/esm/plugins/savedate.js +1 -1
  97. package/dist/esm/plugins/special-use.d.ts +0 -8
  98. package/dist/esm/plugins/special-use.js +23 -0
  99. package/dist/esm/quirks.d.ts +28 -0
  100. package/dist/esm/quirks.js +121 -0
  101. package/dist/esm/random.d.ts +10 -0
  102. package/dist/esm/random.js +19 -0
  103. package/dist/esm/rest.d.ts +54 -0
  104. package/dist/esm/rest.js +559 -0
  105. package/dist/esm/script.d.ts +33 -4
  106. package/dist/esm/script.js +63 -4
  107. package/dist/esm/server.d.ts +199 -9
  108. package/dist/esm/server.js +606 -230
  109. package/dist/esm/smtp-listener.d.ts +3 -2
  110. package/dist/esm/smtp-listener.js +10 -6
  111. package/dist/esm/storage-schema.d.ts +139 -0
  112. package/dist/esm/storage-schema.js +218 -0
  113. package/dist/esm/store-operations.d.ts +171 -0
  114. package/dist/esm/store-operations.js +410 -0
  115. package/dist/esm/types.d.ts +26 -1
  116. package/dist/plugin-help.json +3 -16
  117. package/package.json +11 -3
  118. package/dist/cjs/plugins/xtoybird.d.ts +0 -2
  119. package/dist/cjs/plugins/xtoybird.js +0 -236
  120. package/dist/esm/plugins/xtoybird.d.ts +0 -2
  121. package/dist/esm/plugins/xtoybird.js +0 -218
@@ -0,0 +1,425 @@
1
+ /**
2
+ * The control API, `server.control`: inspects and changes the server state from a test, without an IMAP session.
3
+ * Every change reaches the connected sessions as if another session had made it (EXISTS, EXPUNGE or VANISHED,
4
+ * unsolicited FETCH, BYE, NOTIFY events, CONDSTORE mod-sequences), with no session as its origin. The API is the
5
+ * operator: ACL does not apply, but every argument is checked. Mailboxes are addressed by their storage name
6
+ * (modified UTF-7), messages by mailbox and UID. Methods return plain data and throw an ImapKitError with a `code`:
7
+ * NONEXISTENT, ALREADYEXISTS, INVALID, or the response code of a failed mailbox operation (CANNOT, HASCHILDREN ...)
8
+ */
9
+ import { ImapKitError } from './store-operations.js';
10
+ import type { FlagMode, UidValidityOptions } from './store-operations.js';
11
+ import type { IMAPConnection, IMAPServer, Mailbox, Message, StorageMailbox, StorageNamespace, UserData } from './types.js';
12
+ /** A mailbox as `getMailbox()` and `listMailboxes()` describe it */
13
+ interface MailboxInfo {
14
+ path: string;
15
+ delimiter: string;
16
+ /** mailbox attributes, e.g. \Noselect, \HasChildren */
17
+ flags: string[];
18
+ /** false for a \Noselect name that only holds child mailboxes */
19
+ selectable: boolean;
20
+ subscribed: boolean;
21
+ messages: number;
22
+ unseen: number;
23
+ uidnext: number;
24
+ uidvalidity: number;
25
+ /** the flags of the FLAGS response, SELECT adds \* to PERMANENTFLAGS when new keywords are allowed */
26
+ permanentFlags: string[];
27
+ /** only with CONDSTORE */
28
+ highestModseq?: number;
29
+ /** only with SPECIAL-USE */
30
+ specialUse?: string[];
31
+ /** only with OBJECTID */
32
+ mailboxId?: string;
33
+ }
34
+ /** A message as `getMessage()` and `listMessages()` describe it */
35
+ interface MessageInfo {
36
+ uid: number;
37
+ flags: string[];
38
+ internaldate: string;
39
+ /** size of the source in octets */
40
+ size: number;
41
+ /** only with CONDSTORE */
42
+ modseq?: number;
43
+ /** only with OBJECTID */
44
+ emailId?: string;
45
+ threadId?: string;
46
+ /** the message source, only when asked for */
47
+ raw?: Buffer;
48
+ }
49
+ /** A connected session as `sessions()` describes it */
50
+ interface SessionInfo {
51
+ session: number;
52
+ user: string | null;
53
+ state: string;
54
+ /** storage name of the selected mailbox */
55
+ mailbox: string | null;
56
+ readOnly: boolean;
57
+ /** extensions enabled with ENABLE */
58
+ enabled: string[];
59
+ secure: boolean;
60
+ compressed: boolean;
61
+ remoteAddress: string | null;
62
+ }
63
+ interface NewMessage {
64
+ /** the message source, a string is encoded as UTF-8 */
65
+ raw: string | Uint8Array;
66
+ flags?: string[] | undefined;
67
+ /** a Date or a RFC 3501 date-time string, the current time if not set */
68
+ internaldate?: Date | string | undefined;
69
+ }
70
+ /** The credentials of a user, see UserData */
71
+ type UserOptions = Pick<UserData, 'password' | 'xoauth2'>;
72
+ /** What a REST route handler gets, see src/rest.ts */
73
+ interface RouteRequest {
74
+ params: Record<string, string>;
75
+ query: URLSearchParams;
76
+ body: any;
77
+ }
78
+ /** A REST route of the control API, see src/rest.ts */
79
+ interface ControlRoute {
80
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE';
81
+ /** URL path, `{name}` matches one URL encoded segment */
82
+ path: string;
83
+ summary: string;
84
+ /** returns the response body, `{ status, body }` for another status than 200 */
85
+ handler(request: RouteRequest): unknown;
86
+ }
87
+ /** Selects sessions: a session number, or the sessions of a user */
88
+ type SessionFilter = number | {
89
+ session?: number | undefined;
90
+ user?: string | undefined;
91
+ };
92
+ declare class Control {
93
+ [key: string]: any;
94
+ server: IMAPServer;
95
+ /** REST routes that plugins registered, the REST API serves them after its own */
96
+ routes: ControlRoute[];
97
+ /** `(mailbox, copy)` functions that put plugin data that is not JSON into the snapshot of a mailbox */
98
+ snapshotHandlers: ((mailbox: Mailbox, copy: StorageMailbox) => void)[];
99
+ /** `(mailbox, info)` and `(message, info)` functions that add plugin fields to getMailbox() and getMessage() */
100
+ mailboxInfoHandlers: ((mailbox: Mailbox, info: MailboxInfo) => void)[];
101
+ messageInfoHandlers: ((message: Message, info: MessageInfo) => void)[];
102
+ constructor(server: IMAPServer);
103
+ /**
104
+ * Adds an operation of a plugin, e.g. `server.control.setAcl()` of ACL, so that a plugin that is not loaded
105
+ * leaves no trace. The operation runs with no session as its origin, like the built-in ones, and throws
106
+ * ImapKitErrors (see storeError() in store-operations.ts)
107
+ *
108
+ * @param {String} name Method name on server.control
109
+ * @param {Function} fn Operation
110
+ * @param {Array} [routes] REST routes of the operation
111
+ */
112
+ register(name: string, fn: (...args: any[]) => unknown, routes?: ControlRoute[]): void;
113
+ /**
114
+ * Runs a change with no session as its origin, also when a listener of a command event calls the API
115
+ *
116
+ * @param {Function} fn Change
117
+ * @return {*} the result of fn
118
+ */
119
+ run<T>(fn: () => T): T;
120
+ /**
121
+ * Finds a mailbox by its storage name
122
+ *
123
+ * @param {String} path Storage name, INBOX in any case
124
+ * @param {Boolean} [selectable] true if the mailbox must hold messages (not \Noselect)
125
+ * @return {Object} mailbox
126
+ * @throws {ImapKitError} NONEXISTENT
127
+ */
128
+ requireMailbox(path: unknown, selectable?: boolean): Mailbox;
129
+ /**
130
+ * Checks a new mailbox name
131
+ *
132
+ * @param {String} path Storage name
133
+ * @throws {ImapKitError} INVALID for a name that is not valid modified UTF-7
134
+ */
135
+ checkName(path: unknown): asserts path is string;
136
+ /**
137
+ * Checks that a mailbox argument is a name, the store operations check the rest
138
+ *
139
+ * @param {String} path Storage name
140
+ * @throws {ImapKitError} INVALID
141
+ */
142
+ checkPath(path: unknown): asserts path is string;
143
+ /**
144
+ * Finds messages by UID
145
+ *
146
+ * @param {Object} mailbox Mailbox
147
+ * @param {Array} uids UIDs of the messages
148
+ * @return {Array} messages in the order of the UIDs, without duplicates
149
+ * @throws {ImapKitError} INVALID for a list that is not UIDs, NONEXISTENT for a UID that is not in the mailbox
150
+ */
151
+ requireMessages(mailbox: Mailbox, uids: unknown): Message[];
152
+ /**
153
+ * Finds the sessions a filter selects
154
+ *
155
+ * @param {Number|Object} filter A session number, or `{ session, user }`
156
+ * @return {Array} connections
157
+ */
158
+ findSessions(filter: SessionFilter): IMAPConnection[];
159
+ /**
160
+ * Returns the storage as JSON data in the shape of the `storage` option, so that `imapkit({ storage })` with it
161
+ * starts from the same mailboxes, messages, UIDs, flags and subscriptions. Plugin data on mailboxes and messages
162
+ * is included as far as it is JSON data. Subscriptions of names that are not mailboxes are not part of it
163
+ *
164
+ * @return {Object} storage
165
+ */
166
+ snapshot(): Record<string, StorageNamespace>;
167
+ /**
168
+ * Describes every mailbox, including \Noselect hierarchy levels
169
+ *
170
+ * @return {Array} mailboxes ordered by name
171
+ */
172
+ listMailboxes(): MailboxInfo[];
173
+ /**
174
+ * Describes a mailbox
175
+ *
176
+ * @param {String} path Storage name
177
+ * @return {Object} mailbox info
178
+ */
179
+ getMailbox(path: string): MailboxInfo;
180
+ describeMailbox(mailbox: Mailbox): MailboxInfo;
181
+ /**
182
+ * Describes the messages of a mailbox
183
+ *
184
+ * @param {String} path Storage name
185
+ * @param {Object} [options] `{ uids, raw }`: only these UIDs, include the message source
186
+ * @return {Array} messages ordered by UID
187
+ */
188
+ listMessages(path: string, options?: {
189
+ uids?: number[] | undefined;
190
+ raw?: boolean | undefined;
191
+ }): MessageInfo[];
192
+ /**
193
+ * Describes a message
194
+ *
195
+ * @param {String} path Storage name
196
+ * @param {Number} uid UID of the message
197
+ * @param {Object} [options] `{ raw }`: include the message source, true by default
198
+ * @return {Object} message info
199
+ */
200
+ getMessage(path: string, uid: number, options?: {
201
+ raw?: boolean | undefined;
202
+ }): MessageInfo;
203
+ describeMessage(message: Message, raw: boolean): MessageInfo;
204
+ /**
205
+ * Describes the connected sessions
206
+ *
207
+ * @return {Array} sessions ordered by number
208
+ */
209
+ sessions(): SessionInfo[];
210
+ /**
211
+ * Adds a message to a mailbox, like a delivery from outside: sessions that have the mailbox selected get EXISTS,
212
+ * the first read-write one sees it as \Recent
213
+ *
214
+ * @param {String} path Storage name
215
+ * @param {Object} message `{ raw, flags, internaldate }`
216
+ * @param {Object} [options] `{ checks }`: true runs the checks APPEND runs (QUOTA, APPENDLIMIT ...), a failed
217
+ * one throws an ImapKitError with its response code, e.g. OVERQUOTA
218
+ * @return {Object} `{ uid, uidvalidity }`
219
+ */
220
+ addMessage(path: string, message: NewMessage, options?: {
221
+ checks?: boolean | undefined;
222
+ }): {
223
+ uid: number;
224
+ uidvalidity: number;
225
+ };
226
+ /**
227
+ * Changes the flags of messages. Sessions that have the mailbox selected get unsolicited FETCH responses, with
228
+ * CONDSTORE the messages get new mod-sequences
229
+ *
230
+ * @param {String} path Storage name
231
+ * @param {Array} uids UIDs of the messages
232
+ * @param {Array} flags Flags
233
+ * @param {String} [mode] "set" (default), "add" or "remove"
234
+ * @return {Array} `{ uid, flags }` of every message
235
+ */
236
+ setFlags(path: string, uids: number[], flags: string[], mode?: FlagMode): {
237
+ uid: number;
238
+ flags: string[];
239
+ }[];
240
+ /**
241
+ * Removes messages. Sessions that have the mailbox selected get EXPUNGE (VANISHED with QRESYNC), following the
242
+ * RFC 2180 rules a session's EXPUNGE would
243
+ *
244
+ * @param {String} path Storage name
245
+ * @param {Array} uids UIDs of the messages
246
+ * @return {Array} the removed UIDs
247
+ */
248
+ expungeMessages(path: string, uids: number[]): number[];
249
+ /**
250
+ * Copies messages to another mailbox, the copies keep flags and internal date and get new UIDs
251
+ *
252
+ * @param {String} path Storage name of the source
253
+ * @param {Array} uids UIDs of the messages
254
+ * @param {String} target Storage name of the target
255
+ * @return {Object} `{ uidvalidity, uids }`: UIDVALIDITY of the target, `{ uid, targetUid }` for every message
256
+ */
257
+ copyMessages(path: string, uids: number[], target: string): {
258
+ uidvalidity: number;
259
+ uids: {
260
+ uid: number;
261
+ targetUid: number;
262
+ }[];
263
+ };
264
+ /**
265
+ * Moves messages to another mailbox: copies them and expunges them from the source
266
+ *
267
+ * @param {String} path Storage name of the source
268
+ * @param {Array} uids UIDs of the messages
269
+ * @param {String} target Storage name of the target
270
+ * @return {Object} `{ uidvalidity, uids }`: UIDVALIDITY of the target, `{ uid, targetUid }` for every message
271
+ */
272
+ moveMessages(path: string, uids: number[], target: string): {
273
+ uidvalidity: number;
274
+ uids: {
275
+ uid: number;
276
+ targetUid: number;
277
+ }[];
278
+ };
279
+ transfer(path: string, uids: number[], target: string, move: boolean): {
280
+ uidvalidity: number;
281
+ uids: {
282
+ uid: number;
283
+ targetUid: number;
284
+ }[];
285
+ };
286
+ /**
287
+ * Replaces a message. The content of a UID never changes (RFC 9051 section 2.3.1.1), so this adds the new
288
+ * message and expunges the old one, the new message gets a new UID. Flags and internal date of the old
289
+ * message are kept unless given
290
+ *
291
+ * @param {String} path Storage name
292
+ * @param {Number} uid UID of the message to replace
293
+ * @param {Object} message `{ raw, flags, internaldate }`
294
+ * @return {Object} `{ uid, uidvalidity }` of the new message
295
+ */
296
+ replaceMessage(path: string, uid: number, message: NewMessage): {
297
+ uid: number;
298
+ uidvalidity: number;
299
+ };
300
+ /**
301
+ * Creates a mailbox, with any missing superior levels
302
+ *
303
+ * @param {String} path Storage name
304
+ * @param {Object} [options] `{ subscribed }`
305
+ * @return {Object} mailbox info
306
+ */
307
+ createMailbox(path: string, options?: {
308
+ subscribed?: boolean | undefined;
309
+ }): MailboxInfo;
310
+ /**
311
+ * Deletes a mailbox. Sessions that have it selected are disconnected with BYE, like after DELETE in another session
312
+ *
313
+ * @param {String} path Storage name
314
+ */
315
+ deleteMailbox(path: string): void;
316
+ /**
317
+ * Renames a mailbox, with the RENAME rules (renaming INBOX moves its messages)
318
+ *
319
+ * @param {String} path Storage name
320
+ * @param {String} newPath New storage name
321
+ * @return {Object} info of the renamed mailbox
322
+ */
323
+ renameMailbox(path: string, newPath: string): MailboxInfo;
324
+ /**
325
+ * Gives a mailbox a new UIDVALIDITY, optionally with new UIDs ("keep", "renumber", "shuffle" or "offset"). Sessions
326
+ * that have the mailbox selected are disconnected with BYE, as a UID must not change during a session
327
+ *
328
+ * @param {String} path Storage name
329
+ * @param {Object} [options] `{ uidvalidity, uids, offset, seed }`
330
+ * @return {Object} `{ uidvalidity, uidnext, uids }`, `uids` lists `{ uid, newUid }` for every message
331
+ */
332
+ resetUidValidity(path: string, options?: UidValidityOptions): {
333
+ uidvalidity: number;
334
+ uidnext: number;
335
+ uids: {
336
+ uid: number;
337
+ newUid: number;
338
+ }[];
339
+ };
340
+ /**
341
+ * Subscribes a mailbox
342
+ *
343
+ * @param {String} path Storage name
344
+ * @return {Boolean} true if the subscription changed
345
+ */
346
+ subscribe(path: string): boolean;
347
+ /**
348
+ * Unsubscribes a name, it does not have to be a mailbox
349
+ *
350
+ * @param {String} path Storage name
351
+ * @return {Boolean} true if the subscription changed
352
+ */
353
+ unsubscribe(path: string): boolean;
354
+ /**
355
+ * Lists the users, without credentials
356
+ *
357
+ * @return {Array} `{ name, xoauth2 }`, xoauth2 is true for a user with an access token
358
+ */
359
+ listUsers(): {
360
+ name: string;
361
+ xoauth2: boolean;
362
+ }[];
363
+ /**
364
+ * Adds a user
365
+ *
366
+ * @param {String} name User name
367
+ * @param {Object} options `{ password, xoauth2: { accessToken, sessionTimeout } }`
368
+ */
369
+ addUser(name: string, options: UserOptions): void;
370
+ /**
371
+ * Changes the password or the XOAUTH2 token of a user
372
+ *
373
+ * @param {String} name User name
374
+ * @param {Object} options `{ password, xoauth2 }`, null xoauth2 removes the token
375
+ */
376
+ updateUser(name: string, options: UserOptions): void;
377
+ /**
378
+ * Deletes a user, its sessions are disconnected with BYE unless `disconnect` is false
379
+ *
380
+ * @param {String} name User name
381
+ * @param {Object} [options] `{ disconnect }`
382
+ */
383
+ deleteUser(name: string, options?: {
384
+ disconnect?: boolean | undefined;
385
+ }): void;
386
+ requireUser(name: unknown): UserData;
387
+ userData(user: UserData, options: UserOptions): UserData;
388
+ /**
389
+ * Disconnects sessions
390
+ *
391
+ * @param {Number|Object} filter A session number, or `{ session, user }`
392
+ * @param {Object} [options] `{ text, reset }`: the text of the untagged BYE, or reset the TCP connection without BYE
393
+ * @return {Number} how many sessions were disconnected
394
+ */
395
+ disconnect(filter: SessionFilter, options?: {
396
+ text?: string | undefined;
397
+ reset?: boolean | undefined;
398
+ }): number;
399
+ /**
400
+ * Writes bytes to a session as they are, e.g. an untagged response between commands (ALERT, BYE, EXISTS).
401
+ * Nothing checks that they are valid IMAP
402
+ *
403
+ * @param {Number} session Session number
404
+ * @param {String|Buffer} data Bytes to send, a string is encoded as UTF-8
405
+ */
406
+ inject(session: number, data: string | Uint8Array): void;
407
+ /**
408
+ * Restores the mailboxes and users of the server options and disconnects every session with BYE, so that a
409
+ * long running server (the imapkit command) can be reused between tests. Plugins restore their own state on
410
+ * the `reset` event (QUOTA limits, server annotations). Script rules stay, `server.script.clear()` removes them
411
+ */
412
+ reset(): void;
413
+ /**
414
+ * Stops the server. A graceful shutdown stops accepting connections and waits until the clients disconnect,
415
+ * otherwise the sessions are closed right away
416
+ *
417
+ * @param {Object} [options] `{ graceful }`, true by default
418
+ * @return {Promise} resolves when the server is closed
419
+ */
420
+ shutdown(options?: {
421
+ graceful?: boolean | undefined;
422
+ }): Promise<void>;
423
+ }
424
+ export { Control, ImapKitError };
425
+ export type { MailboxInfo, MessageInfo, SessionInfo, NewMessage, UserOptions, SessionFilter, ControlRoute, RouteRequest };