Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,16 +9,30 @@ def extract_latest_message(raw_email):
|
|
9 |
# Parse the email using mail-parser
|
10 |
mail = mailparser.parse_from_string(raw_email)
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Check if the email contains plain text parts
|
13 |
if mail.text_plain:
|
14 |
body = mail.text_plain[0]
|
15 |
st.write("Extracted plain text body from email.")
|
16 |
-
|
17 |
# If no plain text is available, fall back to HTML body
|
18 |
-
body = mail.
|
19 |
st.write("Extracted HTML body from email. Converting to plain text...")
|
20 |
# Use BeautifulSoup to strip HTML tags and convert to plain text
|
21 |
body = BeautifulSoup(body, "html.parser").get_text()
|
|
|
|
|
22 |
|
23 |
# Debugging: Output the cleaned-up email body before using EmailReplyParser
|
24 |
st.write("Cleaned-up email body before parsing:")
|
|
|
9 |
# Parse the email using mail-parser
|
10 |
mail = mailparser.parse_from_string(raw_email)
|
11 |
|
12 |
+
# Debugging: Display entire mail object to inspect its content
|
13 |
+
st.write("Parsed Email Object:")
|
14 |
+
st.json(mail.mail_json)
|
15 |
+
|
16 |
+
# Inspect text parts of the email (plain text and HTML)
|
17 |
+
text_parts = mail.text_plain
|
18 |
+
html_parts = mail.text_html
|
19 |
+
|
20 |
+
# Debugging: Output all parts to check what's available
|
21 |
+
st.write("Text Parts:", text_parts)
|
22 |
+
st.write("HTML Parts:", html_parts)
|
23 |
+
|
24 |
# Check if the email contains plain text parts
|
25 |
if mail.text_plain:
|
26 |
body = mail.text_plain[0]
|
27 |
st.write("Extracted plain text body from email.")
|
28 |
+
elif mail.text_html:
|
29 |
# If no plain text is available, fall back to HTML body
|
30 |
+
body = mail.text_html[0]
|
31 |
st.write("Extracted HTML body from email. Converting to plain text...")
|
32 |
# Use BeautifulSoup to strip HTML tags and convert to plain text
|
33 |
body = BeautifulSoup(body, "html.parser").get_text()
|
34 |
+
else:
|
35 |
+
body = "No body content found in email."
|
36 |
|
37 |
# Debugging: Output the cleaned-up email body before using EmailReplyParser
|
38 |
st.write("Cleaned-up email body before parsing:")
|