-
Notifications
You must be signed in to change notification settings - Fork 30.2k
/
index.d.ts
365 lines (334 loc) · 13.7 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
// Type definitions for smtp-server 3.5
// Project: https://github.com/nodemailer/smtp-server, https://github.com/andris9/smtp-server
// Definitions by: markisme <https://github.com/markisme>
// taisiias <https://github.com/Taisiias>
// Piotr Roszatycki <https://github.com/dex4er>
// Paul Oms <https://github.com/paul-oms>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.3
/// <reference types="node" />
/// <reference types="nodemailer" />
import { EventEmitter } from 'events';
import * as net from 'net';
import * as shared from 'nodemailer/lib/shared';
import { PassThrough } from 'stream';
import * as tls from 'tls';
export type ms = number;
export interface SMTPServerAddress {
/**
* the address provided with the MAIL FROM or RCPT TO command
*/
address: string;
/**
* an object with additional arguments (all key names are uppercase)
*/
args: object;
}
export interface SMTPServerAuthentication {
/**
* indicates the authentication method used, 'PLAIN', 'LOGIN' or 'XOAUTH2'
*/
method: 'PLAIN' | 'LOGIN' | 'XOAUTH2';
/**
* the username of the user
*/
username?: string;
/**
* the password if LOGIN or PLAIN was used
*/
password?: string;
/**
* the OAuth2 bearer access token if 'XOAUTH2' was used as the authentication method
*/
accessToken?: string;
/**
* a function for validating CRAM-MD5 challenge responses.
* Takes the password of the user as an argument and returns true if the response matches the password
*/
validatePassword(password: string): boolean;
}
export interface SMTPServerAuthenticationResponse {
/**
* can be any value - if this is set then the user is considered logged in
* and this value is used later with the session data to identify the user.
* If this value is empty, then the authentication is considered failed
*/
user?: any;
/**
* an object to return if XOAUTH2 authentication failed (do not set the error object in this case).
* This value is serialized to JSON and base64 encoded automatically, so you can just return the object
*/
data?: object;
}
export interface SMTPServerSession {
/**
* random string identificator generated when the client connected
*/
id: string;
/**
* local IP address for the connected client
*/
localAddress: string;
/**
* local port number for the connected client
*/
localPort: number;
/**
* remote IP address for the connected client
*/
remoteAddress: string;
/**
* remote port number for the connected client
*/
remotePort: number;
/**
* reverse resolved hostname for remoteAddress
*/
clientHostname: string;
/**
* the opening SMTP command (HELO/EHLO/LHLO)
*/
openingCommand: string;
/**
* hostname the client provided with HELO/EHLO call
*/
hostNameAppearsAs: string;
/**
* Envelope Object
*/
envelope: SMTPServerEnvelope;
/**
* If true, then the connection is using TLS
*/
secure: boolean;
transmissionType: string;
tlsOptions: tls.TlsOptions;
/*
* Optional parameter that is added to the session object if provided to the onAuth callback
*/
user?: string;
}
export interface SMTPServerDataStream extends PassThrough {
/**
* number of bytes read from DATA stream
*/
byteLength: number;
/**
* boolean, if set to true, the message was oversized.
* When creating the server you can define maximum allowed message size with
* the size option, see RFC1870 for details.
*/
sizeExceeded: boolean;
}
export interface SMTPServerEnvelope {
/**
* includes an address object or is set to false
*/
mailFrom: SMTPServerAddress | false;
/**
* includes an array of address objects
*/
rcptTo: SMTPServerAddress[];
}
export interface SMTPServerOptions extends tls.TlsOptions {
/**
* if true, the connection will use TLS. The default is false.
* If the server doesn't start in TLS mode,
* it is still possible to upgrade clear text socket to
* TLS socket with the STARTTLS command (unless you disable support for it).
* If secure is true, additional tls options for tls.
* createServer can be added directly onto this options object.
*/
secure?: boolean;
/** indicate an TLS server where TLS is handled upstream */
secured?: boolean;
/**
* optional hostname of the server,
* used for identifying to the client (defaults to os.hostname())
*/
name?: string;
/**
* optional greeting message.
* This message is appended to the default ESMTP response.
*/
banner?: string;
/**
* optional maximum allowed message size in bytes
* ([see details](https://github.com/andris9/smtp-server#using-size-extension))
*/
size?: number;
/**
* optional array of allowed authentication methods, defaults to ['PLAIN', 'LOGIN'].
* Only the methods listed in this array are allowed,
* so if you set it to ['XOAUTH2'] then PLAIN and LOGIN are not available.
* Use ['PLAIN', 'LOGIN', 'XOAUTH2'] to allow all three.
* Authentication is only allowed in secure mode
* (either the server is started with secure: true option or STARTTLS command is used)
*/
authMethods?: string[];
/**
* allow authentication, but do not require it
*/
authOptional?: boolean;
/**
* optional array of disabled commands (see all supported commands here).
* For example if you want to disable authentication,
* use ['AUTH'] as this value.
* If you want to allow authentication in clear text, set it to ['STARTTLS'].
*/
disabledCommands?: string[]; // TODO: ('AUTH' | 'STARTTLS' | 'XCLIENT' | 'XFORWARD')[];
/**
* optional boolean, if set to true then allow using STARTTLS
* but do not advertise or require it. It only makes sense
* when creating integration test servers for testing the scenario
* where you want to try STARTTLS even when it is not advertised
*/
hideSTARTTLS?: boolean;
/**
* optional boolean, if set to true then does not show PIPELINING in feature list
*/
hidePIPELINING?: boolean;
/**
* optional boolean, if set to true then does not show 8BITMIME in features list
*/
hide8BITMIME?: boolean;
/**
* optional boolean, if set to true then does not show SMTPUTF8 in features list
*/
hideSMTPUTF8?: boolean;
/**
* optional boolean, if set to true allows authentication even if connection is not secured first
*/
allowInsecureAuth?: boolean;
/**
* optional boolean, if set to true then does not try to reverse resolve client hostname
*/
disableReverseLookup?: boolean;
/**
* optional Map or an object of TLS options for SNI where servername is the key. Overrided by SNICallback.
*/
sniOptions?: { [servername: string]: tls.TlsOptions } | Map<string, tls.TlsOptions>;
/**
* optional boolean, if set to true then upgrade sockets to TLS immediately after connection is established. Works with secure: true
*/
needsUpgrade?: boolean;
/**
* optional bunyan compatible logger instance.
* If set to true then logs to console.
* If value is not set or is false then nothing is logged
*/
logger?: shared.Logger | boolean;
/**
* sets the maximum number of concurrently connected clients, defaults to Infinity
*/
maxClients?: number;
/**
* boolean, if set to true expects to be behind a proxy that emits a
* [PROXY](http://www.haproxy.org/download/1.5/doc/proxy-protocol.txt) header (version 1 only)
*/
useProxy?: boolean;
/**
* boolean, if set to true, enables usage of
* [XCLIENT](http://www.postfix.org/XCLIENT_README.html) extension to override connection properties.
* See session.xClient (Map object) for the details provided by the client
*/
useXClient?: boolean;
/**
* boolean, if set to true, enables usage of [XFORWARD](http://www.postfix.org/XFORWARD_README.html) extension.
* See session.xForward (Map object) for the details provided by the client
*/
useXForward?: boolean;
/**
* boolean, if set to true use LMTP protocol instead of SMTP
*/
lmtp?: boolean;
/**
* How many milliseconds of inactivity to allow before disconnecting the client (defaults to 1 minute)
*/
socketTimeout?: ms;
/**
* How many millisceonds to wait before disconnecting pending
* connections once `server.close()` has been called (defaults to 30 seconds)
*/
closeTimeout?: ms;
/**
* The callback to handle authentications ([see details](https://github.com/andris9/smtp-server#handling-authentication))
*/
onAuth?(auth: SMTPServerAuthentication, session: SMTPServerSession, callback: (err: Error | null | undefined, response?: SMTPServerAuthenticationResponse) => void): void;
/**
* The callback to handle the client connection. ([see details](https://github.com/andris9/smtp-server#validating-client-connection))
*/
onConnect?(session: SMTPServerSession, callback: (err?: Error | null) => void): void;
/**
* the callback to validate MAIL FROM commands ([see details](https://github.com/andris9/smtp-server#validating-sender-addresses))
*/
onMailFrom?(address: SMTPServerAddress, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
/**
* The callback to validate RCPT TO commands ([see details](https://github.com/andris9/smtp-server#validating-recipient-addresses))
*/
onRcptTo?(address: SMTPServerAddress, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
/**
* the callback to handle incoming messages ([see details](https://github.com/andris9/smtp-server#processing-incoming-message))
*/
onData?(stream: SMTPServerDataStream, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
/**
* the callback that informs about closed client connection
*/
onClose?(session: SMTPServerSession, callback: (err?: Error | null) => void): void;
}
/** Creates a SMTP server instance */
export class SMTPServer extends EventEmitter {
options: SMTPServerOptions;
logger: shared.Logger;
secureContext: Map<string, tls.SecureContext>;
connections: Set<any>;
server: net.Server;
constructor(options?: SMTPServerOptions);
/** Start listening on selected port and interface */
listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): net.Server;
listen(port?: number, hostname?: string, listeningListener?: () => void): net.Server;
listen(port?: number, backlog?: number, listeningListener?: () => void): net.Server; // tslint:disable-line unified-signatures
listen(port?: number, listeningListener?: () => void): net.Server;
listen(path: string, backlog?: number, listeningListener?: () => void): net.Server;
listen(path: string, listeningListener?: () => void): void;
listen(options: net.ListenOptions, listeningListener?: () => void): net.Server;
listen(handle: any, backlog?: number, listeningListener?: () => void): net.Server; // tslint:disable-line unified-signatures
listen(handle: any, listeningListener?: () => void): net.Server; // tslint:disable-line unified-signatures
/** Closes the server */
close(callback?: () => void): void;
updateSecureContext(options: tls.TlsOptions): void;
/** Authentication handler. Override this */
onAuth(auth: SMTPServerAuthentication, session: SMTPServerSession, callback: (err: Error | null | undefined, response?: SMTPServerAuthenticationResponse) => void): void;
/** Override this */
onClose(session: SMTPServerSession, callback: (err?: Error | null) => void): void;
/** Override this */
onConnect(session: SMTPServerSession, callback: (err?: Error | null) => void): void;
/** Override this */
onData(stream: SMTPServerDataStream, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
/** Override this */
onMailFrom(address: SMTPServerAddress, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
/** Override this */
onRcptTo(address: SMTPServerAddress, session: SMTPServerSession, callback: (err?: Error | null) => void): void;
addListener(event: 'close', listener: () => void): this;
addListener(event: 'error', listener: (err: Error) => void): this;
emit(event: 'close'): boolean;
emit(event: 'error', err: Error): boolean;
listenerCount(event: 'close' | 'error'): number;
listeners(event: 'close'): Array<() => void>;
listeners(event: 'error'): Array<(err: Error) => void>;
off(event: 'close', listener: () => void): this;
off(event: 'error', listener: (err: Error) => void): this;
on(event: 'close', listener: () => void): this;
on(event: 'error', listener: (err: Error) => void): this;
once(event: 'close', listener: () => void): this;
once(event: 'error', listener: (err: Error) => void): this;
prependListener(event: 'close', listener: () => void): this;
prependListener(event: 'error', listener: (err: Error) => void): this;
prependOnceListener(event: 'close', listener: () => void): this;
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
rawListeners(event: 'close'): Array<() => void>;
rawListeners(event: 'error'): Array<(err: Error) => void>;
removeAllListener(event: 'close' | 'error'): this;
removeListener(event: 'close', listener: () => void): this;
removeListener(event: 'error', listener: (err: Error) => void): this;
}