[net.mail] ReadMessage returns nil, io.EOF when email w/o body.

73 views
Skip to first unread message

Karan Gupta

unread,
Jul 18, 2023, 7:36:42 PM7/18/23
to golang-nuts
Hello Everyone

RFC 5322 (https://www.rfc-editor.org/rfc/rfc5322#section-3.5) allows for messages without bodies.
` A message consists of header fields, optionally followed by a message body `

However, the net/mail . ReadMessage returns an error when an email does not contain a body.
To demonstrate this I have written a small program (attached) that shows the difference in values returned by mail.ReadMessage when the input email message ends in
1. a 'field' where field is defined as in RFC5322. with focus on the fact that 'field' ends in  a single CRLF
2. a body. In this specific case, I have chosen to use an empty body. Email is constructed by appending 2 consecutive CRLFs to the message from (1). The first CRLF is to separate the header from the body and the second to terminate an empty body

Is this a bug in the go standard library?

-Karan
email.go

Ian Lance Taylor

unread,
Jul 18, 2023, 7:46:04 PM7/18/23
to Karan Gupta, golang-nuts
I think you are describing https://go.dev/issue/33823, which, as it
happens, is fixed in the upcoming Go 1.21 release.

Ian

Karan Gupta

unread,
Jul 18, 2023, 9:07:41 PM7/18/23
to Ian Lance Taylor, golang-nuts
That is correct. It is the same issue. 
Thanks for the help.

-Karan

Jim Idle

unread,
Jul 19, 2023, 12:04:50 AM7/19/23
to golang-nuts
If you are doing any serious email work, you might find that the enmime module is useful.  

https://github.com/jhillyerd/enmime

And perhaps this:

https://github.com/gatherstars-com/jwz

Jim

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAAtLhrc4tohZW9taHcyUHr09UN7X5u84XaJS6B_CSr2g-SurVw%40mail.gmail.com.

Karan Gupta

unread,
Jul 19, 2023, 7:31:14 AM7/19/23
to Jim Idle, golang-nuts
Thanks will try the library shortly. Looks good

You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/M4NcVrIY7P0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAGPPfg-QEXMcOVoYvJeZMZ_jN_1CdpVjKv1BeUcSFfxQEjS5tQ%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages