fix(structure): Unify structure even further
This commit is contained in:
@ -438,76 +438,34 @@ export class DcRouter {
|
||||
* This implements the consolidated emailConfig approach
|
||||
*/
|
||||
private async setupUnifiedEmailHandling(): Promise<void> {
|
||||
logger.log('info', 'Setting up unified email handling with pattern-based routing');
|
||||
|
||||
if (!this.options.emailConfig) {
|
||||
throw new Error('Email configuration is required for unified email handling');
|
||||
}
|
||||
|
||||
const emailConfig = this.options.emailConfig;
|
||||
|
||||
// Map external ports to internal ports with support for custom port mapping
|
||||
const defaultPortMapping = {
|
||||
const portMapping = this.options.emailPortConfig?.portMapping || {
|
||||
25: 10025, // SMTP
|
||||
587: 10587, // Submission
|
||||
465: 10465 // SMTPS
|
||||
};
|
||||
|
||||
// Use custom port mapping if provided, otherwise fall back to defaults
|
||||
const portMapping = this.options.emailPortConfig?.portMapping || defaultPortMapping;
|
||||
|
||||
// Create internal email server configuration
|
||||
const internalEmailConfig: IEmailConfig = {
|
||||
// Create unified email server with mapped internal ports
|
||||
this.emailServer = new UnifiedEmailServer(this, {
|
||||
...emailConfig,
|
||||
domains: emailConfig.domains || [], // Provide default empty array
|
||||
ports: emailConfig.ports.map(port => portMapping[port] || port + 10000),
|
||||
hostname: 'localhost' // Listen on localhost for SmartProxy forwarding
|
||||
};
|
||||
});
|
||||
|
||||
// If custom MTA options are provided, merge them
|
||||
if (this.options.emailPortConfig?.portSettings) {
|
||||
// Will be used in MTA configuration
|
||||
logger.log('info', 'Custom port settings detected for email configuration');
|
||||
}
|
||||
// Set up error handling
|
||||
this.emailServer.on('error', (err: Error) => {
|
||||
logger.log('error', `UnifiedEmailServer error: ${err.message}`);
|
||||
});
|
||||
|
||||
// Configure custom email storage path if specified
|
||||
if (this.options.emailPortConfig?.receivedEmailsPath) {
|
||||
logger.log('info', `Custom email storage path configured: ${this.options.emailPortConfig.receivedEmailsPath}`);
|
||||
}
|
||||
// Start the server
|
||||
await this.emailServer.start();
|
||||
|
||||
try {
|
||||
// Create unified email server with all components
|
||||
this.emailServer = new UnifiedEmailServer(this, {
|
||||
ports: emailConfig.ports.map(port => portMapping[port] || port + 10000),
|
||||
hostname: 'localhost', // Listen on localhost for SmartProxy forwarding
|
||||
domains: emailConfig.domains || [],
|
||||
domainRules: emailConfig.domainRules,
|
||||
defaultMode: emailConfig.defaultMode,
|
||||
defaultServer: emailConfig.defaultServer,
|
||||
defaultPort: emailConfig.defaultPort,
|
||||
defaultTls: emailConfig.defaultTls,
|
||||
maxMessageSize: emailConfig.maxMessageSize,
|
||||
auth: emailConfig.auth,
|
||||
tls: emailConfig.tls,
|
||||
dkim: emailConfig.dkim,
|
||||
outbound: emailConfig.outbound,
|
||||
rateLimits: emailConfig.rateLimits,
|
||||
debug: emailConfig.debug
|
||||
});
|
||||
|
||||
// Set up event listeners
|
||||
this.emailServer.on('error', (err: Error) => {
|
||||
logger.log('error', `UnifiedEmailServer error: ${err.message}`);
|
||||
});
|
||||
|
||||
// Start the unified email server
|
||||
await this.emailServer.start();
|
||||
|
||||
logger.log('info', `Unified email handling configured with ${emailConfig.domainRules.length} domain rules`);
|
||||
logger.log('info', `Email server listening on internal ports: ${this.emailServer['options'].ports.join(', ')}`);
|
||||
} catch (error) {
|
||||
logger.log('error', `Error setting up unified email handling: ${error.message}`);
|
||||
throw error;
|
||||
}
|
||||
logger.log('info', `Email server started on ports: ${this.emailServer['options'].ports.join(', ')}`);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user