From fef03885345af693bccb9037462c8bcac487206a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Feb 2026 20:05:12 +0000 Subject: [PATCH] Quote parent's message in email replies Add standard > -prefixed quote block to outbound replies so parents can see what they wrote in the previous message, matching natural email client behaviour. The quote header uses the German "Am schrieb :" convention (matching Outlook/Thunderbird). - email_channel.py: add _build_quoted_block() helper; extend send_reply() with optional quoted_text/quoted_from params - main.py: pass msg["body"] and msg["from"] as quoted_text/quoted_from https://claude.ai/code/session_01HaUFs7SaLD5SoiuGCY27Tw --- main.py | 2 ++ src/channels/email_channel.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/main.py b/main.py index 9ad8e7b..348281c 100644 --- a/main.py +++ b/main.py @@ -100,6 +100,8 @@ def run_poll_loop(agent: EmailAgent, channel: EmailChannel, poll_interval: int) body=reply, in_reply_to=msg["message_id"], references=msg["references"], + quoted_text=msg["body"], + quoted_from=msg["from"], ) except Exception: logger.exception( diff --git a/src/channels/email_channel.py b/src/channels/email_channel.py index cc0b5f9..624407b 100644 --- a/src/channels/email_channel.py +++ b/src/channels/email_channel.py @@ -94,6 +94,23 @@ def _generate_message_id(from_addr: str) -> str: return f"<{time.time():.6f}.{id(from_addr)}@{domain}>" +def _build_quoted_block(original_text: str, from_addr: str) -> str: + """Format original_text as a standard email quote block. + + Produces the classic: + + On , wrote: + > line 1 + > line 2 + """ + date_str = time.strftime("%a, %d %b %Y %H:%M", time.localtime()) + header = f"Am {date_str} schrieb {from_addr}:" + quoted_lines = "\n".join( + f"> {line}" for line in original_text.splitlines() + ) + return f"\n\n{header}\n{quoted_lines}" + + # --------------------------------------------------------------------------- # Main class # --------------------------------------------------------------------------- @@ -201,9 +218,14 @@ class EmailChannel: body: str, in_reply_to: str = "", references: str = "", + quoted_text: str = "", + quoted_from: str = "", ) -> str: """Send an email reply. + If quoted_text is provided it is appended to body as a standard + ``> ``-prefixed quote block so parents can see what they wrote. + Returns the new Message-ID so the caller can track the thread. """ new_message_id = _generate_message_id(self._from_email) @@ -216,6 +238,10 @@ class EmailChannel: ref_parts = [r for r in [references, in_reply_to] if r] new_references = " ".join(ref_parts) + # Append quoted original message + if quoted_text.strip(): + body = body + _build_quoted_block(quoted_text, quoted_from or to) + msg = MIMEMultipart("alternative") msg["From"] = self._from_email msg["To"] = to