This commit is contained in:
parent
64749a578b
commit
8207d54933
@ -118,6 +118,33 @@ func cloneConfig(source *Config) *Config {
|
||||
return &clone
|
||||
}
|
||||
|
||||
type MailPorts struct {
|
||||
SMTP int
|
||||
IMAP int
|
||||
POP3 int
|
||||
}
|
||||
|
||||
func CurrentMailPorts() MailPorts {
|
||||
ports := MailPorts{SMTP: 25, IMAP: 143, POP3: 110}
|
||||
manager := CurrentManager()
|
||||
if manager == nil {
|
||||
return ports
|
||||
}
|
||||
runtime := manager.Snapshot()
|
||||
if runtime.Generation == 0 {
|
||||
return ports
|
||||
}
|
||||
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
|
||||
}
|
||||
return ports
|
||||
}
|
||||
func cloneHTTPConfig(source HTTPConfig) HTTPConfig {
|
||||
clone := source
|
||||
clone.TrustedProxyCIDRs = append([]string(nil), source.TrustedProxyCIDRs...)
|
||||
|
||||
@ -27,8 +27,9 @@ func StarTLS() error {
|
||||
return err
|
||||
}
|
||||
instanceTLS = server
|
||||
log.Infof("IMAP With TLS Server Start On Port :993")
|
||||
if err := instanceTLS.ListenAndServeTLS(":993"); err != nil {
|
||||
port := config.CurrentMailPorts().IMAP
|
||||
log.Infof("IMAP With TLS Server Start On Port :%d", port)
|
||||
if err := instanceTLS.ListenAndServeTLS(fmt.Sprintf(":%d", port)); err != nil {
|
||||
return fmt.Errorf("serve IMAP TLS: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
@ -51,9 +51,10 @@ func Start() error {
|
||||
tlsConfig.Certificates = []tls.Certificate{crt}
|
||||
tlsConfig.Time = time.Now
|
||||
tlsConfig.Rand = rand.Reader
|
||||
instance = gopop.NewPop3Server(110, "pop."+cfg.Domain, false, tlsConfig, action{})
|
||||
port := config.CurrentMailPorts().POP3
|
||||
instance = gopop.NewPop3Server(port, "pop."+cfg.Domain, false, tlsConfig, action{})
|
||||
instance.ConnectAliveTime = 5 * time.Minute
|
||||
log.Infof("POP3 Server Start On Port :110")
|
||||
log.Infof("POP3 Server Start On Port :%d", port)
|
||||
|
||||
err = instance.Start()
|
||||
if err != nil {
|
||||
|
||||
@ -95,7 +95,7 @@ func Start() error {
|
||||
|
||||
instance = smtp.NewServer(be)
|
||||
|
||||
instance.Addr = ":25"
|
||||
instance.Addr = fmt.Sprintf(":%d", config.CurrentMailPorts().SMTP)
|
||||
instance.Domain = cfg.Domain
|
||||
instance.ReadTimeout = 10 * time.Second
|
||||
instance.WriteTimeout = 10 * time.Second
|
||||
|
||||
Loading…
Reference in New Issue
Block a user