补齐IMAP和POP3配置并统一邮件协议监听端口

This commit is contained in:
xuans committed 2026-09-06 15:53:59 +08:00
1 parent 9b60eb2177
commit 24829c1199
27 files changed
+868 -80

No files matched your search

+8 -2
View File
@@ -444,8 +444,10 @@ func publicConfigSection(runtime config.RuntimeConfig, section config.Section) (
"security": runtime.Root.Security,
}, nil
case config.SectionSMTP:
ports := config.ResolveMailPorts(runtime.SMTP, runtime.Email)
return map[string]any{
"meta": runtime.SMTP.Meta,
"meta": runtime.SMTP.Meta,
"listener": config.SMTPListenerConfig{Port: ports.SMTP, STARTTLSPort: ports.SMTPSTARTTLS, TLSPort: ports.SMTPTLS},
"relay": map[string]any{
"relayHost": runtime.SMTP.Relay.RelayHost,
"relayPort": runtime.SMTP.Relay.RelayPort,
@@ -460,7 +462,11 @@ func publicConfigSection(runtime config.RuntimeConfig, section config.Section) (
"relayPasswordStatus": publicSecret(runtime.SMTP.Relay.Password),
}, nil
case config.SectionEmail:
return runtime.Email, nil
ports := config.ResolveMailPorts(runtime.SMTP, runtime.Email)
value := runtime.Email
value.IMAP = config.IMAPListenerConfig{TLSPort: ports.IMAP}
value.POP3 = config.POP3ListenerConfig{Port: ports.POP3, TLSPort: ports.POP3TLS}
return value, nil
case config.SectionSSL:
return runtime.SSL, nil
case config.SectionPlugins:
@@ -0,0 +1,49 @@
package controllers
import (
"encoding/json"
"testing"
"git.pcux.cn/xuans/Smail/config"
)
func TestPublicMailPortsMatchListenersWithoutChangingSnapshot(t *testing.T) {
for _, custom := range []bool{false, true} {
runtime := config.RuntimeConfig{
SMTP: config.SMTPSectionConfig{Relay: config.SMTPConfig{RelayPort: 9999}},
Email: config.EmailSectionConfig{Policy: config.EmailConfig{SMTPPort: 2525, IMAPPort: 1143, POP3Port: 1110}},
}
if custom {
runtime.SMTP.Listener = config.SMTPListenerConfig{Port: 3025, STARTTLSPort: 3587, TLSPort: 3465}
runtime.Email.IMAP.TLSPort = 3993
runtime.Email.POP3 = config.POP3ListenerConfig{Port: 3110, TLSPort: 3995}
}
before := runtime.Email
want := config.ResolveMailPorts(runtime.SMTP, runtime.Email)
smtpPublic, err := publicConfigSection(runtime, config.SectionSMTP)
if err != nil {
t.Fatal(err)
}
data, err := json.Marshal(smtpPublic)
if err != nil {
t.Fatal(err)
}
var smtp struct {
Listener config.SMTPListenerConfig `json:"listener"`
}
if err := json.Unmarshal(data, &smtp); err != nil {
t.Fatal(err)
}
emailPublic, err := publicConfigSection(runtime, config.SectionEmail)
if err != nil {
t.Fatal(err)
}
email := emailPublic.(config.EmailSectionConfig)
if smtp.Listener.Port != want.SMTP || smtp.Listener.STARTTLSPort != want.SMTPSTARTTLS || smtp.Listener.TLSPort != want.SMTPTLS || email.IMAP.TLSPort != want.IMAP || email.POP3.Port != want.POP3 || email.POP3.TLSPort != want.POP3TLS {
t.Fatal("public ports differ from listener configuration")
}
if before != runtime.Email {
t.Fatal("public view changed runtime configuration")
}
}
}