This commit is contained in:
2025-05-21 00:12:49 +00:00
parent 5c85188183
commit b1890f59ee
27 changed files with 2096 additions and 705 deletions

View File

@ -1,13 +1,13 @@
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import type { SzPlatformService } from '../../classes.platformservice.js';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
/**
* Configures MTA storage settings for the platform service
* @param platformService Reference to the platform service
* Configures email server storage settings
* @param emailServer Reference to the unified email server
* @param options Configuration options containing storage paths
*/
export function configureMtaStorage(platformService: SzPlatformService, options: any): void {
export function configureEmailStorage(emailServer: UnifiedEmailServer, options: any): void {
// Extract the receivedEmailsPath if available
if (options?.emailPortConfig?.receivedEmailsPath) {
const receivedEmailsPath = options.emailPortConfig.receivedEmailsPath;
@ -15,52 +15,54 @@ export function configureMtaStorage(platformService: SzPlatformService, options:
// Ensure the directory exists
plugins.smartfile.fs.ensureDirSync(receivedEmailsPath);
// Apply configuration to MTA service if available
if (platformService.mtaService) {
platformService.mtaService.configure({
storagePath: receivedEmailsPath
});
// Set path for received emails
if (emailServer) {
// Storage paths are now handled by the unified email server system
plugins.smartfile.fs.ensureDirSync(paths.receivedEmailsDir);
console.log(`Configured MTA to store received emails to: ${receivedEmailsPath}`);
console.log(`Configured email server to store received emails to: ${receivedEmailsPath}`);
}
}
}
/**
* Configure MTA service with port and storage settings
* @param platformService Reference to the platform service
* @param config Configuration settings for MTA
* Configure email server with port and storage settings
* @param emailServer Reference to the unified email server
* @param config Configuration settings for email server
*/
export function configureMtaService(
platformService: SzPlatformService,
export function configureEmailServer(
emailServer: UnifiedEmailServer,
config: {
port?: number;
host?: string;
secure?: boolean;
ports?: number[];
hostname?: string;
tls?: {
certPath?: string;
keyPath?: string;
caPath?: string;
};
storagePath?: string;
}
): boolean {
if (!platformService?.mtaService) {
console.error('MTA service not available in platform service');
if (!emailServer) {
console.error('Email server not available');
return false;
}
// Configure MTA with the provided port
const mtaConfig = {
port: config.port, // Use the port provided by the config
host: config.host || 'localhost',
secure: config.secure || false,
storagePath: config.storagePath
// Configure the email server with updated options
const serverOptions = {
ports: config.ports || [25, 587, 465],
hostname: config.hostname || 'localhost',
tls: config.tls
};
// Configure the MTA service
platformService.mtaService.configure(mtaConfig);
// Update the email server options
emailServer.updateOptions(serverOptions);
console.log(`Configured MTA service on port ${mtaConfig.port}`);
console.log(`Configured email server on ports ${serverOptions.ports.join(', ')}`);
// Set up storage path if provided
if (config.storagePath) {
configureMtaStorage(platformService, {
configureEmailStorage(emailServer, {
emailPortConfig: {
receivedEmailsPath: config.storagePath
}