From 3d33aeb0dd7b83676019847f8237b689c661484a Mon Sep 17 00:00:00 2001 From: Zichao Lin Date: Thu, 2 Jul 2026 20:35:28 +0800 Subject: [PATCH] fix: parse sender email properly & show confirmation tag clearly - Use email.utils.parseaddr() to extract pure email from sender field (was passing raw 'Name ' to SMTP, causing 550 error) - AI reply selection now shows confirmation status as bold tag on its own line for better visibility --- src/tg_bot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/tg_bot.py b/src/tg_bot.py index 7716c3f..f26fb61 100644 --- a/src/tg_bot.py +++ b/src/tg_bot.py @@ -1,8 +1,8 @@ import json import logging +from email.utils import parseaddr import requests from src.config import TelegramConfig, Config -# reply suggestions come embedded in summary_data from summarize_email from src.smtp_client import send_reply from src.retry import retry @@ -230,8 +230,8 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict): text = "*AI 建议回复,请选择:*\n\n" for i, s in enumerate(suggestions, 1): - tag = "✅ 可直接发送" if s.get("is_simple") else "📝 需确认" - text += f"{i}\\. {_escape(s['text'])} _{tag}_\n" + tag = "✅ 无需确认" if s.get("is_simple") else "📝 需确认后发送" + text += f"{i}\\. {_escape(s['text'])}\n *{tag}*\n" _tg_req(tg_cfg, "editMessageText", { "chat_id": chat_id, "message_id": msg_id, "text": text, "parse_mode": "MarkdownV2", @@ -308,6 +308,8 @@ def _do_send_reply(tg_cfg: TelegramConfig, cfg: Config, if not acct.smtp: send_text(tg_cfg, str(chat_id), "❌ 该邮箱未配置 SMTP,无法发送回复。") return - to_addr = ctx["sender"] + to_addr = parseaddr(ctx["sender"])[1] + if not to_addr: + to_addr = ctx["sender"] subject = ctx["subject"] send_reply(acct, to_addr, subject, reply_text)