This commit is contained in:
hailin 2025-07-22 00:25:58 +08:00
parent 7f9d821b71
commit 572ef7e01a
1 changed files with 18 additions and 4 deletions

View File

@ -12,6 +12,9 @@ from datetime import datetime
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.utils import formataddr
import base64
import random
import string
CONFIG_DIR = os.path.join(os.path.dirname(__file__), "config")
logging.basicConfig(level=logging.INFO,
@ -51,10 +54,20 @@ def detect_smtp_port(host: str):
logging.error(f"SMTP 端口探测失败: {e}")
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 进制字符串"""
return "".join(f"{ord(c) ^ key:02x}" for c in src)
# def xor_encode(src: str, key: int) -> str:
# """把邮箱做异或后返回 16 进制字符串"""
# return "".join(f"{ord(c) ^ key:02x}" for c in src)
# ---------- 读取 port 并建立连接 ---------- ✨ new
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:
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_template
.replace("{{recipient_name}}", recipient_name)