~emersion/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[PATCH go-message] textproto: Support headers without body

Details
Message ID
<20191225233131.34079-1-shiroyasha@tobiichi.moe>
DKIM signature
missing
Download raw message
Patch: +32 -0
---
I'm not familiarized with the codebase so I'm not sure if this is the
best solution, but at least it doesn't break any existing tests.

For the test, I just copy-pasted one of the already existing ones and
removed the additional CRLF.

 textproto/header.go      |  3 +++
 textproto/header_test.go | 29 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/textproto/header.go b/textproto/header.go
index 3942513..d9b12c2 100644
--- a/textproto/header.go
+++ b/textproto/header.go
@@ -401,6 +401,9 @@ func ReadHeader(r *bufio.Reader) (Header, error) {
	for {
		kv, err := readContinuedLineSlice(r)
		if len(kv) == 0 {
			if err == io.EOF {
				err = nil
			}
			return newHeader(fs), err
		}

diff --git a/textproto/header_test.go b/textproto/header_test.go
index df2cfe9..0dd7c36 100644
--- a/textproto/header_test.go
+++ b/textproto/header_test.go
@@ -205,6 +205,35 @@ func TestReadHeader(t *testing.T) {
	}
}

const testHeaderWithoutBody = "Received: from example.com by example.org\r\n" +
	"Received: from localhost by example.com\r\n" +
	"To: Taki Tachibana <taki.tachibana@example.org>\r\n" +
	"From: Mitsuha Miyamizu <mitsuha.miyamizu@example.com>\r\n"

func TestReadHeaderWithoutBody(t *testing.T) {
	r := bufio.NewReader(strings.NewReader(testHeaderWithoutBody))
	h, err := ReadHeader(r)
	if err != nil {
		t.Fatalf("readHeader() returned error: %v", err)
	}

	l := collectHeaderFields(h.Fields())
	want := []string{
		"Received: from example.com by example.org",
		"Received: from localhost by example.com",
		"To: Taki Tachibana <taki.tachibana@example.org>",
		"From: Mitsuha Miyamizu <mitsuha.miyamizu@example.com>",
	}
	if !reflect.DeepEqual(l, want) {
		t.Errorf("Fields() reported incorrect values: got \n%#v\n but want \n%#v", l, want)
	}

	b := make([]byte, 1)
	if _, err := r.Read(b); err != io.EOF {
		t.Errorf("Read() didn't return EOF: %v", err)
	}
}

const testLFHeader = `From: contact@example.org
To: contact@example.org
Subject: A little message, just for you
--
2.24.1
Details
Message ID
<m0yIVH0tNgUJEpT4ZSC99eeLgv2G0-X0_1CM7sGW5IMmPaFLu_bkLTQzp7XQfyb1c_7WTEtzu-86Sc-0cm9pY2BhISzrj4oktTrC-PnYU4k=@emersion.fr>
In-Reply-To
<20191225233131.34079-1-shiroyasha@tobiichi.moe> (view parent)
DKIM signature
missing
Download raw message
LGTM, pushed:

To github.com:emersion/go-message
   8eb6e2ed7b81..d6e6e18c7578  master -> master

Thanks!
Reply to thread Export thread (mbox)