Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,77 +1,74 @@
|
|
1 |
import gradio as gr
|
2 |
import re
|
3 |
import dns.resolver
|
4 |
-
import
|
5 |
-
import smtplib
|
6 |
-
from typing import Tuple, Union
|
7 |
|
8 |
-
def check_syntax(mail_address: str) -> bool:
|
9 |
"""์ด๋ฉ์ผ ์ฃผ์ ๊ตฌ๋ฌธ ๊ฒ์ฌ"""
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def check_dns(domain: str) -> Tuple[bool, str]:
|
14 |
"""DNS MX ๋ ์ฝ๋ ๊ฒ์ฌ"""
|
15 |
try:
|
16 |
-
records = dns.resolver.
|
17 |
-
|
18 |
-
|
|
|
19 |
except Exception as e:
|
20 |
-
return False, str(e)
|
21 |
-
|
22 |
-
def check_smtp(mail_address: str, mx_record: str) -> bool:
|
23 |
-
"""SMTP ์๋ฒ ์ฐ๊ฒฐ ๊ฒ์ฌ"""
|
24 |
-
try:
|
25 |
-
local_host = socket.gethostname()
|
26 |
-
server = smtplib.SMTP(timeout=10)
|
27 |
-
server.set_debuglevel(0)
|
28 |
-
server.connect(mx_record)
|
29 |
-
server.helo(local_host)
|
30 |
-
server.mail('test_test_test@yahoo.co.jp')
|
31 |
-
code, message = server.rcpt(str(mail_address))
|
32 |
-
server.quit()
|
33 |
-
return code == 250
|
34 |
-
except Exception:
|
35 |
-
return False
|
36 |
|
37 |
def validate_email(mail_address: str) -> str:
|
38 |
"""์ด๋ฉ์ผ ์ฃผ์ ์ข
ํฉ ๊ฒ์ฆ"""
|
39 |
-
|
40 |
-
result_messages = []
|
41 |
|
42 |
# 1. ๊ตฌ๋ฌธ ๊ฒ์ฌ
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
# 2. ๋๋ฉ์ธ ์ถ์ถ
|
48 |
-
domain = mail_address.split('@')[1]
|
49 |
|
50 |
-
#
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
60 |
|
61 |
-
return "\n".join(
|
62 |
|
63 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
64 |
iface = gr.Interface(
|
65 |
fn=validate_email,
|
66 |
-
inputs=gr.Textbox(
|
|
|
|
|
|
|
67 |
outputs=gr.Textbox(label="๊ฒ์ฆ ๊ฒฐ๊ณผ"),
|
68 |
title="์ด๋ฉ์ผ ์ฃผ์ ๊ฒ์ฆ ๋๊ตฌ",
|
69 |
-
description="
|
|
|
|
|
|
|
|
|
70 |
examples=[
|
71 |
-
["test@
|
72 |
-
["
|
|
|
73 |
["malformed@@email.com"]
|
74 |
-
]
|
|
|
75 |
)
|
76 |
|
77 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
|
|
1 |
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 |
+
match = re.match(pattern, mail_address)
|
11 |
+
if match:
|
12 |
+
return True, "โ
์ด๋ฉ์ผ ์ฃผ์ ํ์์ด ์ฌ๋ฐ๋ฆ
๋๋ค."
|
13 |
+
return False, "โ ์ด๋ฉ์ผ ์ฃผ์ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค."
|
14 |
|
15 |
def check_dns(domain: str) -> Tuple[bool, str]:
|
16 |
"""DNS MX ๋ ์ฝ๋ ๊ฒ์ฌ"""
|
17 |
try:
|
18 |
+
records = dns.resolver.resolve(domain, 'MX') # query ๋์ resolve ์ฌ์ฉ
|
19 |
+
if records:
|
20 |
+
return True, "โ
๋๋ฉ์ธ์ ๋ฉ์ผ ์๋ฒ๊ฐ ์กด์ฌํฉ๋๋ค."
|
21 |
+
return False, "โ ๋๋ฉ์ธ์ ๋ฉ์ผ ์๋ฒ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."
|
22 |
except Exception as e:
|
23 |
+
return False, f"โ DNS ํ์ธ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
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 |
+
# 2. ๋๋ฉ์ธ ์ถ์ถ ๋ฐ DNS ๊ฒ์ฌ
|
36 |
+
try:
|
37 |
+
domain = mail_address.split('@')[1]
|
38 |
+
dns_valid, dns_msg = check_dns(domain)
|
39 |
+
results.append(dns_msg)
|
40 |
+
if not dns_valid:
|
41 |
+
return "\n".join(results)
|
42 |
+
|
43 |
+
# ๊ฒ์ฆ ์ฑ๊ณต
|
44 |
+
results.append("โ
์ด๋ฉ์ผ ์ฃผ์๊ฐ ์ ํจํฉ๋๋ค.")
|
45 |
+
|
46 |
+
except Exception as e:
|
47 |
+
results.append(f"โ ๊ฒ์ฆ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
48 |
|
49 |
+
return "\n".join(results)
|
50 |
|
51 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
52 |
iface = gr.Interface(
|
53 |
fn=validate_email,
|
54 |
+
inputs=gr.Textbox(
|
55 |
+
label="์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์
๋ ฅํ์ธ์",
|
56 |
+
placeholder="example@domain.com"
|
57 |
+
),
|
58 |
outputs=gr.Textbox(label="๊ฒ์ฆ ๊ฒฐ๊ณผ"),
|
59 |
title="์ด๋ฉ์ผ ์ฃผ์ ๊ฒ์ฆ ๋๊ตฌ",
|
60 |
+
description="""
|
61 |
+
์ด ๋๊ตฌ๋ ๋ค์ ์ฌํญ๋ค์ ๊ฒ์ฆํฉ๋๋ค:
|
62 |
+
1. ์ด๋ฉ์ผ ์ฃผ์ ํ์ ๊ฒ์ฌ
|
63 |
+
2. ๋๋ฉ์ธ์ ๋ฉ์ผ ์๋ฒ(MX ๋ ์ฝ๋) ์กด์ฌ ์ฌ๋ถ ํ์ธ
|
64 |
+
""",
|
65 |
examples=[
|
66 |
+
["test@gmail.com"],
|
67 |
+
["user@yahoo.com"],
|
68 |
+
["invalid@nonexistent.domain"],
|
69 |
["malformed@@email.com"]
|
70 |
+
],
|
71 |
+
theme=gr.themes.Soft() # ๋ถ๋๋ฌ์ด ํ
๋ง ์ ์ฉ
|
72 |
)
|
73 |
|
74 |
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|