princemaxp commited on
Commit
67a74ee
·
verified ·
1 Parent(s): 90ca431

Update analyze_email_main.py

Browse files
Files changed (1) hide show
  1. analyze_email_main.py +16 -11
analyze_email_main.py CHANGED
@@ -4,13 +4,17 @@ from body_analyzer import analyze_body
4
  from url_analyzer import analyze_urls
5
 
6
  def analyze(file_path):
 
7
  headers, body, urls = parse_email(file_path)
8
 
 
9
  header_findings, header_score = analyze_headers(headers)
10
  body_findings, body_score, highlighted_body = analyze_body(body)
11
  url_findings, url_score = analyze_urls(urls)
12
 
13
- total_score = header_score + body_score + url_score
 
 
14
  if total_score > 100:
15
  total_score = 100
16
 
@@ -24,7 +28,7 @@ def analyze(file_path):
24
  else:
25
  verdict = "✅ Safe"
26
 
27
- # --- Attack Type ---
28
  body_lower = body.lower()
29
  if any(word in body_lower for word in ["invoice", "payment", "wire transfer", "bank details"]):
30
  attack_type = "Invoice/Payment Fraud (BEC)"
@@ -39,34 +43,35 @@ def analyze(file_path):
39
  else:
40
  attack_type = "General Phishing"
41
 
42
- # --- Collect tags ---
43
  tags = []
44
  for finding in header_findings + body_findings + url_findings:
45
- if "domain" in finding.lower():
 
46
  tags.append("Suspicious Sender Domain")
47
- if "phishing" in finding.lower():
48
- tags.append("Phishing URL")
49
- if "urgent" in finding.lower() or "suspicious phrase" in finding.lower():
50
  tags.append("Urgent Language")
51
- if "spam" in finding.lower():
52
  tags.append("Spam Tone")
53
 
54
- # --- Build report ---
55
  report = [
56
  f"Attack Score: {total_score}",
57
  f"Attack Type: {attack_type}",
58
  f"Final Verdict: {verdict}",
59
  "---- Attack Analysis Tags ----",
60
- ", ".join(set(tags)) if tags else "No special tags",
61
  "---- Detailed Findings ----",
62
  ]
63
-
64
  report.extend(header_findings + body_findings + url_findings)
65
  report.append("---- Highlighted Body ----")
66
  report.append(highlighted_body)
67
 
68
  return report
69
 
 
70
  if __name__ == "__main__":
71
  file_path = "sample.eml"
72
  findings = analyze(file_path)
 
4
  from url_analyzer import analyze_urls
5
 
6
  def analyze(file_path):
7
+ # --- Parse email ---
8
  headers, body, urls = parse_email(file_path)
9
 
10
+ # --- Analyze different components ---
11
  header_findings, header_score = analyze_headers(headers)
12
  body_findings, body_score, highlighted_body = analyze_body(body)
13
  url_findings, url_score = analyze_urls(urls)
14
 
15
+ # --- Weighted total score ---
16
+ # Give extra weight to URLs and phishing indicators
17
+ total_score = header_score + body_score + (url_score * 1.5)
18
  if total_score > 100:
19
  total_score = 100
20
 
 
28
  else:
29
  verdict = "✅ Safe"
30
 
31
+ # --- Determine attack type ---
32
  body_lower = body.lower()
33
  if any(word in body_lower for word in ["invoice", "payment", "wire transfer", "bank details"]):
34
  attack_type = "Invoice/Payment Fraud (BEC)"
 
43
  else:
44
  attack_type = "General Phishing"
45
 
46
+ # --- Collect tags for detailed analysis ---
47
  tags = []
48
  for finding in header_findings + body_findings + url_findings:
49
+ f_lower = finding.lower()
50
+ if "domain" in f_lower:
51
  tags.append("Suspicious Sender Domain")
52
+ if "phishing" in f_lower or "malicious url" in f_lower:
53
+ tags.append("Phishing / Malicious URL")
54
+ if "urgent" in f_lower or "suspicious phrase" in f_lower:
55
  tags.append("Urgent Language")
56
+ if "spam" in f_lower or "marketing" in f_lower:
57
  tags.append("Spam Tone")
58
 
59
+ # --- Build final report ---
60
  report = [
61
  f"Attack Score: {total_score}",
62
  f"Attack Type: {attack_type}",
63
  f"Final Verdict: {verdict}",
64
  "---- Attack Analysis Tags ----",
65
+ ", ".join(sorted(set(tags))) if tags else "No special tags",
66
  "---- Detailed Findings ----",
67
  ]
 
68
  report.extend(header_findings + body_findings + url_findings)
69
  report.append("---- Highlighted Body ----")
70
  report.append(highlighted_body)
71
 
72
  return report
73
 
74
+ # --- For testing locally ---
75
  if __name__ == "__main__":
76
  file_path = "sample.eml"
77
  findings = analyze(file_path)