feat: handle Reply-To header, add account_email field, decode address headers

This commit is contained in:
2026-07-02 22:37:15 +08:00
parent d7daddf491
commit c684090b9c
4 changed files with 43 additions and 14 deletions

View File

@@ -22,7 +22,8 @@ _conversations: dict[int, dict] = {}
@retry()
def send_summary(tg_cfg: TelegramConfig, chat_id: str, summary_text: str,
summary_data: dict, original_body: str, account_idx: int,
original_sender: str = "", original_recipient: str = "") -> int:
original_sender: str = "", original_recipient: str = "",
original_reply_to: str = "", account_email: str = "") -> int:
can_reply = summary_data.get("can_reply", True)
result = _tg_req(tg_cfg, "sendMessage", {
"chat_id": chat_id,
@@ -37,7 +38,9 @@ def send_summary(tg_cfg: TelegramConfig, chat_id: str, summary_text: str,
"original_body": original_body[:10000],
"original_sender": original_sender or summary_data.get("sender", ""),
"original_recipient": original_recipient or summary_data.get("recipient", ""),
"original_reply_to": original_reply_to,
"account_idx": account_idx,
"account_email": account_email,
"sender": summary_data.get("sender", ""),
"subject": summary_data.get("subject", ""),
"can_reply": can_reply,
@@ -89,7 +92,7 @@ def poll_telegram(tg_cfg: TelegramConfig, cfg: Config, last_update_id: int) -> i
# ── Formatting ──────────────────────────────────────────
def format_summary(data: dict) -> str:
def format_summary(data: dict, account_email: str = "") -> str:
priority = data.get("priority", "medium")
icon = _priority_icon.get(priority, "")
lines = [
@@ -97,6 +100,7 @@ def format_summary(data: dict) -> str:
"━━━━━━━━━━━━━━━━━━",
f"*收件人:* {_escape(data.get('recipient', '未知'))}",
f"*发件人:* {_escape(data.get('sender', '未知'))}",
f"*账户:* {_escape(account_email)}",
f"*优先级:* {icon} {priority.upper()}",
"",
_escape(data.get("summary", "")),
@@ -407,7 +411,9 @@ def _do_send_reply(tg_cfg: TelegramConfig, cfg: Config,
if not acct.smtp:
send_text(tg_cfg, str(chat_id), "❌ 该邮箱未配置 SMTP无法发送回复。")
return
to_addr = parseaddr(ctx["original_sender"])[1]
to_addr = parseaddr(ctx.get("original_reply_to", ""))[1]
if not to_addr:
to_addr = parseaddr(ctx["original_sender"])[1]
if not to_addr:
to_addr = parseaddr(ctx["sender"])[1]
if not to_addr: