feat(services): 新增标准 IMAP 邮箱服务支持(Gmail/QQ/163等)

- 新增 EmailServiceType.IMAP_MAIL 枚举值和默认配置
- 新建 ImapMailService(imaplib 标准库,强制直连)
- 注册路由新增 imap_mail 分支和 available-services 键
- 邮箱服务路由新增 imap_mail stats 统计和类型描述
- accounts 路由 _build_inbox_config 支持 imap_mail
- 前端表单/列表/编辑完整支持 IMAP 子类型
- 无新增依赖
This commit is contained in:
cnlimiter
2026-03-20 15:37:27 +08:00
parent 9ada1f6ec6
commit 0059cf97bd
10 changed files with 399 additions and 12 deletions

View File

@@ -1002,6 +1002,7 @@ def _build_inbox_config(db, service_type, email: str) -> dict:
EST.TEMP_MAIL: "temp_mail",
EST.DUCK_MAIL: "duck_mail",
EST.FREEMAIL: "freemail",
EST.IMAP_MAIL: "imap_mail",
EST.OUTLOOK: "outlook",
}
db_type = type_map.get(service_type)

View File

@@ -146,6 +146,7 @@ async def get_email_services_stats():
'temp_mail_count': 0,
'duck_mail_count': 0,
'freemail_count': 0,
'imap_mail_count': 0,
'tempmail_available': True, # 临时邮箱始终可用
'enabled_count': enabled_count
}
@@ -161,6 +162,8 @@ async def get_email_services_stats():
stats['duck_mail_count'] = count
elif service_type == 'freemail':
stats['freemail_count'] = count
elif service_type == 'imap_mail':
stats['imap_mail_count'] = count
return stats
@@ -231,6 +234,18 @@ async def get_service_types():
{"name": "admin_token", "label": "Admin Token", "required": True, "secret": True},
{"name": "domain", "label": "邮箱域名", "required": False, "placeholder": "example.com"},
]
},
{
"value": "imap_mail",
"label": "IMAP 邮箱",
"description": "标准 IMAP 协议邮箱Gmail/QQ/163等仅用于接收验证码强制直连",
"config_fields": [
{"name": "host", "label": "IMAP 服务器", "required": True, "placeholder": "imap.gmail.com"},
{"name": "port", "label": "端口", "required": False, "default": 993},
{"name": "use_ssl", "label": "使用 SSL", "required": False, "default": True},
{"name": "email", "label": "邮箱地址", "required": True},
{"name": "password", "label": "密码/授权码", "required": True, "secret": True},
]
}
]
}

View File

@@ -372,6 +372,20 @@ def _run_sync_registration_task(task_uuid: str, email_service_type: str, proxy:
logger.info(f"使用数据库 Freemail 服务: {db_service.name}")
else:
raise ValueError("没有可用的 Freemail 邮箱服务,请先在邮箱服务页面添加服务")
elif service_type == EmailServiceType.IMAP_MAIL:
from ...database.models import EmailService as EmailServiceModel
db_service = db.query(EmailServiceModel).filter(
EmailServiceModel.service_type == "imap_mail",
EmailServiceModel.enabled == True
).order_by(EmailServiceModel.priority.asc()).first()
if db_service and db_service.config:
config = _normalize_email_service_config(service_type, db_service.config, actual_proxy_url)
crud.update_registration_task(db, task_uuid, email_service_id=db_service.id)
logger.info(f"使用数据库 IMAP 邮箱服务: {db_service.name}")
else:
raise ValueError("没有可用的 IMAP 邮箱服务,请先在邮箱服务中添加")
else:
config = email_service_config or {}
@@ -1110,6 +1124,11 @@ async def get_available_email_services():
"available": False,
"count": 0,
"services": []
},
"imap_mail": {
"available": False,
"count": 0,
"services": []
}
}
@@ -1219,6 +1238,25 @@ async def get_available_email_services():
result["freemail"]["count"] = len(freemail_services)
result["freemail"]["available"] = len(freemail_services) > 0
imap_mail_services = db.query(EmailServiceModel).filter(
EmailServiceModel.service_type == "imap_mail",
EmailServiceModel.enabled == True
).order_by(EmailServiceModel.priority.asc()).all()
for service in imap_mail_services:
config = service.config or {}
result["imap_mail"]["services"].append({
"id": service.id,
"name": service.name,
"type": "imap_mail",
"email": config.get("email"),
"host": config.get("host"),
"priority": service.priority
})
result["imap_mail"]["count"] = len(imap_mail_services)
result["imap_mail"]["available"] = len(imap_mail_services) > 0
return result