feat(mail): Add support for multiple domains per mail service
- Add `Domains` field to MailServiceConfig for managing additional domains under single API - Implement `matchDomain` helper function for precise and subdomain matching logic - Update `GetServiceByDomain` to check both primary domain and additional domains list - Enhance EmailConfig UI to display domain count and allow comma-separated domain input - Add domains field to mail service request/response structures in API handlers - Update frontend types to include domains array in MailService interface - Improve documentation with clarification on primary vs additional domains usage - Allows single mail service API to manage multiple email domains for verification and operations
This commit is contained in:
@@ -100,14 +100,31 @@ func GetRandomService() config.MailServiceConfig {
|
||||
return currentMailServices[rand.Intn(len(currentMailServices))]
|
||||
}
|
||||
|
||||
// matchDomain 检查邮箱域名是否匹配服务域名(精确匹配或子域名匹配)
|
||||
func matchDomain(emailDomain, serviceDomain string) bool {
|
||||
if serviceDomain == "" {
|
||||
return false
|
||||
}
|
||||
return emailDomain == serviceDomain || strings.HasSuffix(emailDomain, "."+serviceDomain)
|
||||
}
|
||||
|
||||
// GetServiceByDomain 根据域名获取对应的邮箱服务
|
||||
// 会同时检查 Domain(主域名)和 Domains(附加域名列表)
|
||||
func GetServiceByDomain(domain string) *config.MailServiceConfig {
|
||||
mailServicesMutex.RLock()
|
||||
defer mailServicesMutex.RUnlock()
|
||||
|
||||
for _, s := range currentMailServices {
|
||||
if s.Domain == domain || strings.HasSuffix(domain, "."+s.Domain) {
|
||||
return &s
|
||||
for i := range currentMailServices {
|
||||
s := ¤tMailServices[i]
|
||||
// 检查主域名
|
||||
if matchDomain(domain, s.Domain) {
|
||||
return s
|
||||
}
|
||||
// 检查附加域名列表
|
||||
for _, d := range s.Domains {
|
||||
if matchDomain(domain, d) {
|
||||
return s
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user