community[patch]: added latin-1 decoder to gmail search tool (#18116)

some mails from flipkart , amazon are encoded with other plain text
format so to handle UnicodeDecode error , added exception and latin
decoder

Thank you for contributing to LangChain!

@hwchase17
This commit is contained in:
Sanjaypranav V M 2024-02-29 00:58:29 +05:30 committed by GitHub
parent 6da08d0f22
commit b9a495e56e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -98,7 +98,12 @@ class GmailSearch(GmailBaseTool):
ctype = part.get_content_type()
cdispo = str(part.get("Content-Disposition"))
if ctype == "text/plain" and "attachment" not in cdispo:
message_body = part.get_payload(decode=True).decode("utf-8")
try:
message_body = part.get_payload(decode=True).decode("utf-8")
except UnicodeDecodeError:
message_body = part.get_payload(decode=True).decode(
"latin-1"
)
break
else:
message_body = email_msg.get_payload(decode=True).decode("utf-8")