优化了 gui
This commit is contained in:
+26
-16
@@ -1,5 +1,6 @@
|
||||
"""登录工作线程模块"""
|
||||
|
||||
import re
|
||||
import threading
|
||||
import time
|
||||
from queue import Queue
|
||||
@@ -8,33 +9,31 @@ from loguru import logger
|
||||
|
||||
from douyu import DouyuLogin
|
||||
from douyu.config import Account, ProxyConfig
|
||||
from douyu.email_verifier import get_email_config_for_account
|
||||
|
||||
|
||||
# IMAP服务器映射
|
||||
IMAP_SERVERS = {
|
||||
'qq.com': 'imap.qq.com',
|
||||
'163.com': 'imap.163.com',
|
||||
'126.com': 'imap.126.com',
|
||||
'gmail.com': 'imap.gmail.com',
|
||||
'outlook.com': 'outlook.office365.com',
|
||||
'hotmail.com': 'outlook.office365.com',
|
||||
'yeah.net': 'imap.yeah.net',
|
||||
'sohu.com': 'imap.sohu.com',
|
||||
'sina.com': 'imap.sina.com',
|
||||
}
|
||||
EMAIL_PATTERN = re.compile(r'^[^\s@|]+@[^\s@|]+\.[^\s@|]+$')
|
||||
|
||||
|
||||
def get_imap_server(email: str) -> str:
|
||||
"""从邮箱地址推导IMAP服务器"""
|
||||
domain = email.split('@')[-1].lower()
|
||||
return IMAP_SERVERS.get(domain, f'imap.{domain}')
|
||||
return get_email_config_for_account(email)['server']
|
||||
|
||||
|
||||
def _is_ascii(value: str) -> bool:
|
||||
"""检查字符串是否为ASCII。"""
|
||||
try:
|
||||
value.encode('ascii')
|
||||
return True
|
||||
except UnicodeEncodeError:
|
||||
return False
|
||||
|
||||
|
||||
def parse_accounts_text(text: str) -> list[Account]:
|
||||
"""
|
||||
解析账号文本
|
||||
|
||||
格式:用户名|密码|邮箱|邮箱密码(每行一个)
|
||||
格式:用户名|密码|邮箱|邮箱密码
|
||||
|
||||
Returns:
|
||||
Account列表
|
||||
@@ -47,7 +46,7 @@ def parse_accounts_text(text: str) -> list[Account]:
|
||||
continue
|
||||
|
||||
parts = line.split('|')
|
||||
if len(parts) < 4:
|
||||
if len(parts) != 4:
|
||||
logger.warning(f"第{line_num}行格式错误,需要4个字段,实际{len(parts)}个: {line}")
|
||||
continue
|
||||
|
||||
@@ -57,6 +56,17 @@ def parse_accounts_text(text: str) -> list[Account]:
|
||||
logger.warning(f"第{line_num}行存在空字段: {line}")
|
||||
continue
|
||||
|
||||
if not EMAIL_PATTERN.match(email) or not _is_ascii(email):
|
||||
logger.warning(
|
||||
f"第{line_num}行邮箱格式不正确: {email},"
|
||||
"请确认格式为:用户名|密码|邮箱|邮箱密码"
|
||||
)
|
||||
continue
|
||||
|
||||
if not _is_ascii(email_password):
|
||||
logger.warning(f"第{line_num}行邮箱密码/授权码包含非ASCII字符,IMAP可能无法登录")
|
||||
continue
|
||||
|
||||
accounts.append(Account(
|
||||
username=username,
|
||||
password=password,
|
||||
|
||||
Reference in New Issue
Block a user