mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-27 08:58:48 +00:00
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:
parent
6da08d0f22
commit
b9a495e56e
@ -98,7 +98,12 @@ class GmailSearch(GmailBaseTool):
|
|||||||
ctype = part.get_content_type()
|
ctype = part.get_content_type()
|
||||||
cdispo = str(part.get("Content-Disposition"))
|
cdispo = str(part.get("Content-Disposition"))
|
||||||
if ctype == "text/plain" and "attachment" not in cdispo:
|
if ctype == "text/plain" and "attachment" not in cdispo:
|
||||||
|
try:
|
||||||
message_body = part.get_payload(decode=True).decode("utf-8")
|
message_body = part.get_payload(decode=True).decode("utf-8")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
message_body = part.get_payload(decode=True).decode(
|
||||||
|
"latin-1"
|
||||||
|
)
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
message_body = email_msg.get_payload(decode=True).decode("utf-8")
|
message_body = email_msg.get_payload(decode=True).decode("utf-8")
|
||||||
|
Loading…
Reference in New Issue
Block a user