Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,15 +13,17 @@ 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 |
|
| 18 |
-
# Extract
|
| 19 |
-
attack_score =
|
| 20 |
-
attack_type =
|
| 21 |
-
verdict =
|
| 22 |
|
|
|
|
| 23 |
score_val = int("".join(filter(str.isdigit, attack_score)))
|
| 24 |
-
if score_val > 100:
|
| 25 |
score_val = 100
|
| 26 |
|
| 27 |
# Verdict color
|
|
@@ -34,19 +36,11 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 34 |
verdict_color = "#f1c40f"
|
| 35 |
|
| 36 |
# Extract sections
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
body_index = results.index("---- Highlighted Body ----")
|
| 41 |
-
except ValueError:
|
| 42 |
-
html = "<pre>" + "\n".join(results) + "</pre>"
|
| 43 |
-
return html, None
|
| 44 |
|
| 45 |
-
|
| 46 |
-
findings = results[findings_index + 1 : body_index]
|
| 47 |
-
highlighted_body = results[body_index + 1 :]
|
| 48 |
-
|
| 49 |
-
# HTML Report with collapsible sections
|
| 50 |
html = f"""
|
| 51 |
<div style='font-family: Arial, sans-serif; padding: 20px; max-width: 800px; margin:auto;'>
|
| 52 |
<h2 style="color:#2c3e50;">π§ Email Security Report</h2>
|
|
@@ -58,7 +52,7 @@ def analyze_email(file_path, export_pdf=False):
|
|
| 58 |
</div>
|
| 59 |
<p><b>Attack Type:</b> {attack_type}</p>
|
| 60 |
<p><b>Final Verdict:</b> <span style="background:{verdict_color}; color:white; padding:4px 10px; border-radius:6px;">
|
| 61 |
-
{verdict
|
| 62 |
</span></p>
|
| 63 |
<details style="margin-top:15px;">
|
| 64 |
<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 |
+
# Updated analyzer returns summary (dict) and details (dict)
|
| 17 |
+
summary, details = analyze(file_path)
|
| 18 |
|
| 19 |
+
# Extract score, attack type, verdict
|
| 20 |
+
attack_score = summary.get("Attack Score", "0")
|
| 21 |
+
attack_type = summary.get("Attack Type", "Unknown")
|
| 22 |
+
verdict = summary.get("Final Verdict", "Safe")
|
| 23 |
|
| 24 |
+
# Cap score at 100
|
| 25 |
score_val = int("".join(filter(str.isdigit, attack_score)))
|
| 26 |
+
if score_val > 100:
|
| 27 |
score_val = 100
|
| 28 |
|
| 29 |
# Verdict color
|
|
|
|
| 36 |
verdict_color = "#f1c40f"
|
| 37 |
|
| 38 |
# Extract sections
|
| 39 |
+
tags = details.get("Attack Analysis Tags", [])
|
| 40 |
+
findings = details.get("Detailed Findings", [])
|
| 41 |
+
highlighted_body = details.get("Highlighted Body", [])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
+
# HTML Report
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
</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>
|