thread fix
This commit is contained in:
parent
d58fb8841b
commit
a58ba11566
11 changed files with 177 additions and 30 deletions
|
|
@ -4,19 +4,13 @@ from html import unescape
|
|||
# Patterns that mark the start of quoted previous-message content.
|
||||
TEXT_QUOTE_MARKERS = [
|
||||
re.compile(r"\n-{2,}\s*Original Message\s*-{2,}", re.IGNORECASE),
|
||||
re.compile(
|
||||
r"\nOn .+? wrote:\s*\n",
|
||||
re.IGNORECASE,
|
||||
),
|
||||
re.compile(
|
||||
r"\nOn .+?, .+? at .+? .+? wrote:\s*\n",
|
||||
re.IGNORECASE,
|
||||
),
|
||||
re.compile(r"(?:^|\n)\s*On .+? wrote:\s*", re.IGNORECASE),
|
||||
re.compile(
|
||||
r"\nFrom:\s*.+\nSent:\s*.+\nTo:\s*.+\nSubject:\s*.+",
|
||||
re.IGNORECASE,
|
||||
),
|
||||
re.compile(r"\n_{5,}\n"),
|
||||
re.compile(r"\n\s*> ?"),
|
||||
]
|
||||
|
||||
HTML_QUOTE_PATTERNS = [
|
||||
|
|
@ -110,6 +104,46 @@ def extract_new_reply_content(
|
|||
}
|
||||
|
||||
|
||||
def reply_fields_for_message(
|
||||
message: dict,
|
||||
*,
|
||||
body_text: str | None,
|
||||
body_html: str | None = None,
|
||||
) -> dict[str, str | bool]:
|
||||
if "new_reply_content" in message:
|
||||
return {
|
||||
"new_reply_content": message.get("new_reply_content", ""),
|
||||
"quoted_content": message.get("quoted_content", ""),
|
||||
"has_quoted_text": bool(message.get("has_quoted_text") or message.get("quoted_content")),
|
||||
}
|
||||
built = build_reply_display(body_text=body_text, body_html=body_html)
|
||||
return {
|
||||
"new_reply_content": built["new_reply_content"],
|
||||
"quoted_content": built["quoted_content"],
|
||||
"has_quoted_text": built["has_quoted_text"],
|
||||
}
|
||||
|
||||
|
||||
def build_reply_display(
|
||||
*,
|
||||
body_text: str | None,
|
||||
body_html: str | None = None,
|
||||
limit: int = 240,
|
||||
) -> dict[str, str | bool]:
|
||||
extracted = extract_new_reply_content(body_text=body_text, body_html=body_html)
|
||||
new_content = extracted["new_reply_content"]
|
||||
quoted = extracted["quoted_content"]
|
||||
fallback = re.sub(r"\s+", " ", (body_text or "")).strip()
|
||||
snippet_source = new_content or fallback
|
||||
return {
|
||||
"new_reply_content": new_content,
|
||||
"quoted_content": quoted,
|
||||
"has_quoted_text": bool(quoted),
|
||||
"raw_body": extracted["raw_body"],
|
||||
"snippet": re.sub(r"\s+", " ", snippet_source).strip()[:limit],
|
||||
}
|
||||
|
||||
|
||||
def validate_external_reply_body(body: str) -> bool:
|
||||
normalized = (body or "").strip()
|
||||
if not normalized:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue