format
This commit is contained in:
@@ -99,6 +99,28 @@ def _extract_message_bodies(payload):
|
||||
}
|
||||
|
||||
|
||||
def _format_body_content(text_body: str, html_body: str) -> str:
|
||||
"""
|
||||
Helper function to format message body content with HTML fallback and truncation.
|
||||
|
||||
Args:
|
||||
text_body: Plain text body content
|
||||
html_body: HTML body content
|
||||
|
||||
Returns:
|
||||
Formatted body content string
|
||||
"""
|
||||
if text_body.strip():
|
||||
return text_body
|
||||
elif html_body.strip():
|
||||
# Truncate very large HTML to keep responses manageable
|
||||
if len(html_body) > HTML_BODY_TRUNCATE_LIMIT:
|
||||
html_body = html_body[:HTML_BODY_TRUNCATE_LIMIT] + "\n\n[HTML content truncated...]"
|
||||
return f"[HTML Content Converted]\n{html_body}"
|
||||
else:
|
||||
return "[No readable content found]"
|
||||
|
||||
|
||||
def _extract_headers(payload: dict, header_names: List[str]) -> Dict[str, str]:
|
||||
"""
|
||||
Extract specified headers from a Gmail message payload.
|
||||
@@ -357,15 +379,7 @@ async def get_gmail_message_content(
|
||||
html_body = bodies.get("html", "")
|
||||
|
||||
# Format body content with HTML fallback
|
||||
if text_body.strip():
|
||||
body_data = text_body
|
||||
elif html_body.strip():
|
||||
# Truncate very large HTML to keep responses manageable
|
||||
if len(html_body) > HTML_BODY_TRUNCATE_LIMIT:
|
||||
html_body = html_body[:HTML_BODY_TRUNCATE_LIMIT] + "\n\n[HTML content truncated...]"
|
||||
body_data = f"[HTML Content Converted]\n{html_body}"
|
||||
else:
|
||||
body_data = "[No readable content found]"
|
||||
body_data = _format_body_content(text_body, html_body)
|
||||
|
||||
content_text = "\n".join(
|
||||
[
|
||||
@@ -534,15 +548,7 @@ async def get_gmail_messages_content_batch(
|
||||
html_body = bodies.get("html", "")
|
||||
|
||||
# Format body content with HTML fallback
|
||||
if text_body.strip():
|
||||
body_data = text_body
|
||||
elif html_body.strip():
|
||||
# Truncate very large HTML to keep batch responses manageable
|
||||
if len(html_body) > HTML_BODY_TRUNCATE_LIMIT:
|
||||
html_body = html_body[:HTML_BODY_TRUNCATE_LIMIT] + "\n\n[HTML content truncated...]"
|
||||
body_data = f"[HTML Content Converted]\n{html_body}"
|
||||
else:
|
||||
body_data = "[No readable content found]"
|
||||
body_data = _format_body_content(text_body, html_body)
|
||||
|
||||
output_messages.append(
|
||||
f"Message ID: {mid}\n"
|
||||
@@ -779,15 +785,7 @@ def _format_thread_content(thread_data: dict, thread_id: str) -> str:
|
||||
html_body = bodies.get("html", "")
|
||||
|
||||
# Format body content with HTML fallback
|
||||
if text_body.strip():
|
||||
body_data = text_body
|
||||
elif html_body.strip():
|
||||
# Truncate very large HTML to keep batch responses manageable
|
||||
if len(html_body) > HTML_BODY_TRUNCATE_LIMIT:
|
||||
html_body = html_body[:HTML_BODY_TRUNCATE_LIMIT] + "\n\n[HTML content truncated...]"
|
||||
body_data = f"[HTML Content Converted]\n{html_body}"
|
||||
else:
|
||||
body_data = "[No readable content found]"
|
||||
body_data = _format_body_content(text_body, html_body)
|
||||
|
||||
# Add message to content
|
||||
content_lines.extend(
|
||||
|
||||
Reference in New Issue
Block a user