Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,23 +2,80 @@ import gradio as gr
|
|
2 |
import re
|
3 |
import dns.resolver
|
4 |
from typing import Tuple
|
|
|
5 |
|
6 |
def check_syntax(mail_address: str) -> Tuple[bool, str]:
|
7 |
"""μ΄λ©μΌ μ£Όμ ꡬ문 κ²μ¬"""
|
8 |
-
# λ
|
9 |
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
def check_dns(domain: str) -> Tuple[bool, str]:
|
16 |
"""DNS MX λ μ½λ κ²μ¬"""
|
17 |
try:
|
18 |
-
|
19 |
-
if
|
20 |
-
return
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
except Exception as e:
|
23 |
return False, f"β DNS νμΈ μ€ μ€λ₯ λ°μ: {str(e)}"
|
24 |
|
@@ -26,13 +83,21 @@ def validate_email(mail_address: str) -> str:
|
|
26 |
"""μ΄λ©μΌ μ£Όμ μ’
ν© κ²μ¦"""
|
27 |
results = []
|
28 |
|
29 |
-
# 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
syntax_valid, syntax_msg = check_syntax(mail_address)
|
31 |
results.append(syntax_msg)
|
32 |
if not syntax_valid:
|
33 |
return "\n".join(results)
|
34 |
|
35 |
-
#
|
36 |
try:
|
37 |
domain = mail_address.split('@')[1]
|
38 |
dns_valid, dns_msg = check_dns(domain)
|
@@ -40,7 +105,7 @@ def validate_email(mail_address: str) -> str:
|
|
40 |
if not dns_valid:
|
41 |
return "\n".join(results)
|
42 |
|
43 |
-
# κ²μ¦
|
44 |
results.append("β
μ΄λ©μΌ μ£Όμκ° μ ν¨ν©λλ€.")
|
45 |
|
46 |
except Exception as e:
|
@@ -59,16 +124,21 @@ iface = gr.Interface(
|
|
59 |
title="μ΄λ©μΌ μ£Όμ κ²μ¦ λꡬ",
|
60 |
description="""
|
61 |
μ΄ λꡬλ λ€μ μ¬νλ€μ κ²μ¦ν©λλ€:
|
62 |
-
1. μ΄λ©μΌ μ£Όμ νμ κ²μ¬
|
63 |
2. λλ©μΈμ λ©μΌ μλ²(MX λ μ½λ) μ‘΄μ¬ μ¬λΆ νμΈ
|
|
|
|
|
64 |
""",
|
65 |
examples=[
|
66 |
-
["
|
67 |
-
["
|
68 |
["invalid@nonexistent.domain"],
|
69 |
-
["malformed@@email.com"]
|
|
|
|
|
|
|
70 |
],
|
71 |
-
theme=gr.themes.Soft()
|
72 |
)
|
73 |
|
74 |
# μ ν리μΌμ΄μ
μ€ν
|
|
|
2 |
import re
|
3 |
import dns.resolver
|
4 |
from typing import Tuple
|
5 |
+
from dns.exception import DNSException
|
6 |
|
7 |
def check_syntax(mail_address: str) -> Tuple[bool, str]:
|
8 |
"""μ΄λ©μΌ μ£Όμ ꡬ문 κ²μ¬"""
|
9 |
+
# RFC 5322 νμ€μ κΈ°λ°μΌλ‘ ν λ μ격ν μ΄λ©μΌ μ κ·μ ν¨ν΄
|
10 |
pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
|
11 |
+
|
12 |
+
# κΈ°λ³Έ ν¨ν΄ κ²μ¬
|
13 |
+
if not re.match(pattern, mail_address):
|
14 |
+
return False, "β μ΄λ©μΌ μ£Όμ νμμ΄ μ¬λ°λ₯΄μ§ μμ΅λλ€."
|
15 |
+
|
16 |
+
# μΆκ° μ ν¨μ± κ²μ¬
|
17 |
+
local_part, domain = mail_address.split('@')
|
18 |
+
|
19 |
+
# λ‘컬 ννΈ κ²μ¬
|
20 |
+
if len(local_part) > 64:
|
21 |
+
return False, "β μ΄λ©μΌ μ£Όμμ @ μλΆλΆμ΄ λ무 κΉλλ€."
|
22 |
+
if local_part.startswith('.') or local_part.endswith('.'):
|
23 |
+
return False, "β μ΄λ©μΌ μ£Όμμ @ μλΆλΆμ΄ μ (.)μΌλ‘ μμνκ±°λ λλ μ μμ΅λλ€."
|
24 |
+
if '..' in local_part:
|
25 |
+
return False, "β μ΄λ©μΌ μ£Όμμ @ μλΆλΆμ μ°μλ μ (..)μ΄ μμ μ μμ΅λλ€."
|
26 |
+
|
27 |
+
# λλ©μΈ ννΈ κ²μ¬
|
28 |
+
if len(domain) > 255:
|
29 |
+
return False, "β λλ©μΈμ΄ λ무 κΉλλ€."
|
30 |
+
if domain.startswith('-') or domain.endswith('-'):
|
31 |
+
return False, "β λλ©μΈμ νμ΄ν(-)μΌλ‘ μμνκ±°λ λλ μ μμ΅λλ€."
|
32 |
+
if not all(part.isalnum() or '-' in part for part in domain.split('.')):
|
33 |
+
return False, "β λλ©μΈμ νμ©λμ§ μλ λ¬Έμκ° ν¬ν¨λμ΄ μμ΅λλ€."
|
34 |
+
|
35 |
+
return True, "β
μ΄λ©μΌ μ£Όμ νμμ΄ μ¬λ°λ¦
λλ€."
|
36 |
+
|
37 |
+
def is_disposable_domain(domain: str) -> bool:
|
38 |
+
"""μμ μ΄λ©μΌ λλ©μΈ 체ν¬"""
|
39 |
+
disposable_domains = {
|
40 |
+
'tempmail.com', 'throwawaymail.com', 'mailinator.com',
|
41 |
+
'temp-mail.org', 'fake-email.com', 'temporary-mail.net'
|
42 |
+
}
|
43 |
+
return domain.lower() in disposable_domains
|
44 |
|
45 |
def check_dns(domain: str) -> Tuple[bool, str]:
|
46 |
"""DNS MX λ μ½λ κ²μ¬"""
|
47 |
try:
|
48 |
+
# μμ μ΄λ©μΌ λλ©μΈ 체ν¬
|
49 |
+
if is_disposable_domain(domain):
|
50 |
+
return False, "β μμ μ΄λ©μΌ λλ©μΈμ μ¬μ©ν μ μμ΅λλ€."
|
51 |
+
|
52 |
+
# DNS MX λ μ½λ νμΈ
|
53 |
+
records = dns.resolver.resolve(domain, 'MX')
|
54 |
+
if not records:
|
55 |
+
return False, "β λλ©μΈμ λ©μΌ μλ²λ₯Ό μ°Ύμ μ μμ΅λλ€."
|
56 |
+
|
57 |
+
# μ€μ MX λ μ½λ λ΄μ© νμΈ
|
58 |
+
mx_records = [str(r.exchange).rstrip('.') for r in records]
|
59 |
+
if not mx_records:
|
60 |
+
return False, "β μ ν¨ν λ©μΌ μλ² μ λ³΄κ° μμ΅λλ€."
|
61 |
+
|
62 |
+
# A λ μ½λλ νμΈ
|
63 |
+
try:
|
64 |
+
dns.resolver.resolve(domain, 'A')
|
65 |
+
except DNSException:
|
66 |
+
try:
|
67 |
+
dns.resolver.resolve(domain, 'AAAA')
|
68 |
+
except DNSException:
|
69 |
+
return False, "β λλ©μΈμ΄ μ€μ λ‘ μ‘΄μ¬νμ§ μμ΅λλ€."
|
70 |
+
|
71 |
+
return True, "β
λλ©μΈμ λ©μΌ μλ²κ° μ‘΄μ¬ν©λλ€."
|
72 |
+
|
73 |
+
except dns.resolver.NXDOMAIN:
|
74 |
+
return False, "β μ‘΄μ¬νμ§ μλ λλ©μΈμ
λλ€."
|
75 |
+
except dns.resolver.NoAnswer:
|
76 |
+
return False, "β λλ©μΈμ λ©μΌ μλ² μ λ³΄κ° μμ΅λλ€."
|
77 |
+
except dns.resolver.NoNameservers:
|
78 |
+
return False, "β DNS μλ²μ μ°κ²°ν μ μμ΅λλ€."
|
79 |
except Exception as e:
|
80 |
return False, f"β DNS νμΈ μ€ μ€λ₯ λ°μ: {str(e)}"
|
81 |
|
|
|
83 |
"""μ΄λ©μΌ μ£Όμ μ’
ν© κ²μ¦"""
|
84 |
results = []
|
85 |
|
86 |
+
# 1. κΈ°λ³Έ μ
λ ₯κ° κ²μ¬
|
87 |
+
if not mail_address or not isinstance(mail_address, str):
|
88 |
+
return "β μ ν¨νμ§ μμ μ
λ ₯μ
λλ€."
|
89 |
+
|
90 |
+
mail_address = mail_address.strip()
|
91 |
+
if not mail_address:
|
92 |
+
return "β μ΄λ©μΌ μ£Όμλ₯Ό μ
λ ₯ν΄μ£ΌμΈμ."
|
93 |
+
|
94 |
+
# 2. ꡬ문 κ²μ¬
|
95 |
syntax_valid, syntax_msg = check_syntax(mail_address)
|
96 |
results.append(syntax_msg)
|
97 |
if not syntax_valid:
|
98 |
return "\n".join(results)
|
99 |
|
100 |
+
# 3. λλ©μΈ μΆμΆ λ° DNS κ²μ¬
|
101 |
try:
|
102 |
domain = mail_address.split('@')[1]
|
103 |
dns_valid, dns_msg = check_dns(domain)
|
|
|
105 |
if not dns_valid:
|
106 |
return "\n".join(results)
|
107 |
|
108 |
+
# λͺ¨λ κ²μ¦ ν΅κ³Ό
|
109 |
results.append("β
μ΄λ©μΌ μ£Όμκ° μ ν¨ν©λλ€.")
|
110 |
|
111 |
except Exception as e:
|
|
|
124 |
title="μ΄λ©μΌ μ£Όμ κ²μ¦ λꡬ",
|
125 |
description="""
|
126 |
μ΄ λꡬλ λ€μ μ¬νλ€μ κ²μ¦ν©λλ€:
|
127 |
+
1. μ΄λ©μΌ μ£Όμ νμ κ²μ¬ (RFC 5322 νμ€ μ€μ)
|
128 |
2. λλ©μΈμ λ©μΌ μλ²(MX λ μ½λ) μ‘΄μ¬ μ¬λΆ νμΈ
|
129 |
+
3. λλ©μΈμ μ€μ μ‘΄μ¬ μ¬λΆ νμΈ
|
130 |
+
4. μμ μ΄λ©μΌ λλ©μΈ νν°λ§
|
131 |
""",
|
132 |
examples=[
|
133 |
+
["user@gmail.com"],
|
134 |
+
["test@yahoo.com"],
|
135 |
["invalid@nonexistent.domain"],
|
136 |
+
["malformed@@email.com"],
|
137 |
+
["user@tempmail.com"],
|
138 |
+
["test@domain"],
|
139 |
+
["user.name@subdomain.example.com"]
|
140 |
],
|
141 |
+
theme=gr.themes.Soft()
|
142 |
)
|
143 |
|
144 |
# μ ν리μΌμ΄μ
μ€ν
|