Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import re
|
3 |
+
import dns.resolver
|
4 |
+
import socket
|
5 |
+
import smtplib
|
6 |
+
from typing import Tuple, Union
|
7 |
+
|
8 |
+
def check_syntax(mail_address: str) -> bool:
|
9 |
+
"""์ด๋ฉ์ผ ์ฃผ์ ๊ตฌ๋ฌธ ๊ฒ์ฌ"""
|
10 |
+
match = re.match('[A-Za-z0-9._+]+@[A-Za-z]+.[A-Za-z]', mail_address)
|
11 |
+
return match is not None
|
12 |
+
|
13 |
+
def check_dns(domain: str) -> Tuple[bool, str]:
|
14 |
+
"""DNS MX ๋ ์ฝ๋ ๊ฒ์ฌ"""
|
15 |
+
try:
|
16 |
+
records = dns.resolver.query(domain, 'MX')
|
17 |
+
mx_record = str(records[0].exchange)
|
18 |
+
return True, mx_record
|
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('[email protected]')
|
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 |
+
if not check_syntax(mail_address):
|
44 |
+
return "โ ์ด๋ฉ์ผ ์ฃผ์ ํ์์ด ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค."
|
45 |
+
result_messages.append("โ
์ด๋ฉ์ผ ์ฃผ์ ํ์์ด ์ฌ๋ฐ๋ฆ
๋๋ค.")
|
46 |
+
|
47 |
+
# 2. ๋๋ฉ์ธ ์ถ์ถ
|
48 |
+
domain = mail_address.split('@')[1]
|
49 |
+
|
50 |
+
# 3. DNS MX ๋ ์ฝ๋ ๊ฒ์ฌ
|
51 |
+
dns_valid, mx_record = check_dns(domain)
|
52 |
+
if not dns_valid:
|
53 |
+
return "\n".join(result_messages + ["โ ๋๋ฉ์ธ์ ๋ฉ์ผ ์๋ฒ๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค."])
|
54 |
+
result_messages.append("โ
๋๋ฉ์ธ์ ๋ฉ์ผ ์๋ฒ๊ฐ ์กด์ฌํฉ๋๋ค.")
|
55 |
+
|
56 |
+
# 4. SMTP ๊ฒ์ฌ
|
57 |
+
if not check_smtp(mail_address, mx_record):
|
58 |
+
return "\n".join(result_messages + ["โ ์ด๋ฉ์ผ ์ฃผ์๊ฐ ์กด์ฌํ์ง ์๊ฑฐ๋ ํ์ธํ ์ ์์ต๋๋ค."])
|
59 |
+
result_messages.append("โ
์ด๋ฉ์ผ ์ฃผ์๊ฐ ์ ํจํฉ๋๋ค.")
|
60 |
+
|
61 |
+
return "\n".join(result_messages)
|
62 |
+
|
63 |
+
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
64 |
+
iface = gr.Interface(
|
65 |
+
fn=validate_email,
|
66 |
+
inputs=gr.Textbox(label="์ด๋ฉ์ผ ์ฃผ์๋ฅผ ์
๋ ฅํ์ธ์", placeholder="[email protected]"),
|
67 |
+
outputs=gr.Textbox(label="๊ฒ์ฆ ๊ฒฐ๊ณผ"),
|
68 |
+
title="์ด๋ฉ์ผ ์ฃผ์ ๊ฒ์ฆ ๋๊ตฌ",
|
69 |
+
description="์
๋ ฅ๋ ์ด๋ฉ์ผ ์ฃผ์์ ์ ํจ์ฑ์ ์ฌ๋ฌ ๋จ๊ณ์ ๊ฑธ์ณ ๊ฒ์ฆํฉ๋๋ค.",
|
70 |
+
examples=[
|
71 |
+
["[email protected]"],
|
72 |
+
["[email protected]"],
|
73 |
+
["malformed@@email.com"]
|
74 |
+
]
|
75 |
+
)
|
76 |
+
|
77 |
+
# ์ ํ๋ฆฌ์ผ์ด์
์คํ
|
78 |
+
if __name__ == "__main__":
|
79 |
+
iface.launch()
|