Skip to content

Commit

Permalink
Parse DATA\r\n\r\n.\r\n as \r\n\r\n message
Browse files Browse the repository at this point in the history
  • Loading branch information
foxcpp authored and emersion committed Jan 21, 2024
1 parent df9dfa9 commit 434ddca
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func (r *dataReader) Read(b []byte) (n int, err error) {
r.state = stateDot
continue
}
if c == '\r' {
r.state = stateCR
break
}
r.state = stateData
case stateDot:
if c == '\r' {
Expand Down
39 changes: 39 additions & 0 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,45 @@ func TestServer_LFDotLF(t *testing.T) {
}
}

func TestServer_EmptyMessage(t *testing.T) {
be, s, c, scanner := testServerAuthenticated(t)
defer s.Close()
defer c.Close()

io.WriteString(c, "MAIL FROM:<[email protected]>\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid MAIL response:", scanner.Text())
}

io.WriteString(c, "RCPT TO:<[email protected]>\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid RCPT response:", scanner.Text())
}

io.WriteString(c, "DATA\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "354 ") {
t.Fatal("Invalid DATA response:", scanner.Text())
}

io.WriteString(c, "\r\n\r\n.\r\n")
scanner.Scan()
if !strings.HasPrefix(scanner.Text(), "250 ") {
t.Fatal("Invalid DATA response:", scanner.Text())
}

if len(be.messages) != 1 || len(be.anonmsgs) != 0 {
t.Fatal("Invalid number of sent messages:", be.messages, be.anonmsgs)
}

msg := be.messages[0]
if string(msg.Data) != "\r\n\r\n" {
t.Fatal("Invalid mail data:", string(msg.Data), msg.Data)
}
}

func TestServer_authDisabled(t *testing.T) {
_, s, c, scanner, caps := testServerEhlo(t, authDisabled)
defer s.Close()
Expand Down

0 comments on commit 434ddca

Please sign in to comment.