@push.rocks/smartmta 5.1.2 → 5.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/changelog.md +14 -0
  2. package/dist_ts/00_commitinfo_data.d.ts +8 -0
  3. package/dist_ts/00_commitinfo_data.js +9 -0
  4. package/dist_ts/index.d.ts +3 -0
  5. package/dist_ts/index.js +4 -0
  6. package/dist_ts/logger.d.ts +17 -0
  7. package/dist_ts/logger.js +76 -0
  8. package/dist_ts/mail/core/classes.bouncemanager.d.ts +185 -0
  9. package/dist_ts/mail/core/classes.bouncemanager.js +569 -0
  10. package/dist_ts/mail/core/classes.email.d.ts +291 -0
  11. package/dist_ts/mail/core/classes.email.js +802 -0
  12. package/dist_ts/mail/core/classes.emailvalidator.d.ts +61 -0
  13. package/dist_ts/mail/core/classes.emailvalidator.js +184 -0
  14. package/dist_ts/mail/core/classes.templatemanager.d.ts +95 -0
  15. package/dist_ts/mail/core/classes.templatemanager.js +240 -0
  16. package/dist_ts/mail/core/index.d.ts +4 -0
  17. package/dist_ts/mail/core/index.js +6 -0
  18. package/dist_ts/mail/delivery/classes.delivery.queue.d.ts +163 -0
  19. package/dist_ts/mail/delivery/classes.delivery.queue.js +488 -0
  20. package/dist_ts/mail/delivery/classes.delivery.system.d.ts +160 -0
  21. package/dist_ts/mail/delivery/classes.delivery.system.js +630 -0
  22. package/dist_ts/mail/delivery/classes.unified.rate.limiter.d.ts +200 -0
  23. package/dist_ts/mail/delivery/classes.unified.rate.limiter.js +820 -0
  24. package/dist_ts/mail/delivery/index.d.ts +4 -0
  25. package/dist_ts/mail/delivery/index.js +6 -0
  26. package/dist_ts/mail/delivery/interfaces.d.ts +140 -0
  27. package/dist_ts/mail/delivery/interfaces.js +17 -0
  28. package/dist_ts/mail/index.d.ts +7 -0
  29. package/dist_ts/mail/index.js +12 -0
  30. package/dist_ts/mail/routing/classes.dkim.manager.d.ts +25 -0
  31. package/dist_ts/mail/routing/classes.dkim.manager.js +127 -0
  32. package/dist_ts/mail/routing/classes.dns.manager.d.ts +79 -0
  33. package/dist_ts/mail/routing/classes.dns.manager.js +415 -0
  34. package/dist_ts/mail/routing/classes.domain.registry.d.ts +54 -0
  35. package/dist_ts/mail/routing/classes.domain.registry.js +119 -0
  36. package/dist_ts/mail/routing/classes.email.action.executor.d.ts +33 -0
  37. package/dist_ts/mail/routing/classes.email.action.executor.js +137 -0
  38. package/dist_ts/mail/routing/classes.email.router.d.ts +171 -0
  39. package/dist_ts/mail/routing/classes.email.router.js +494 -0
  40. package/dist_ts/mail/routing/classes.unified.email.server.d.ts +241 -0
  41. package/dist_ts/mail/routing/classes.unified.email.server.js +935 -0
  42. package/dist_ts/mail/routing/index.d.ts +7 -0
  43. package/dist_ts/mail/routing/index.js +9 -0
  44. package/dist_ts/mail/routing/interfaces.d.ts +187 -0
  45. package/dist_ts/mail/routing/interfaces.js +2 -0
  46. package/dist_ts/mail/security/classes.dkimcreator.d.ts +72 -0
  47. package/dist_ts/mail/security/classes.dkimcreator.js +360 -0
  48. package/dist_ts/mail/security/classes.spfverifier.d.ts +62 -0
  49. package/dist_ts/mail/security/classes.spfverifier.js +87 -0
  50. package/dist_ts/mail/security/index.d.ts +2 -0
  51. package/dist_ts/mail/security/index.js +4 -0
  52. package/dist_ts/paths.d.ts +14 -0
  53. package/dist_ts/paths.js +39 -0
  54. package/dist_ts/plugins.d.ts +24 -0
  55. package/dist_ts/plugins.js +28 -0
  56. package/dist_ts/security/classes.contentscanner.d.ts +130 -0
  57. package/dist_ts/security/classes.contentscanner.js +338 -0
  58. package/dist_ts/security/classes.ipreputationchecker.d.ts +73 -0
  59. package/dist_ts/security/classes.ipreputationchecker.js +263 -0
  60. package/dist_ts/security/classes.rustsecuritybridge.d.ts +398 -0
  61. package/dist_ts/security/classes.rustsecuritybridge.js +484 -0
  62. package/dist_ts/security/classes.securitylogger.d.ts +140 -0
  63. package/dist_ts/security/classes.securitylogger.js +235 -0
  64. package/dist_ts/security/index.d.ts +4 -0
  65. package/dist_ts/security/index.js +5 -0
  66. package/package.json +6 -1
  67. package/readme.md +52 -9
  68. package/ts/00_commitinfo_data.ts +8 -0
  69. package/ts/index.ts +3 -0
  70. package/ts/logger.ts +91 -0
  71. package/ts/mail/core/classes.bouncemanager.ts +731 -0
  72. package/ts/mail/core/classes.email.ts +942 -0
  73. package/ts/mail/core/classes.emailvalidator.ts +239 -0
  74. package/ts/mail/core/classes.templatemanager.ts +320 -0
  75. package/ts/mail/core/index.ts +5 -0
  76. package/ts/mail/delivery/classes.delivery.queue.ts +645 -0
  77. package/ts/mail/delivery/classes.delivery.system.ts +816 -0
  78. package/ts/mail/delivery/classes.unified.rate.limiter.ts +1053 -0
  79. package/ts/mail/delivery/index.ts +5 -0
  80. package/ts/mail/delivery/interfaces.ts +167 -0
  81. package/ts/mail/index.ts +17 -0
  82. package/ts/mail/routing/classes.dkim.manager.ts +157 -0
  83. package/ts/mail/routing/classes.dns.manager.ts +573 -0
  84. package/ts/mail/routing/classes.domain.registry.ts +139 -0
  85. package/ts/mail/routing/classes.email.action.executor.ts +175 -0
  86. package/ts/mail/routing/classes.email.router.ts +575 -0
  87. package/ts/mail/routing/classes.unified.email.server.ts +1207 -0
  88. package/ts/mail/routing/index.ts +9 -0
  89. package/ts/mail/routing/interfaces.ts +202 -0
  90. package/ts/mail/security/classes.dkimcreator.ts +447 -0
  91. package/ts/mail/security/classes.spfverifier.ts +126 -0
  92. package/ts/mail/security/index.ts +3 -0
  93. package/ts/paths.ts +48 -0
  94. package/ts/plugins.ts +53 -0
  95. package/ts/security/classes.contentscanner.ts +400 -0
  96. package/ts/security/classes.ipreputationchecker.ts +315 -0
  97. package/ts/security/classes.rustsecuritybridge.ts +943 -0
  98. package/ts/security/classes.securitylogger.ts +299 -0
  99. package/ts/security/index.ts +40 -0
