mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-26 00:23:25 +00:00
fix multipart email body retrieval (#9790)
Description: Gmail message retrieval in GmailGetMessage and GmailSearch returned an empty string when encountering multipart emails. This change correctly extracts the email body for multipart emails. Dependencies: None @hwchase17 @vowelparrot
This commit is contained in:
parent
7d8bb78e5c
commit
50ca44c79f
@ -46,7 +46,16 @@ class GmailGetMessage(GmailBaseTool):
|
||||
subject = email_msg["Subject"]
|
||||
sender = email_msg["From"]
|
||||
|
||||
message_body = email_msg.get_payload()
|
||||
message_body = ""
|
||||
if email_msg.is_multipart():
|
||||
for part in email_msg.walk():
|
||||
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")
|
||||
break
|
||||
else:
|
||||
message_body = email_msg.get_payload(decode=True).decode("utf-8")
|
||||
|
||||
body = clean_email_body(message_body)
|
||||
|
||||
|
@ -91,7 +91,16 @@ class GmailSearch(GmailBaseTool):
|
||||
subject = email_msg["Subject"]
|
||||
sender = email_msg["From"]
|
||||
|
||||
message_body = email_msg.get_payload()
|
||||
message_body = ""
|
||||
if email_msg.is_multipart():
|
||||
for part in email_msg.walk():
|
||||
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")
|
||||
break
|
||||
else:
|
||||
message_body = email_msg.get_payload(decode=True).decode("utf-8")
|
||||
|
||||
body = clean_email_body(message_body)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user