1 parent
d4c3994102
commit
9b19268c00
6 files changed
+99
-44
No files matched your search
@@ -161,6 +161,27 @@ func CurrentMailDomains() MailDomains {
|
||||
return domains
|
||||
}
|
||||
|
||||
func CurrentEmailPolicy() EmailConfig {
|
||||
manager := CurrentManager()
|
||||
if manager != nil {
|
||||
runtime := manager.Snapshot()
|
||||
if runtime.Generation != 0 {
|
||||
return runtime.Email.Policy
|
||||
}
|
||||
}
|
||||
|
||||
cfg := CurrentConfig()
|
||||
if cfg == nil {
|
||||
return EmailConfig{}
|
||||
}
|
||||
return EmailConfig{
|
||||
SMTPPort: cfg.SMTPPort,
|
||||
SpamFilterLevel: cfg.SpamFilterLevel,
|
||||
LoginVerificationPolicy: cfg.LoginPolicy,
|
||||
ExternalRecoveryEnabled: cfg.ExternalRecoveryEnabled,
|
||||
}
|
||||
}
|
||||
|
||||
type SMTPRuntimeSettings struct {
|
||||
Relay SMTPConfig
|
||||
Password string
|
||||
@@ -213,22 +234,15 @@ func CurrentSMTPRuntimeSettings() (SMTPRuntimeSettings, error) {
|
||||
|
||||
func CurrentMailPorts() MailPorts {
|
||||
ports := MailPorts{SMTP: 25, IMAP: 143, POP3: 110}
|
||||
manager := CurrentManager()
|
||||
if manager == nil {
|
||||
return ports
|
||||
policy := CurrentEmailPolicy()
|
||||
if policy.SMTPPort > 0 && policy.SMTPPort <= 65535 {
|
||||
ports.SMTP = policy.SMTPPort
|
||||
}
|
||||
runtime := manager.Snapshot()
|
||||
if runtime.Generation == 0 {
|
||||
return ports
|
||||
if policy.IMAPPort > 0 && policy.IMAPPort <= 65535 {
|
||||
ports.IMAP = policy.IMAPPort
|
||||
}
|
||||
if runtime.Email.Policy.SMTPPort > 0 && runtime.Email.Policy.SMTPPort <= 65535 {
|
||||
ports.SMTP = runtime.Email.Policy.SMTPPort
|
||||
}
|
||||
if runtime.Email.Policy.IMAPPort > 0 && runtime.Email.Policy.IMAPPort <= 65535 {
|
||||
ports.IMAP = runtime.Email.Policy.IMAPPort
|
||||
}
|
||||
if runtime.Email.Policy.POP3Port > 0 && runtime.Email.Policy.POP3Port <= 65535 {
|
||||
ports.POP3 = runtime.Email.Policy.POP3Port
|
||||
if policy.POP3Port > 0 && policy.POP3Port <= 65535 {
|
||||
ports.POP3 = policy.POP3Port
|
||||
}
|
||||
return ports
|
||||
}
|
||||
|
||||
@@ -75,6 +75,52 @@ func TestCurrentMailPortsUsesSafeDefaultsWithoutRuntimeManager(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrentEmailPolicyReadsPartitionSnapshot(t *testing.T) {
|
||||
previousManager := CurrentManager()
|
||||
defer SetRuntimeManager(previousManager)
|
||||
|
||||
runtime := validRuntimeConfig()
|
||||
runtime.Email.Policy = EmailConfig{
|
||||
SMTPPort: 2525,
|
||||
IMAPPort: 1143,
|
||||
POP3Port: 1110,
|
||||
MaxMessageBytes: 8 << 20,
|
||||
SpamFilterLevel: 2,
|
||||
LoginVerificationPolicy: "new_device",
|
||||
ExternalRecoveryEnabled: true,
|
||||
}
|
||||
SetRuntimeManager(&ConfigManager{snapshots: runtimeAccessSnapshotStore{runtime: runtime}})
|
||||
|
||||
got := CurrentEmailPolicy()
|
||||
if got != runtime.Email.Policy {
|
||||
t.Fatalf("email policy = %+v, want partition snapshot", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrentEmailPolicyFallsBackToLegacyConfig(t *testing.T) {
|
||||
previousManager := CurrentManager()
|
||||
previousInstance := Instance
|
||||
defer func() {
|
||||
SetRuntimeManager(previousManager)
|
||||
Instance = previousInstance
|
||||
PublishConfigSnapshot(previousInstance)
|
||||
}()
|
||||
SetRuntimeManager(nil)
|
||||
|
||||
Instance = &Config{
|
||||
SMTPPort: 2525,
|
||||
SpamFilterLevel: 2,
|
||||
LoginPolicy: "new_device",
|
||||
ExternalRecoveryEnabled: true,
|
||||
}
|
||||
PublishConfigSnapshot(Instance)
|
||||
|
||||
got := CurrentEmailPolicy()
|
||||
if got.SMTPPort != 2525 || got.IMAPPort != 0 || got.POP3Port != 0 || got.MaxMessageBytes != 0 || got.SpamFilterLevel != 2 || got.LoginVerificationPolicy != "new_device" || !got.ExternalRecoveryEnabled {
|
||||
t.Fatalf("legacy email policy = %+v, want mapped fallback", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCurrentMailPortsReadsEmailPolicySnapshot(t *testing.T) {
|
||||
previousManager := CurrentManager()
|
||||
defer SetRuntimeManager(previousManager)
|
||||
|
||||
Reference in new issue
Block a user