@nocobase/plugin-workflow-mailer 2.4.0-alpha.1 → 2.4.0-alpha.10
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.
- package/dist/externalVersion.js +6 -6
- package/dist/node_modules/joi/dist/joi-browser.min.js +1 -1
- package/dist/node_modules/joi/lib/index.js +1 -1
- package/dist/node_modules/joi/lib/messages.js +35 -6
- package/dist/node_modules/joi/lib/types/keys.js +18 -1
- package/dist/node_modules/joi/lib/types/link.js +18 -2
- package/dist/node_modules/joi/lib/types/string.js +2 -2
- package/dist/node_modules/joi/package.json +1 -1
- package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.d.ts +59 -0
- package/dist/node_modules/nodemailer/dist/cjs/addressparser/index.js +790 -0
- package/dist/node_modules/nodemailer/dist/cjs/base64/index.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/cjs/base64/index.js +119 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/index.d.ts +52 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/index.js +228 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.d.ts +48 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/message-parser.js +180 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/relaxed-body.js +148 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.d.ts +52 -0
- package/dist/node_modules/nodemailer/dist/cjs/dkim/sign.js +165 -0
- package/dist/node_modules/nodemailer/dist/cjs/errors.d.ts +96 -0
- package/dist/node_modules/nodemailer/dist/cjs/errors.js +70 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.d.ts +107 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/cookies.js +282 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/cjs/fetch/index.js +384 -0
- package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.d.ts +64 -0
- package/dist/node_modules/nodemailer/dist/cjs/json-transport/index.js +99 -0
- package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.d.ts +174 -0
- package/dist/node_modules/nodemailer/dist/cjs/mail-composer/index.js +613 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/index.d.ts +237 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/index.js +415 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.d.ts +97 -0
- package/dist/node_modules/nodemailer/dist/cjs/mailer/mail-message.js +342 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.d.ts +161 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/index.js +787 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-funcs/mime-types.js +2103 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.d.ts +333 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/index.js +1493 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.d.ts +5 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/last-newline.js +32 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.d.ts +9 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-unix.js +40 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.d.ts +10 -0
- package/dist/node_modules/nodemailer/dist/cjs/mime-node/le-windows.js +47 -0
- package/dist/node_modules/nodemailer/dist/cjs/nodemailer.d.ts +124 -0
- package/dist/node_modules/nodemailer/dist/cjs/nodemailer.js +1 -0
- package/dist/node_modules/nodemailer/dist/cjs/package-info.d.ts +3 -0
- package/dist/node_modules/nodemailer/dist/cjs/package-info.js +7 -0
- package/dist/node_modules/nodemailer/dist/cjs/package.json +3 -0
- package/dist/node_modules/nodemailer/dist/cjs/punycode/index.d.ts +73 -0
- package/dist/node_modules/nodemailer/{lib → dist/cjs}/punycode/index.js +63 -112
- package/dist/node_modules/nodemailer/dist/cjs/qp/index.d.ts +32 -0
- package/dist/node_modules/nodemailer/dist/cjs/qp/index.js +207 -0
- package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.d.ts +69 -0
- package/dist/node_modules/nodemailer/dist/cjs/sendmail-transport/index.js +210 -0
- package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.d.ts +112 -0
- package/dist/node_modules/nodemailer/dist/cjs/ses-transport/index.js +252 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/index.d.ts +260 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/index.js +680 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/objects.d.ts +23 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/objects.js +43 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/url.d.ts +21 -0
- package/dist/node_modules/nodemailer/dist/cjs/shared/url.js +255 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.d.ts +15 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/data-stream.js +108 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.d.ts +47 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/http-proxy-client.js +189 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.d.ts +416 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-connection/index.js +1837 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.d.ts +133 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/index.js +569 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.d.ts +62 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-pool/pool-resource.js +257 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.d.ts +156 -0
- package/dist/node_modules/nodemailer/dist/cjs/smtp-transport/index.js +371 -0
- package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/cjs/stream-transport/index.js +146 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/index.d.ts +35 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/index.js +41 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/services.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/cjs/well-known/services.js +674 -0
- package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.d.ts +201 -0
- package/dist/node_modules/nodemailer/dist/cjs/xoauth2/index.js +426 -0
- package/dist/node_modules/nodemailer/dist/esm/addressparser/index.d.ts +59 -0
- package/dist/node_modules/nodemailer/dist/esm/addressparser/index.js +786 -0
- package/dist/node_modules/nodemailer/dist/esm/base64/index.d.ts +36 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/base64/index.js +39 -68
- package/dist/node_modules/nodemailer/dist/esm/dkim/index.d.ts +52 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/dkim/index.js +62 -92
- package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.d.ts +48 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/message-parser.js +176 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.d.ts +36 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/relaxed-body.js +141 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/sign.d.ts +52 -0
- package/dist/node_modules/nodemailer/dist/esm/dkim/sign.js +125 -0
- package/dist/node_modules/nodemailer/dist/esm/errors.d.ts +96 -0
- package/dist/node_modules/nodemailer/dist/esm/errors.js +67 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.d.ts +107 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/cookies.js +242 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/esm/fetch/index.js +344 -0
- package/dist/node_modules/nodemailer/dist/esm/json-transport/index.d.ts +64 -0
- package/dist/node_modules/nodemailer/dist/esm/json-transport/index.js +62 -0
- package/dist/node_modules/nodemailer/dist/esm/mail-composer/index.d.ts +174 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mail-composer/index.js +283 -275
- package/dist/node_modules/nodemailer/dist/esm/mailer/index.d.ts +237 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/index.js +151 -205
- package/dist/node_modules/nodemailer/dist/esm/mailer/mail-message.d.ts +97 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mailer/mail-message.js +111 -125
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.d.ts +161 -0
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/index.js +738 -0
- package/dist/node_modules/nodemailer/dist/esm/mime-funcs/mime-types.d.ts +2 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-funcs/mime-types.js +43 -49
- package/dist/node_modules/nodemailer/dist/esm/mime-node/index.d.ts +333 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/index.js +576 -437
- package/dist/node_modules/nodemailer/dist/esm/mime-node/last-newline.d.ts +5 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/last-newline.js +4 -10
- package/dist/node_modules/nodemailer/dist/esm/mime-node/le-unix.d.ts +9 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-unix.js +7 -15
- package/dist/node_modules/nodemailer/dist/esm/mime-node/le-windows.d.ts +10 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/mime-node/le-windows.js +6 -16
- package/dist/node_modules/nodemailer/dist/esm/nodemailer.d.ts +124 -0
- package/dist/node_modules/nodemailer/dist/esm/nodemailer.js +166 -0
- package/dist/node_modules/nodemailer/dist/esm/package-info.d.ts +3 -0
- package/dist/node_modules/nodemailer/dist/esm/package-info.js +4 -0
- package/dist/node_modules/nodemailer/dist/esm/package.json +3 -0
- package/dist/node_modules/nodemailer/dist/esm/punycode/index.d.ts +73 -0
- package/dist/node_modules/nodemailer/dist/esm/punycode/index.js +405 -0
- package/dist/node_modules/nodemailer/dist/esm/qp/index.d.ts +32 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/qp/index.js +59 -77
- package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.d.ts +69 -0
- package/dist/node_modules/nodemailer/dist/esm/sendmail-transport/index.js +170 -0
- package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.d.ts +112 -0
- package/dist/node_modules/nodemailer/dist/esm/ses-transport/index.js +212 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/index.d.ts +260 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/index.js +631 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/objects.d.ts +23 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/objects.js +38 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/url.d.ts +21 -0
- package/dist/node_modules/nodemailer/dist/esm/shared/url.js +214 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.d.ts +15 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/data-stream.js +103 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.d.ts +47 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/http-proxy-client.js +149 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.d.ts +416 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-connection/index.js +1797 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-pool/index.d.ts +133 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/index.js +195 -314
- package/dist/node_modules/nodemailer/dist/esm/smtp-pool/pool-resource.d.ts +62 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/smtp-pool/pool-resource.js +70 -107
- package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.d.ts +156 -0
- package/dist/node_modules/nodemailer/dist/esm/smtp-transport/index.js +331 -0
- package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.d.ts +65 -0
- package/dist/node_modules/nodemailer/dist/esm/stream-transport/index.js +106 -0
- package/dist/node_modules/nodemailer/dist/esm/well-known/index.d.ts +35 -0
- package/dist/node_modules/nodemailer/{lib → dist/esm}/well-known/index.js +12 -23
- package/dist/node_modules/nodemailer/dist/esm/well-known/services.d.ts +2 -0
- package/dist/node_modules/nodemailer/dist/esm/well-known/services.js +671 -0
- package/dist/node_modules/nodemailer/dist/esm/xoauth2/index.d.ts +201 -0
- package/dist/node_modules/nodemailer/dist/esm/xoauth2/index.js +386 -0
- package/dist/node_modules/nodemailer/dist/well-known/services.json +640 -0
- package/dist/node_modules/nodemailer/package.json +1 -1
- package/package.json +4 -4
- package/dist/node_modules/nodemailer/.gitattributes +0 -6
- package/dist/node_modules/nodemailer/.ncurc.js +0 -7
- package/dist/node_modules/nodemailer/.prettierrc.js +0 -8
- package/dist/node_modules/nodemailer/lib/addressparser/index.js +0 -313
- package/dist/node_modules/nodemailer/lib/dkim/message-parser.js +0 -155
- package/dist/node_modules/nodemailer/lib/dkim/relaxed-body.js +0 -154
- package/dist/node_modules/nodemailer/lib/dkim/sign.js +0 -117
- package/dist/node_modules/nodemailer/lib/fetch/cookies.js +0 -281
- package/dist/node_modules/nodemailer/lib/fetch/index.js +0 -274
- package/dist/node_modules/nodemailer/lib/json-transport/index.js +0 -82
- package/dist/node_modules/nodemailer/lib/mime-funcs/index.js +0 -625
- package/dist/node_modules/nodemailer/lib/nodemailer.js +0 -1
- package/dist/node_modules/nodemailer/lib/sendmail-transport/index.js +0 -210
- package/dist/node_modules/nodemailer/lib/ses-transport/index.js +0 -349
- package/dist/node_modules/nodemailer/lib/shared/index.js +0 -688
- package/dist/node_modules/nodemailer/lib/smtp-connection/data-stream.js +0 -108
- package/dist/node_modules/nodemailer/lib/smtp-connection/http-proxy-client.js +0 -143
- package/dist/node_modules/nodemailer/lib/smtp-connection/index.js +0 -1825
- package/dist/node_modules/nodemailer/lib/smtp-transport/index.js +0 -416
- package/dist/node_modules/nodemailer/lib/stream-transport/index.js +0 -135
- package/dist/node_modules/nodemailer/lib/well-known/services.json +0 -343
- package/dist/node_modules/nodemailer/lib/xoauth2/index.js +0 -376
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import * as shared from '../shared/index.js';
|
|
3
|
+
import type { SMTPTransportOptions, SMTPTransportGetSocketCallback, SMTPTransportSendCallback, SMTPSentMessageInfo } from '../smtp-transport/index.js';
|
|
4
|
+
import type MailMessage from '../mailer/mail-message.js';
|
|
5
|
+
import type { default as Mail, SendMailOptions, VerifyCallback } from '../mailer/index.js';
|
|
6
|
+
/**
|
|
7
|
+
* Options for the pooled SMTP transport, the SMTP transport options plus the pool settings
|
|
8
|
+
*/
|
|
9
|
+
export interface SMTPPoolOptions extends SMTPTransportOptions {
|
|
10
|
+
/** Set to true to get this pooled transport from createTransport */
|
|
11
|
+
pool?: boolean | undefined;
|
|
12
|
+
/** Maximum number of open connections, defaults to 5 */
|
|
13
|
+
maxConnections?: number | undefined;
|
|
14
|
+
/** Number of messages a connection sends before it is closed and replaced, defaults to 100 */
|
|
15
|
+
maxMessages?: number | undefined;
|
|
16
|
+
/** Maximum number of messages to send in rateDelta milliseconds, unlimited when not set */
|
|
17
|
+
rateLimit?: number | undefined;
|
|
18
|
+
/** Time window for rateLimit in milliseconds, defaults to 1000 */
|
|
19
|
+
rateDelta?: number | undefined;
|
|
20
|
+
/** How many times a message is requeued when its connection closes while sending, defaults to 5, a negative value means unlimited */
|
|
21
|
+
maxRequeues?: number | undefined;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The pool options once the constructor has applied the defaults
|
|
25
|
+
*/
|
|
26
|
+
export type SMTPPoolResolvedOptions = SMTPPoolOptions & {
|
|
27
|
+
maxConnections: number;
|
|
28
|
+
maxMessages: number;
|
|
29
|
+
maxRequeues: number;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Result of a message sent through the pool, same as for the SMTP transport
|
|
33
|
+
*/
|
|
34
|
+
export type SMTPPoolSentMessageInfo = SMTPSentMessageInfo;
|
|
35
|
+
/**
|
|
36
|
+
* Callback for send()
|
|
37
|
+
*/
|
|
38
|
+
export type SMTPPoolSendCallback = SMTPTransportSendCallback;
|
|
39
|
+
/**
|
|
40
|
+
* A message waiting in the pool queue
|
|
41
|
+
*/
|
|
42
|
+
export interface SMTPPoolQueueEntry {
|
|
43
|
+
/** The message to send */
|
|
44
|
+
mail: MailMessage;
|
|
45
|
+
/** How many times the entry was put back on the queue after its connection closed */
|
|
46
|
+
requeueAttempts: number;
|
|
47
|
+
/** Callback to run once the message is sent or failed */
|
|
48
|
+
callback: SMTPPoolSendCallback;
|
|
49
|
+
/** Message-ID value without the angle brackets, set when the entry is assigned to a connection */
|
|
50
|
+
messageId?: string | undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Rate limiter state of the pool
|
|
54
|
+
*/
|
|
55
|
+
export interface SMTPPoolRateLimit {
|
|
56
|
+
/** Messages assigned within the current window */
|
|
57
|
+
counter: number;
|
|
58
|
+
/** Timer that clears the current window */
|
|
59
|
+
timeout: NodeJS.Timeout | null;
|
|
60
|
+
/** Availability callbacks waiting for the window to clear */
|
|
61
|
+
waiting: Array<() => void>;
|
|
62
|
+
/** Start of the current window as a timestamp, false when no window is open */
|
|
63
|
+
checkpoint: number | false;
|
|
64
|
+
/** Window length in milliseconds */
|
|
65
|
+
delta: number;
|
|
66
|
+
/** Maximum number of messages per window, 0 for no limit */
|
|
67
|
+
limit: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Creates a SMTP pool transport object for Nodemailer
|
|
71
|
+
*
|
|
72
|
+
* @constructor
|
|
73
|
+
* @param options SMTP Connection options
|
|
74
|
+
*/
|
|
75
|
+
declare class SMTPPool extends EventEmitter {
|
|
76
|
+
options: SMTPPoolResolvedOptions;
|
|
77
|
+
logger: shared.Logger;
|
|
78
|
+
name: string;
|
|
79
|
+
version: string;
|
|
80
|
+
idling: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* The Mail instance using this transport, assigned by Mail
|
|
83
|
+
*/
|
|
84
|
+
mailer?: Mail<SMTPPoolSentMessageInfo, SMTPPoolOptions> | undefined;
|
|
85
|
+
constructor(options?: SMTPPoolOptions | string);
|
|
86
|
+
/**
|
|
87
|
+
* Placeholder function for creating proxy sockets. This method immediatelly returns
|
|
88
|
+
* without a socket
|
|
89
|
+
*
|
|
90
|
+
* @param options Connection options
|
|
91
|
+
* @param callback Callback function to run with the socket keys
|
|
92
|
+
*/
|
|
93
|
+
getSocket(options: SMTPPoolOptions, callback: SMTPTransportGetSocketCallback): void;
|
|
94
|
+
/**
|
|
95
|
+
* Queues an e-mail to be sent using the selected settings
|
|
96
|
+
*
|
|
97
|
+
* @param mail Mail object
|
|
98
|
+
* @param callback Callback function
|
|
99
|
+
*/
|
|
100
|
+
send(mail: MailMessage<SMTPPoolSentMessageInfo>, callback: SMTPPoolSendCallback): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Closes all connections in the pool. If there is a message being sent, the connection
|
|
103
|
+
* is closed later
|
|
104
|
+
*/
|
|
105
|
+
close(): void;
|
|
106
|
+
/**
|
|
107
|
+
* Returns true if there are free slots in the queue
|
|
108
|
+
*/
|
|
109
|
+
isIdle(): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Verifies SMTP configuration
|
|
112
|
+
*
|
|
113
|
+
* @returns Promise that resolves to true if the configuration is usable
|
|
114
|
+
*/
|
|
115
|
+
verify(): Promise<true>;
|
|
116
|
+
/**
|
|
117
|
+
* Verifies SMTP configuration
|
|
118
|
+
*
|
|
119
|
+
* @param callback Callback function
|
|
120
|
+
*/
|
|
121
|
+
verify(callback: VerifyCallback): void;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Type aliases in the layout of @types/nodemailer, so `SMTPPool.Options` style references keep working
|
|
125
|
+
*/
|
|
126
|
+
declare namespace SMTPPool {
|
|
127
|
+
type Options = SMTPPoolOptions;
|
|
128
|
+
type MailOptions = SendMailOptions;
|
|
129
|
+
type SentMessageInfo = SMTPPoolSentMessageInfo;
|
|
130
|
+
}
|
|
131
|
+
/** The same aliases as module level exports, for `import * as SMTPPool` and `import SMTPPool = require()` */
|
|
132
|
+
export type { SMTPPoolOptions as Options, SendMailOptions as MailOptions, SMTPPoolSentMessageInfo as SentMessageInfo };
|
|
133
|
+
export default SMTPPool;
|
|
@@ -0,0 +1,569 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const node_events_1 = require("node:events");
|
|
40
|
+
const pool_resource_js_1 = __importDefault(require("./pool-resource.js"));
|
|
41
|
+
const index_js_1 = __importDefault(require("../smtp-connection/index.js"));
|
|
42
|
+
const index_js_2 = __importDefault(require("../well-known/index.js"));
|
|
43
|
+
const shared = __importStar(require("../shared/index.js"));
|
|
44
|
+
const errors = __importStar(require("../errors.js"));
|
|
45
|
+
const packageData = __importStar(require("../package-info.js"));
|
|
46
|
+
/** First delay before a requeued message is retried, doubled on every further requeue */
|
|
47
|
+
const REQUEUE_BASE_DELAY = 50;
|
|
48
|
+
/** Upper bound for the requeue delay */
|
|
49
|
+
const REQUEUE_MAX_DELAY = 2000;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a SMTP pool transport object for Nodemailer
|
|
52
|
+
*
|
|
53
|
+
* @constructor
|
|
54
|
+
* @param options SMTP Connection options
|
|
55
|
+
*/
|
|
56
|
+
class SMTPPool extends node_events_1.EventEmitter {
|
|
57
|
+
constructor(options) {
|
|
58
|
+
super();
|
|
59
|
+
options = options || {};
|
|
60
|
+
if (typeof options === 'string') {
|
|
61
|
+
options = {
|
|
62
|
+
url: options
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
let urlData;
|
|
66
|
+
let service = options.service;
|
|
67
|
+
if (typeof options.getSocket === 'function') {
|
|
68
|
+
this.getSocket = options.getSocket;
|
|
69
|
+
}
|
|
70
|
+
if (options.url) {
|
|
71
|
+
urlData = shared.parseConnectionUrl(options.url);
|
|
72
|
+
service = service || urlData.service;
|
|
73
|
+
}
|
|
74
|
+
this.options = shared.assign(false, // create new object
|
|
75
|
+
options, // regular options
|
|
76
|
+
urlData, // url options
|
|
77
|
+
(service && (0, index_js_2.default)(service)) // wellknown options
|
|
78
|
+
);
|
|
79
|
+
this.options.maxConnections = this.options.maxConnections || 5;
|
|
80
|
+
this.options.maxMessages = this.options.maxMessages || 100;
|
|
81
|
+
// a default bound, a server that closes every connection before the greeting would otherwise be retried forever
|
|
82
|
+
this.options.maxRequeues = typeof this.options.maxRequeues === 'number' ? this.options.maxRequeues : 5;
|
|
83
|
+
this.logger = shared.getLogger(this.options, {
|
|
84
|
+
component: this.options.component || 'smtp-pool'
|
|
85
|
+
});
|
|
86
|
+
this.name = 'SMTP (pool)';
|
|
87
|
+
this.version = packageData.version + '[client:' + packageData.version + ']';
|
|
88
|
+
this._rateLimit = {
|
|
89
|
+
counter: 0,
|
|
90
|
+
timeout: null,
|
|
91
|
+
waiting: [],
|
|
92
|
+
checkpoint: false,
|
|
93
|
+
delta: Number(this.options.rateDelta) || 1000,
|
|
94
|
+
limit: Number(this.options.rateLimit) || 0
|
|
95
|
+
};
|
|
96
|
+
this._closed = false;
|
|
97
|
+
this._queue = [];
|
|
98
|
+
this._connections = [];
|
|
99
|
+
this._connectionCounter = 0;
|
|
100
|
+
this.idling = true;
|
|
101
|
+
setImmediate(() => {
|
|
102
|
+
if (this.idling) {
|
|
103
|
+
this.emit('idle');
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Placeholder function for creating proxy sockets. This method immediatelly returns
|
|
109
|
+
* without a socket
|
|
110
|
+
*
|
|
111
|
+
* @param options Connection options
|
|
112
|
+
* @param callback Callback function to run with the socket keys
|
|
113
|
+
*/
|
|
114
|
+
getSocket(options, callback) {
|
|
115
|
+
// return immediatelly
|
|
116
|
+
setImmediate(() => callback(null, false));
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Queues an e-mail to be sent using the selected settings
|
|
120
|
+
*
|
|
121
|
+
* @param mail Mail object
|
|
122
|
+
* @param callback Callback function
|
|
123
|
+
*/
|
|
124
|
+
send(mail, callback) {
|
|
125
|
+
if (this._closed) {
|
|
126
|
+
// Mail.sendMail ignores the return value, so without a callback its promise would never settle
|
|
127
|
+
const err = new Error('Connection pool was closed');
|
|
128
|
+
err.code = errors.ECONNECTION;
|
|
129
|
+
setImmediate(() => callback(err));
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
this._queue.push({
|
|
133
|
+
mail,
|
|
134
|
+
requeueAttempts: 0,
|
|
135
|
+
callback
|
|
136
|
+
});
|
|
137
|
+
if (this.idling && this._queue.length >= this.options.maxConnections) {
|
|
138
|
+
this.idling = false;
|
|
139
|
+
}
|
|
140
|
+
setImmediate(() => this._processMessages());
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Closes all connections in the pool. If there is a message being sent, the connection
|
|
145
|
+
* is closed later
|
|
146
|
+
*/
|
|
147
|
+
close() {
|
|
148
|
+
let connection;
|
|
149
|
+
const len = this._connections.length;
|
|
150
|
+
this._closed = true;
|
|
151
|
+
// release connections gated by the rate limiter so they become
|
|
152
|
+
// available and are torn down below instead of leaking with a
|
|
153
|
+
// cleared timer that never fires
|
|
154
|
+
this._clearRateLimit();
|
|
155
|
+
if (!len && !this._queue.length) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
// remove all available connections
|
|
159
|
+
for (let i = len - 1; i >= 0; i--) {
|
|
160
|
+
if (this._connections[i] && this._connections[i].available) {
|
|
161
|
+
connection = this._connections[i];
|
|
162
|
+
connection.close();
|
|
163
|
+
this.logger.info({
|
|
164
|
+
tnx: 'connection',
|
|
165
|
+
cid: connection.id,
|
|
166
|
+
action: 'removed'
|
|
167
|
+
}, 'Connection #%s removed', connection.id);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (len && !this._connections.length) {
|
|
171
|
+
this.logger.debug({
|
|
172
|
+
tnx: 'connection'
|
|
173
|
+
}, 'All connections removed');
|
|
174
|
+
}
|
|
175
|
+
if (!this._queue.length) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
// make sure that entire queue would be cleaned
|
|
179
|
+
const invokeCallbacks = () => {
|
|
180
|
+
if (!this._queue.length) {
|
|
181
|
+
this.logger.debug({
|
|
182
|
+
tnx: 'connection'
|
|
183
|
+
}, 'Pending queue entries cleared');
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const entry = this._queue.shift();
|
|
187
|
+
if (entry && typeof entry.callback === 'function') {
|
|
188
|
+
try {
|
|
189
|
+
entry.callback(new Error('Connection pool was closed'));
|
|
190
|
+
}
|
|
191
|
+
catch (E) {
|
|
192
|
+
// the queue is drained without a connection, so there is no cid to log
|
|
193
|
+
this.logger.error({
|
|
194
|
+
err: E,
|
|
195
|
+
tnx: 'callback'
|
|
196
|
+
}, 'Callback error: %s', E.message);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
setImmediate(invokeCallbacks);
|
|
200
|
+
};
|
|
201
|
+
setImmediate(invokeCallbacks);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Check the queue and available connections. If there is a message to be sent and there is
|
|
205
|
+
* an available connection, then use this connection to send the mail
|
|
206
|
+
* @internal
|
|
207
|
+
*/
|
|
208
|
+
_processMessages() {
|
|
209
|
+
// do nothing if already closed
|
|
210
|
+
if (this._closed) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
// do nothing if queue is empty
|
|
214
|
+
if (!this._queue.length) {
|
|
215
|
+
if (!this.idling) {
|
|
216
|
+
// no pending jobs
|
|
217
|
+
this.idling = true;
|
|
218
|
+
this.emit('idle');
|
|
219
|
+
}
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// find first available connection
|
|
223
|
+
let connection = this._connections.find(c => c.available);
|
|
224
|
+
if (!connection && this._connections.length < this.options.maxConnections) {
|
|
225
|
+
connection = this._createConnection();
|
|
226
|
+
}
|
|
227
|
+
if (!connection) {
|
|
228
|
+
// no more free connection slots available
|
|
229
|
+
this.idling = false;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
// check if there is free space in the processing queue
|
|
233
|
+
if (!this.idling && this._queue.length < this.options.maxConnections) {
|
|
234
|
+
this.idling = true;
|
|
235
|
+
this.emit('idle');
|
|
236
|
+
}
|
|
237
|
+
const entry = (connection.queueEntry = this._queue.shift());
|
|
238
|
+
entry.messageId = (connection.queueEntry.mail.message.getHeader('message-id') || '').replace(/[<>\s]/g, '');
|
|
239
|
+
connection.available = false;
|
|
240
|
+
this.logger.debug({
|
|
241
|
+
tnx: 'pool',
|
|
242
|
+
cid: connection.id,
|
|
243
|
+
messageId: entry.messageId,
|
|
244
|
+
action: 'assign'
|
|
245
|
+
}, 'Assigned message <%s> to #%s (%s)', entry.messageId, connection.id, connection.messages + 1);
|
|
246
|
+
if (this._rateLimit.limit) {
|
|
247
|
+
this._rateLimit.counter++;
|
|
248
|
+
if (!this._rateLimit.checkpoint) {
|
|
249
|
+
this._rateLimit.checkpoint = Date.now();
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
connection.send(entry.mail, (err, info) => {
|
|
253
|
+
// only process callback if current handler is not changed
|
|
254
|
+
if (entry === connection.queueEntry) {
|
|
255
|
+
try {
|
|
256
|
+
entry.callback(err, info);
|
|
257
|
+
}
|
|
258
|
+
catch (E) {
|
|
259
|
+
this.logger.error({
|
|
260
|
+
err: E,
|
|
261
|
+
tnx: 'callback',
|
|
262
|
+
cid: connection.id
|
|
263
|
+
}, 'Callback error for #%s: %s', connection.id, E.message);
|
|
264
|
+
}
|
|
265
|
+
connection.queueEntry = false;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Creates a new pool resource
|
|
271
|
+
* @internal
|
|
272
|
+
*/
|
|
273
|
+
_createConnection() {
|
|
274
|
+
const connection = new pool_resource_js_1.default(this);
|
|
275
|
+
connection.id = ++this._connectionCounter;
|
|
276
|
+
this.logger.info({
|
|
277
|
+
tnx: 'pool',
|
|
278
|
+
cid: connection.id,
|
|
279
|
+
action: 'conection'
|
|
280
|
+
}, 'Created new pool resource #%s', connection.id);
|
|
281
|
+
// resource comes available
|
|
282
|
+
connection.on('available', () => {
|
|
283
|
+
this.logger.debug({
|
|
284
|
+
tnx: 'connection',
|
|
285
|
+
cid: connection.id,
|
|
286
|
+
action: 'available'
|
|
287
|
+
}, 'Connection #%s became available', connection.id);
|
|
288
|
+
if (this._closed) {
|
|
289
|
+
// if already closed run close() that will remove this connections from connections list
|
|
290
|
+
this.close();
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
// check if there's anything else to send
|
|
294
|
+
this._processMessages();
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
// resource is terminated with an error
|
|
298
|
+
connection.once('error', (err) => {
|
|
299
|
+
if (err.code !== errors.EMAXLIMIT) {
|
|
300
|
+
this.logger.warn({
|
|
301
|
+
err,
|
|
302
|
+
tnx: 'pool',
|
|
303
|
+
cid: connection.id
|
|
304
|
+
}, 'Pool Error for #%s: %s', connection.id, err.message);
|
|
305
|
+
}
|
|
306
|
+
else {
|
|
307
|
+
this.logger.debug({
|
|
308
|
+
tnx: 'pool',
|
|
309
|
+
cid: connection.id,
|
|
310
|
+
action: 'maxlimit'
|
|
311
|
+
}, 'Max messages limit exchausted for #%s', connection.id);
|
|
312
|
+
}
|
|
313
|
+
if (connection.queueEntry) {
|
|
314
|
+
try {
|
|
315
|
+
connection.queueEntry.callback(err);
|
|
316
|
+
}
|
|
317
|
+
catch (E) {
|
|
318
|
+
this.logger.error({
|
|
319
|
+
err: E,
|
|
320
|
+
tnx: 'callback',
|
|
321
|
+
cid: connection.id
|
|
322
|
+
}, 'Callback error for #%s: %s', connection.id, E.message);
|
|
323
|
+
}
|
|
324
|
+
connection.queueEntry = false;
|
|
325
|
+
}
|
|
326
|
+
// remove the erroneus connection from connections list
|
|
327
|
+
this._removeConnection(connection);
|
|
328
|
+
this._continueProcessing();
|
|
329
|
+
});
|
|
330
|
+
connection.once('close', () => {
|
|
331
|
+
this.logger.info({
|
|
332
|
+
tnx: 'connection',
|
|
333
|
+
cid: connection.id,
|
|
334
|
+
action: 'closed'
|
|
335
|
+
}, 'Connection #%s was closed', connection.id);
|
|
336
|
+
this._removeConnection(connection);
|
|
337
|
+
if (connection.queueEntry) {
|
|
338
|
+
// If the connection closed when sending, add the message to the queue again
|
|
339
|
+
// if max number of requeues is not reached yet
|
|
340
|
+
// Note that we must wait a bit.. because the callback of the 'error' handler might be called
|
|
341
|
+
// in the next event loop
|
|
342
|
+
setTimeout(() => {
|
|
343
|
+
let delay = 0;
|
|
344
|
+
if (connection.queueEntry) {
|
|
345
|
+
if (this._shouldRequeuOnConnectionClose(connection.queueEntry)) {
|
|
346
|
+
delay = this._requeueEntryOnConnectionClose(connection);
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
this._failDeliveryOnConnectionClose(connection);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (delay) {
|
|
353
|
+
// back off, a server that keeps dropping connections is not hammered
|
|
354
|
+
setTimeout(() => this._continueProcessing(), delay);
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
this._continueProcessing();
|
|
358
|
+
}
|
|
359
|
+
}, 50);
|
|
360
|
+
}
|
|
361
|
+
else {
|
|
362
|
+
if (!this._closed && this.idling && !this._connections.length) {
|
|
363
|
+
this.emit('clear');
|
|
364
|
+
}
|
|
365
|
+
this._continueProcessing();
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
this._connections.push(connection);
|
|
369
|
+
return connection;
|
|
370
|
+
}
|
|
371
|
+
/** @internal */
|
|
372
|
+
_shouldRequeuOnConnectionClose(queueEntry) {
|
|
373
|
+
if (this.options.maxRequeues < 0) {
|
|
374
|
+
return true;
|
|
375
|
+
}
|
|
376
|
+
return queueEntry.requeueAttempts < this.options.maxRequeues;
|
|
377
|
+
}
|
|
378
|
+
/** @internal */
|
|
379
|
+
_failDeliveryOnConnectionClose(connection) {
|
|
380
|
+
if (connection.queueEntry && connection.queueEntry.callback) {
|
|
381
|
+
try {
|
|
382
|
+
const err = new Error('Reached maximum number of retries after connection was closed');
|
|
383
|
+
err.code = errors.ECONNECTION;
|
|
384
|
+
connection.queueEntry.callback(err);
|
|
385
|
+
}
|
|
386
|
+
catch (E) {
|
|
387
|
+
this.logger.error({
|
|
388
|
+
err: E,
|
|
389
|
+
tnx: 'callback',
|
|
390
|
+
messageId: connection.queueEntry.messageId,
|
|
391
|
+
cid: connection.id
|
|
392
|
+
}, 'Callback error for #%s: %s', connection.id, E.message);
|
|
393
|
+
}
|
|
394
|
+
connection.queueEntry = false;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
/** @internal */
|
|
398
|
+
_requeueEntryOnConnectionClose(connection) {
|
|
399
|
+
const delay = Math.min(REQUEUE_BASE_DELAY * 2 ** connection.queueEntry.requeueAttempts, REQUEUE_MAX_DELAY);
|
|
400
|
+
connection.queueEntry.requeueAttempts += 1;
|
|
401
|
+
this.logger.debug({
|
|
402
|
+
tnx: 'pool',
|
|
403
|
+
cid: connection.id,
|
|
404
|
+
messageId: connection.queueEntry.messageId,
|
|
405
|
+
action: 'requeue'
|
|
406
|
+
}, 'Re-queued message <%s> for #%s. Attempt: #%s', connection.queueEntry.messageId, connection.id, connection.queueEntry.requeueAttempts);
|
|
407
|
+
this._queue.unshift(connection.queueEntry);
|
|
408
|
+
connection.queueEntry = false;
|
|
409
|
+
return delay;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Continue to process message if the pool hasn't closed
|
|
413
|
+
* @internal
|
|
414
|
+
*/
|
|
415
|
+
_continueProcessing() {
|
|
416
|
+
if (this._closed) {
|
|
417
|
+
this.close();
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
setTimeout(() => this._processMessages(), 100);
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Remove resource from pool
|
|
425
|
+
*
|
|
426
|
+
* @param connection The PoolResource to remove
|
|
427
|
+
* @internal
|
|
428
|
+
*/
|
|
429
|
+
_removeConnection(connection) {
|
|
430
|
+
const index = this._connections.indexOf(connection);
|
|
431
|
+
if (index !== -1) {
|
|
432
|
+
this._connections.splice(index, 1);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Checks if connections have hit current rate limit and if so, queues the availability callback
|
|
437
|
+
*
|
|
438
|
+
* @param callback Callback function to run once rate limiter has been cleared
|
|
439
|
+
* @internal
|
|
440
|
+
*/
|
|
441
|
+
_checkRateLimit(callback) {
|
|
442
|
+
if (!this._rateLimit.limit) {
|
|
443
|
+
return callback();
|
|
444
|
+
}
|
|
445
|
+
const now = Date.now();
|
|
446
|
+
if (this._rateLimit.counter < this._rateLimit.limit) {
|
|
447
|
+
return callback();
|
|
448
|
+
}
|
|
449
|
+
this._rateLimit.waiting.push(callback);
|
|
450
|
+
if (this._rateLimit.checkpoint <= now - this._rateLimit.delta) {
|
|
451
|
+
return this._clearRateLimit();
|
|
452
|
+
}
|
|
453
|
+
if (!this._rateLimit.timeout) {
|
|
454
|
+
this._rateLimit.timeout = setTimeout(() => this._clearRateLimit(), this._rateLimit.delta - (now - this._rateLimit.checkpoint));
|
|
455
|
+
this._rateLimit.checkpoint = now;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Clears current rate limit limitation and runs paused callback
|
|
460
|
+
* @internal
|
|
461
|
+
*/
|
|
462
|
+
_clearRateLimit() {
|
|
463
|
+
clearTimeout(this._rateLimit.timeout);
|
|
464
|
+
this._rateLimit.timeout = null;
|
|
465
|
+
this._rateLimit.counter = 0;
|
|
466
|
+
this._rateLimit.checkpoint = false;
|
|
467
|
+
// resume all paused connections
|
|
468
|
+
while (this._rateLimit.waiting.length) {
|
|
469
|
+
const cb = this._rateLimit.waiting.shift();
|
|
470
|
+
setImmediate(cb);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* Returns true if there are free slots in the queue
|
|
475
|
+
*/
|
|
476
|
+
isIdle() {
|
|
477
|
+
return this.idling;
|
|
478
|
+
}
|
|
479
|
+
verify(callback) {
|
|
480
|
+
let promise;
|
|
481
|
+
if (!callback) {
|
|
482
|
+
promise = new Promise((resolve, reject) => {
|
|
483
|
+
callback = shared.callbackPromise(resolve, reject);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
// the error paths hand over the error alone
|
|
487
|
+
const done = callback;
|
|
488
|
+
const auth = new pool_resource_js_1.default(this).auth;
|
|
489
|
+
this.getSocket(this.options, (err, socketOptions) => {
|
|
490
|
+
if (err) {
|
|
491
|
+
return done(err);
|
|
492
|
+
}
|
|
493
|
+
let options = this.options;
|
|
494
|
+
if (socketOptions && socketOptions.connection) {
|
|
495
|
+
this.logger.info({
|
|
496
|
+
tnx: 'proxy',
|
|
497
|
+
remoteAddress: socketOptions.connection.remoteAddress,
|
|
498
|
+
remotePort: socketOptions.connection.remotePort,
|
|
499
|
+
destHost: options.host || '',
|
|
500
|
+
destPort: options.port || '',
|
|
501
|
+
action: 'connected'
|
|
502
|
+
}, 'Using proxied socket from %s:%s to %s:%s', socketOptions.connection.remoteAddress, socketOptions.connection.remotePort, options.host || '', options.port || '');
|
|
503
|
+
options = Object.assign(shared.assign(false, options), socketOptions);
|
|
504
|
+
}
|
|
505
|
+
const connection = new index_js_1.default(options);
|
|
506
|
+
let returned = false;
|
|
507
|
+
connection.once('error', err => {
|
|
508
|
+
if (returned) {
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
returned = true;
|
|
512
|
+
connection.close();
|
|
513
|
+
return done(err);
|
|
514
|
+
});
|
|
515
|
+
connection.once('end', () => {
|
|
516
|
+
if (returned) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
returned = true;
|
|
520
|
+
return done(new Error('Connection closed'));
|
|
521
|
+
});
|
|
522
|
+
const finalize = () => {
|
|
523
|
+
if (returned) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
returned = true;
|
|
527
|
+
connection.quit();
|
|
528
|
+
return done(null, true);
|
|
529
|
+
};
|
|
530
|
+
connection.connect(err => {
|
|
531
|
+
if (returned) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
if (err) {
|
|
535
|
+
returned = true;
|
|
536
|
+
connection.close();
|
|
537
|
+
return done(err);
|
|
538
|
+
}
|
|
539
|
+
if (auth && (connection.allowsAuth || options.forceAuth)) {
|
|
540
|
+
connection.login(auth, err => {
|
|
541
|
+
if (returned) {
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (err) {
|
|
545
|
+
returned = true;
|
|
546
|
+
connection.close();
|
|
547
|
+
return done(err);
|
|
548
|
+
}
|
|
549
|
+
finalize();
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
else if (!auth && connection.allowsAuth && options.forceAuth) {
|
|
553
|
+
const err = new Error('Authentication info was not provided');
|
|
554
|
+
err.code = errors.ENOAUTH;
|
|
555
|
+
returned = true;
|
|
556
|
+
connection.close();
|
|
557
|
+
return done(err);
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
finalize();
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
});
|
|
564
|
+
return promise;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
exports.default = SMTPPool;
|
|
568
|
+
module.exports = exports.default;
|
|
569
|
+
Object.defineProperty(module.exports, 'default', { value: exports.default, enumerable: false, writable: true, configurable: true });
|