albertoarrigoni commited on
Commit
a6b8e87
·
verified ·
1 Parent(s): 21b56e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -9,15 +9,21 @@ def extract_latest_message(raw_email):
9
  # Parse the email using mail-parser
10
  mail = mailparser.parse_from_string(raw_email)
11
 
12
- # Extract the plain text body if available
13
  if mail.text_plain:
14
  body = mail.text_plain[0]
 
15
  else:
16
- # If plain text is not available, fallback to HTML body and convert to plain text
17
  body = mail.body
18
- # Use BeautifulSoup to strip HTML tags and get plain text
 
19
  body = BeautifulSoup(body, "html.parser").get_text()
20
 
 
 
 
 
21
  # Use email-reply-parser to extract only the latest reply (remove quoted thread)
22
  latest_reply = EmailReplyParser.parse_reply(body)
23
 
 
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
  else:
17
+ # If no plain text is available, fall back to HTML body
18
  body = mail.body
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:")
25
+ st.text_area("Parsed Body", value=body, height=200)
26
+
27
  # Use email-reply-parser to extract only the latest reply (remove quoted thread)
28
  latest_reply = EmailReplyParser.parse_reply(body)
29