diff --git a/email-worker-nodejs/src/worker/message-processor.ts b/email-worker-nodejs/src/worker/message-processor.ts index cdec270..1e01da3 100644 --- a/email-worker-nodejs/src/worker/message-processor.ts +++ b/email-worker-nodejs/src/worker/message-processor.ts @@ -135,6 +135,7 @@ export class MessageProcessor { let finalRawBytes = rawBytes; let fromAddrFinal = fromAddr; let isBounce = false; + let parsedFinal: ParsedMail | null = null; // <-- Hier deklarieren try { const parsed = await parseEmail(rawBytes); @@ -147,7 +148,6 @@ export class MessageProcessor { subject, workerName, ); - isBounce = bounceResult.isBounce; finalRawBytes = bounceResult.rawBytes; @@ -165,17 +165,17 @@ export class MessageProcessor { } // Re-parse after modifications for rules processing - var parsedFinal = await parseEmail(finalRawBytes); + parsedFinal = await parseEmail(finalRawBytes); } catch (err: any) { log( - `⚠ Parsing/Logic Error: ${err.message ?? err}. Sending original.`, + `⚠ Parsing/Logic Error: ${err.message ?? err}. Sending original RAW mail without rules.`, 'WARNING', workerName, ); log(`Full error: ${err.stack ?? err}`, 'ERROR', workerName); fromAddrFinal = fromAddr; isBounce = false; - var parsedFinal = await parseEmail(rawBytes); + parsedFinal = null; // <-- GANZ WICHTIG: Kein erneuter Parse-Versuch! } // 6. BLOCKLIST CHECK @@ -215,7 +215,7 @@ export class MessageProcessor { } // Process rules (OOO, Forwarding) — not for bounces or already forwarded - if (!isBounce && !skipRules) { + if (!isBounce && !skipRules && parsedFinal !== null) { const metricsCallback = (action: 'autoreply' | 'forward', dom: string) => { if (action === 'autoreply') this.metrics?.incrementAutoreply(dom); else if (action === 'forward') this.metrics?.incrementForward(dom);