@push.rocks/smartmta 5.1.3 → 5.2.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 (98) hide show
  1. package/changelog.md +15 -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 +403 -0
  61. package/dist_ts/security/classes.rustsecuritybridge.js +502 -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/ts/00_commitinfo_data.ts +8 -0
  68. package/ts/index.ts +3 -0
  69. package/ts/logger.ts +91 -0
  70. package/ts/mail/core/classes.bouncemanager.ts +731 -0
  71. package/ts/mail/core/classes.email.ts +942 -0
  72. package/ts/mail/core/classes.emailvalidator.ts +239 -0
  73. package/ts/mail/core/classes.templatemanager.ts +320 -0
  74. package/ts/mail/core/index.ts +5 -0
  75. package/ts/mail/delivery/classes.delivery.queue.ts +645 -0
  76. package/ts/mail/delivery/classes.delivery.system.ts +816 -0
  77. package/ts/mail/delivery/classes.unified.rate.limiter.ts +1053 -0
  78. package/ts/mail/delivery/index.ts +5 -0
  79. package/ts/mail/delivery/interfaces.ts +167 -0
  80. package/ts/mail/index.ts +17 -0
  81. package/ts/mail/routing/classes.dkim.manager.ts +157 -0
  82. package/ts/mail/routing/classes.dns.manager.ts +573 -0
  83. package/ts/mail/routing/classes.domain.registry.ts +139 -0
  84. package/ts/mail/routing/classes.email.action.executor.ts +175 -0
  85. package/ts/mail/routing/classes.email.router.ts +575 -0
  86. package/ts/mail/routing/classes.unified.email.server.ts +1207 -0
  87. package/ts/mail/routing/index.ts +9 -0
  88. package/ts/mail/routing/interfaces.ts +202 -0
  89. package/ts/mail/security/classes.dkimcreator.ts +447 -0
  90. package/ts/mail/security/classes.spfverifier.ts +126 -0
  91. package/ts/mail/security/index.ts +3 -0
  92. package/ts/paths.ts +48 -0
  93. package/ts/plugins.ts +53 -0
  94. package/ts/security/classes.contentscanner.ts +400 -0
  95. package/ts/security/classes.ipreputationchecker.ts +315 -0
  96. package/ts/security/classes.rustsecuritybridge.ts +964 -0
  97. package/ts/security/classes.securitylogger.ts +299 -0
  98. package/ts/security/index.ts +40 -0
