feat: show email subject and sender in all status messages
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
import re
|
||||
from typing import Generator, Optional
|
||||
from src.config import Config
|
||||
from src.email_client import fetch_unseen_emails, mark_as_seen, Email
|
||||
@@ -7,6 +8,17 @@ from src.tg_bot import send_summary, send_thinking, edit_message, format_summary
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
_MD_SPECIAL = re.compile(r"([_*\[\]()~`>#+\-=|{}.!\\])")
|
||||
|
||||
def _escape_md(text: str) -> str:
|
||||
return _MD_SPECIAL.sub(r"\\\1", text)
|
||||
|
||||
|
||||
def _mail_label(mail: Email) -> str:
|
||||
sender_short = mail.sender.split("<")[0].strip() if "<" in mail.sender else mail.sender.split("@")[0]
|
||||
subject_short = mail.subject[:30] + ("…" if len(mail.subject) > 30 else "")
|
||||
return f"{_escape_md(sender_short)} · {_escape_md(subject_short)}"
|
||||
|
||||
|
||||
def poll_accounts(cfg: Config, skip_uids: set[bytes] | None = None) -> Generator[tuple[int, Email], None, None]:
|
||||
for idx, acct in enumerate(cfg.email_accounts):
|
||||
@@ -23,14 +35,15 @@ def poll_accounts(cfg: Config, skip_uids: set[bytes] | None = None) -> Generator
|
||||
|
||||
def ai_process(cfg: Config, acct_idx: int, mail: Email, tg_msg_id: int = 0) -> Optional[dict]:
|
||||
logger.info(f" 正在摘要: {mail.subject}")
|
||||
label = _mail_label(mail)
|
||||
# 阶段1:显示等待处理
|
||||
if tg_msg_id:
|
||||
edit_message(cfg.telegram, cfg.telegram.chat_id, tg_msg_id, "⏳ 等待处理…")
|
||||
edit_message(cfg.telegram, cfg.telegram.chat_id, tg_msg_id, f"⏳ *等待处理…*\n{label}")
|
||||
else:
|
||||
tg_msg_id = send_thinking(cfg.telegram, cfg.telegram.chat_id, "⏳ 等待处理…")
|
||||
tg_msg_id = send_thinking(cfg.telegram, cfg.telegram.chat_id, f"⏳ *等待处理…*\n{label}")
|
||||
|
||||
# 阶段2:AI 处理,更新为思考中
|
||||
edit_message(cfg.telegram, cfg.telegram.chat_id, tg_msg_id, "🤖 AI思考中…")
|
||||
edit_message(cfg.telegram, cfg.telegram.chat_id, tg_msg_id, f"🤖 *AI思考中…*\n{label}")
|
||||
summary = summarize_email(cfg.ai, mail.recipient, mail.subject, mail.sender, mail.body, mail.account_email)
|
||||
summary["recipient"] = mail.recipient
|
||||
if "@" not in summary.get("sender", ""):
|
||||
|
||||
Reference in New Issue
Block a user