Skip to content

fix(ts): clean French mail like Python - #939

Merged
NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
kevin9327:fix/ts-french-mail
Oct 5, 2026
Merged

NandhaKishorM merged 1 commit into
NandhaKishorM:mainfrom
kevin9327:fix/ts-french-mail

Conversation

@kevin9327

@kevin9327 kevin9327 commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

What

Port the French mail cleaning that the Python clean_email_body already has (#736, #913) to the TypeScript cleanEmailBody in laya-ts/src/email.ts:

  • Gmail French reply headers (Le lun. 3 mars 2025 à 10:00, Jean <[email protected]> a écrit :), including the wrapped two-line form
  • Outlook French separators (-----Message d'origine-----) and De : / Envoyé : / À : / Objet : header blocks
  • French sign-offs (Cordialement, Bien à vous, Merci, Bonne journée, …)
  • French device footers (Envoyé depuis mon iPhone, …) while keeping sentences that merely mention a device
  • French confidentiality disclaimers

Why

The TS port is documented to behave like Python, but for French mail it currently keeps the whole quoted history, the sign-off block and the "Envoyé depuis mon iPhone" footer, so classifyEmail / routing see different text in TS than in Python for the same input.

Example:

cleanEmailBody("Bonjour,\n\nLe colis n'est jamais arrivé.\n\nCordialement,\nJean\n\nLe lun. 3 mars 2025 à 10:00, Support <[email protected]> a écrit :\n> Votre commande a été expédiée.")
  • Before: "Bonjour,\n\nLe colis n'est jamais arrivé.\n\nCordialement,\nJean\n\nLe lun. 3 mars 2025 à 10:00, Support <[email protected]> a écrit :" (sign-off and French reply header kept)
  • After: "Bonjour,\n\nLe colis n'est jamais arrivé.", same as Python

How it was verified

cd laya-ts
npx vitest run                 # 34 files, 633 tests passed
npx tsc --noEmit -p tsconfig.json
  • Added four French parity tests to tests/email-presets.test.ts, mirroring the French cases in tests/test_email.py. Three of them fail on main and all pass with this change.
  • Ran a differential check of ~4000 generated English/French emails through Python clean_email_body and TS cleanEmailBody: 50+ mismatches before, 0 after.

Checklist

  • Focused on one change (split unrelated work into another PR)
  • Rebased on the latest main
  • Tests pass locally
  • Docs or examples updated when the public API changed (no API change)

@NandhaKishorM
NandhaKishorM merged commit b0c7c9f into NandhaKishorM:main Oct 5, 2026
29 checks passed
@NandhaKishorM

Copy link
Copy Markdown
Owner

Merged.

The TypeScript runtime is documented to behave like Python, so French mail keeping its whole quoted history, sign-off block and device footer was the port silently disagreeing with the reference on real input. Four parity tests mirrored from tests/test_email.py, three of which fail on main, is the right evidence for that claim.

The differential run over about 4,000 generated English and French emails, 50 or more mismatches before and 0 after, is what makes this convincing rather than case-by-case. Keeping sentences that merely mention a device while removing the footer is the part that would have been easy to get wrong in the other direction.

Verified on the merged tree: 654 TypeScript tests pass across 34 files, tsc --noEmit clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants