Skip to content

Commit

Permalink
Give up implicit identification of network type
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedas committed Mar 27, 2023
1 parent 2eaf662 commit e45e8b1
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"log"
"net"
"os"
"strings"
"sync"
"time"

Expand All @@ -30,11 +29,13 @@ type Logger interface {

// A SMTP server.
type Server struct {
// The type of network, "tcp" or "unix".
Network string
// TCP or Unix address to listen on.
Addr string
// The server TLS configuration.
TLSConfig *tls.Config
// Enable LMTP mode.
// Enable LMTP mode, as defined in RFC 2033.
LMTP bool

Domain string
Expand Down Expand Up @@ -213,25 +214,24 @@ func (s *Server) handleConn(c *Conn) error {
// ListenAndServe listens on the network address s.Addr and then calls Serve
// to handle requests on incoming connections.
//
// If s.Addr is blank and LMTP is disabled, ":smtp" is used. If it is enabled,
// ":24" (any private mail system) is used.
// If s.Addr contains "/", UNIX domain socket is used. Otherwise TCP socket
// is used.
// If s.Network is "tcp" (default) and s.Addr is blank, ":24" (any private
// mail system) for LMTP or ":smtp" for (E)SMTP is used.
// If s.Network is "unix", s.Addr must be given explicitly.
func (s *Server) ListenAndServe() error {
network := s.Network
if network == "" {
network = "tcp"
}

addr := s.Addr
if addr == "" {
if addr == "" && network == "tcp" {
if s.LMTP {
addr = ":24"
} else {
addr = ":smtp"
}
}

network := "tcp"
if strings.Contains(addr, "/") {
network = "unix"
}

l, err := net.Listen(network, addr)
if err != nil {
return err
Expand All @@ -243,18 +243,18 @@ func (s *Server) ListenAndServe() error {
// ListenAndServeTLS listens on the TCP network address s.Addr and then calls
// Serve to handle requests on incoming TLS connections.
//
// If s.Addr is blank, ":465" (Message Submission over TLS) is used.
// If s.Addr contains "/", UNIX domain socket is used. Otherwise TCP socket
// is used.
// If s.Network is "tcp" (default) and s.Addr is blank, ":465" (Message
// Submission over TLS) is used.
// If s.Network is "unix", s.Addr must be given explicitly.
func (s *Server) ListenAndServeTLS() error {
addr := s.Addr
if addr == "" {
addr = ":465"
network := s.Network
if network == "" {
network = "tcp"
}

network := "tcp"
if strings.Contains(addr, "/") {
network = "unix"
addr := s.Addr
if addr == "" && network == "tcp" {
addr = ":465"
}

l, err := tls.Listen(network, addr, s.TLSConfig)
Expand Down

0 comments on commit e45e8b1

Please sign in to comment.