This commit is contained in:
2025-05-20 19:46:59 +00:00
parent f3f06ed06d
commit f37cddf26d
18 changed files with 338 additions and 553 deletions

View File

@ -11,7 +11,8 @@ import { UnifiedDeliveryQueue, type IQueueOptions } from './mail/delivery/classe
import { MultiModeDeliverySystem, type IMultiModeDeliveryOptions } from './mail/delivery/classes.delivery.system.js';
import { UnifiedRateLimiter, type IHierarchicalRateLimits } from './mail/delivery/classes.unified.rate.limiter.js';
import { logger } from './logger.js';
import { applyCustomEmailStorage } from './mail/delivery/classes.mta.patch.js';
// Import the MTA configuration helpers directly from mail/delivery
import { configureMtaStorage, configureMtaService } from './mail/delivery/index.js';
export interface IDcRouterOptions {
/**
@ -121,7 +122,7 @@ export class DcRouter {
// Apply custom email storage configuration if available
if (this.platformServiceRef && this.options.emailPortConfig?.receivedEmailsPath) {
logger.log('info', 'Applying custom email storage configuration');
applyCustomEmailStorage(this.platformServiceRef, this.options);
configureMtaStorage(this.platformServiceRef, this.options);
}
}
@ -160,7 +161,9 @@ export class DcRouter {
// If email config exists, automatically add email routes
if (this.options.emailConfig) {
const emailRoutes = this.generateEmailRoutes(this.options.emailConfig);
routes = [...routes, ...emailRoutes];
console.log(`Email Routes are:`)
console.log(emailRoutes)
routes = [...routes, /* ...emailRoutes */];
}
// Merge TLS/ACME configuration if provided at root level
@ -662,6 +665,63 @@ export class DcRouter {
return stats;
}
/**
* Configure MTA for email handling with custom port and storage settings
* @param config Configuration for the MTA service
*/
public async configureEmailMta(config: {
internalPort: number;
host?: string;
secure?: boolean;
storagePath?: string;
portMapping?: Record<number, number>;
}): Promise<boolean> {
logger.log('info', 'Configuring MTA service with custom settings');
if (!this.platformServiceRef) {
throw new Error('Platform service reference is required for MTA configuration');
}
// Update email port configuration
if (!this.options.emailPortConfig) {
this.options.emailPortConfig = {};
}
// Configure storage paths for received emails
if (config.storagePath) {
// Set the storage path for received emails
this.options.emailPortConfig.receivedEmailsPath = config.storagePath;
}
// Apply port mapping if provided
if (config.portMapping) {
this.options.emailPortConfig.portMapping = {
...this.options.emailPortConfig.portMapping,
...config.portMapping
};
logger.log('info', `Updated MTA port mappings: ${JSON.stringify(this.options.emailPortConfig.portMapping)}`);
}
// Use the dedicated helper to configure the MTA service
// Pass through the port specified by the implementation
configureMtaService(this.platformServiceRef, {
port: config.internalPort, // Use whatever port the implementation specifies
host: config.host,
secure: config.secure,
storagePath: config.storagePath
});
// If email handling is already set up, restart it to apply changes
if (this.unifiedEmailServer) {
logger.log('info', 'Restarting unified email handling to apply MTA configuration changes');
await this.stopUnifiedEmailComponents();
await this.setupUnifiedEmailHandling();
}
return true;
}
}
export default DcRouter;