fix(structure): Unify structure even further

This commit is contained in:
2025-05-27 18:00:14 +00:00
parent 243a45d24c
commit 2aeb52bf13
10 changed files with 231 additions and 115 deletions

View File

@ -22,7 +22,6 @@ import type {
} from './classes.email.config.js';
import { Email } from '../core/classes.email.js';
import { BounceManager, BounceType, BounceCategory } from '../core/classes.bouncemanager.js';
import * as tls from 'node:tls';
import { createSmtpServer } from '../delivery/smtpserver/index.js';
import { createPooledSmtpClient } from '../delivery/smtpclient/create-client.js';
import type { SmtpClient } from '../delivery/smtpclient/smtp-client.js';
@ -167,17 +166,16 @@ export class UnifiedEmailServer extends EventEmitter {
private domainRouter: DomainRouter;
private servers: any[] = [];
private stats: IServerStats;
private processingTimes: number[] = [];
// Add components needed for sending and securing emails
public dkimCreator: DKIMCreator;
private ipReputationChecker: IPReputationChecker;
private ipReputationChecker: IPReputationChecker; // TODO: Implement IP reputation checks in processEmailByMode
private bounceManager: BounceManager;
private ipWarmupManager: IPWarmupManager;
private senderReputationMonitor: SenderReputationMonitor;
public deliveryQueue: UnifiedDeliveryQueue;
public deliverySystem: MultiModeDeliverySystem;
private rateLimiter: UnifiedRateLimiter;
private rateLimiter: UnifiedRateLimiter; // TODO: Implement rate limiting in SMTP server handlers
private dkimKeys: Map<string, string> = new Map(); // domain -> private key
private smtpClients: Map<string, SmtpClient> = new Map(); // host:port -> client
@ -265,7 +263,7 @@ export class UnifiedEmailServer extends EventEmitter {
bounceHandler: {
processSmtpFailure: this.processSmtpFailure.bind(this)
},
onDeliverySuccess: async (item, result) => {
onDeliverySuccess: async (item, _result) => {
// Record delivery success event for reputation monitoring
const email = item.processingResult as Email;
const senderDomain = email.from.split('@')[1];
@ -479,13 +477,7 @@ export class UnifiedEmailServer extends EventEmitter {
logger.log('info', 'Stopping UnifiedEmailServer');
try {
// Stop all SMTP servers
for (const server of this.servers) {
// Nothing to do, servers will be garbage collected
// The server.stop() method is not needed during this transition
}
// Clear the servers array
// Clear the servers array - servers will be garbage collected
this.servers = [];
// Stop the delivery system
@ -523,26 +515,6 @@ export class UnifiedEmailServer extends EventEmitter {
/**
* Update processing time statistics
*/
private updateProcessingTimeStats(): void {
if (this.processingTimes.length === 0) return;
// Keep only the last 1000 processing times
if (this.processingTimes.length > 1000) {
this.processingTimes = this.processingTimes.slice(-1000);
}
// Calculate stats
const sum = this.processingTimes.reduce((acc, time) => acc + time, 0);
const avg = sum / this.processingTimes.length;
const max = Math.max(...this.processingTimes);
const min = Math.min(...this.processingTimes);
this.stats.processingTime = { avg, max, min };
}
/**
* Process email based on the determined mode
*/
@ -825,7 +797,6 @@ export class UnifiedEmailServer extends EventEmitter {
}
const selector = this.options.dkim?.selector || 'default';
const keySize = this.options.dkim?.keySize || 2048;
for (const domain of this.options.domains) {
try {
@ -973,15 +944,6 @@ export class UnifiedEmailServer extends EventEmitter {
return { ...this.stats };
}
/**
* Validate email address format
*/
private isValidEmail(email: string): boolean {
// Basic validation - a more comprehensive validation could be used
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
/**
* Send an email through the delivery system
* @param email The email to send