feat(smtp): quote original message in replies by default#48
Open
ilyasturki wants to merge 1 commit into
Open
Conversation
Until now `reply_email` sent only the user-supplied body, so the
recipient saw a context-free reply ("Sorry for the delay, can we do
this now?") with no reference to what was being replied to. Every
desktop mail client (Thunderbird, Outlook, Apple Mail) prepends the
original message as quoted text by default — the MCP didn't.
- New tool parameter `quoteOriginal: boolean` (default `true`) on
`reply_email`. Pass `false` to send the bare body only.
- New `src/utils/quote.ts` produces:
- Plain text replies: "On DATE, NAME <addr> wrote:" attribution
followed by `>`-prefixed original body (Thunderbird/Mutt style).
- HTML replies: same attribution, original body wrapped in
`<blockquote type="cite">` which every client recognizes as
quoted material.
- For text replies whose original was HTML-only, the HTML is stripped
to plain text first via the same stripper used elsewhere in the
codebase. For HTML replies whose original was text-only, the text is
HTML-escaped and wrapped in `<pre>`.
- Sender names and email addresses in the HTML attribution are
properly escaped to prevent injection.
Tests:
- New `quote.test.ts` covers text/html quoting, name/address
formatting, blank-line preservation, and HTML escaping.
- Extended `smtp.service.test.ts` with a `replyToEmail quote_original`
suite (default-on, html path, explicit opt-out).
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds reply-quoting support so replies include a standard “On , wrote:” attribution plus quoted original content, improving context for recipients.
Changes:
- Introduces
quoteOriginalAsText/quoteOriginalAsHtmlutilities for generating quoted blocks. - Adds
quoteOriginalparameter (defaulttrue) to the send/reply tool + SMTP reply path to optionally append the quote. - Adds unit tests for quoting helpers and SMTP reply behavior with/without quoting.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/utils/quote.ts | Adds utilities to quote original emails as text or HTML. |
| src/utils/quote.test.ts | Adds tests for text/HTML quote generation and escaping behavior. |
| src/tools/send.tool.ts | Extends tool schema with quoteOriginal flag (default enabled). |
| src/services/smtp.service.ts | Appends quoted original to reply body by default; supports opt-out. |
| src/services/smtp.service.test.ts | Adds tests validating quoting behavior in SMTP reply flow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+70
to
+72
| if (original.bodyHtml) { | ||
| inner = original.bodyHtml; | ||
| } else if (original.bodyText) { |
Comment on lines
+54
to
+60
| const attribution = `On ${original.date}, ${formatSender(original.from)} wrote:`; | ||
| const body = original.bodyText ?? (original.bodyHtml ? stripHtml(original.bodyHtml) : ''); | ||
| const quoted = body | ||
| .split('\n') | ||
| .map((line) => (line.length > 0 ? `> ${line}` : '>')) | ||
| .join('\n'); | ||
| return `\n\n${attribution}\n${quoted}`; |
| * > line 2 | ||
| */ | ||
| export function quoteOriginalAsText(original: Email): string { | ||
| const attribution = `On ${original.date}, ${formatSender(original.from)} wrote:`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a new
quoteOriginal: booleanparameter (defaulttrue) to thereply_emailMCP tool. When enabled (the default), the original message is appended below the user's reply body as a quoted block — the same convention every desktop client (Thunderbird, Outlook, Apple Mail) uses automatically.Why
Until now
reply_emailsent only the user-supplied body, so the recipient saw a context-free reply ("Sorry for the delay, can we do this now?") with no reference to what was being replied to. This makes the MCP feel less polished than a regular mail client and forces the recipient to dig into the thread to remember what's being answered.There is no existing issue for this — opening it as a feature PR.
Changes
src/utils/quote.tsproduces:On DATE, NAME <addr> wrote:attribution line followed by>-prefixed original body (Thunderbird/Mutt style).<blockquote type="cite">— recognized by every client as quoted material.emails.tool.ts).<pre>.API
Set
quoteOriginal: falseto send the bare body only (current behavior).Tests
quote.test.tscovers text/html quoting paths, name/address formatting, blank-line preservation, HTML escaping.smtp.service.test.tswith areplyToEmail quote_originalsuite (default-on, html path, explicit opt-out).Manual integration test
End-to-end: account A sends a seed mail to account B → account B calls
reply_emailwith defaultquoteOriginal=true→ account A receives a reply containing both the new body on top AND the original quoted below. Verified the rendered output in Thunderbird matches expectations.