File size: 2,474 Bytes
2ec2072
 
 
800e08b
2ec2072
800e08b
2ec2072
800e08b
 
 
 
 
 
2ec2072
 
 
 
800e08b
 
 
 
2ec2072
800e08b
2ec2072
 
 
800e08b
2ec2072
 
800e08b
 
 
 
2ec2072
800e08b
 
 
 
 
 
 
 
 
 
 
 
 
2ec2072
800e08b
2ec2072
 
 
 
800e08b
 
 
 
2ec2072
 
800e08b
 
 
 
 
2ec2072
800e08b
 
 
2ec2072
800e08b
 
2ec2072
 
 
 
 
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import gradio as gr
import re
import dns.resolver
from typing import Tuple

def check_syntax(mail_address: str) -> Tuple[bool, str]:
    """์ด๋ฉ”์ผ ์ฃผ์†Œ ๊ตฌ๋ฌธ ๊ฒ€์‚ฌ"""
    # ๋” ์ •ํ™•ํ•œ ์ด๋ฉ”์ผ ์ •๊ทœ์‹ ํŒจํ„ด
    pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
    match = re.match(pattern, mail_address)
    if match:
        return True, "โœ… ์ด๋ฉ”์ผ ์ฃผ์†Œ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฆ…๋‹ˆ๋‹ค."
    return False, "โŒ ์ด๋ฉ”์ผ ์ฃผ์†Œ ํ˜•์‹์ด ์˜ฌ๋ฐ”๋ฅด์ง€ ์•Š์Šต๋‹ˆ๋‹ค."

def check_dns(domain: str) -> Tuple[bool, str]:
    """DNS MX ๋ ˆ์ฝ”๋“œ ๊ฒ€์‚ฌ"""
    try:
        records = dns.resolver.resolve(domain, 'MX')  # query ๋Œ€์‹  resolve ์‚ฌ์šฉ
        if records:
            return True, "โœ… ๋„๋ฉ”์ธ์˜ ๋ฉ”์ผ ์„œ๋ฒ„๊ฐ€ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค."
        return False, "โŒ ๋„๋ฉ”์ธ์˜ ๋ฉ”์ผ ์„œ๋ฒ„๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค."
    except Exception as e:
        return False, f"โŒ DNS ํ™•์ธ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}"

def validate_email(mail_address: str) -> str:
    """์ด๋ฉ”์ผ ์ฃผ์†Œ ์ข…ํ•ฉ ๊ฒ€์ฆ"""
    results = []
    
    # 1. ๊ตฌ๋ฌธ ๊ฒ€์‚ฌ
    syntax_valid, syntax_msg = check_syntax(mail_address)
    results.append(syntax_msg)
    if not syntax_valid:
        return "\n".join(results)
    
    # 2. ๋„๋ฉ”์ธ ์ถ”์ถœ ๋ฐ DNS ๊ฒ€์‚ฌ
    try:
        domain = mail_address.split('@')[1]
        dns_valid, dns_msg = check_dns(domain)
        results.append(dns_msg)
        if not dns_valid:
            return "\n".join(results)
        
        # ๊ฒ€์ฆ ์„ฑ๊ณต
        results.append("โœ… ์ด๋ฉ”์ผ ์ฃผ์†Œ๊ฐ€ ์œ ํšจํ•ฉ๋‹ˆ๋‹ค.")
        
    except Exception as e:
        results.append(f"โŒ ๊ฒ€์ฆ ์ค‘ ์˜ค๋ฅ˜ ๋ฐœ์ƒ: {str(e)}")
    
    return "\n".join(results)

# Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
iface = gr.Interface(
    fn=validate_email,
    inputs=gr.Textbox(
        label="์ด๋ฉ”์ผ ์ฃผ์†Œ๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”",
        placeholder="[email protected]"
    ),
    outputs=gr.Textbox(label="๊ฒ€์ฆ ๊ฒฐ๊ณผ"),
    title="์ด๋ฉ”์ผ ์ฃผ์†Œ ๊ฒ€์ฆ ๋„๊ตฌ",
    description="""
    ์ด ๋„๊ตฌ๋Š” ๋‹ค์Œ ์‚ฌํ•ญ๋“ค์„ ๊ฒ€์ฆํ•ฉ๋‹ˆ๋‹ค:
    1. ์ด๋ฉ”์ผ ์ฃผ์†Œ ํ˜•์‹ ๊ฒ€์‚ฌ
    2. ๋„๋ฉ”์ธ์˜ ๋ฉ”์ผ ์„œ๋ฒ„(MX ๋ ˆ์ฝ”๋“œ) ์กด์žฌ ์—ฌ๋ถ€ ํ™•์ธ
    """,
    examples=[
        ["[email protected]"],
        ["[email protected]"],
        ["[email protected]"],
        ["malformed@@email.com"]
    ],
    theme=gr.themes.Soft()  # ๋ถ€๋“œ๋Ÿฌ์šด ํ…Œ๋งˆ ์ ์šฉ
)

# ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰
if __name__ == "__main__":
    iface.launch()