a stdio mcp server for apple mail
1/**
2 * Parse List-Unsubscribe URLs from raw email headers.
3 *
4 * Handles RFC 2822 header folding (continuation lines) and extracts
5 * all angle-bracket-delimited URIs from the List-Unsubscribe header.
6 */
7export function parseListUnsubscribe(rawHeaders: string): string[] | null {
8 // Unfold continuation lines (RFC 2822: CRLF followed by whitespace)
9 const unfolded = rawHeaders.replace(/\r?\n[ \t]+/g, " ");
10 const match = unfolded.match(/^List-Unsubscribe:\s*(.+)$/im);
11 if (!match) return null;
12 const urls = [...match[1].matchAll(/<([^>]+)>/g)].map((m) => m[1]);
13 return urls.length > 0 ? urls : null;
14}