UNPKG

maildev

Version:

SMTP Server and Web Interface for reading and testing emails during development

127 lines 3.54 kB
/** * MailDev Environment Variable Configuration * * Maps MAILDEV_* environment variables to configuration options */ /** * Environment variable to config key mapping */ const ENV_MAPPING = { // SMTP MAILDEV_SMTP_PORT: 'smtp', MAILDEV_IP: 'ip', MAILDEV_INCOMING_USER: 'incomingUser', MAILDEV_INCOMING_PASS: 'incomingPass', // Web/API MAILDEV_WEB_PORT: 'web', MAILDEV_WEB_IP: 'webIp', MAILDEV_WEB_USER: 'webUser', MAILDEV_WEB_PASS: 'webPass', MAILDEV_BASE_PATHNAME: 'basePathname', // Outgoing/Relay MAILDEV_OUTGOING_HOST: 'outgoingHost', MAILDEV_OUTGOING_PORT: 'outgoingPort', MAILDEV_OUTGOING_USER: 'outgoingUser', MAILDEV_OUTGOING_PASS: 'outgoingPass', // Storage MAILDEV_MAIL_DIRECTORY: 'mailDirectory', // API URL (for MCP client mode) MAILDEV_API_URL: 'webIp', // Special handling needed }; /** * Environment variables that should be parsed as numbers */ const NUMBER_VARS = new Set([ 'MAILDEV_SMTP_PORT', 'MAILDEV_WEB_PORT', 'MAILDEV_OUTGOING_PORT', ]); /** * Environment variables that should be parsed as booleans */ const BOOLEAN_VARS = new Set([ 'MAILDEV_INCOMING_SECURE', 'MAILDEV_OUTGOING_SECURE', 'MAILDEV_HTTPS', 'MAILDEV_DISABLE_WEB', 'MAILDEV_MCP', 'MAILDEV_VERBOSE', 'MAILDEV_SILENT', ]); /** * Parse boolean environment variable */ function parseBoolean(value) { return value.toLowerCase() === 'true' || value === '1'; } /** * Load configuration from environment variables * * @returns Partial configuration from environment */ export function loadEnvConfig() { const config = {}; for (const [envVar, configKey] of Object.entries(ENV_MAPPING)) { const value = process.env[envVar]; if (value === undefined) continue; if (NUMBER_VARS.has(envVar)) { const num = parseInt(value, 10); if (!isNaN(num)) { ; config[configKey] = num; } } else { ; config[configKey] = value; } } // Handle boolean environment variables for (const envVar of BOOLEAN_VARS) { const value = process.env[envVar]; if (value !== undefined) { const key = envVarToConfigKey(envVar); if (key) { ; config[key] = parseBoolean(value); } } } return config; } /** * Convert environment variable name to config key */ function envVarToConfigKey(envVar) { // Remove MAILDEV_ prefix and convert to camelCase const withoutPrefix = envVar.replace(/^MAILDEV_/, ''); const parts = withoutPrefix.toLowerCase().split('_'); const camelCase = parts .map((part, i) => (i === 0 ? part : part.charAt(0).toUpperCase() + part.slice(1))) .join(''); // Map specific env vars to config keys const mapping = { smtpPort: 'smtp', webPort: 'web', incomingSecure: 'incomingSecure', outgoingSecure: 'outgoingSecure', disableWeb: 'disableWeb', verbose: 'verbose', silent: 'silent', mcp: 'mcp', }; return mapping[camelCase] || null; } /** * Get environment variable name for a config key * (useful for error messages and documentation) */ export function getEnvVarName(configKey) { for (const [envVar, key] of Object.entries(ENV_MAPPING)) { if (key === configKey) return envVar; } return null; } //# sourceMappingURL=env.js.map