import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
/**
 * Configures email server storage settings
 * @param emailServer Reference to the unified email server
 * @param options Configuration options containing storage paths
 */
export async function configureEmailStorage(emailServer, options) {
    // Extract the receivedEmailsPath if available
    if (options?.emailPortConfig?.receivedEmailsPath) {
        const receivedEmailsPath = options.emailPortConfig.receivedEmailsPath;
        // Ensure the directory exists
        await plugins.smartfs.directory(receivedEmailsPath).recursive().create();
        // Set path for received emails
        if (emailServer) {
            // Storage paths are now handled by the unified email server system
            await plugins.smartfs.directory(paths.receivedEmailsDir).recursive().create();
            console.log(`Configured email server to store received emails to: ${receivedEmailsPath}`);
        }
    }
}
/**
 * Configure email server with port and storage settings
 * @param emailServer Reference to the unified email server
 * @param config Configuration settings for email server
 */
export async function configureEmailServer(emailServer, config) {
    if (!emailServer) {
        console.error('Email server not available');
        return false;
    }
    // Configure the email server with updated options
    const serverOptions = {
        ports: config.ports || [25, 587, 465],
        hostname: config.hostname || 'localhost',
        tls: config.tls
    };
    // Update the email server options
    emailServer.updateOptions(serverOptions);
    console.log(`Configured email server on ports ${serverOptions.ports.join(', ')}`);
    // Set up storage path if provided
    if (config.storagePath) {
        await configureEmailStorage(emailServer, {
            emailPortConfig: {
                receivedEmailsPath: config.storagePath
            }
        });
    }
    return true;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xhc3Nlcy5tdGEuY29uZmlnLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vdHMvbWFpbC9kZWxpdmVyeS9jbGFzc2VzLm10YS5jb25maWcudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxLQUFLLE9BQU8sTUFBTSxrQkFBa0IsQ0FBQztBQUM1QyxPQUFPLEtBQUssS0FBSyxNQUFNLGdCQUFnQixDQUFDO0FBR3hDOzs7O0dBSUc7QUFDSCxNQUFNLENBQUMsS0FBSyxVQUFVLHFCQ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