feat: implement route-based email routing system
- Add core interfaces (IEmailRoute, IEmailMatch, IEmailAction, IEmailContext) - Create EmailRouter class with comprehensive matching capabilities - Support for recipient/sender patterns, IP/CIDR matching, auth checks - Add content matching (headers, size, subject, attachments) - Implement pattern caching for performance - Update plan with completed steps
This commit is contained in:
@@ -169,42 +169,42 @@ const router = new EmailRouter(routes);
|
||||
- [x] Call sort in constructor
|
||||
|
||||
### Step 3: Implement Route Matching (3 hours)
|
||||
- [ ] Add `evaluateRoutes(context: IEmailContext): Promise<IEmailRoute | null>` method
|
||||
- [ ] Add `matchesRoute(route: IEmailRoute, context: IEmailContext): boolean` method
|
||||
- [ ] Implement `matchesRecipients()` with glob support
|
||||
- [ ] Implement `matchesSenders()` with glob support
|
||||
- [ ] Implement `matchesClientIp()` with CIDR support
|
||||
- [ ] Implement `matchesAuthenticated()` check
|
||||
- [ ] Add pattern cache for performance
|
||||
- [x] Add `evaluateRoutes(context: IEmailContext): Promise<IEmailRoute | null>` method
|
||||
- [x] Add `matchesRoute(route: IEmailRoute, context: IEmailContext): boolean` method
|
||||
- [x] Implement `matchesRecipients()` with glob support
|
||||
- [x] Implement `matchesSenders()` with glob support
|
||||
- [x] Implement `matchesClientIp()` with CIDR support
|
||||
- [x] Implement `matchesAuthenticated()` check
|
||||
- [x] Add pattern cache for performance
|
||||
|
||||
### Step 4: Update UnifiedEmailServer Configuration (2 hours)
|
||||
- [ ] Update `IUnifiedEmailServerOptions` interface
|
||||
- [ ] Replace `domainRules` with `routes: IEmailRoute[]`
|
||||
- [ ] Remove `defaultMode`, `defaultServer`, etc.
|
||||
- [ ] Update constructor to create EmailRouter with routes
|
||||
- [ ] Replace DomainRouter usage with EmailRouter
|
||||
- [x] Update `IUnifiedEmailServerOptions` interface
|
||||
- [x] Replace `domainRules` with `routes: IEmailRoute[]`
|
||||
- [x] Remove `defaultMode`, `defaultServer`, etc.
|
||||
- [x] Update constructor to create EmailRouter with routes
|
||||
- [x] Replace DomainRouter usage with EmailRouter
|
||||
|
||||
### Step 5: Implement Action Execution (4 hours)
|
||||
- [ ] Add `executeAction(action: IEmailAction, email: Email, context: IEmailContext): Promise<void>` to UnifiedEmailServer
|
||||
- [ ] Implement 'forward' action:
|
||||
- [ ] Get SMTP client via `getSmtpClient()`
|
||||
- [ ] Add forwarding headers (X-Forwarded-For, etc.)
|
||||
- [ ] Send email using pooled client
|
||||
- [ ] Handle errors with bounce manager
|
||||
- [ ] Implement 'process' action:
|
||||
- [ ] Use existing `handleProcessMode()` logic
|
||||
- [ ] Apply scan/dkim options from action
|
||||
- [ ] Implement 'deliver' action:
|
||||
- [ ] Queue for local delivery
|
||||
- [ ] Implement 'reject' action:
|
||||
- [ ] Return SMTP rejection with code/message
|
||||
- [x] Add `executeAction(action: IEmailAction, email: Email, context: IEmailContext): Promise<void>` to UnifiedEmailServer
|
||||
- [x] Implement 'forward' action:
|
||||
- [x] Get SMTP client via `getSmtpClient()`
|
||||
- [x] Add forwarding headers (X-Forwarded-For, etc.)
|
||||
- [x] Send email using pooled client
|
||||
- [x] Handle errors with bounce manager
|
||||
- [x] Implement 'process' action:
|
||||
- [x] Use existing `handleProcessMode()` logic
|
||||
- [x] Apply scan/dkim options from action
|
||||
- [x] Implement 'deliver' action:
|
||||
- [x] Queue for local delivery
|
||||
- [x] Implement 'reject' action:
|
||||
- [x] Return SMTP rejection with code/message
|
||||
|
||||
### Step 6: Refactor processEmailByMode (2 hours)
|
||||
- [ ] Update `processEmailByMode()` to use EmailRouter
|
||||
- [ ] Call `evaluateRoutes()` for each recipient
|
||||
- [ ] Call `executeAction()` based on matched route
|
||||
- [ ] Handle no-match case (default reject)
|
||||
- [ ] Remove old mode-based logic
|
||||
- [x] Update `processEmailByMode()` to use EmailRouter
|
||||
- [x] Call `evaluateRoutes()` for each recipient
|
||||
- [x] Call `executeAction()` based on matched route
|
||||
- [x] Handle no-match case (default reject)
|
||||
- [x] Remove old mode-based logic
|
||||
|
||||
### Step 7: Testing (4 hours)
|
||||
- [ ] Create `test/test.email.router.ts`
|
||||
|
||||
Reference in New Issue
Block a user