diff --git a/src/summarizer.py b/src/summarizer.py index df7df7d..4946d05 100644 --- a/src/summarizer.py +++ b/src/summarizer.py @@ -31,6 +31,7 @@ def ai_process(cfg: Config, acct_idx: int, mail: Email) -> Optional[dict]: "text": text, "data": summary, "original_body": mail.body, + "original_sender": mail.sender, "acct_idx": acct_idx, "uid": mail.uid, } @@ -40,6 +41,7 @@ def tg_send_and_mark(cfg: Config, info: dict): acct = cfg.email_accounts[info["acct_idx"]] send_summary(cfg.telegram, cfg.telegram.chat_id, info["text"], info["data"], - info["original_body"], info["acct_idx"]) + info["original_body"], info["acct_idx"], + original_sender=info.get("original_sender", "")) mark_as_seen(acct, [info["uid"]]) logger.info(f" 已发送并标记已读") diff --git a/src/tg_bot.py b/src/tg_bot.py index 116e11a..540f554 100644 --- a/src/tg_bot.py +++ b/src/tg_bot.py @@ -21,7 +21,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) -> int: + summary_data: dict, original_body: str, account_idx: int, + original_sender: str = "") -> int: can_reply = summary_data.get("can_reply", True) result = _tg_req(tg_cfg, "sendMessage", { "chat_id": chat_id, @@ -34,6 +35,7 @@ def send_summary(tg_cfg: TelegramConfig, chat_id: str, summary_text: str, "summary_text": summary_text, "summary_data": summary_data, "original_body": original_body[:10000], + "original_sender": original_sender or summary_data.get("sender", ""), "account_idx": account_idx, "sender": summary_data.get("sender", ""), "subject": summary_data.get("subject", ""), @@ -381,7 +383,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["sender"])[1] + to_addr = parseaddr(ctx["original_sender"])[1] + if not to_addr: + to_addr = parseaddr(ctx["sender"])[1] if not to_addr: to_addr = ctx["sender"] subject = ctx["subject"]