Skip to content

Commit 4213770

Browse files
0xc0dgopherbot
authored andcommitted
net/mail: fix EOF error while reading header-only message
Check if any header found in case of EOF to recognize header-only messages and if so, return a Message with the found headers and a body from the reader which is already empty. Fixes #33823. Change-Id: I2f0396b08e9be4e6c89c212ce62b9c87b5f63123 GitHub-Last-Rev: 356a942 GitHub-Pull-Request: #47898 Reviewed-on: https://go-review.googlesource.com/c/go/+/344269 Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent c994067 commit 4213770

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/net/mail/message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func ReadMessage(r io.Reader) (msg *Message, err error) {
5454
tp := textproto.NewReader(bufio.NewReader(r))
5555

5656
hdr, err := tp.ReadMIMEHeader()
57-
if err != nil {
57+
if err != nil && (err != io.EOF || len(hdr) == 0) {
5858
return nil, err
5959
}
6060

src/net/mail/message_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,19 @@ So, "Hello".
3939
},
4040
body: "This is a message just to say hello.\nSo, \"Hello\".\n",
4141
},
42+
{
43+
// RFC 5965, Appendix B.1, a part of the multipart message (a header-only sub message)
44+
in: `Feedback-Type: abuse
45+
User-Agent: SomeGenerator/1.0
46+
Version: 1
47+
`,
48+
header: Header{
49+
"Feedback-Type": []string{"abuse"},
50+
"User-Agent": []string{"SomeGenerator/1.0"},
51+
"Version": []string{"1"},
52+
},
53+
body: "",
54+
},
4255
}
4356

4457
func TestParsing(t *testing.T) {

0 commit comments

Comments
 (0)