Skip to content

Commit

Permalink
writer: add Mime-Version header when missing
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimír Dudr authored and emersion committed May 21, 2020
1 parent c512562 commit 0e60ea0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 6 additions & 4 deletions entity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func testMakeMultipart() *Entity {
return e
}

const testMultipartHeader = "Content-Type: multipart/alternative; boundary=IMTHEBOUNDARY\r\n" +
"\r\n"
const testMultipartHeader = "Mime-Version: 1.0\r\n"+
"Content-Type: multipart/alternative; boundary=IMTHEBOUNDARY\r\n\r\n"

const testMultipartBody = "--IMTHEBOUNDARY\r\n" +
"Content-Type: text/plain\r\n" +
Expand Down Expand Up @@ -161,7 +161,8 @@ func TestEntity_WriteTo_decode(t *testing.T) {
t.Fatal("Expected no error while writing entity, got", err)
}

expected := "Content-Type: text/plain; charset=utf-8\r\n" +
expected := "Mime-Version: 1.0\r\n" +
"Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
"cc sava"

Expand All @@ -184,7 +185,8 @@ func TestEntity_WriteTo_convert(t *testing.T) {
t.Fatal("Expected no error while writing entity, got", err)
}

expected := "Content-Transfer-Encoding: quoted-printable\r\n" +
expected := "Mime-Version: 1.0\r\n" +
"Content-Transfer-Encoding: quoted-printable\r\n" +
"Content-Type: text/plain; charset=utf-8\r\n" +
"\r\n" +
"Bonjour =C3=A0 tous"
Expand Down
4 changes: 4 additions & 0 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func createWriter(w io.Writer, header *Header) (*Writer, error) {
// encoding, data written to the Writer will automatically be encoded with it.
// The charset needs to be utf-8 or us-ascii.
func CreateWriter(w io.Writer, header Header) (*Writer, error) {

// If the message uses MIME, it has to include MIME-Version
header.Set("MIME-Version", "1.0")

ww, err := createWriter(w, &header)
if err != nil {
return nil, err
Expand Down

0 comments on commit 0e60ea0

Please sign in to comment.