fix(watcher): handle wrapped Subject lines in forwarded emails

Update the parseForwardedHeader function to correctly join wrapped Subject lines before the To: line, ensuring accurate parsing of Gmail forwarded messages. Enhance tests to validate this behavior with Tokopedia email examples.
This commit is contained in:
2026-09-14 00:04:26 +07:00
parent c446d794a8
commit 39eb1bce2f
3 changed files with 17 additions and 3 deletions
+10
View File
@@ -43,6 +43,16 @@ describe("parseForwardedHeader", () => {
assert.equal(h.subject, "Pembayaran Berhasil!");
});
it("joins wrapped Subject lines before To", () => {
const h = parseForwardedHeader(tokopediaMultiForwardedBody);
assert.ok(h);
assert.match(h.from, /noreply@tokopedia\.com/);
assert.equal(
h.subject,
"Pesanan Selesai: “sandal jepit ANDA pria casual...” dan 1 Item Lainnya",
);
});
it("returns null when there is no Fwd block", () => {
assert.equal(parseForwardedHeader(livinDirectBody), null);
});