Skip to content

Commit

Permalink
server: Correct protocol name in greeting banner.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedas authored and emersion committed Apr 9, 2023
1 parent 2a6fdd3 commit 7bfb069
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
6 changes: 5 additions & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,11 @@ func (c *Conn) Reject() {
}

func (c *Conn) greet() {
c.writeResponse(220, NoEnhancedCode, fmt.Sprintf("%v ESMTP Service Ready", c.server.Domain))
protocol := "ESMTP"
if c.server.LMTP {
protocol = "LMTP"
}
c.writeResponse(220, NoEnhancedCode, fmt.Sprintf("%v %s Service Ready", c.server.Domain, protocol))
}

func (c *Conn) writeResponse(code int, enhCode EnhancedCode, text ...string) {
Expand Down
20 changes: 16 additions & 4 deletions lmtp_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import (
"bufio"
"errors"
"io"
"net"
"strings"
"testing"

"github.com/emersion/go-smtp"
)

func testServerGreetedLMTP(t *testing.T, fn ...serverConfigureFunc) (be *backend, s *smtp.Server, c net.Conn, scanner *bufio.Scanner) {
be, s, c, scanner = testServer(t, fn...)

scanner.Scan()
if scanner.Text() != "220 localhost LMTP Service Ready" {
t.Fatal("Invalid greeting:", scanner.Text())
}

return
}

func sendDeliveryCmdsLMTP(t *testing.T, scanner *bufio.Scanner, c io.Writer) {
sendLHLO(t, scanner, c)

Expand Down Expand Up @@ -43,7 +55,7 @@ func sendLHLO(t *testing.T, scanner *bufio.Scanner, c io.Writer) {
}

func TestServer_LMTP(t *testing.T) {
be, s, c, scanner := testServerGreeted(t, func(s *smtp.Server) {
be, s, c, scanner := testServerGreetedLMTP(t, func(s *smtp.Server) {
s.LMTP = true
be := s.Backend.(*backend)
be.implementLMTPData = true
Expand Down Expand Up @@ -80,7 +92,7 @@ func TestServer_LMTP_Early(t *testing.T) {

lmtpStatusSync := make(chan struct{})

be, s, c, scanner := testServerGreeted(t, func(s *smtp.Server) {
be, s, c, scanner := testServerGreetedLMTP(t, func(s *smtp.Server) {
s.LMTP = true
be := s.Backend.(*backend)
be.implementLMTPData = true
Expand Down Expand Up @@ -124,7 +136,7 @@ func TestServer_LMTP_Expand(t *testing.T) {
// correctly expands results if backend doesn't
// implement LMTPSession.

be, s, c, scanner := testServerGreeted(t, func(s *smtp.Server) {
be, s, c, scanner := testServerGreetedLMTP(t, func(s *smtp.Server) {
s.LMTP = true
})
defer s.Close()
Expand All @@ -147,7 +159,7 @@ func TestServer_LMTP_Expand(t *testing.T) {
}

func TestServer_LMTP_DuplicatedRcpt(t *testing.T) {
be, s, c, scanner := testServerGreeted(t, func(s *smtp.Server) {
be, s, c, scanner := testServerGreetedLMTP(t, func(s *smtp.Server) {
s.LMTP = true
be := s.Backend.(*backend)
be.implementLMTPData = true
Expand Down

0 comments on commit 7bfb069

Please sign in to comment.