Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func ReadWithOptions(r io.Reader, opts *ReadOptions) (*Entity, error) {
if err != nil {
return nil, err
}
if !h.Valid() {
return nil, nil
}

lr.N = math.MaxInt64

Expand Down
9 changes: 9 additions & 0 deletions textproto/header.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ func (h *Header) Len() int {
return len(h.l)
}

// Valid returns if the data structure is valid, if it was initialized correctly
func (h *Header) Valid() bool {
return h.l != nil && h.m != nil
}

// Map returns all header fields as a map.
//
// This function is provided for interoperability with the standard library.
Expand Down Expand Up @@ -533,6 +538,10 @@ func ReadHeader(r *bufio.Reader) (Header, error) {

for {
kv, err := readContinuedLineSlice(r)
if kv == nil && len(fs) == 0 {
// Construct an invalid header.
return Header{}, err
}
if len(kv) == 0 {
return newHeader(fs), err
}
Expand Down