a stdio mcp server for apple mail
1import { describe, expect, test } from "bun:test";
2import { parseListUnsubscribe } from "../parse-headers.js";
3
4describe("parseListUnsubscribe", () => {
5 test("extracts single https URL", () => {
6 const headers = "List-Unsubscribe: <https://example.com/unsub?id=123>\r\n";
7 expect(parseListUnsubscribe(headers)).toEqual(["https://example.com/unsub?id=123"]);
8 });
9
10 test("extracts multiple URLs", () => {
11 const headers = "List-Unsubscribe: <https://example.com/unsub>, <mailto:unsub@example.com>\r\n";
12 expect(parseListUnsubscribe(headers)).toEqual([
13 "https://example.com/unsub",
14 "mailto:unsub@example.com",
15 ]);
16 });
17
18 test("handles mailto + https combination", () => {
19 const headers =
20 "List-Unsubscribe: <mailto:leave@list.example.com>, <https://list.example.com/unsubscribe>\r\n";
21 expect(parseListUnsubscribe(headers)).toEqual([
22 "mailto:leave@list.example.com",
23 "https://list.example.com/unsubscribe",
24 ]);
25 });
26
27 test("handles folded headers (continuation lines)", () => {
28 const headers =
29 "List-Unsubscribe: <https://example.com/unsub>,\r\n <mailto:unsub@example.com>\r\n";
30 expect(parseListUnsubscribe(headers)).toEqual([
31 "https://example.com/unsub",
32 "mailto:unsub@example.com",
33 ]);
34 });
35
36 test("handles tab-folded continuation", () => {
37 const headers =
38 "List-Unsubscribe: <https://example.com/unsub>,\n\t<mailto:unsub@example.com>\n";
39 expect(parseListUnsubscribe(headers)).toEqual([
40 "https://example.com/unsub",
41 "mailto:unsub@example.com",
42 ]);
43 });
44
45 test("returns null when header is missing", () => {
46 const headers = "From: sender@example.com\r\nTo: recipient@example.com\r\n";
47 expect(parseListUnsubscribe(headers)).toBeNull();
48 });
49
50 test("returns null for empty headers", () => {
51 expect(parseListUnsubscribe("")).toBeNull();
52 });
53
54 test("returns null when header has no angle-bracket URLs", () => {
55 const headers = "List-Unsubscribe: not a valid url\r\n";
56 expect(parseListUnsubscribe(headers)).toBeNull();
57 });
58
59 test("is case-insensitive for header name", () => {
60 const headers = "list-unsubscribe: <https://example.com/unsub>\r\n";
61 expect(parseListUnsubscribe(headers)).toEqual(["https://example.com/unsub"]);
62 });
63
64 test("finds header among other headers", () => {
65 const headers = [
66 "From: sender@example.com",
67 "To: recipient@example.com",
68 "List-Unsubscribe: <https://example.com/unsub>",
69 "Date: Mon, 1 Jan 2024 00:00:00 +0000",
70 ].join("\r\n");
71 expect(parseListUnsubscribe(headers)).toEqual(["https://example.com/unsub"]);
72 });
73});