Skip to content

net/mail: ReadMessage fails on header-only messages #33823

Closed
@pam4

Description

@pam4

Sorry to open this again (see #15632, #24256).
Postfix just landed one such message on my Maildir mailbox, and my Go tools choked on it.
(I receive messages one per file, in raw format, with LF line endings from Postfix.)

The message has no body and only one LF at the end. The X-Mailer header field says MIME-tools 5.503 (Entity 5.501). It was sent by a person.

You can see it here (slightly altered).
Isn't it standard compliant?
According to RFC 5322 it seems that the body is optional and the empty line is required only if the body is present:

message = (fields / obs-fields)
          [CRLF body]

And such message is what mail.ReadMessage should be able to parse.

Postfix can send header-only messages, and it preserves the absence of the empty line.
To reproduce it, setup Postfix to deliver to a Maildir mailbox, then send yourself a header-only message using the sendmail command.
(If you use an mbox mailbox you get multiple messages per file, and an empty line is added as a separator, in addition to the "From_ line", but an mbox is not a message.)

I agree that header-only messages are rare and not very useful and this is a minor issue, but not completely worthless.

The simplest solution would be to filter out EOF in mail.ReadMessage here. But that would make it succeed even in case of incomplete last line (possibly truncated message).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions