feat(rust): scaffold Rust workspace and fix TypeScript build errors

- Add @git.zone/tsrust with linux_amd64/linux_arm64 cross-compilation
- Scaffold Rust workspace with 5 crates: mailer-core, mailer-smtp, mailer-security, mailer-napi, mailer-bin
- Fix all TypeScript compilation errors for upgraded dependencies (smartfile v13, mailauth v4.13, smartproxy v23)
- Replace smartfile.fs/memory with @push.rocks/smartfs throughout codebase
- Fix .ts import extensions to .js for NodeNext module resolution
- Update DKIMSignOptions usage to match mailauth v4.13 API
- Add MTA error classes with permissive signatures for legacy SMTP client
- Replace removed DcRouter/StorageManager/deliverability imports with local interfaces
This commit is contained in:
2026-02-10 15:31:31 +00:00
parent bcde137332
commit 237dba3bab
86 changed files with 6518 additions and 2869 deletions

View File

@@ -1,9 +1,9 @@
import * as plugins from '../../plugins.ts';
import * as paths from '../../paths.ts';
import { logger } from '../../logger.ts';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.ts';
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import { logger } from '../../logger.js';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.js';
import { LRUCache } from 'lru-cache';
import type { Email } from './classes.email.ts';
import type { Email } from './classes.email.js';
/**
* Bounce types for categorizing the reasons for bounces
@@ -650,10 +650,9 @@ export class BounceManager {
await this.storageManager.set('/email/bounces/suppression-list.json', suppressionData);
} else {
// Fall back to filesystem
plugins.smartfile.memory.toFsSync(
suppressionData,
await plugins.smartfs.file(
plugins.path.join(paths.dataDir, 'emails', 'suppression_list.json')
);
).write(suppressionData);
}
} catch (error) {
logger.log('error', `Failed to save suppression list: ${error.message}`);
@@ -744,9 +743,9 @@ export class BounceManager {
// Ensure directory exists
const bounceDir = plugins.path.join(paths.dataDir, 'emails', 'bounces');
plugins.smartfile.fs.ensureDirSync(bounceDir);
plugins.smartfile.memory.toFsSync(bounceData, bouncePath);
await plugins.smartfs.directory(bounceDir).recursive().create();
await plugins.smartfs.file(bouncePath).write(bounceData);
}
} catch (error) {
logger.log('error', `Failed to save bounce record: ${error.message}`);

View File

@@ -1,5 +1,5 @@
import * as plugins from '../../plugins.ts';
import { EmailValidator } from './classes.emailvalidator.ts';
import * as plugins from '../../plugins.js';
import { EmailValidator } from './classes.emailvalidator.js';
export interface IAttachment {
filename: string;
@@ -614,10 +614,11 @@ export class Email {
// Add attachments
for (const attachment of this.attachments) {
const smartAttachment = await plugins.smartfile.SmartFile.fromBuffer(
attachment.filename,
attachment.content
);
const smartAttachment = new plugins.smartfile.SmartFile({
path: attachment.filename,
contentBuffer: attachment.content,
base: process.cwd(),
});
// Set content type if available
if (attachment.contentType) {

View File

@@ -1,5 +1,5 @@
import * as plugins from '../../plugins.ts';
import { logger } from '../../logger.ts';
import * as plugins from '../../plugins.js';
import { logger } from '../../logger.js';
import { LRUCache } from 'lru-cache';
export interface IEmailValidationResult {

View File

@@ -1,7 +1,7 @@
import * as plugins from '../../plugins.ts';
import * as paths from '../../paths.ts';
import { logger } from '../../logger.ts';
import { Email, type IEmailOptions, type IAttachment } from './classes.email.ts';
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import { logger } from '../../logger.js';
import { Email, type IEmailOptions, type IAttachment } from './classes.email.js';
/**
* Email template type definition

View File

@@ -1,5 +1,5 @@
// Core email components
export * from './classes.email.ts';
export * from './classes.emailvalidator.ts';
export * from './classes.templatemanager.ts';
export * from './classes.bouncemanager.ts';
export * from './classes.email.js';
export * from './classes.emailvalidator.js';
export * from './classes.templatemanager.js';
export * from './classes.bouncemanager.js';

View File

@@ -1,10 +1,10 @@
import * as plugins from '../../plugins.ts';
import * as plugins from '../../plugins.js';
import { EventEmitter } from 'node:events';
import * as fs from 'node:fs';
import * as path from 'node:path';
import { logger } from '../../logger.ts';
import { type EmailProcessingMode } from '../routing/classes.email.config.ts';
import type { IEmailRoute } from '../routing/interfaces.ts';
import { logger } from '../../logger.js';
import { type EmailProcessingMode } from '../routing/classes.email.config.js';
import type { IEmailRoute } from '../routing/interfaces.js';
/**
* Queue item status

View File

@@ -1,17 +1,17 @@
import * as plugins from '../../plugins.ts';
import * as plugins from '../../plugins.js';
import { EventEmitter } from 'node:events';
import * as net from 'node:net';
import * as tls from 'node:tls';
import { logger } from '../../logger.ts';
import { logger } from '../../logger.js';
import {
SecurityLogger,
SecurityLogLevel,
SecurityEventType
} from '../../security/index.ts';
import { UnifiedDeliveryQueue, type IQueueItem } from './classes.delivery.queue.ts';
import type { Email } from '../core/classes.email.ts';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.ts';
import type { SmtpClient } from './smtpclient/smtp-client.ts';
} from '../../security/index.js';
import { UnifiedDeliveryQueue, type IQueueItem } from './classes.delivery.queue.js';
import type { Email } from '../core/classes.email.js';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
import type { SmtpClient } from './smtpclient/smtp-client.js';
/**
* Delivery status enumeration
@@ -768,7 +768,11 @@ export class MultiModeDeliverySystem extends EventEmitter {
const rawEmail = email.toRFC822String();
// Sign the email
const dkimPrivateKey = (await this.emailServer.dkimCreator.readDKIMKeys(domainName)).privateKey;
const signResult = await plugins.dkimSign(rawEmail, {
signingDomain: domainName,
selector: keySelector,
privateKey: dkimPrivateKey,
canonicalization: 'relaxed/relaxed',
algorithm: 'rsa-sha256',
signTime: new Date(),
@@ -776,7 +780,7 @@ export class MultiModeDeliverySystem extends EventEmitter {
{
signingDomain: domainName,
selector: keySelector,
privateKey: (await this.emailServer.dkimCreator.readDKIMKeys(domainName)).privateKey,
privateKey: dkimPrivateKey,
algorithm: 'rsa-sha256',
canonicalization: 'relaxed/relaxed'
}

View File

@@ -1,10 +1,10 @@
import * as plugins from '../../plugins.ts';
import * as paths from '../../paths.ts';
import { Email } from '../core/classes.email.ts';
import { EmailSignJob } from './classes.emailsignjob.ts';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.ts';
import type { SmtpClient } from './smtpclient/smtp-client.ts';
import type { ISmtpSendResult } from './smtpclient/interfaces.ts';
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import { Email } from '../core/classes.email.js';
import { EmailSignJob } from './classes.emailsignjob.js';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
import type { SmtpClient } from './smtpclient/smtp-client.js';
import type { ISmtpSendResult } from './smtpclient/interfaces.js';
// Configuration options for email sending
export interface IEmailSendOptions {
@@ -400,13 +400,13 @@ export class EmailSendJob {
const fileName = `${Date.now()}_${this.email.from}_to_${this.email.to[0]}_success.eml`;
const filePath = plugins.path.join(paths.sentEmailsDir, fileName);
await plugins.smartfile.fs.ensureDir(paths.sentEmailsDir);
await plugins.smartfile.memory.toFs(emailContent, filePath);
await plugins.smartfs.directory(paths.sentEmailsDir).recursive().create();
await plugins.smartfs.file(filePath).write(emailContent);
// Also save delivery info
const infoFileName = `${Date.now()}_${this.email.from}_to_${this.email.to[0]}_info.json`;
const infoPath = plugins.path.join(paths.sentEmailsDir, infoFileName);
await plugins.smartfile.memory.toFs(JSON.stringify(this.deliveryInfo, null, 2), infoPath);
await plugins.smartfs.file(infoPath).write(JSON.stringify(this.deliveryInfo, null, 2));
this.log(`Email saved to ${fileName}`);
} catch (error) {
@@ -424,13 +424,13 @@ export class EmailSendJob {
const fileName = `${Date.now()}_${this.email.from}_to_${this.email.to[0]}_failed.eml`;
const filePath = plugins.path.join(paths.failedEmailsDir, fileName);
await plugins.smartfile.fs.ensureDir(paths.failedEmailsDir);
await plugins.smartfile.memory.toFs(emailContent, filePath);
await plugins.smartfs.directory(paths.failedEmailsDir).recursive().create();
await plugins.smartfs.file(filePath).write(emailContent);
// Also save delivery info with error details
const infoFileName = `${Date.now()}_${this.email.from}_to_${this.email.to[0]}_error.json`;
const infoPath = plugins.path.join(paths.failedEmailsDir, infoFileName);
await plugins.smartfile.memory.toFs(JSON.stringify(this.deliveryInfo, null, 2), infoPath);
await plugins.smartfs.file(infoPath).write(JSON.stringify(this.deliveryInfo, null, 2));
this.log(`Failed email saved to ${fileName}`);
} catch (error) {

View File

@@ -1,5 +1,5 @@
import * as plugins from '../../plugins.ts';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.ts';
import * as plugins from '../../plugins.js';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
interface Headers {
[key: string]: string;
@@ -27,37 +27,21 @@ export class EmailSignJob {
}
public async getSignatureHeader(emailMessage: string): Promise<string> {
const privateKey = await this.loadPrivateKey();
const signResult = await plugins.dkimSign(emailMessage, {
// Optional, default canonicalization, default is "relaxed/relaxed"
canonicalization: 'relaxed/relaxed', // c=
// Optional, default signing and hashing algorithm
// Mostly useful when you want to use rsa-sha1, otherwise no need to set
signingDomain: this.jobOptions.domain,
selector: this.jobOptions.selector,
privateKey,
canonicalization: 'relaxed/relaxed',
algorithm: 'rsa-sha256',
// Optional, default is current time
signTime: new Date(), // t=
// Keys for one or more signatures
// Different signatures can use different algorithms (mostly useful when
// you want to sign a message both with RSA and Ed25519)
signTime: new Date(),
signatureData: [
{
signingDomain: this.jobOptions.domain, // d=
selector: this.jobOptions.selector, // s=
// supported key types: RSA, Ed25519
privateKey: await this.loadPrivateKey(), // k=
// Optional algorithm, default is derived from the key.
// Overrides whatever was set in parent object
signingDomain: this.jobOptions.domain,
selector: this.jobOptions.selector,
privateKey,
algorithm: 'rsa-sha256',
// Optional signature specifc canonicalization, overrides whatever was set in parent object
canonicalization: 'relaxed/relaxed', // c=
// Maximum number of canonicalized body bytes to sign (eg. the "l=" tag).
// Do not use though. This is available only for compatibility testing.
// maxBodyLength: 12345
canonicalization: 'relaxed/relaxed',
},
],
});

View File

@@ -1,25 +1,25 @@
import * as plugins from '../../plugins.ts';
import * as paths from '../../paths.ts';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.ts';
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import type { UnifiedEmailServer } from '../routing/classes.unified.email.server.js';
/**
* Configures email server storage settings
* @param emailServer Reference to the unified email server
* @param options Configuration options containing storage paths
*/
export function configureEmailStorage(emailServer: UnifiedEmailServer, options: any): void {
export async function configureEmailStorage(emailServer: UnifiedEmailServer, options: any): Promise<void> {
// Extract the receivedEmailsPath if available
if (options?.emailPortConfig?.receivedEmailsPath) {
const receivedEmailsPath = options.emailPortConfig.receivedEmailsPath;
// Ensure the directory exists
plugins.smartfile.fs.ensureDirSync(receivedEmailsPath);
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
plugins.smartfile.fs.ensureDirSync(paths.receivedEmailsDir);
await plugins.smartfs.directory(paths.receivedEmailsDir).recursive().create();
console.log(`Configured email server to store received emails to: ${receivedEmailsPath}`);
}
}
@@ -30,8 +30,8 @@ export function configureEmailStorage(emailServer: UnifiedEmailServer, options:
* @param emailServer Reference to the unified email server
* @param config Configuration settings for email server
*/
export function configureEmailServer(
emailServer: UnifiedEmailServer,
export async function configureEmailServer(
emailServer: UnifiedEmailServer,
config: {
ports?: number[];
hostname?: string;
@@ -42,32 +42,32 @@ export function configureEmailServer(
};
storagePath?: string;
}
): boolean {
): Promise<boolean> {
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) {
configureEmailStorage(emailServer, {
await configureEmailStorage(emailServer, {
emailPortConfig: {
receivedEmailsPath: config.storagePath
}
});
}
return true;
}

View File

@@ -1,4 +1,4 @@
import { logger } from '../../logger.ts';
import { logger } from '../../logger.js';
/**
* Configuration options for rate limiter

View File

@@ -1,10 +1,10 @@
import * as plugins from '../../plugins.ts';
import { logger } from '../../logger.ts';
import * as plugins from '../../plugins.js';
import { logger } from '../../logger.js';
import {
SecurityLogger,
SecurityLogLevel,
SecurityEventType
} from '../../security/index.ts';
} from '../../security/index.js';
import {
MtaConnectionError,
@@ -13,10 +13,10 @@ import {
MtaConfigurationError,
MtaTimeoutError,
MtaProtocolError
} from '../../errors/index.ts';
} from '../../errors/index.js';
import { Email } from '../core/classes.email.ts';
import type { EmailProcessingMode } from './interfaces.ts';
import { Email } from '../core/classes.email.js';
import type { EmailProcessingMode } from './interfaces.js';
// Custom error type extension
interface NodeNetworkError extends Error {
@@ -851,22 +851,33 @@ export class SmtpClient {
// Sign email
const signOptions = {
domainName: this.options.dkim.domain,
keySelector: this.options.dkim.selector,
signingDomain: this.options.dkim.domain,
selector: this.options.dkim.selector,
privateKey: this.options.dkim.privateKey,
headerFieldNames: this.options.dkim.headers || [
'from', 'to', 'subject', 'date', 'message-id'
canonicalization: 'relaxed/relaxed' as const,
algorithm: 'rsa-sha256' as const,
signTime: new Date(),
signatureData: [
{
signingDomain: this.options.dkim.domain,
selector: this.options.dkim.selector,
privateKey: this.options.dkim.privateKey,
algorithm: 'rsa-sha256',
canonicalization: 'relaxed/relaxed',
}
]
};
const signedEmail = await dkimSign(emailContent, signOptions);
// Replace headers in original email
const dkimHeader = signedEmail.substring(0, signedEmail.indexOf('\r\n\r\n')).split('\r\n')
.find(line => line.startsWith('DKIM-Signature: '));
if (dkimHeader) {
email.addHeader('DKIM-Signature', dkimHeader.substring('DKIM-Signature: '.length));
const signResult = await dkimSign(emailContent, signOptions);
// Add DKIM-Signature header from the signing result
if (signResult.signatures) {
const dkimHeader = signResult.signatures.split('\r\n')
.find(line => line.startsWith('DKIM-Signature: '));
if (dkimHeader) {
email.addHeader('DKIM-Signature', dkimHeader.substring('DKIM-Signature: '.length));
}
}
logger.log('debug', 'DKIM signature applied successfully');

View File

@@ -1,7 +1,7 @@
import * as plugins from '../../plugins.ts';
import * as plugins from '../../plugins.js';
import { EventEmitter } from 'node:events';
import { logger } from '../../logger.ts';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.ts';
import { logger } from '../../logger.js';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.js';
/**
* Interface for rate limit configuration

View File

@@ -1,24 +1,24 @@
// Email delivery components
export * from './classes.emailsignjob.ts';
export * from './classes.delivery.queue.ts';
export * from './classes.delivery.system.ts';
export * from './classes.emailsignjob.js';
export * from './classes.delivery.queue.js';
export * from './classes.delivery.system.js';
// Handle exports with naming conflicts
export { EmailSendJob } from './classes.emailsendjob.ts';
export { DeliveryStatus } from './classes.delivery.system.ts';
export { EmailSendJob } from './classes.emailsendjob.js';
export { DeliveryStatus } from './classes.delivery.system.js';
// Rate limiter exports - fix naming conflict
export { RateLimiter } from './classes.ratelimiter.ts';
export type { IRateLimitConfig } from './classes.ratelimiter.ts';
export { RateLimiter } from './classes.ratelimiter.js';
export type { IRateLimitConfig } from './classes.ratelimiter.js';
// Unified rate limiter
export * from './classes.unified.rate.limiter.ts';
export * from './classes.unified.rate.limiter.js';
// SMTP client and configuration
export * from './classes.mta.config.ts';
export * from './classes.mta.config.js';
// Import and export SMTP modules as namespaces to avoid conflicts
import * as smtpClientMod from './smtpclient/index.ts';
import * as smtpServerMod from './smtpserver/index.ts';
import * as smtpClientMod from './smtpclient/index.js';
import * as smtpServerMod from './smtpserver/index.js';
export { smtpClientMod, smtpServerMod };

View File

@@ -2,7 +2,7 @@
* SMTP and email delivery interface definitions
*/
import type { Email } from '../core/classes.email.ts';
import type { Email } from '../core/classes.email.js';
/**
* SMTP session state enumeration

View File

@@ -3,22 +3,22 @@
* Authentication mechanisms implementation
*/
import { AUTH_METHODS } from './constants.ts';
import { AUTH_METHODS } from './constants.js';
import type {
ISmtpConnection,
ISmtpAuthOptions,
ISmtpClientOptions,
ISmtpResponse,
IOAuth2Options
} from './interfaces.ts';
} from './interfaces.js';
import {
encodeAuthPlain,
encodeAuthLogin,
generateOAuth2String,
isSuccessCode
} from './utils/helpers.ts';
import { logAuthentication, logDebug } from './utils/logging.ts';
import type { CommandHandler } from './command-handler.ts';
} from './utils/helpers.js';
import { logAuthentication, logDebug } from './utils/logging.js';
import type { CommandHandler } from './command-handler.js';
export class AuthHandler {
private options: ISmtpClientOptions;

View File

@@ -4,20 +4,20 @@
*/
import { EventEmitter } from 'node:events';
import { SMTP_COMMANDS, SMTP_CODES, LINE_ENDINGS } from './constants.ts';
import { SMTP_COMMANDS, SMTP_CODES, LINE_ENDINGS } from './constants.js';
import type {
ISmtpConnection,
ISmtpResponse,
ISmtpClientOptions,
ISmtpCapabilities
} from './interfaces.ts';
} from './interfaces.js';
import {
parseSmtpResponse,
parseEhloResponse,
formatCommand,
isSuccessCode
} from './utils/helpers.ts';
import { logCommand, logDebug } from './utils/logging.ts';
} from './utils/helpers.js';
import { logCommand, logDebug } from './utils/logging.js';
export class CommandHandler extends EventEmitter {
private options: ISmtpClientOptions;

View File

@@ -6,15 +6,15 @@
import * as net from 'node:net';
import * as tls from 'node:tls';
import { EventEmitter } from 'node:events';
import { DEFAULTS, CONNECTION_STATES } from './constants.ts';
import { DEFAULTS, CONNECTION_STATES } from './constants.js';
import type {
ISmtpClientOptions,
ISmtpConnection,
IConnectionPoolStatus,
ConnectionState
} from './interfaces.ts';
import { logConnection, logDebug } from './utils/logging.ts';
import { generateConnectionId } from './utils/helpers.ts';
} from './interfaces.js';
import { logConnection, logDebug } from './utils/logging.js';
import { generateConnectionId } from './utils/helpers.js';
export class ConnectionManager extends EventEmitter {
private options: ISmtpClientOptions;

View File

@@ -3,15 +3,15 @@
* Factory function for client creation and dependency injection
*/
import { SmtpClient } from './smtp-client.ts';
import { ConnectionManager } from './connection-manager.ts';
import { CommandHandler } from './command-handler.ts';
import { AuthHandler } from './auth-handler.ts';
import { TlsHandler } from './tls-handler.ts';
import { SmtpErrorHandler } from './error-handler.ts';
import type { ISmtpClientOptions } from './interfaces.ts';
import { validateClientOptions } from './utils/validation.ts';
import { DEFAULTS } from './constants.ts';
import { SmtpClient } from './smtp-client.js';
import { ConnectionManager } from './connection-manager.js';
import { CommandHandler } from './command-handler.js';
import { AuthHandler } from './auth-handler.js';
import { TlsHandler } from './tls-handler.js';
import { SmtpErrorHandler } from './error-handler.js';
import type { ISmtpClientOptions } from './interfaces.js';
import { validateClientOptions } from './utils/validation.js';
import { DEFAULTS } from './constants.js';
/**
* Create a complete SMTP client with all components

View File

@@ -3,9 +3,9 @@
* Error classification and recovery strategies
*/
import { SmtpErrorType } from './constants.ts';
import type { ISmtpResponse, ISmtpErrorContext, ISmtpClientOptions } from './interfaces.ts';
import { logDebug } from './utils/logging.ts';
import { SmtpErrorType } from './constants.js';
import type { ISmtpResponse, ISmtpErrorContext, ISmtpClientOptions } from './interfaces.js';
import { logDebug } from './utils/logging.js';
export class SmtpErrorHandler {
private options: ISmtpClientOptions;

View File

@@ -4,21 +4,21 @@
*/
// Main client class and factory
export * from './smtp-client.ts';
export * from './create-client.ts';
export * from './smtp-client.js';
export * from './create-client.js';
// Core handlers
export * from './connection-manager.ts';
export * from './command-handler.ts';
export * from './auth-handler.ts';
export * from './tls-handler.ts';
export * from './error-handler.ts';
export * from './connection-manager.js';
export * from './command-handler.js';
export * from './auth-handler.js';
export * from './tls-handler.js';
export * from './error-handler.js';
// Interfaces and types
export * from './interfaces.ts';
export * from './constants.ts';
export * from './interfaces.js';
export * from './constants.js';
// Utilities
export * from './utils/validation.ts';
export * from './utils/logging.ts';
export * from './utils/helpers.ts';
export * from './utils/validation.js';
export * from './utils/logging.js';
export * from './utils/helpers.js';

View File

@@ -5,7 +5,7 @@
import type * as tls from 'node:tls';
import type * as net from 'node:net';
import type { Email } from '../../core/classes.email.ts';
import type { Email } from '../../core/classes.email.js';
/**
* SMTP client connection options

View File

@@ -4,22 +4,22 @@
*/
import { EventEmitter } from 'node:events';
import type { Email } from '../../core/classes.email.ts';
import type { Email } from '../../core/classes.email.js';
import type {
ISmtpClientOptions,
ISmtpSendResult,
ISmtpConnection,
IConnectionPoolStatus,
ConnectionState
} from './interfaces.ts';
import { CONNECTION_STATES, SmtpErrorType } from './constants.ts';
import type { ConnectionManager } from './connection-manager.ts';
import type { CommandHandler } from './command-handler.ts';
import type { AuthHandler } from './auth-handler.ts';
import type { TlsHandler } from './tls-handler.ts';
import type { SmtpErrorHandler } from './error-handler.ts';
import { validateSender, validateRecipients } from './utils/validation.ts';
import { logEmailSend, logPerformance, logDebug } from './utils/logging.ts';
} from './interfaces.js';
import { CONNECTION_STATES, SmtpErrorType } from './constants.js';
import type { ConnectionManager } from './connection-manager.js';
import type { CommandHandler } from './command-handler.js';
import type { AuthHandler } from './auth-handler.js';
import type { TlsHandler } from './tls-handler.js';
import type { SmtpErrorHandler } from './error-handler.js';
import { validateSender, validateRecipients } from './utils/validation.js';
import { logEmailSend, logPerformance, logDebug } from './utils/logging.js';
interface ISmtpClientDependencies {
options: ISmtpClientOptions;

View File

@@ -5,16 +5,16 @@
import * as tls from 'node:tls';
import * as net from 'node:net';
import { DEFAULTS } from './constants.ts';
import { DEFAULTS } from './constants.js';
import type {
ISmtpConnection,
ISmtpClientOptions,
ConnectionState
} from './interfaces.ts';
import { CONNECTION_STATES } from './constants.ts';
import { logTLS, logDebug } from './utils/logging.ts';
import { isSuccessCode } from './utils/helpers.ts';
import type { CommandHandler } from './command-handler.ts';
} from './interfaces.js';
import { CONNECTION_STATES } from './constants.js';
import { logTLS, logDebug } from './utils/logging.js';
import { isSuccessCode } from './utils/helpers.js';
import type { CommandHandler } from './command-handler.js';
export class TlsHandler {
private options: ISmtpClientOptions;

View File

@@ -3,8 +3,8 @@
* Protocol helper functions and utilities
*/
import { SMTP_CODES, REGEX_PATTERNS, LINE_ENDINGS } from '../constants.ts';
import type { ISmtpResponse, ISmtpCapabilities } from '../interfaces.ts';
import { SMTP_CODES, REGEX_PATTERNS, LINE_ENDINGS } from '../constants.js';
import type { ISmtpResponse, ISmtpCapabilities } from '../interfaces.js';
/**
* Parse SMTP server response

View File

@@ -3,8 +3,8 @@
* Client-side logging utilities for SMTP operations
*/
import { logger } from '../../../../logger.ts';
import type { ISmtpResponse, ISmtpClientOptions } from '../interfaces.ts';
import { logger } from '../../../../logger.js';
import type { ISmtpResponse, ISmtpClientOptions } from '../interfaces.js';
export interface ISmtpClientLogData {
component: string;

View File

@@ -3,8 +3,8 @@
* Input validation functions for SMTP client operations
*/
import { REGEX_PATTERNS } from '../constants.ts';
import type { ISmtpClientOptions, ISmtpAuthOptions } from '../interfaces.ts';
import { REGEX_PATTERNS } from '../constants.js';
import type { ISmtpClientOptions, ISmtpAuthOptions } from '../interfaces.js';
/**
* Validate email address format

View File

@@ -5,7 +5,7 @@
import * as fs from 'fs';
import * as tls from 'tls';
import { SmtpLogger } from './utils/logging.ts';
import { SmtpLogger } from './utils/logging.js';
/**
* Certificate data

View File

@@ -3,15 +3,15 @@
* Responsible for parsing and handling SMTP commands
*/
import * as plugins from '../../../plugins.ts';
import { SmtpState } from './interfaces.ts';
import type { ISmtpSession, IEnvelopeRecipient } from './interfaces.ts';
import type { ICommandHandler, ISmtpServer } from './interfaces.ts';
import { SmtpCommand, SmtpResponseCode, SMTP_DEFAULTS, SMTP_EXTENSIONS } from './constants.ts';
import { SmtpLogger } from './utils/logging.ts';
import { adaptiveLogger } from './utils/adaptive-logging.ts';
import { extractCommandName, extractCommandArgs, formatMultilineResponse } from './utils/helpers.ts';
import { validateEhlo, validateMailFrom, validateRcptTo, isValidCommandSequence } from './utils/validation.ts';
import * as plugins from '../../../plugins.js';
import { SmtpState } from './interfaces.js';
import type { ISmtpSession, IEnvelopeRecipient } from './interfaces.js';
import type { ICommandHandler, ISmtpServer } from './interfaces.js';
import { SmtpCommand, SmtpResponseCode, SMTP_DEFAULTS, SMTP_EXTENSIONS } from './constants.js';
import { SmtpLogger } from './utils/logging.js';
import { adaptiveLogger } from './utils/adaptive-logging.js';
import { extractCommandName, extractCommandArgs, formatMultilineResponse } from './utils/helpers.js';
import { validateEhlo, validateMailFrom, validateRcptTo, isValidCommandSequence } from './utils/validation.js';
/**
* Handles SMTP commands and responses

View File

@@ -3,12 +3,12 @@
* Responsible for managing socket connections to the SMTP server
*/
import * as plugins from '../../../plugins.ts';
import type { IConnectionManager, ISmtpServer } from './interfaces.ts';
import { SmtpResponseCode, SMTP_DEFAULTS, SmtpState } from './constants.ts';
import { SmtpLogger } from './utils/logging.ts';
import { adaptiveLogger } from './utils/adaptive-logging.ts';
import { getSocketDetails, formatMultilineResponse } from './utils/helpers.ts';
import * as plugins from '../../../plugins.js';
import type { IConnectionManager, ISmtpServer } from './interfaces.js';
import { SmtpResponseCode, SMTP_DEFAULTS, SmtpState } from './constants.js';
import { SmtpLogger } from './utils/logging.js';
import { adaptiveLogger } from './utils/adaptive-logging.js';
import { getSocketDetails, formatMultilineResponse } from './utils/helpers.js';
/**
* Manager for SMTP connections

View File

@@ -3,7 +3,7 @@
* This file contains all constants and enums used by the SMTP server
*/
import { SmtpState } from '../interfaces.ts';
import { SmtpState } from '../interfaces.js';
// Re-export SmtpState enum from the main interfaces file
export { SmtpState };

View File

@@ -3,15 +3,15 @@
* Provides a simple way to create a complete SMTP server
*/
import { SmtpServer } from './smtp-server.ts';
import { SessionManager } from './session-manager.ts';
import { ConnectionManager } from './connection-manager.ts';
import { CommandHandler } from './command-handler.ts';
import { DataHandler } from './data-handler.ts';
import { TlsHandler } from './tls-handler.ts';
import { SecurityHandler } from './security-handler.ts';
import type { ISmtpServerOptions } from './interfaces.ts';
import { UnifiedEmailServer } from '../../routing/classes.unified.email.server.ts';
import { SmtpServer } from './smtp-server.js';
import { SessionManager } from './session-manager.js';
import { ConnectionManager } from './connection-manager.js';
import { CommandHandler } from './command-handler.js';
import { DataHandler } from './data-handler.js';
import { TlsHandler } from './tls-handler.js';
import { SecurityHandler } from './security-handler.js';
import type { ISmtpServerOptions } from './interfaces.js';
import { UnifiedEmailServer } from '../../routing/classes.unified.email.server.js';
/**
* Create a complete SMTP server with all components

View File

@@ -3,16 +3,16 @@
* Responsible for processing email data during and after DATA command
*/
import * as plugins from '../../../plugins.ts';
import * as plugins from '../../../plugins.js';
import * as fs from 'fs';
import * as path from 'path';
import { SmtpState } from './interfaces.ts';
import type { ISmtpSession, ISmtpTransactionResult } from './interfaces.ts';
import type { IDataHandler, ISmtpServer } from './interfaces.ts';
import { SmtpResponseCode, SMTP_PATTERNS, SMTP_DEFAULTS } from './constants.ts';
import { SmtpLogger } from './utils/logging.ts';
import { detectHeaderInjection } from './utils/validation.ts';
import { Email } from '../../core/classes.email.ts';
import { SmtpState } from './interfaces.js';
import type { ISmtpSession, ISmtpTransactionResult } from './interfaces.js';
import type { IDataHandler, ISmtpServer } from './interfaces.js';
import { SmtpResponseCode, SMTP_PATTERNS, SMTP_DEFAULTS } from './constants.js';
import { SmtpLogger } from './utils/logging.js';
import { detectHeaderInjection } from './utils/validation.js';
import { Email } from '../../core/classes.email.js';
/**
* Handles SMTP DATA command and email data processing

View File

@@ -4,29 +4,29 @@
*/
// Export interfaces
export * from './interfaces.ts';
export * from './interfaces.js';
// Export server classes
export { SmtpServer } from './smtp-server.ts';
export { SessionManager } from './session-manager.ts';
export { ConnectionManager } from './connection-manager.ts';
export { CommandHandler } from './command-handler.ts';
export { DataHandler } from './data-handler.ts';
export { TlsHandler } from './tls-handler.ts';
export { SecurityHandler } from './security-handler.ts';
export { SmtpServer } from './smtp-server.js';
export { SessionManager } from './session-manager.js';
export { ConnectionManager } from './connection-manager.js';
export { CommandHandler } from './command-handler.js';
export { DataHandler } from './data-handler.js';
export { TlsHandler } from './tls-handler.js';
export { SecurityHandler } from './security-handler.js';
// Export constants
export * from './constants.ts';
export * from './constants.js';
// Export utilities
export { SmtpLogger } from './utils/logging.ts';
export * from './utils/validation.ts';
export * from './utils/helpers.ts';
export { SmtpLogger } from './utils/logging.js';
export * from './utils/validation.js';
export * from './utils/helpers.js';
// Export TLS and certificate utilities
export * from './certificate-utils.ts';
export * from './secure-server.ts';
export * from './starttls-handler.ts';
export * from './certificate-utils.js';
export * from './secure-server.js';
export * from './starttls-handler.js';
// Factory function to create a complete SMTP server with default components
export { createSmtpServer } from './create-server.ts';
export { createSmtpServer } from './create-server.js';

View File

@@ -3,15 +3,15 @@
* Defines all the interfaces used by the SMTP server implementation
*/
import * as plugins from '../../../plugins.ts';
import type { Email } from '../../core/classes.email.ts';
import type { UnifiedEmailServer } from '../../routing/classes.unified.email.server.ts';
import * as plugins from '../../../plugins.js';
import type { Email } from '../../core/classes.email.js';
import type { UnifiedEmailServer } from '../../routing/classes.unified.email.server.js';
// Re-export types from other modules
import { SmtpState } from '../interfaces.ts';
import { SmtpCommand } from './constants.ts';
import { SmtpState } from '../interfaces.js';
import { SmtpCommand } from './constants.js';
export { SmtpState, SmtpCommand };
export type { IEnvelopeRecipient } from '../interfaces.ts';
export type { IEnvelopeRecipient } from '../interfaces.js';
/**
* Interface for components that need cleanup

View File

@@ -3,14 +3,14 @@
* Provides helper functions for creating and managing secure TLS server
*/
import * as plugins from '../../../plugins.ts';
import * as plugins from '../../../plugins.js';
import {
loadCertificatesFromString,
generateSelfSignedCertificates,
createTlsOptions,
type ICertificateData
} from './certificate-utils.ts';
import { SmtpLogger } from './utils/logging.ts';
} from './certificate-utils.js';
import { SmtpLogger } from './utils/logging.js';
/**
* Create a secure TLS server for direct TLS connections

View File

@@ -4,14 +4,14 @@
* email validation, and authentication
*/
import * as plugins from '../../../plugins.ts';
import type { ISmtpSession, ISmtpAuth } from './interfaces.ts';
import type { ISecurityHandler, ISmtpServer } from './interfaces.ts';
import { SmtpLogger } from './utils/logging.ts';
import { SecurityEventType, SecurityLogLevel } from './constants.ts';
import { isValidEmail } from './utils/validation.ts';
import { getSocketDetails, getTlsDetails } from './utils/helpers.ts';
import { IPReputationChecker } from '../../../security/classes.ipreputationchecker.ts';
import * as plugins from '../../../plugins.js';
import type { ISmtpSession, ISmtpAuth } from './interfaces.js';
import type { ISecurityHandler, ISmtpServer } from './interfaces.js';
import { SmtpLogger } from './utils/logging.js';
import { SecurityEventType, SecurityLogLevel } from './constants.js';
import { isValidEmail } from './utils/validation.js';
import { getSocketDetails, getTlsDetails } from './utils/helpers.js';
import { IPReputationChecker } from '../../../security/classes.ipreputationchecker.js';
/**
* Interface for IP denylist entry

View File

@@ -3,13 +3,13 @@
* Responsible for creating, managing, and cleaning up SMTP sessions
*/
import * as plugins from '../../../plugins.ts';
import { SmtpState } from './interfaces.ts';
import type { ISmtpSession, ISmtpEnvelope } from './interfaces.ts';
import type { ISessionManager, ISessionEvents } from './interfaces.ts';
import { SMTP_DEFAULTS } from './constants.ts';
import { generateSessionId, getSocketDetails } from './utils/helpers.ts';
import { SmtpLogger } from './utils/logging.ts';
import * as plugins from '../../../plugins.js';
import { SmtpState } from './interfaces.js';
import type { ISmtpSession, ISmtpEnvelope } from './interfaces.js';
import type { ISessionManager, ISessionEvents } from './interfaces.js';
import { SMTP_DEFAULTS } from './constants.js';
import { generateSessionId, getSocketDetails } from './utils/helpers.js';
import { SmtpLogger } from './utils/logging.js';
/**
* Manager for SMTP sessions

View File

@@ -3,21 +3,21 @@
* Core implementation for the refactored SMTP server
*/
import * as plugins from '../../../plugins.ts';
import { SmtpState } from './interfaces.ts';
import type { ISmtpServerOptions } from './interfaces.ts';
import type { ISmtpServer, ISmtpServerConfig, ISessionManager, IConnectionManager, ICommandHandler, IDataHandler, ITlsHandler, ISecurityHandler } from './interfaces.ts';
import { SessionManager } from './session-manager.ts';
import { ConnectionManager } from './connection-manager.ts';
import { CommandHandler } from './command-handler.ts';
import { DataHandler } from './data-handler.ts';
import { TlsHandler } from './tls-handler.ts';
import { SecurityHandler } from './security-handler.ts';
import { SMTP_DEFAULTS } from './constants.ts';
import { mergeWithDefaults } from './utils/helpers.ts';
import { SmtpLogger } from './utils/logging.ts';
import { adaptiveLogger } from './utils/adaptive-logging.ts';
import { UnifiedEmailServer } from '../../routing/classes.unified.email.server.ts';
import * as plugins from '../../../plugins.js';
import { SmtpState } from './interfaces.js';
import type { ISmtpServerOptions } from './interfaces.js';
import type { ISmtpServer, ISmtpServerConfig, ISessionManager, IConnectionManager, ICommandHandler, IDataHandler, ITlsHandler, ISecurityHandler } from './interfaces.js';
import { SessionManager } from './session-manager.js';
import { ConnectionManager } from './connection-manager.js';
import { CommandHandler } from './command-handler.js';
import { DataHandler } from './data-handler.js';
import { TlsHandler } from './tls-handler.js';
import { SecurityHandler } from './security-handler.js';
import { SMTP_DEFAULTS } from './constants.js';
import { mergeWithDefaults } from './utils/helpers.js';
import { SmtpLogger } from './utils/logging.js';
import { adaptiveLogger } from './utils/adaptive-logging.js';
import { UnifiedEmailServer } from '../../routing/classes.unified.email.server.js';
/**
* SMTP Server implementation

View File

@@ -3,16 +3,16 @@
* Provides an improved implementation for STARTTLS upgrades
*/
import * as plugins from '../../../plugins.ts';
import { SmtpLogger } from './utils/logging.ts';
import * as plugins from '../../../plugins.js';
import { SmtpLogger } from './utils/logging.js';
import {
loadCertificatesFromString,
createTlsOptions,
type ICertificateData
} from './certificate-utils.ts';
import { getSocketDetails } from './utils/helpers.ts';
import type { ISmtpSession, ISessionManager, IConnectionManager } from './interfaces.ts';
import { SmtpState } from '../interfaces.ts';
} from './certificate-utils.js';
import { getSocketDetails } from './utils/helpers.js';
import type { ISmtpSession, ISessionManager, IConnectionManager } from './interfaces.js';
import { SmtpState } from '../interfaces.js';
/**
* Enhanced STARTTLS handler for more reliable TLS upgrades

View File

@@ -3,18 +3,18 @@
* Responsible for handling TLS-related SMTP functionality
*/
import * as plugins from '../../../plugins.ts';
import type { ITlsHandler, ISmtpServer, ISmtpSession } from './interfaces.ts';
import { SmtpResponseCode, SecurityEventType, SecurityLogLevel } from './constants.ts';
import { SmtpLogger } from './utils/logging.ts';
import { getSocketDetails, getTlsDetails } from './utils/helpers.ts';
import * as plugins from '../../../plugins.js';
import type { ITlsHandler, ISmtpServer, ISmtpSession } from './interfaces.js';
import { SmtpResponseCode, SecurityEventType, SecurityLogLevel } from './constants.js';
import { SmtpLogger } from './utils/logging.js';
import { getSocketDetails, getTlsDetails } from './utils/helpers.js';
import {
loadCertificatesFromString,
generateSelfSignedCertificates,
createTlsOptions,
type ICertificateData
} from './certificate-utils.ts';
import { SmtpState } from '../interfaces.ts';
} from './certificate-utils.js';
import { SmtpState } from '../interfaces.js';
/**
* Handles TLS functionality for SMTP server

View File

@@ -4,11 +4,11 @@
* to maintain performance during high-concurrency scenarios
*/
import * as plugins from '../../../../plugins.ts';
import { logger } from '../../../../logger.ts';
import { SecurityLogLevel, SecurityEventType } from '../constants.ts';
import type { ISmtpSession } from '../interfaces.ts';
import type { LogLevel, ISmtpLogOptions } from './logging.ts';
import * as plugins from '../../../../plugins.js';
import { logger } from '../../../../logger.js';
import { SecurityLogLevel, SecurityEventType } from '../constants.js';
import type { ISmtpSession } from '../interfaces.js';
import type { LogLevel, ISmtpLogOptions } from './logging.js';
/**
* Log modes based on server load

View File

@@ -3,9 +3,9 @@
* Provides utility functions for SMTP server implementation
*/
import * as plugins from '../../../../plugins.ts';
import { SMTP_DEFAULTS } from '../constants.ts';
import type { ISmtpSession, ISmtpServerOptions } from '../interfaces.ts';
import * as plugins from '../../../../plugins.js';
import { SMTP_DEFAULTS } from '../constants.js';
import type { ISmtpSession, ISmtpServerOptions } from '../interfaces.js';
/**
* Formats a multi-line SMTP response according to RFC 5321

View File

@@ -3,10 +3,10 @@
* Provides structured logging for SMTP server components
*/
import * as plugins from '../../../../plugins.ts';
import { logger } from '../../../../logger.ts';
import { SecurityLogLevel, SecurityEventType } from '../constants.ts';
import type { ISmtpSession } from '../interfaces.ts';
import * as plugins from '../../../../plugins.js';
import { logger } from '../../../../logger.js';
import { SecurityLogLevel, SecurityEventType } from '../constants.js';
import type { ISmtpSession } from '../interfaces.js';
/**
* SMTP connection metadata to include in logs

View File

@@ -3,8 +3,8 @@
* Provides validation functions for SMTP server
*/
import { SmtpState } from '../interfaces.ts';
import { SMTP_PATTERNS } from '../constants.ts';
import { SmtpState } from '../interfaces.js';
import { SMTP_PATTERNS } from '../constants.js';
/**
* Header injection patterns to detect malicious input
@@ -88,7 +88,7 @@ export function sanitizeInput(input: string): string {
.replace(/%0[aAdD]/gi, '') // Remove URL encoded CRLF
.trim();
}
import { SmtpLogger } from './logging.ts';
import { SmtpLogger } from './logging.js';
/**
* Validates an email address

View File

@@ -1,19 +1,17 @@
// Export all mail modules for simplified imports
export * from './routing/index.ts';
export * from './security/index.ts';
export * from './routing/index.js';
export * from './security/index.js';
// Make the core and delivery modules accessible
import * as Core from './core/index.ts';
import * as Delivery from './delivery/index.ts';
import * as Core from './core/index.js';
import * as Delivery from './delivery/index.js';
export { Core, Delivery };
// For direct imports
import { Email } from './core/classes.email.ts';
import { DcRouter } from '../classes.dcrouter.ts';
import { Email } from './core/classes.email.js';
// Re-export commonly used classes
export {
Email,
DcRouter
};

View File

@@ -1,8 +1,18 @@
import * as plugins from '../../plugins.ts';
import type { IEmailDomainConfig } from './interfaces.ts';
import { logger } from '../../logger.ts';
import type { DcRouter } from '../../classes.dcrouter.ts';
import type { StorageManager } from '../../storage/index.ts';
import * as plugins from '../../plugins.js';
import type { IEmailDomainConfig } from './interfaces.js';
import { logger } from '../../logger.js';
/** External DcRouter interface shape used by DnsManager */
interface IDcRouterLike {
storageManager: IStorageManagerLike;
dnsServer?: any;
options?: { dnsNsDomains?: string[]; dnsScopes?: string[] };
}
/** External StorageManager interface shape used by DnsManager */
interface IStorageManagerLike {
get(key: string): Promise<string | null>;
set(key: string, value: string): Promise<void>;
}
/**
* DNS validation result
@@ -30,10 +40,10 @@ interface IDnsRecords {
* Handles both validation and creation of DNS records
*/
export class DnsManager {
private dcRouter: DcRouter;
private storageManager: StorageManager;
private dcRouter: IDcRouterLike;
private storageManager: IStorageManagerLike;
constructor(dcRouter: DcRouter) {
constructor(dcRouter: IDcRouterLike) {
this.dcRouter = dcRouter;
this.storageManager = dcRouter.storageManager;
}

View File

@@ -1,6 +1,6 @@
import * as plugins from '../../plugins.ts';
import * as paths from '../../paths.ts';
import { DKIMCreator } from '../security/classes.dkimcreator.ts';
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import { DKIMCreator } from '../security/classes.dkimcreator.js';
/**
* Interface for DNS record information
@@ -57,7 +57,7 @@ export class DNSManager {
}
// Ensure the DNS records directory exists
plugins.smartfile.fs.ensureDirSync(paths.dnsRecordsDir);
plugins.fs.mkdirSync(paths.dnsRecordsDir, { recursive: true });
}
/**
@@ -417,7 +417,7 @@ export class DNSManager {
public async saveDnsRecommendations(domain: string, records: IDnsRecord[]): Promise<void> {
try {
const filePath = plugins.path.join(paths.dnsRecordsDir, `${domain}.recommendations.json`);
plugins.smartfile.memory.toFsSync(JSON.stringify(records, null, 2), filePath);
await plugins.smartfs.file(filePath).write(JSON.stringify(records, null, 2));
console.log(`DNS recommendations for ${domain} saved to ${filePath}`);
} catch (error) {
console.error(`Error saving DNS recommendations for ${domain}:`, error);

View File

@@ -1,5 +1,5 @@
import type { IEmailDomainConfig } from './interfaces.ts';
import { logger } from '../../logger.ts';
import type { IEmailDomainConfig } from './interfaces.js';
import { logger } from '../../logger.js';
/**
* Registry for email domain configurations

View File

@@ -1,4 +1,4 @@
import type { EmailProcessingMode } from '../delivery/interfaces.ts';
import type { EmailProcessingMode } from '../delivery/interfaces.js';
// Re-export EmailProcessingMode type
export type { EmailProcessingMode };

View File

@@ -1,7 +1,7 @@
import * as plugins from '../../plugins.ts';
import * as plugins from '../../plugins.js';
import { EventEmitter } from 'node:events';
import type { IEmailRoute, IEmailMatch, IEmailAction, IEmailContext } from './interfaces.ts';
import type { Email } from '../core/classes.email.ts';
import type { IEmailRoute, IEmailMatch, IEmailAction, IEmailContext } from './interfaces.js';
import type { Email } from '../core/classes.email.js';
/**
* Email router that evaluates routes and determines actions

View File

@@ -1,35 +1,63 @@
import * as plugins from '../../plugins.ts';
import * as paths from '../../paths.ts';
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import { EventEmitter } from 'events';
import { logger } from '../../logger.ts';
import { logger } from '../../logger.js';
import {
SecurityLogger,
SecurityLogLevel,
SecurityEventType
} from '../../security/index.ts';
import { DKIMCreator } from '../security/classes.dkimcreator.ts';
import { IPReputationChecker } from '../../security/classes.ipreputationchecker.ts';
import {
IPWarmupManager,
type IIPWarmupConfig,
SenderReputationMonitor,
type IReputationMonitorConfig
} from '../../deliverability/index.ts';
import { EmailRouter } from './classes.email.router.ts';
import type { IEmailRoute, IEmailAction, IEmailContext, IEmailDomainConfig } from './interfaces.ts';
import { Email } from '../core/classes.email.ts';
import { DomainRegistry } from './classes.domain.registry.ts';
import { DnsManager } from './classes.dns.manager.ts';
import { BounceManager, BounceType, BounceCategory } from '../core/classes.bouncemanager.ts';
import { createSmtpServer } from '../delivery/smtpserver/index.ts';
import { createPooledSmtpClient } from '../delivery/smtpclient/create-client.ts';
import type { SmtpClient } from '../delivery/smtpclient/smtp-client.ts';
import { MultiModeDeliverySystem, type IMultiModeDeliveryOptions } from '../delivery/classes.delivery.system.ts';
import { UnifiedDeliveryQueue, type IQueueOptions } from '../delivery/classes.delivery.queue.ts';
import { UnifiedRateLimiter, type IHierarchicalRateLimits } from '../delivery/classes.unified.rate.limiter.ts';
import { SmtpState } from '../delivery/interfaces.ts';
import type { EmailProcessingMode, ISmtpSession as IBaseSmtpSession } from '../delivery/interfaces.ts';
import type { DcRouter } from '../../classes.dcrouter.ts';
} from '../../security/index.js';
import { DKIMCreator } from '../security/classes.dkimcreator.js';
import { IPReputationChecker } from '../../security/classes.ipreputationchecker.js';
// Deliverability types (IPWarmupManager and SenderReputationMonitor are optional external modules)
interface IIPWarmupConfig {
enabled?: boolean;
ips?: string[];
[key: string]: any;
}
interface IReputationMonitorConfig {
enabled?: boolean;
domains?: string[];
[key: string]: any;
}
interface IPWarmupManager {
getWarmupStatus(ip: string): any;
addIPToWarmup(ip: string, config?: any): void;
removeIPFromWarmup(ip: string): void;
updateMetrics(ip: string, metrics: any): void;
canSendMoreToday(ip: string): boolean;
canSendMoreThisHour(ip: string): boolean;
getBestIPForSending(...args: any[]): string | null;
setActiveAllocationPolicy(policy: string): void;
recordSend(...args: any[]): void;
}
interface SenderReputationMonitor {
getReputationData(domain: string): any;
getReputationSummary(): any;
addDomain(domain: string): void;
removeDomain(domain: string): void;
recordSendEvent(domain: string, event: any): void;
}
import { EmailRouter } from './classes.email.router.js';
import type { IEmailRoute, IEmailAction, IEmailContext, IEmailDomainConfig } from './interfaces.js';
import { Email } from '../core/classes.email.js';
import { DomainRegistry } from './classes.domain.registry.js';
import { DnsManager } from './classes.dns.manager.js';
import { BounceManager, BounceType, BounceCategory } from '../core/classes.bouncemanager.js';
import { createSmtpServer } from '../delivery/smtpserver/index.js';
import { createPooledSmtpClient } from '../delivery/smtpclient/create-client.js';
import type { SmtpClient } from '../delivery/smtpclient/smtp-client.js';
import { MultiModeDeliverySystem, type IMultiModeDeliveryOptions } from '../delivery/classes.delivery.system.js';
import { UnifiedDeliveryQueue, type IQueueOptions } from '../delivery/classes.delivery.queue.js';
import { UnifiedRateLimiter, type IHierarchicalRateLimits } from '../delivery/classes.unified.rate.limiter.js';
import { SmtpState } from '../delivery/interfaces.js';
import type { EmailProcessingMode, ISmtpSession as IBaseSmtpSession } from '../delivery/interfaces.js';
/** External DcRouter interface shape used by UnifiedEmailServer */
interface DcRouter {
storageManager: any;
dnsServer?: any;
options?: any;
}
/**
* Extended SMTP session interface with route information
@@ -127,7 +155,7 @@ export interface ISmtpSession extends IBaseSmtpSession {
/**
* Authentication data for SMTP
*/
import type { ISmtpAuth } from '../delivery/interfaces.ts';
import type { ISmtpAuth } from '../delivery/interfaces.js';
export type IAuthData = ISmtpAuth;
/**
@@ -166,8 +194,8 @@ export class UnifiedEmailServer extends EventEmitter {
public dkimCreator: DKIMCreator;
private ipReputationChecker: IPReputationChecker; // TODO: Implement IP reputation checks in processEmailByMode
private bounceManager: BounceManager;
private ipWarmupManager: IPWarmupManager;
private senderReputationMonitor: SenderReputationMonitor;
private ipWarmupManager: IPWarmupManager | null;
private senderReputationMonitor: SenderReputationMonitor | null;
public deliveryQueue: UnifiedDeliveryQueue;
public deliverySystem: MultiModeDeliverySystem;
private rateLimiter: UnifiedRateLimiter; // TODO: Implement rate limiting in SMTP server handlers
@@ -206,21 +234,10 @@ export class UnifiedEmailServer extends EventEmitter {
storageManager: dcRouter.storageManager
});
// Initialize IP warmup manager
this.ipWarmupManager = IPWarmupManager.getInstance(options.ipWarmupConfig || {
enabled: true,
ipAddresses: [],
targetDomains: []
});
// Initialize sender reputation monitor with storage manager
this.senderReputationMonitor = SenderReputationMonitor.getInstance(
options.reputationMonitorConfig || {
enabled: true,
domains: []
},
dcRouter.storageManager
);
// IP warmup manager and sender reputation monitor are optional
// They will be initialized when the deliverability module is available
this.ipWarmupManager = null;
this.senderReputationMonitor = null;
// Initialize domain registry
this.domainRegistry = new DomainRegistry(options.domains, options.defaults);
@@ -836,15 +853,21 @@ export class UnifiedEmailServer extends EventEmitter {
}
// Sign the email
const dkimDomain = options.dkimOptions.domainName;
const dkimSelector = options.dkimOptions.keySelector || 'mta';
const dkimPrivateKey = (await this.dkimCreator.readDKIMKeys(dkimDomain)).privateKey;
const signResult = await plugins.dkimSign(rawEmail, {
signingDomain: dkimDomain,
selector: dkimSelector,
privateKey: dkimPrivateKey,
canonicalization: 'relaxed/relaxed',
algorithm: 'rsa-sha256',
signTime: new Date(),
signatureData: [
{
signingDomain: options.dkimOptions.domainName,
selector: options.dkimOptions.keySelector || 'mta',
privateKey: (await this.dkimCreator.readDKIMKeys(options.dkimOptions.domainName)).privateKey,
signingDomain: dkimDomain,
selector: dkimSelector,
privateKey: dkimPrivateKey,
algorithm: 'rsa-sha256',
canonicalization: 'relaxed/relaxed'
}
@@ -1435,6 +1458,9 @@ export class UnifiedEmailServer extends EventEmitter {
// Sign the email
const signResult = await plugins.dkimSign(rawEmail, {
signingDomain: domain,
selector: selector,
privateKey: privateKey,
canonicalization: 'relaxed/relaxed',
algorithm: 'rsa-sha256',
signTime: new Date(),

View File

@@ -1,6 +1,6 @@
// Email routing components
export * from './classes.email.router.ts';
export * from './classes.unified.email.server.ts';
export * from './classes.dns.manager.ts';
export * from './interfaces.ts';
export * from './classes.domain.registry.ts';
export * from './classes.email.router.js';
export * from './classes.unified.email.server.js';
export * from './classes.dns.manager.js';
export * from './interfaces.js';
export * from './classes.domain.registry.js';

View File

@@ -1,5 +1,5 @@
import type { Email } from '../core/classes.email.ts';
import type { IExtendedSmtpSession } from './classes.unified.email.server.ts';
import type { Email } from '../core/classes.email.js';
import type { IExtendedSmtpSession } from './classes.unified.email.server.js';
/**
* Route configuration for email routing

View File

@@ -1,7 +1,7 @@
import * as plugins from '../../plugins.ts';
import * as paths from '../../paths.ts';
import * as plugins from '../../plugins.js';
import * as paths from '../../paths.js';
import { Email } from '../core/classes.email.ts';
import { Email } from '../core/classes.email.js';
// MtaService reference removed
const readFile = plugins.util.promisify(plugins.fs.readFile);
@@ -46,8 +46,8 @@ export class DKIMCreator {
console.log(`No DKIM keys found for ${domainArg}. Generating...`);
await this.createAndStoreDKIMKeys(domainArg);
const dnsValue = await this.getDNSRecordForDomain(domainArg);
plugins.smartfile.fs.ensureDirSync(paths.dnsRecordsDir);
plugins.smartfile.memory.toFsSync(JSON.stringify(dnsValue, null, 2), plugins.path.join(paths.dnsRecordsDir, `${domainArg}.dkimrecord.json`));
await plugins.smartfs.directory(paths.dnsRecordsDir).recursive().create();
await plugins.smartfs.file(plugins.path.join(paths.dnsRecordsDir, `${domainArg}.dkimrecord.json`)).write(JSON.stringify(dnsValue, null, 2));
}
}

View File

@@ -1,7 +1,7 @@
import * as plugins from '../../plugins.ts';
import * as plugins from '../../plugins.js';
// MtaService reference removed
import { logger } from '../../logger.ts';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.ts';
import { logger } from '../../logger.js';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.js';
/**
* Result of a DKIM verification
@@ -66,10 +66,10 @@ export class DKIMVerifier {
const result: IDkimVerificationResult = {
isValid,
domain: dkimResult.domain,
domain: dkimResult.signingDomain,
selector: dkimResult.selector,
status: dkimResult.status.result,
signatureFields: dkimResult.signature,
signatureFields: (dkimResult as any).signature,
details: options.returnDetails ? verificationMailauth : undefined
};
@@ -79,19 +79,19 @@ export class DKIMVerifier {
timestamp: Date.now()
});
logger.log(isValid ? 'info' : 'warn', `DKIM Verification using mailauth: ${isValid ? 'pass' : 'fail'} for domain ${dkimResult.domain}`);
logger.log(isValid ? 'info' : 'warn', `DKIM Verification using mailauth: ${isValid ? 'pass' : 'fail'} for domain ${dkimResult.signingDomain}`);
// Enhanced security logging
SecurityLogger.getInstance().logEvent({
level: isValid ? SecurityLogLevel.INFO : SecurityLogLevel.WARN,
type: SecurityEventType.DKIM,
message: `DKIM verification ${isValid ? 'passed' : 'failed'} for domain ${dkimResult.domain}`,
message: `DKIM verification ${isValid ? 'passed' : 'failed'} for domain ${dkimResult.signingDomain}`,
details: {
selector: dkimResult.selector,
signatureFields: dkimResult.signature,
signatureFields: (dkimResult as any).signature,
result: dkimResult.status.result
},
domain: dkimResult.domain,
domain: dkimResult.signingDomain,
success: isValid
});

View File

@@ -1,9 +1,9 @@
import * as plugins from '../../plugins.ts';
import { logger } from '../../logger.ts';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.ts';
import * as plugins from '../../plugins.js';
import { logger } from '../../logger.js';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.js';
// MtaService reference removed
import type { Email } from '../core/classes.email.ts';
import type { IDnsVerificationResult } from '../routing/classes.dnsmanager.ts';
import type { Email } from '../core/classes.email.js';
import type { IDnsVerificationResult } from '../routing/classes.dnsmanager.js';
/**
* DMARC policy types

View File

@@ -1,9 +1,9 @@
import * as plugins from '../../plugins.ts';
import { logger } from '../../logger.ts';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.ts';
import * as plugins from '../../plugins.js';
import { logger } from '../../logger.js';
import { SecurityLogger, SecurityLogLevel, SecurityEventType } from '../../security/index.js';
// MtaService reference removed
import type { Email } from '../core/classes.email.ts';
import type { IDnsVerificationResult } from '../routing/classes.dnsmanager.ts';
import type { Email } from '../core/classes.email.js';
import type { IDnsVerificationResult } from '../routing/classes.dnsmanager.js';
/**
* SPF result qualifiers

View File

@@ -1,5 +1,5 @@
// Email security components
export * from './classes.dkimcreator.ts';
export * from './classes.dkimverifier.ts';
export * from './classes.dmarcverifier.ts';
export * from './classes.spfverifier.ts';
export * from './classes.dkimcreator.js';
export * from './classes.dkimverifier.js';
export * from './classes.dmarcverifier.js';
export * from './classes.spfverifier.js';