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
pull/9791/head^2
Juhee Kim 1 year ago committed by GitHub
parent 7d8bb78e5c
commit 50ca44c79f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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…
Cancel
Save