pop3server.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package pop3_server
  2. import (
  3. "crypto/rand"
  4. "crypto/tls"
  5. "github.com/Jinnrry/gopop"
  6. log "github.com/sirupsen/logrus"
  7. "pmail/config"
  8. "time"
  9. )
  10. var instance *gopop.Server
  11. var instanceTls *gopop.Server
  12. func StartWithTls() {
  13. crt, err := tls.LoadX509KeyPair(config.Instance.SSLPublicKeyPath, config.Instance.SSLPrivateKeyPath)
  14. if err != nil {
  15. panic(err)
  16. }
  17. tlsConfig := &tls.Config{}
  18. tlsConfig.Certificates = []tls.Certificate{crt}
  19. tlsConfig.Time = time.Now
  20. tlsConfig.Rand = rand.Reader
  21. instanceTls = gopop.NewPop3Server(995, "pop."+config.Instance.Domain, true, tlsConfig, action{})
  22. instanceTls.ConnectAliveTime = 5 * time.Minute
  23. log.Infof("POP3 With TLS Server Start On Port :995")
  24. err = instanceTls.Start()
  25. if err != nil {
  26. panic(err)
  27. }
  28. }
  29. func Start() {
  30. crt, err := tls.LoadX509KeyPair(config.Instance.SSLPublicKeyPath, config.Instance.SSLPrivateKeyPath)
  31. if err != nil {
  32. panic(err)
  33. }
  34. tlsConfig := &tls.Config{}
  35. tlsConfig.Certificates = []tls.Certificate{crt}
  36. tlsConfig.Time = time.Now
  37. tlsConfig.Rand = rand.Reader
  38. instance = gopop.NewPop3Server(110, "pop."+config.Instance.Domain, false, tlsConfig, action{})
  39. instance.ConnectAliveTime = 5 * time.Minute
  40. log.Infof("POP3 Server Start On Port :110")
  41. err = instance.Start()
  42. if err != nil {
  43. panic(err)
  44. }
  45. }
  46. func Stop() {
  47. if instance != nil {
  48. instance.Stop()
  49. }
  50. if instanceTls != nil {
  51. instanceTls.Stop()
  52. }
  53. }