Files
smartmta/dist_ts/mail/routing/classes.email.router.d.ts

172 lines
4.8 KiB
TypeScript
Raw Normal View History

2026-02-10 15:54:09 +00:00
import { EventEmitter } from 'node:events';
import type { IEmailRoute, IEmailContext } from './interfaces.js';
/**
* Email router that evaluates routes and determines actions
*/
export declare class EmailRouter extends EventEmitter {
private routes;
private patternCache;
private storageManager?;
private persistChanges;
/**
* Create a new email router
* @param routes Array of email routes
* @param options Router options
*/
constructor(routes: IEmailRoute[], options?: {
storageManager?: any;
persistChanges?: boolean;
});
/**
* Sort routes by priority (higher priority first)
* @param routes Routes to sort
* @returns Sorted routes
*/
private sortRoutesByPriority;
/**
* Get all configured routes
* @returns Array of routes
*/
getRoutes(): IEmailRoute[];
/**
* Update routes
* @param routes New routes
* @param persist Whether to persist changes (defaults to persistChanges setting)
*/
updateRoutes(routes: IEmailRoute[], persist?: boolean): Promise<void>;
/**
* Set routes (alias for updateRoutes)
* @param routes New routes
* @param persist Whether to persist changes
*/
setRoutes(routes: IEmailRoute[], persist?: boolean): Promise<void>;
/**
* Clear the pattern cache
*/
clearCache(): void;
/**
* Evaluate routes and find the first match
* @param context Email context
* @returns Matched route or null
*/
evaluateRoutes(context: IEmailContext): Promise<IEmailRoute | null>;
/**
* Check if a route matches the context
* @param route Route to check
* @param context Email context
* @returns True if route matches
*/
private matchesRoute;
/**
* Check if email recipients match patterns
* @param email Email to check
* @param patterns Patterns to match
* @returns True if any recipient matches
*/
private matchesRecipients;
/**
* Check if email sender matches patterns
* @param email Email to check
* @param patterns Patterns to match
* @returns True if sender matches
*/
private matchesSenders;
/**
* Check if client IP matches patterns
* @param context Email context
* @param patterns IP patterns to match
* @returns True if IP matches
*/
private matchesClientIp;
/**
* Check if email headers match patterns
* @param email Email to check
* @param headerPatterns Header patterns to match
* @returns True if headers match
*/
private matchesHeaders;
/**
* Check if email size matches range
* @param email Email to check
* @param sizeRange Size range to match
* @returns True if size is in range
*/
private matchesSize;
/**
* Check if email subject matches pattern
* @param email Email to check
* @param pattern Pattern to match
* @returns True if subject matches
*/
private matchesSubject;
/**
* Check if a string matches a glob pattern
* @param str String to check
* @param pattern Glob pattern
* @returns True if matches
*/
private matchesPattern;
/**
* Convert glob pattern to RegExp
* @param pattern Glob pattern
* @returns Regular expression
*/
private globToRegExp;
/**
* Check if IP is in CIDR range
* @param ip IP address to check
* @param cidr CIDR notation (e.g., '192.168.0.0/16')
* @returns True if IP is in range
*/
private ipInCidr;
/**
* Convert IP address to number
* @param ip IP address
* @returns Number representation
*/
private ipToNumber;
/**
* Calculate approximate email size in bytes
* @param email Email to measure
* @returns Size in bytes
*/
private calculateEmailSize;
/**
* Save current routes to storage
*/
saveRoutes(): Promise<void>;
/**
* Load routes from storage
* @param options Load options
*/
loadRoutes(options?: {
merge?: boolean;
replace?: boolean;
}): Promise<IEmailRoute[]>;
/**
* Add a route
* @param route Route to add
* @param persist Whether to persist changes
*/
addRoute(route: IEmailRoute, persist?: boolean): Promise<void>;
/**
* Remove a route by name
* @param name Route name
* @param persist Whether to persist changes
*/
removeRoute(name: string, persist?: boolean): Promise<void>;
/**
* Update a route
* @param name Route name
* @param route Updated route data
* @param persist Whether to persist changes
*/
updateRoute(name: string, route: IEmailRoute, persist?: boolean): Promise<void>;
/**
* Get a route by name
* @param name Route name
* @returns Route or undefined
*/
getRoute(name: string): IEmailRoute | undefined;
}