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 <date> schrieb <addr>:" 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
This commit is contained in:
@@ -100,6 +100,8 @@ def run_poll_loop(agent: EmailAgent, channel: EmailChannel, poll_interval: int)
|
|||||||
body=reply,
|
body=reply,
|
||||||
in_reply_to=msg["message_id"],
|
in_reply_to=msg["message_id"],
|
||||||
references=msg["references"],
|
references=msg["references"],
|
||||||
|
quoted_text=msg["body"],
|
||||||
|
quoted_from=msg["from"],
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception(
|
logger.exception(
|
||||||
|
|||||||
@@ -94,6 +94,23 @@ def _generate_message_id(from_addr: str) -> str:
|
|||||||
return f"<{time.time():.6f}.{id(from_addr)}@{domain}>"
|
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 <date>, <from> 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
|
# Main class
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
@@ -201,9 +218,14 @@ class EmailChannel:
|
|||||||
body: str,
|
body: str,
|
||||||
in_reply_to: str = "",
|
in_reply_to: str = "",
|
||||||
references: str = "",
|
references: str = "",
|
||||||
|
quoted_text: str = "",
|
||||||
|
quoted_from: str = "",
|
||||||
) -> str:
|
) -> str:
|
||||||
"""Send an email reply.
|
"""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.
|
Returns the new Message-ID so the caller can track the thread.
|
||||||
"""
|
"""
|
||||||
new_message_id = _generate_message_id(self._from_email)
|
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]
|
ref_parts = [r for r in [references, in_reply_to] if r]
|
||||||
new_references = " ".join(ref_parts)
|
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 = MIMEMultipart("alternative")
|
||||||
msg["From"] = self._from_email
|
msg["From"] = self._from_email
|
||||||
msg["To"] = to
|
msg["To"] = to
|
||||||
|
|||||||
Reference in New Issue
Block a user