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 json
|
||||||
import logging
|
import logging
|
||||||
|
from email.utils import parseaddr
|
||||||
import requests
|
import requests
|
||||||
from src.config import TelegramConfig, Config
|
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.smtp_client import send_reply
|
||||||
from src.retry import retry
|
from src.retry import retry
|
||||||
|
|
||||||
@@ -230,8 +230,8 @@ def _handle_callback(tg_cfg: TelegramConfig, cfg: Config, cb: dict):
|
|||||||
|
|
||||||
text = "*AI 建议回复,请选择:*\n\n"
|
text = "*AI 建议回复,请选择:*\n\n"
|
||||||
for i, s in enumerate(suggestions, 1):
|
for i, s in enumerate(suggestions, 1):
|
||||||
tag = "✅ 可直接发送" if s.get("is_simple") else "📝 需确认"
|
tag = "✅ 无需确认" if s.get("is_simple") else "📝 需确认后发送"
|
||||||
text += f"{i}\\. {_escape(s['text'])} _{tag}_\n"
|
text += f"{i}\\. {_escape(s['text'])}\n *{tag}*\n"
|
||||||
_tg_req(tg_cfg, "editMessageText", {
|
_tg_req(tg_cfg, "editMessageText", {
|
||||||
"chat_id": chat_id, "message_id": msg_id,
|
"chat_id": chat_id, "message_id": msg_id,
|
||||||
"text": text, "parse_mode": "MarkdownV2",
|
"text": text, "parse_mode": "MarkdownV2",
|
||||||
@@ -308,6 +308,8 @@ def _do_send_reply(tg_cfg: TelegramConfig, cfg: Config,
|
|||||||
if not acct.smtp:
|
if not acct.smtp:
|
||||||
send_text(tg_cfg, str(chat_id), "❌ 该邮箱未配置 SMTP,无法发送回复。")
|
send_text(tg_cfg, str(chat_id), "❌ 该邮箱未配置 SMTP,无法发送回复。")
|
||||||
return
|
return
|
||||||
|
to_addr = parseaddr(ctx["sender"])[1]
|
||||||
|
if not to_addr:
|
||||||
to_addr = ctx["sender"]
|
to_addr = ctx["sender"]
|
||||||
subject = ctx["subject"]
|
subject = ctx["subject"]
|
||||||
send_reply(acct, to_addr, subject, reply_text)
|
send_reply(acct, to_addr, subject, reply_text)
|
||||||
|
|||||||
Reference in New Issue
Block a user