fix: wrap original text in code block to avoid MarkdownV2 parse errors Email bodies contain *, _, etc. that break MarkdownV2 entity parsing. Wrapping in backtick code block prevents Telegram from parsing internals.
This commit is contained in:
@@ -365,7 +365,13 @@ def _handle_callback(bot_token: str, cfg: Config, cb: dict):
|
|||||||
|
|
||||||
if action == CALLBACK_VIEW_ORIG and ctx:
|
if action == CALLBACK_VIEW_ORIG and ctx:
|
||||||
can_reply = ctx.get("can_reply", True)
|
can_reply = ctx.get("can_reply", True)
|
||||||
text = f"*📄 原文 \\- {_escape(ctx['subject'])}*\n\n{_escape(ctx.get('plain_text', ctx['original_body']))}"
|
subject = ctx.get("subject", "邮件")
|
||||||
|
body = ctx.get("plain_text", ctx["original_body"])
|
||||||
|
if len(body) > 3500:
|
||||||
|
body = body[:3500] + "\n\n... (内容过长已截断)"
|
||||||
|
# 用代码块包裹原文,避免 MarkdownV2 解析特殊字符
|
||||||
|
escaped_body = body.replace("\\", "\\\\").replace("`", "\\`")
|
||||||
|
text = f"*📄 原文 \\- {_escape(subject)}*\n\n`{escaped_body}`"
|
||||||
_tg_req(bot_token, "editMessageText", {
|
_tg_req(bot_token, "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",
|
||||||
|
|||||||
Reference in New Issue
Block a user