This commit is contained in:
parent
7f9d821b71
commit
572ef7e01a
|
|
@ -12,6 +12,9 @@ from datetime import datetime
|
||||||
from email.mime.text import MIMEText
|
from email.mime.text import MIMEText
|
||||||
from email.mime.multipart import MIMEMultipart
|
from email.mime.multipart import MIMEMultipart
|
||||||
from email.utils import formataddr
|
from email.utils import formataddr
|
||||||
|
import base64
|
||||||
|
import random
|
||||||
|
import string
|
||||||
|
|
||||||
CONFIG_DIR = os.path.join(os.path.dirname(__file__), "config")
|
CONFIG_DIR = os.path.join(os.path.dirname(__file__), "config")
|
||||||
logging.basicConfig(level=logging.INFO,
|
logging.basicConfig(level=logging.INFO,
|
||||||
|
|
@ -51,10 +54,20 @@ def detect_smtp_port(host: str):
|
||||||
logging.error(f"SMTP 端口探测失败: {e}")
|
logging.error(f"SMTP 端口探测失败: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def encode_with_random_wrapper(email: str) -> str:
|
||||||
|
"""
|
||||||
|
生成符合后端要求的 ID:<1~5位前缀> + base64(email) + <1~5位后缀>
|
||||||
|
后端 slice(1, -1) 后可 base64 decode 出原始 email
|
||||||
|
"""
|
||||||
|
base64_email = base64.b64encode(email.encode('utf-8')).decode('utf-8')
|
||||||
|
prefix = ''.join(random.choices(string.ascii_letters + string.digits, k=random.randint(1, 5)))
|
||||||
|
suffix = ''.join(random.choices(string.ascii_letters + string.digits, k=random.randint(1, 5)))
|
||||||
|
return prefix + base64_email + suffix
|
||||||
|
|
||||||
def xor_encode(src: str, key: int) -> str:
|
|
||||||
"""把邮箱做异或后返回 16 进制字符串"""
|
# def xor_encode(src: str, key: int) -> str:
|
||||||
return "".join(f"{ord(c) ^ key:02x}" for c in src)
|
# """把邮箱做异或后返回 16 进制字符串"""
|
||||||
|
# return "".join(f"{ord(c) ^ key:02x}" for c in src)
|
||||||
|
|
||||||
# ---------- 读取 port 并建立连接 ---------- ✨ new
|
# ---------- 读取 port 并建立连接 ---------- ✨ new
|
||||||
def connect_smtp(host: str, config: dict):
|
def connect_smtp(host: str, config: dict):
|
||||||
|
|
@ -105,7 +118,8 @@ def send_email(key, to_address, subject, body_template, recipient_name,
|
||||||
if not recipient_name:
|
if not recipient_name:
|
||||||
recipient_name = "老板" if language == "chinese" else "there"
|
recipient_name = "老板" if language == "chinese" else "there"
|
||||||
|
|
||||||
encoded_email = xor_encode(to_address, 0xAE)
|
# encoded_email = xor_encode(to_address, 0xAE)
|
||||||
|
encoded_email = encode_with_random_wrapper(to_address)
|
||||||
body = (
|
body = (
|
||||||
body_template
|
body_template
|
||||||
.replace("{{recipient_name}}", recipient_name)
|
.replace("{{recipient_name}}", recipient_name)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue