Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,17 +13,16 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 13 |
if file_path is None:
|
| 14 |
return "<p style='color:red;'>Please upload a .eml file to analyze.</p>", None
|
| 15 |
|
| 16 |
-
|
| 17 |
-
summary, details = analyze(file_path)
|
| 18 |
|
| 19 |
-
# Extract
|
| 20 |
-
attack_score =
|
| 21 |
-
attack_type =
|
| 22 |
-
verdict =
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
score_val = int(
|
| 26 |
-
if score_val > 100:
|
| 27 |
score_val = 100
|
| 28 |
|
| 29 |
# Verdict color
|
|
@@ -36,11 +35,19 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 36 |
verdict_color = "#f1c40f"
|
| 37 |
|
| 38 |
# Extract sections
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
html = f"""
|
| 45 |
<div style='font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin:auto;'>
|
| 46 |
<h2 style="color:#2c3e50;">π§ Email Security Report</h2>
|
|
@@ -52,7 +59,7 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 52 |
</div>
|
| 53 |
<p><b>Attack Type:</b> {attack_type}</p>
|
| 54 |
<p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
|
| 55 |
-
{verdict}
|
| 56 |
</span></p>
|
| 57 |
<details style="margin-top:15px;">
|
| 58 |
<summary>π Attack Analysis Tags ({len(tags)})</summary>
|
|
|
|
| 13 |
if file_path is None:
|
| 14 |
return "<p style='color:red;'>Please upload a .eml file to analyze.</p>", None
|
| 15 |
|
| 16 |
+
results = analyze(file_path)
|
|
|
|
| 17 |
|
| 18 |
+
# Extract basic verdict info
|
| 19 |
+
attack_score = results[0]
|
| 20 |
+
attack_type = results[1]
|
| 21 |
+
verdict = results[2]
|
| 22 |
|
| 23 |
+
# Correct handling of attack_score (already int)
|
| 24 |
+
score_val = int(attack_score)
|
| 25 |
+
if score_val > 100:
|
| 26 |
score_val = 100
|
| 27 |
|
| 28 |
# Verdict color
|
|
|
|
| 35 |
verdict_color = "#f1c40f"
|
| 36 |
|
| 37 |
# Extract sections
|
| 38 |
+
try:
|
| 39 |
+
tags_index = results.index("---- Attack Analysis Tags ----")
|
| 40 |
+
findings_index = results.index("---- Detailed Findings ----")
|
| 41 |
+
body_index = results.index("---- Highlighted Body ----")
|
| 42 |
+
except ValueError:
|
| 43 |
+
html = "<pre>" + "\n".join(results) + "</pre>"
|
| 44 |
+
return html, None
|
| 45 |
|
| 46 |
+
tags = results[tags_index + 1 : findings_index]
|
| 47 |
+
findings = results[findings_index + 1 : body_index]
|
| 48 |
+
highlighted_body = results[body_index + 1 :]
|
| 49 |
+
|
| 50 |
+
# HTML Report with collapsible sections
|
| 51 |
html = f"""
|
| 52 |
<div style='font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin:auto;'>
|
| 53 |
<h2 style="color:#2c3e50;">π§ Email Security Report</h2>
|
|
|
|
| 59 |
</div>
|
| 60 |
<p><b>Attack Type:</b> {attack_type}</p>
|
| 61 |
<p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
|
| 62 |
+
{verdict.replace('Final Verdict:', '').strip()}
|
| 63 |
</span></p>
|
| 64 |
<details style="margin-top:15px;">
|
| 65 |
<summary>π Attack Analysis Tags ({len(tags)})</summary>
|