ForcePilot/backend/package/yuxi/channel/extensions/email_smtp/pairing.py
Kris 59c6caaa64 feat(email-smtp): 新增SMTP/IMAP邮件渠道插件
实现完整的邮件收发渠道,支持IMAP IDLE实时收信、SMTP发信,包含附件校验、重复消息去重、OAuth2认证、邮件内容解析与引用剥离、邮件发送限流与连接池等功能
2026-05-21 10:45:56 +08:00

29 lines
815 B
Python

from __future__ import annotations
import random
import time
class EmailSmtpPairingAdapter:
id_label = "email_address"
def __init__(self):
self._codes: dict[str, dict] = {}
self._code_ttl = 600
def generate_code(self, peer_id: str) -> str:
code = str(random.randint(100000, 999999))
self._codes[peer_id] = {"code": code, "ts": time.monotonic()}
return code
def verify_code(self, peer_id: str, code: str) -> bool:
entry = self._codes.get(peer_id)
if not entry:
return False
if time.monotonic() - entry["ts"] > self._code_ttl:
del self._codes[peer_id]
return False
return entry["code"] == code
def normalize_allow_entry(self, entry: str) -> str:
return entry.strip().lower()