File size: 1,489 Bytes
89419ea | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | """
Outlook 账户数据类
"""
from dataclasses import dataclass
from typing import Dict, Any, Optional
@dataclass
class OutlookAccount:
"""Outlook 账户信息"""
email: str
password: str = ""
client_id: str = ""
refresh_token: str = ""
@classmethod
def from_config(cls, config: Dict[str, Any]) -> "OutlookAccount":
"""从配置创建账户"""
return cls(
email=config.get("email", ""),
password=config.get("password", ""),
client_id=config.get("client_id", ""),
refresh_token=config.get("refresh_token", "")
)
def has_oauth(self) -> bool:
"""是否支持 OAuth2"""
return bool(self.client_id and self.refresh_token)
def validate(self) -> bool:
"""验证账户信息是否有效"""
return bool(self.email and self.password) or self.has_oauth()
def to_dict(self, include_sensitive: bool = False) -> Dict[str, Any]:
"""转换为字典"""
result = {
"email": self.email,
"has_oauth": self.has_oauth(),
}
if include_sensitive:
result.update({
"password": self.password,
"client_id": self.client_id,
"refresh_token": self.refresh_token[:20] + "..." if self.refresh_token else "",
})
return result
def __str__(self) -> str:
"""字符串表示"""
return f"OutlookAccount({self.email})"
|