Skip to content

Commit 92b0bc5

Browse files
committed
server: Fix \r\n\r\n being mangled into \r\n\n in message body
1 parent 87b76f4 commit 92b0bc5

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

data.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ func (r *dataReader) Read(b []byte) (n int, err error) {
103103
}
104104
if c == '\r' {
105105
r.state = stateCR
106-
continue
107106
}
108107
r.state = stateData
109-
110108
case stateDot:
111109
if c == '\r' {
112110
r.state = stateDotCR
@@ -116,22 +114,20 @@ func (r *dataReader) Read(b []byte) (n int, err error) {
116114
r.state = stateEOF
117115
continue
118116
}
119-
r.state = stateData
120117

118+
r.state = stateData
121119
case stateDotCR:
122120
if c == '\n' {
123121
r.state = stateEOF
124122
continue
125123
}
126124
r.state = stateData
127-
128125
case stateCR:
129126
if c == '\n' {
130127
r.state = stateBeginLine
131128
break
132129
}
133130
r.state = stateData
134-
135131
case stateData:
136132
if c == '\r' {
137133
r.state = stateCR

server_test.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,10 @@ func TestServer(t *testing.T) {
455455
t.Fatal("Invalid DATA response:", scanner.Text())
456456
}
457457

458+
io.WriteString(c, "From: [email protected]\r\n")
459+
io.WriteString(c, "\r\n")
458460
io.WriteString(c, "Hey\r <3\r\n")
461+
io.WriteString(c, "..this dot is fine\r\n")
459462
io.WriteString(c, ".\r\n")
460463
scanner.Scan()
461464
if !strings.HasPrefix(scanner.Text(), "250 ") {
@@ -473,7 +476,7 @@ func TestServer(t *testing.T) {
473476
if len(msg.To) != 1 || msg.To[0] != "[email protected]" {
474477
t.Fatal("Invalid mail recipients:", msg.To)
475478
}
476-
if string(msg.Data) != "Hey\r <3\r\n" {
479+
if string(msg.Data) != "From: [email protected]\r\n\r\nHey\r <3\r\n.this dot is fine\r\n" {
477480
t.Fatal("Invalid mail data:", string(msg.Data))
478481
}
479482
}

0 commit comments

Comments
 (0)