diff options
Diffstat (limited to 'lmtp_server.go')
-rw-r--r-- | lmtp_server.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/lmtp_server.go b/lmtp_server.go index fc3d92d..e97ca55 100644 --- a/lmtp_server.go +++ b/lmtp_server.go @@ -27,6 +27,7 @@ type lmtpSession struct { to []string ctx context.Context cancel context.CancelFunc + s server } func (session *lmtpSession) Reset() { @@ -62,13 +63,13 @@ func (*lmtpHandler) NewSession(_ *smtp.Conn) (smtp.Session, error) { return session, nil } -func serveLMTP(listener net.Listener) error { +func (s *server) serveLMTP(listener net.Listener) error { smtpServer := smtp.NewServer(&lmtpHandler{}) smtpServer.LMTP = true - smtpServer.Domain = config.LMTP.Domain - smtpServer.Addr = config.LMTP.Socket - smtpServer.WriteTimeout = time.Duration(config.LMTP.WriteTimeout) * time.Second - smtpServer.ReadTimeout = time.Duration(config.LMTP.ReadTimeout) * time.Second + smtpServer.Domain = s.config.LMTP.Domain + smtpServer.Addr = s.config.LMTP.Socket + smtpServer.WriteTimeout = time.Duration(s.config.LMTP.WriteTimeout) * time.Second + smtpServer.ReadTimeout = time.Duration(s.config.LMTP.ReadTimeout) * time.Second smtpServer.EnableSMTPUTF8 = true return smtpServer.Serve(listener) } @@ -84,9 +85,9 @@ func (session *lmtpSession) Data(r io.Reader) error { n int64 ) - n, err = io.CopyN(&buf, r, config.LMTP.MaxSize) + n, err = io.CopyN(&buf, r, session.s.config.LMTP.MaxSize) switch { - case n == config.LMTP.MaxSize: + case n == session.s.config.LMTP.MaxSize: err = errors.New("Message too big.") // drain whatever is left in the pipe _, _ = io.Copy(io.Discard, r) @@ -107,7 +108,7 @@ func (session *lmtpSession) Data(r io.Reader) error { switch strings.ToLower(email.Header.Get("Auto-Submitted")) { case "auto-generated", "auto-replied": - // Disregard automatic emails like OOO replies. + // Disregard automatic emails like OOO repliesession.s. slog.Info("ignoring automatic message", "from", session.from, "to", strings.Join(session.to, ","), @@ -132,10 +133,10 @@ func (session *lmtpSession) Data(r io.Reader) error { _ = from for _, to := range to { - if !strings.HasSuffix(to, "@"+config.LMTP.Domain) { + if !strings.HasSuffix(to, "@"+session.s.config.LMTP.Domain) { continue } - localPart := to[:len(to)-len("@"+config.LMTP.Domain)] + localPart := to[:len(to)-len("@"+session.s.config.LMTP.Domain)] var segments []string segments, err = misc.PathToSegments(localPart) if err != nil { |