dcrouter/ts/mail/delivery/classes.mta.config.ts

73 lines
2.1 KiB
TypeScript
Raw Normal View History

2025-05-20 19:46:59 +00:00
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
2025-05-21 00:12:49 +00:00
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
2025-05-20 19:46:59 +00:00
/**
2025-05-21 00:12:49 +00:00
* Configures email server storage settings
* @param emailServer Reference to the unified email server
2025-05-20 19:46:59 +00:00
* @param options Configuration options containing storage paths
*/
2025-05-21 00:12:49 +00:00
export function configureEmailStorage(emailServer: UnifiedEmailServer, options: any): void {
2025-05-20 19:46:59 +00:00
// Extract the receivedEmailsPath if available
if (options?.emailPortConfig?.receivedEmailsPath) {
const receivedEmailsPath = options.emailPortConfig.receivedEmailsPath;
// Ensure the directory exists
plugins.smartfile.fs.ensureDirSync(receivedEmailsPath);
2025-05-21 00:12:49 +00:00
// Set path for received emails
if (emailServer) {
// Storage paths are now handled by the unified email server system
plugins.smartfile.fs.ensureDirSync(paths.receivedEmailsDir);
2025-05-20 19:46:59 +00:00
2025-05-21 00:12:49 +00:00
console.log(`Configured email server to store received emails to: ${receivedEmailsPath}`);
2025-05-20 19:46:59 +00:00
}
}
}
/**
2025-05-21 00:12:49 +00:00
* Configure email server with port and storage settings
* @param emailServer Reference to the unified email server
* @param config Configuration settings for email server
2025-05-20 19:46:59 +00:00
*/
2025-05-21 00:12:49 +00:00
export function configureEmailServer(
emailServer: UnifiedEmailServer,
2025-05-20 19:46:59 +00:00
config: {
2025-05-21 00:12:49 +00:00
ports?: number[];
hostname?: string;
tls?: {
certPath?: string;
keyPath?: string;
caPath?: string;
};
2025-05-20 19:46:59 +00:00
storagePath?: string;
}
): boolean {
2025-05-21 00:12:49 +00:00
if (!emailServer) {
console.error('Email server not available');
2025-05-20 19:46:59 +00:00
return false;
}
2025-05-21 00:12:49 +00:00
// Configure the email server with updated options
const serverOptions = {
ports: config.ports || [25, 587, 465],
hostname: config.hostname || 'localhost',
tls: config.tls
2025-05-20 19:46:59 +00:00
};
2025-05-21 00:12:49 +00:00
// Update the email server options
emailServer.updateOptions(serverOptions);
2025-05-20 19:46:59 +00:00
2025-05-21 00:12:49 +00:00
console.log(`Configured email server on ports ${serverOptions.ports.join(', ')}`);
2025-05-20 19:46:59 +00:00
// Set up storage path if provided
if (config.storagePath) {
2025-05-21 00:12:49 +00:00
configureEmailStorage(emailServer, {
2025-05-20 19:46:59 +00:00
emailPortConfig: {
receivedEmailsPath: config.storagePath
}
});
}
return true;
}