Cleans forwarded email bodies by stripping forwarding headers, subject prefixes, and signatures to extract original content. Reuse when ingesting forwarded mail via Postmark/Supabase.
// Source: https://github.com/CopilotKit/atomic-crm | License: MIT | Copyright 2024-present, Francois Zaninotto, Marmelab
// Provided via justclaw.it.com; keep this notice with the code.
/** Patterns that mark the beginning of a forwarded block in the email body. */
const FORWARD_SEPARATOR_PATTERNS = [
// Gmail
/^-{5,}\s*Forwarded message\s*-{5,}/im,
// Apple Mail
/^Begin forwarded message:/im,
// Outlook / Exchange
/^-{5,}\s*Original Message\s*-{5,}/im,
// French clients (Transféré / Message transféré)
/^-{5,}\s*Message transf[eé]r[eé]\s*-{5,}/im,
/^-{5,}\s*Transf[eé]r[eé]\s*-{5,}/im,
// German (Weitergeleitet)
/^-{5,}\s*Weitergeleitete Nachricht\s*-{5,}/im,
];
export const stripForwardingHeaderBlock = (text: string): string => {
const lines = text.split("\n");
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key