@@ -0,0 +1,291 @@
1
+ import * as plugins from '../../plugins.js';
2
+ export interface IAttachment {
3
+ filename: string;
4
+ content: Buffer;
5
+ contentType: string;
6
+ contentId?: string;
7
+ encoding?: string;
8
+ }
9
+ export interface IEmailOptions {
10
+ from: string;
11
+ to?: string | string[];
12
+ cc?: string | string[];
13
+ bcc?: string | string[];
14
+ subject: string;
15
+ text: string;
16
+ html?: string;
17
+ attachments?: IAttachment[];
18
+ headers?: Record<string, string>;
19
+ mightBeSpam?: boolean;
20
+ priority?: 'high' | 'normal' | 'low';
21
+ skipAdvancedValidation?: boolean;
22
+ variables?: Record<string, any>;
23
+ }
24
+ /**
25
+ * Email class represents a complete email message.
26
+ *
27
+ * This class takes IEmailOptions in the constructor and normalizes the data:
28
+ * - 'to', 'cc', 'bcc' are always converted to arrays
29
+ * - Optional properties get default values
30
+ * - Additional properties like messageId and envelopeFrom are generated
31
+ */
32
+ export declare class Email {
33
+ from: string;
34
+ to: string[];
35
+ cc: string[];
36
+ bcc: string[];
37
+ subject: string;
38
+ text: string;
39
+ html?: string;
40
+ attachments: IAttachment[];
41
+ headers: Record<string, string>;
42
+ mightBeSpam: boolean;
43
+ priority: 'high' | 'normal' | 'low';
44
+ variables: Record<string, any>;
45
+ private envelopeFrom;
46
+ private messageId;
47
+ private static emailValidator;
48
+ constructor(options: IEmailOptions);
49
+ /**
50
+ * Validates an email address using smartmail's EmailAddressValidator
51
+ * For constructor validation, we only check syntax to avoid delays
52
+ * Supports RFC-compliant addresses including display names and bounce addresses.
53
+ *
54
+ * @param email The email address to validate
55
+ * @returns boolean indicating if the email is valid
56
+ */
57
+ private isValidEmail;
58
+ /**
59
+ * Extracts the email address from a string that may contain a display name.
60
+ * Handles formats like:
61
+ * - simple@example.com
62
+ * - "John Doe" <john@example.com>
63
+ * - John Doe <john@example.com>
64
+ *
65
+ * @param emailString The email string to parse
66
+ * @returns The extracted email address or null
67
+ */
68
+ private extractEmailAddress;
69
+ /**
70
+ * Parses and validates recipient email addresses
71
+ * @param recipients A string or array of recipient emails
72
+ * @returns Array of validated email addresses
73
+ */
74
+ private parseRecipients;
75
+ /**
76
+ * Basic sanitization for strings to prevent header injection
77
+ * @param input The string to sanitize
78
+ * @returns Sanitized string
79
+ */
80
+ private sanitizeString;
81
+ /**
82
+ * Gets the domain part of the from email address
83
+ * @returns The domain part of the from email or null if invalid
84
+ */
85
+ getFromDomain(): string | null;
86
+ /**
87
+ * Gets the clean from email address without display name
88
+ * @returns The email address without display name
89
+ */
90
+ getFromAddress(): string;
91
+ /**
92
+ * Converts IDN (International Domain Names) to ASCII
93
+ * @param email The email address to convert
94
+ * @returns The email with ASCII-converted domain
95
+ */
96
+ private convertIDNToASCII;
97
+ /**
98
+ * Gets clean to email addresses without display names
99
+ * @returns Array of email addresses without display names
100
+ */
101
+ getToAddresses(): string[];
102
+ /**
103
+ * Gets clean cc email addresses without display names
104
+ * @returns Array of email addresses without display names
105
+ */
106
+ getCcAddresses(): string[];
107
+ /**
108
+ * Gets clean bcc email addresses without display names
109
+ * @returns Array of email addresses without display names
110
+ */
111
+ getBccAddresses(): string[];
112
+ /**
113
+ * Gets all recipients (to, cc, bcc) as a unique array
114
+ * @returns Array of all unique recipient email addresses
115
+ */
116
+ getAllRecipients(): string[];
117
+ /**
118
+ * Gets primary recipient (first in the to field)
119
+ * @returns The primary recipient email or null if none exists
120
+ */
121
+ getPrimaryRecipient(): string | null;
122
+ /**
123
+ * Checks if the email has attachments
124
+ * @returns Boolean indicating if the email has attachments
125
+ */
126
+ hasAttachments(): boolean;
127
+ /**
128
+ * Add a recipient to the email
129
+ * @param email The recipient email address
130
+ * @param type The recipient type (to, cc, bcc)
131
+ * @returns This instance for method chaining
132
+ */
133
+ addRecipient(email: string, type?: 'to' | 'cc' | 'bcc'): this;
134
+ /**
135
+ * Add an attachment to the email
136
+ * @param attachment The attachment to add
137
+ * @returns This instance for method chaining
138
+ */
139
+ addAttachment(attachment: IAttachment): this;
140
+ /**
141
+ * Add a custom header to the email
142
+ * @param name The header name
143
+ * @param value The header value
144
+ * @returns This instance for method chaining
145
+ */
146
+ addHeader(name: string, value: string): this;
147
+ /**
148
+ * Set the email priority
149
+ * @param priority The priority level
150
+ * @returns This instance for method chaining
151
+ */
152
+ setPriority(priority: 'high' | 'normal' | 'low'): this;
153
+ /**
154
+ * Set a template variable
155
+ * @param key The variable key
156
+ * @param value The variable value
157
+ * @returns This instance for method chaining
158
+ */
159
+ setVariable(key: string, value: any): this;
160
+ /**
161
+ * Set multiple template variables at once
162
+ * @param variables The variables object
163
+ * @returns This instance for method chaining
164
+ */
165
+ setVariables(variables: Record<string, any>): this;
166
+ /**
167
+ * Get the subject with variables applied
168
+ * @param variables Optional additional variables to apply
169
+ * @returns The processed subject
170
+ */
171
+ getSubjectWithVariables(variables?: Record<string, any>): string;
172
+ /**
173
+ * Get the text content with variables applied
174
+ * @param variables Optional additional variables to apply
175
+ * @returns The processed text content
176
+ */
177
+ getTextWithVariables(variables?: Record<string, any>): string;
178
+ /**
179
+ * Get the HTML content with variables applied
180
+ * @param variables Optional additional variables to apply
181
+ * @returns The processed HTML content or undefined if none
182
+ */
183
+ getHtmlWithVariables(variables?: Record<string, any>): string | undefined;
184
+ /**
185
+ * Apply template variables to a string
186
+ * @param template The template string
187
+ * @param additionalVariables Optional additional variables to apply
188
+ * @returns The processed string
189
+ */
190
+ private applyVariables;
191
+ /**
192
+ * Gets the total size of all attachments in bytes
193
+ * @returns Total size of all attachments in bytes
194
+ */
195
+ getAttachmentsSize(): number;
196
+ /**
197
+ * Perform advanced validation on sender and recipient email addresses
198
+ * This should be called separately after instantiation when ready to check MX records
199
+ * @param options Validation options
200
+ * @returns Promise resolving to validation results for all addresses
201
+ */
202
+ validateAddresses(options?: {
203
+ checkMx?: boolean;
204
+ checkDisposable?: boolean;
205
+ checkSenderOnly?: boolean;
206
+ checkFirstRecipientOnly?: boolean;
207
+ }): Promise<{
208
+ sender: {
209
+ email: string;
210
+ result: any;
211
+ };
212
+ recipients: Array<{
213
+ email: string;
214
+ result: any;
215
+ }>;
216
+ isValid: boolean;
217
+ }>;
218
+ /**
219
+ * Convert this email to a smartmail instance
220
+ * @returns A new Smartmail instance
221
+ */
222
+ toSmartmail(): Promise<plugins.smartmail.Smartmail<any>>;
223
+ /**
224
+ * Get the from email address
225
+ * @returns The from email address
226
+ */
227
+ getFromEmail(): string;
228
+ /**
229
+ * Get the subject (Smartmail compatibility method)
230
+ * @returns The email subject
231
+ */
232
+ getSubject(): string;
233
+ /**
234
+ * Get the body content (Smartmail compatibility method)
235
+ * @param isHtml Whether to return HTML content if available
236
+ * @returns The email body (HTML if requested and available, otherwise plain text)
237
+ */
238
+ getBody(isHtml?: boolean): string;
239
+ /**
240
+ * Get the from address (Smartmail compatibility method)
241
+ * @returns The sender email address
242
+ */
243
+ getFrom(): string;
244
+ /**
245
+ * Get the message ID
246
+ * @returns The message ID
247
+ */
248
+ getMessageId(): string;
249
+ /**
250
+ * Convert the Email instance back to IEmailOptions format.
251
+ * Useful for serialization or passing to APIs that expect IEmailOptions.
252
+ * Note: This loses some Email-specific properties like messageId and envelopeFrom.
253
+ *
254
+ * @returns IEmailOptions representation of this email
255
+ */
256
+ toEmailOptions(): IEmailOptions;
257
+ /**
258
+ * Set a custom message ID
259
+ * @param id The message ID to set
260
+ * @returns This instance for method chaining
261
+ */
262
+ setMessageId(id: string): this;
263
+ /**
264
+ * Get the envelope from address (return-path)
265
+ * @returns The envelope from address
266
+ */
267
+ getEnvelopeFrom(): string;
268
+ /**
269
+ * Set the envelope from address (return-path)
270
+ * @param address The envelope from address to set
271
+ * @returns This instance for method chaining
272
+ */
273
+ setEnvelopeFrom(address: string): this;
274
+ /**
275
+ * Creates an RFC822 compliant email string
276
+ * @param variables Optional template variables to apply
277
+ * @returns The email formatted as an RFC822 compliant string
278
+ */
279
+ toRFC822String(variables?: Record<string, any>): string;
280
+ /**
281
+ * Convert to simple Smartmail-compatible object (for backward compatibility)
282
+ * @returns A Promise with a simple Smartmail-compatible object
283
+ */
284
+ toSmartmailBasic(): Promise<any>;
285
+ /**
286
+ * Create an Email instance from a Smartmail object
287
+ * @param smartmail The Smartmail instance to convert
288
+ * @returns A new Email instance
289
+ */
290
+ static fromSmartmail(smartmail: plugins.smartmail.Smartmail<any>): Email;
291
+ }