@@ -0,0 +1,241 @@
1
+ import { EventEmitter } from 'events';
2
+ import { DKIMCreator } from '../security/classes.dkimcreator.js';
3
+ import type { IEmailRoute, IEmailDomainConfig } from './interfaces.js';
4
+ import { Email } from '../core/classes.email.js';
5
+ import { DomainRegistry } from './classes.domain.registry.js';
6
+ import { BounceType, BounceCategory } from '../core/classes.bouncemanager.js';
7
+ import type { ISmtpSendResult } from '../../security/classes.rustsecuritybridge.js';
8
+ import { MultiModeDeliverySystem } from '../delivery/classes.delivery.system.js';
9
+ import { UnifiedDeliveryQueue } from '../delivery/classes.delivery.queue.js';
10
+ import { UnifiedRateLimiter, type IHierarchicalRateLimits } from '../delivery/classes.unified.rate.limiter.js';
11
+ import type { EmailProcessingMode, ISmtpSession as IBaseSmtpSession } from '../delivery/interfaces.js';
12
+ /** External DcRouter interface shape used by UnifiedEmailServer */
13
+ interface DcRouter {
14
+ storageManager: any;
15
+ dnsServer?: any;
16
+ options?: any;
17
+ }
18
+ /**
19
+ * Extended SMTP session interface with route information
20
+ */
21
+ export interface IExtendedSmtpSession extends ISmtpSession {
22
+ /**
23
+ * Matched route for this session
24
+ */
25
+ matchedRoute?: IEmailRoute;
26
+ }
27
+ /**
28
+ * Options for the unified email server
29
+ */
30
+ export interface IUnifiedEmailServerOptions {
31
+ ports: number[];
32
+ hostname: string;
33
+ domains: IEmailDomainConfig[];
34
+ banner?: string;
35
+ debug?: boolean;
36
+ useSocketHandler?: boolean;
37
+ auth?: {
38
+ required?: boolean;
39
+ methods?: ('PLAIN' | 'LOGIN' | 'OAUTH2')[];
40
+ users?: Array<{
41
+ username: string;
42
+ password: string;
43
+ }>;
44
+ };
45
+ tls?: {
46
+ certPath?: string;
47
+ keyPath?: string;
48
+ caPath?: string;
49
+ minVersion?: string;
50
+ ciphers?: string;
51
+ };
52
+ maxMessageSize?: number;
53
+ maxClients?: number;
54
+ maxConnections?: number;
55
+ connectionTimeout?: number;
56
+ socketTimeout?: number;
57
+ routes: IEmailRoute[];
58
+ defaults?: {
59
+ dnsMode?: 'forward' | 'internal-dns' | 'external-dns';
60
+ dkim?: IEmailDomainConfig['dkim'];
61
+ rateLimits?: IEmailDomainConfig['rateLimits'];
62
+ };
63
+ outbound?: {
64
+ maxConnections?: number;
65
+ connectionTimeout?: number;
66
+ socketTimeout?: number;
67
+ retryAttempts?: number;
68
+ defaultFrom?: string;
69
+ };
70
+ rateLimits?: IHierarchicalRateLimits;
71
+ }
72
+ /**
73
+ * Extended SMTP session interface for UnifiedEmailServer
74
+ */
75
+ export interface ISmtpSession extends IBaseSmtpSession {
76
+ /**
77
+ * User information if authenticated
78
+ */
79
+ user?: {
80
+ username: string;
81
+ [key: string]: any;
82
+ };
83
+ /**
84
+ * Matched route for this session
85
+ */
86
+ matchedRoute?: IEmailRoute;
87
+ }
88
+ /**
89
+ * Authentication data for SMTP
90
+ */
91
+ import type { ISmtpAuth } from '../delivery/interfaces.js';
92
+ export type IAuthData = ISmtpAuth;
93
+ /**
94
+ * Server statistics
95
+ */
96
+ export interface IServerStats {
97
+ startTime: Date;
98
+ connections: {
99
+ current: number;
100
+ total: number;
101
+ };
102
+ messages: {
103
+ processed: number;
104
+ delivered: number;
105
+ failed: number;
106
+ };
107
+ processingTime: {
108
+ avg: number;
109
+ max: number;
110
+ min: number;
111
+ };
112
+ }
113
+ /**
114
+ * Unified email server that handles all email traffic with pattern-based routing
115
+ */
116
+ export declare class UnifiedEmailServer extends EventEmitter {
117
+ private dcRouter;
118
+ private options;
119
+ private emailRouter;
120
+ domainRegistry: DomainRegistry;
121
+ private servers;
122
+ private stats;
123
+ dkimCreator: DKIMCreator;
124
+ private rustBridge;
125
+ private bounceManager;
126
+ deliveryQueue: UnifiedDeliveryQueue;
127
+ deliverySystem: MultiModeDeliverySystem;
128
+ private rateLimiter;
129
+ private actionExecutor;
130
+ private dkimManager;
131
+ constructor(dcRouter: DcRouter, options: IUnifiedEmailServerOptions);
132
+ /**
133
+ * Send an outbound email via the Rust SMTP client.
134
+ * Uses connection pooling in the Rust binary for efficiency.
135
+ */
136
+ sendOutboundEmail(host: string, port: number, email: Email, options?: {
137
+ auth?: {
138
+ user: string;
139
+ pass: string;
140
+ };
141
+ dkimDomain?: string;
142
+ dkimSelector?: string;
143
+ tlsOpportunistic?: boolean;
144
+ }): Promise<ISmtpSendResult>;
145
+ /**
146
+ * Start the unified email server
147
+ */
148
+ start(): Promise<void>;
149
+ private startDeliveryPipeline;
150
+ private startRustBridge;
151
+ private initializeDkimAndDns;
152
+ private registerBridgeEventHandlers;
153
+ private startSmtpServer;
154
+ /**
155
+ * Stop the unified email server
156
+ */
157
+ stop(): Promise<void>;
158
+ /**
159
+ * Handle an emailReceived event from the Rust SMTP server.
160
+ */
161
+ private handleRustEmailReceived;
162
+ /**
163
+ * Handle an authRequest event from the Rust SMTP server.
164
+ */
165
+ private handleRustAuthRequest;
166
+ /**
167
+ * Handle a SCRAM credential request from the Rust SMTP server.
168
+ * Computes SCRAM-SHA-256 credentials from the stored password for the given user.
169
+ */
170
+ private handleScramCredentialRequest;
171
+ /**
172
+ * Verify inbound email security (DKIM/SPF/DMARC) using pre-computed Rust results
173
+ * or falling back to IPC call if no pre-computed results are available.
174
+ */
175
+ private verifyInboundSecurity;
176
+ /**
177
+ * Process email based on routing rules
178
+ */
179
+ processEmailByMode(emailData: Email | Buffer, session: IExtendedSmtpSession): Promise<Email>;
180
+ /**
181
+ * Apply per-domain rate limits from domain configurations
182
+ */
183
+ private applyDomainRateLimits;
184
+ /**
185
+ * Generate SmartProxy routes for email ports
186
+ */
187
+ generateProxyRoutes(portMapping?: Record<number, number>): any[];
188
+ /**
189
+ * Update server configuration
190
+ */
191
+ updateOptions(options: Partial<IUnifiedEmailServerOptions>): void;
192
+ /**
193
+ * Update email routes
194
+ */
195
+ updateEmailRoutes(routes: IEmailRoute[]): void;
196
+ /**
197
+ * Get server statistics
198
+ */
199
+ getStats(): IServerStats;
200
+ /**
201
+ * Get domain registry
202
+ */
203
+ getDomainRegistry(): DomainRegistry;
204
+ /**
205
+ * Send an email through the delivery system
206
+ */
207
+ sendEmail(email: Email, mode?: EmailProcessingMode, route?: IEmailRoute, options?: {
208
+ skipSuppressionCheck?: boolean;
209
+ ipAddress?: string;
210
+ isTransactional?: boolean;
211
+ }): Promise<string>;
212
+ processBounceNotification(bounceEmail: Email): Promise<boolean>;
213
+ processSmtpFailure(recipient: string, smtpResponse: string, options?: {
214
+ sender?: string;
215
+ originalEmailId?: string;
216
+ statusCode?: string;
217
+ headers?: Record<string, string>;
218
+ }): Promise<boolean>;
219
+ isEmailSuppressed(email: string): boolean;
220
+ getSuppressionInfo(email: string): {
221
+ reason: string;
222
+ timestamp: number;
223
+ expiresAt?: number;
224
+ } | null;
225
+ getBounceHistory(email: string): {
226
+ lastBounce: number;
227
+ count: number;
228
+ type: BounceType;
229
+ category: BounceCategory;
230
+ } | null;
231
+ getSuppressionList(): string[];
232
+ getHardBouncedAddresses(): string[];
233
+ addToSuppressionList(email: string, reason: string, expiresAt?: number): void;
234
+ removeFromSuppressionList(email: string): void;
235
+ recordBounce(domain: string, receivingDomain: string, bounceType: 'hard' | 'soft', reason: string): void;
236
+ /**
237
+ * Get the rate limiter instance
238
+ */
239
+ getRateLimiter(): UnifiedRateLimiter;
240
+ }
241
+ export {};