Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions libs/community/langchain_google_community/gmail/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def _parse_messages(self, messages: List[Dict[str, Any]]) -> List[Dict[str, Any]

email_msg = email.message_from_bytes(raw_message)

subject = email_msg["Subject"]
sender = email_msg["From"]
subject = email_msg.get("Subject", "")
sender = email_msg.get("From", "")

message_body = ""
if email_msg.is_multipart():
Expand All @@ -99,18 +99,22 @@ def _parse_messages(self, messages: List[Dict[str, Any]]) -> List[Dict[str, Any]
cdispo = str(part.get("Content-Disposition"))
if ctype == "text/plain" and "attachment" not in cdispo:
try:
message_body = part.get_payload(decode=True).decode("utf-8") # type: ignore[union-attr]
message_body = part.get_payload(decode=True).decode( # type: ignore[union-attr]
"utf-8", errors="replace"
)
except UnicodeDecodeError:
message_body = part.get_payload(decode=True).decode( # type: ignore[union-attr]
"latin-1"
"latin-1", errors="replace"
)
break
else:
try:
message_body = email_msg.get_payload(decode=True).decode("utf-8") # type: ignore[union-attr]
message_body = email_msg.get_payload(decode=True).decode( # type: ignore[union-attr]
"utf-8", errors="replace"
)
except UnicodeDecodeError:
message_body = email_msg.get_payload(decode=True).decode( # type: ignore[union-attr]
"latin-1"
"latin-1", errors="replace"
)
Comment on lines 101 to 118
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fallback to latin-1 encoding with errors='replace' is redundant since the primary utf-8 decode now also uses errors='replace'. Consider removing this exception handling block or using a different fallback encoding strategy.

Copilot uses AI. Check for mistakes.
Comment on lines 101 to 118
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the multipart case, this fallback exception handling is now redundant since the primary utf-8 decode uses errors='replace'. Consider removing this block or implementing a different fallback strategy.

Copilot uses AI. Check for mistakes.

body = clean_email_body(message_body)
Expand Down