fix: parse sender email properly & show confirmation tag clearly
- Use email.utils.parseaddr() to extract pure email from sender field (was passing raw 'Name <email>' to SMTP, causing 550 error) - AI reply selection now shows confirmation status as bold tag on its own line for better visibility
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user