fix(mail): align queue, outbound hostname, and DKIM selector behavior across the mail server APIs

This commit is contained in:
2026-04-14 12:17:50 +00:00
parent 04e73c366c
commit 65ecd94540
15 changed files with 387 additions and 147 deletions

View File

@@ -1,5 +1,6 @@
import * as plugins from '../../plugins.js';
import { EventEmitter } from 'node:events';
import { hasStorageManagerMethods, type IStorageManagerLike } from '../interfaces.storage.js';
import type { IEmailRoute, IEmailMatch, IEmailAction, IEmailContext } from './interfaces.js';
import type { Email } from '../core/classes.email.js';
@@ -9,7 +10,7 @@ import type { Email } from '../core/classes.email.js';
export class EmailRouter extends EventEmitter {
private routes: IEmailRoute[];
private patternCache: Map<string, boolean> = new Map();
private storageManager?: any; // StorageManager instance
private storageManager?: IStorageManagerLike;
private persistChanges: boolean;
/**
@@ -18,7 +19,7 @@ export class EmailRouter extends EventEmitter {
* @param options Router options
*/
constructor(routes: IEmailRoute[], options?: {
storageManager?: any;
storageManager?: IStorageManagerLike;
persistChanges?: boolean;
}) {
super();
@@ -27,7 +28,7 @@ export class EmailRouter extends EventEmitter {
this.persistChanges = options?.persistChanges ?? !!this.storageManager;
// If storage manager is provided, try to load persisted routes
if (this.storageManager) {
if (hasStorageManagerMethods(this.storageManager, ['get'])) {
this.loadRoutes({ merge: true }).catch(error => {
console.error(`Failed to load persisted routes: ${error.message}`);
});
@@ -394,7 +395,7 @@ export class EmailRouter extends EventEmitter {
* Save current routes to storage
*/
public async saveRoutes(): Promise<void> {
if (!this.storageManager) {
if (!hasStorageManagerMethods(this.storageManager, ['set'])) {
this.emit('persistenceWarning', 'Cannot save routes: StorageManager not configured');
return;
}
@@ -425,7 +426,7 @@ export class EmailRouter extends EventEmitter {
merge?: boolean; // Merge with existing routes
replace?: boolean; // Replace existing routes
}): Promise<IEmailRoute[]> {
if (!this.storageManager) {
if (!hasStorageManagerMethods(this.storageManager, ['get'])) {
this.emit('persistenceWarning', 'Cannot load routes: StorageManager not configured');
return [];
}
@@ -572,4 +573,4 @@ export class EmailRouter extends EventEmitter {
public getRoute(name: string): IEmailRoute | undefined {
return this.routes.find(r => r.name === name);
}
}
}