feat: 重构配置文件格式并添加 IMAP ID 命令支持
- 配置文件分离:用户配置与项目配置分离,项目级配置(客户端信息、需要 ID 命令的 provider)放在代码中 - 新增 check_id 字段:用户可选择禁用单个账户的 ID 命令发送 - 简化 provider:只保留 163 和 QQ,移除未使用的 Gmail/Outlook/188 等 - 修复 163 邮箱收件箱问题:通过发送 IMAP ID 命令解决 Unsafe Login 错误 BREAKING CHANGE: 配置文件格式变化,旧配置不兼容
This commit is contained in:
63
main.go
63
main.go
@@ -203,6 +203,7 @@ func init() {
|
||||
rootCmd.AddCommand(ManCmd)
|
||||
|
||||
cfg, _ := loadConfig()
|
||||
_ = cfg
|
||||
|
||||
rootCmd.Flags().StringSliceVar(&bcc, "bcc", []string{}, "BCC recipients")
|
||||
rootCmd.Flags().StringSliceVar(&cc, "cc", []string{}, "CC recipients")
|
||||
@@ -211,7 +212,7 @@ func init() {
|
||||
rootCmd.Flags().StringVarP(&body, "body", "b", "", "Email's contents")
|
||||
envFrom := os.Getenv(PopFrom)
|
||||
if envFrom == "" {
|
||||
envFrom = cfg.From
|
||||
envFrom = getDefaultFromEmail()
|
||||
}
|
||||
from = envFrom
|
||||
rootCmd.Flags().StringVarP(&from, "from", "f", envFrom, "Email's sender"+commentStyle.Render("($"+PopFrom+")"))
|
||||
@@ -228,46 +229,52 @@ func init() {
|
||||
}
|
||||
rootCmd.Flags().StringVarP(&signature, "signature", "x", envSignature, "Signature to display at the end of the email."+commentStyle.Render("($"+PopSignature+")"))
|
||||
envSMTPHost := os.Getenv(PopSMTPHost)
|
||||
if envSMTPHost == "" {
|
||||
envSMTPHost = cfg.SMTP.Host
|
||||
}
|
||||
smtpHost = envSMTPHost
|
||||
rootCmd.Flags().StringVarP(&smtpHost, "smtp.host", "H", envSMTPHost, "Host of the SMTP server"+commentStyle.Render("($"+PopSMTPHost+")"))
|
||||
envSMTPPort, _ := strconv.Atoi(os.Getenv(PopSMTPPort))
|
||||
if envSMTPPort == 0 {
|
||||
envSMTPPort = cfg.SMTP.Port
|
||||
envSMTPUsername := os.Getenv(PopSMTPUsername)
|
||||
envSMTPPassword := os.Getenv(PopSMTPPassword)
|
||||
envSMTPEncryption := os.Getenv(PopSMTPEncryption)
|
||||
envInsecureSkipVerify := os.Getenv(PopSMTPInsecureSkipVerify) == "true"
|
||||
|
||||
defaultAccounts, _ := getAccounts()
|
||||
defaultAccount := getDefaultAccount(defaultAccounts, cfg.From.Account)
|
||||
|
||||
if envSMTPHost == "" && defaultAccount != nil {
|
||||
envSMTPHost = defaultAccount.SMTP.Host
|
||||
}
|
||||
if envSMTPPort == 0 && defaultAccount != nil {
|
||||
envSMTPPort = defaultAccount.SMTP.Port
|
||||
if envSMTPPort == 0 {
|
||||
envSMTPPort = 587
|
||||
}
|
||||
}
|
||||
smtpPort = envSMTPPort
|
||||
rootCmd.Flags().IntVarP(&smtpPort, "smtp.port", "P", envSMTPPort, "Port of the SMTP server"+commentStyle.Render("($"+PopSMTPPort+")"))
|
||||
envSMTPUsername := os.Getenv(PopSMTPUsername)
|
||||
if envSMTPUsername == "" {
|
||||
envSMTPUsername = cfg.SMTP.Username
|
||||
if envSMTPUsername == "" && defaultAccount != nil {
|
||||
envSMTPUsername = defaultAccount.SMTP.Username
|
||||
}
|
||||
smtpUsername = envSMTPUsername
|
||||
rootCmd.Flags().StringVarP(&smtpUsername, "smtp.username", "U", envSMTPUsername, "Username of the SMTP server"+commentStyle.Render("($"+PopSMTPUsername+")"))
|
||||
envSMTPPassword := os.Getenv(PopSMTPPassword)
|
||||
if envSMTPPassword == "" {
|
||||
envSMTPPassword = cfg.SMTP.Password
|
||||
if envSMTPPassword == "" && defaultAccount != nil {
|
||||
envSMTPPassword = defaultAccount.SMTP.Password
|
||||
}
|
||||
smtpPassword = envSMTPPassword
|
||||
rootCmd.Flags().StringVarP(&smtpPassword, "smtp.password", "p", envSMTPPassword, "Password of the SMTP server"+commentStyle.Render("($"+PopSMTPPassword+")"))
|
||||
envSMTPEncryption := os.Getenv(PopSMTPEncryption)
|
||||
if envSMTPEncryption == "" {
|
||||
envSMTPEncryption = cfg.SMTP.Encryption
|
||||
if envSMTPEncryption == "" && defaultAccount != nil {
|
||||
envSMTPEncryption = defaultAccount.SMTP.Encryption
|
||||
if envSMTPEncryption == "" {
|
||||
envSMTPEncryption = "starttls"
|
||||
}
|
||||
}
|
||||
smtpEncryption = envSMTPEncryption
|
||||
rootCmd.Flags().StringVarP(&smtpEncryption, "smtp.encryption", "e", envSMTPEncryption, "Encryption type of the SMTP server (starttls, ssl, or none)"+commentStyle.Render("($"+PopSMTPEncryption+")"))
|
||||
envInsecureSkipVerify := os.Getenv(PopSMTPInsecureSkipVerify) == "true"
|
||||
if !envInsecureSkipVerify {
|
||||
envInsecureSkipVerify = cfg.SMTP.InsecureSkipVerify
|
||||
if !envInsecureSkipVerify && defaultAccount != nil {
|
||||
envInsecureSkipVerify = defaultAccount.SMTP.InsecureSkipVerify
|
||||
}
|
||||
|
||||
smtpHost = envSMTPHost
|
||||
smtpPort = envSMTPPort
|
||||
smtpUsername = envSMTPUsername
|
||||
smtpPassword = envSMTPPassword
|
||||
smtpEncryption = envSMTPEncryption
|
||||
smtpInsecureSkipVerify = envInsecureSkipVerify
|
||||
|
||||
rootCmd.Flags().StringVarP(&smtpHost, "smtp.host", "H", envSMTPHost, "Host of the SMTP server"+commentStyle.Render("($"+PopSMTPHost+")"))
|
||||
rootCmd.Flags().IntVarP(&smtpPort, "smtp.port", "P", envSMTPPort, "Port of the SMTP server"+commentStyle.Render("($"+PopSMTPPort+")"))
|
||||
rootCmd.Flags().StringVarP(&smtpUsername, "smtp.username", "U", envSMTPUsername, "Username of the SMTP server"+commentStyle.Render("($"+PopSMTPUsername+")"))
|
||||
rootCmd.Flags().StringVarP(&smtpPassword, "smtp.password", "p", envSMTPPassword, "Password of the SMTP server"+commentStyle.Render("($"+PopSMTPPassword+")"))
|
||||
rootCmd.Flags().StringVarP(&smtpEncryption, "smtp.encryption", "e", envSMTPEncryption, "Encryption type of the SMTP server (starttls, ssl, or none)"+commentStyle.Render("($"+PopSMTPEncryption+")"))
|
||||
rootCmd.Flags().BoolVarP(&smtpInsecureSkipVerify, "smtp.insecure", "i", envInsecureSkipVerify, "Skip TLS verification with SMTP server"+commentStyle.Render("($"+PopSMTPInsecureSkipVerify+")"))
|
||||
envResendAPIKey := os.Getenv(ResendAPIKey)
|
||||
rootCmd.Flags().StringVarP(&resendAPIKey, "resend.key", "r", envResendAPIKey, "API key for the Resend.com"+commentStyle.Render("($"+ResendAPIKey+")"))
|
||||
|
||||
Reference in New Issue
Block a user