Files
mail-tools/tests/core/mbox.test.ts
T
zemion 2ab972a9f3
Verify / verify (push) Canceled after 0s
Release Mail Tools 0.2.0
2026-09-02 10:47:30 +02:00

48 lines
1.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { parseMbox, searchMailbox } from "../../src/core/mbox";
describe("mbox import and threading", () => {
it("splits mboxrd messages, unescapes body From lines, and threads replies", () => {
const source = `From sender@example.test Tue Sep 1 10:00:00 2026
From: Sender <sender@example.test>
Date: Tue, 01 Sep 2026 10:00:00 +0000
Message-ID: <root@example.test>
Subject: Root
First body
>From escaped body line
From reply@example.test Tue Sep 1 10:01:00 2026
From: Reply <reply@example.test>
Date: Tue, 01 Sep 2026 10:01:00 +0000
Message-ID: <reply@example.test>
In-Reply-To: <root@example.test>
References: <root@example.test>
Subject: Re: Root
Reply body
`;
const mailbox = parseMbox(new TextEncoder().encode(source));
expect(mailbox.entries).toHaveLength(2);
expect(mailbox.entries[0]?.message.bodySource).toContain(
"From escaped body line",
);
expect(mailbox.entries[1]).toMatchObject({
parentIndex: 0,
depth: 1,
subject: "Re: Root",
});
expect(
searchMailbox(mailbox, "escaped body").map((entry) => entry.index),
).toEqual([0]);
expect(
searchMailbox(mailbox, "reply root", { includeBodies: false }),
).toHaveLength(1);
});
it("requires an envelope separator", () => {
expect(() =>
parseMbox(new TextEncoder().encode("From: a@example.test\n\nbody")),
).toThrow(/envelope separator/iu);
});
});