Jinnrry 054336fe9e
v2.6.1 (#169)
1、新增垃圾邮件过滤插件
2、使用使用github.com/dlclark/regexp2替换go原生的正则包
3、修复空数据导致的邮件插入失败
2024-07-20 10:39:17 +08:00

41 lines
1.2 KiB
Go

package setup
import (
"fmt"
"github.com/Jinnrry/pmail/i18n"
"github.com/Jinnrry/pmail/services/auth"
"github.com/Jinnrry/pmail/utils/context"
"github.com/Jinnrry/pmail/utils/errors"
"github.com/Jinnrry/pmail/utils/ip"
)
type DNSItem struct {
Type string `json:"type"`
Host string `json:"host"`
Value string `json:"value"`
TTL int `json:"ttl"`
Tips string `json:"tips"`
}
func GetDNSSettings(ctx *context.Context) (map[string][]*DNSItem, error) {
configData, err := ReadConfig()
if err != nil {
return nil, errors.Wrap(err)
}
ret := make(map[string][]*DNSItem)
for _, domain := range configData.Domains {
ret[domain] = []*DNSItem{
{Type: "A", Host: "smtp", Value: ip.GetIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
{Type: "A", Host: "pop", Value: ip.GetIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
{Type: "A", Host: "@", Value: ip.GetIp(), TTL: 3600, Tips: i18n.GetText(ctx.Lang, "ip_taps")},
{Type: "MX", Host: "@", Value: fmt.Sprintf("smtp.%s", domain), TTL: 3600},
{Type: "TXT", Host: "@", Value: "v=spf1 a mx ~all", TTL: 3600},
{Type: "TXT", Host: "default._domainkey", Value: auth.DkimGen(), TTL: 3600},
}
}
return ret, nil
}