File size: 1,500 Bytes
8187a21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import streamlit as st
import email
import email.policy

# Define the phishing detection function
def is_phishing(email_content):
    phishing_keywords = [
        'urgent', 'account verification', 'password reset',
        'login required', 'confirm your identity', 'payment details',
        'verify your account', 'security alert'
    ]

    msg = email.message_from_string(email_content, policy=email.policy.default)
    email_text = msg['subject'] + ' '
    if msg.is_multipart():
        for part in msg.walk():
            content_type = part.get_content_type()
            content_disposition = str(part.get("Content-Disposition"))
            
            if content_type == "text/plain" and "attachment" not in content_disposition:
                email_text += part.get_payload(decode=True).decode()
            elif content_type == "text/html" and "attachment" not in content_disposition:
                email_text += part.get_payload(decode=True).decode()
    else:
        email_text += msg.get_payload(decode=True).decode()

    for keyword in phishing_keywords:
        if keyword in email_text.lower():
            return True

    return False

# Streamlit app layout
st.title('Phishing Email Detector')

# Text area for user input
user_input = st.text_area("Paste the email content here:", height=300)

if st.button('Check Email'):
    if is_phishing(user_input):
        st.error("This email might be a phishing attempt.")
    else:
        st.success("This email seems safe.")