Skip to content

Commit

Permalink
fix: correct MIME-Version header casing (#83)
Browse files Browse the repository at this point in the history
* fix: correct MIME-Version header casing

https://www.w3.org/Protocols/rfc1341/3_MIME-Version.html

* test: correct MIME-Version header casing
  • Loading branch information
Coronon authored Jul 26, 2023
1 parent 0dbf4f5 commit db61a74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions mime.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ func (m *MailYak) buildMimeWithBoundaries(w io.Writer, mb, ab string) error {
return mixed.Close()
}

// writeHeaders writes the Mime-Version, Date, Reply-To, From, To and Subject headers,
// writeHeaders writes the MIME-Version, Date, Reply-To, From, To and Subject headers,
// plus any custom headers set via AddHeader().
func (m *MailYak) writeHeaders(w io.Writer) error {

if _, err := w.Write([]byte(m.fromHeader())); err != nil {
return err
}

if _, err := w.Write([]byte("Mime-Version: 1.0\r\n")); err != nil {
if _, err := w.Write([]byte("MIME-Version: 1.0\r\n")); err != nil {
return err
}

Expand Down
38 changes: 19 additions & 19 deletions mime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func TestMailYakFromHeader(t *testing.T) {
}
}

// TestMailYakWriteHeaders ensures the Mime-Version, Date, Reply-To, From, To and
// TestMailYakWriteHeaders ensures the MIME-Version, Date, Reply-To, From, To and
// Subject headers are correctly wrote
func TestMailYakWriteHeaders(t *testing.T) {
t.Parallel()
Expand All @@ -88,7 +88,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"Test",
"[email protected]",
true,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nReply-To: [email protected]\r\nSubject: Test\r\nTo: [email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nReply-To: [email protected]\r\nSubject: Test\r\nTo: [email protected]\r\n",
},
{
"No reply-to",
Expand All @@ -98,7 +98,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"",
"",
true,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected]\r\n",
},
{
"Multiple To addresses",
Expand All @@ -108,7 +108,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"",
"",
true,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\n",
},
{
"Single Cc address, Multiple To addresses",
Expand All @@ -118,7 +118,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"",
"",
true,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nCC: [email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nCC: [email protected]\r\n",
},
{
"Multiple Cc addresses, Multiple To addresses",
Expand All @@ -128,7 +128,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"",
"",
true,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nCC: [email protected],[email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nCC: [email protected],[email protected]\r\n",
},
{
"Single Bcc address, Multiple To addresses",
Expand All @@ -138,7 +138,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"",
"",
true,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nBCC: [email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nBCC: [email protected]\r\n",
},
{
"Multiple Bcc addresses, Multiple To addresses",
Expand All @@ -148,7 +148,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"",
"",
true,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nBCC: [email protected],[email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nBCC: [email protected],[email protected]\r\n",
},
{
"Multiple Bcc addresses, Multiple To addresses",
Expand All @@ -158,7 +158,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"",
"",
false,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\n",
},
{
"All together now",
Expand All @@ -168,7 +168,7 @@ func TestMailYakWriteHeaders(t *testing.T) {
"",
"",
true,
"From: Dom <[email protected]>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nCC: [email protected],[email protected]\r\nBCC: [email protected],[email protected]\r\n",
"From: Dom <[email protected]>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: [email protected],[email protected]\r\nCC: [email protected],[email protected]\r\nBCC: [email protected],[email protected]\r\n",
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -307,7 +307,7 @@ func TestMailYakBuildMime(t *testing.T) {
"",
"",
"",
"From: \r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
"From: \r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
false,
},
{
Expand All @@ -319,7 +319,7 @@ func TestMailYakBuildMime(t *testing.T) {
"",
"",
"",
"From: \r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n--alt\r\nContent-Transfer-Encoding: quoted-printable\r\nContent-Type: text/html; charset=UTF-8\r\n\r\nHTML\r\n--alt--\r\n\r\n--mixed--\r\n",
"From: \r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n--alt\r\nContent-Transfer-Encoding: quoted-printable\r\nContent-Type: text/html; charset=UTF-8\r\n\r\nHTML\r\n--alt--\r\n\r\n--mixed--\r\n",
false,
},
{
Expand All @@ -331,7 +331,7 @@ func TestMailYakBuildMime(t *testing.T) {
"",
"",
"",
"From: \r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n--alt\r\nContent-Transfer-Encoding: quoted-printable\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\nPlain\r\n--alt--\r\n\r\n--mixed--\r\n",
"From: \r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n--alt\r\nContent-Transfer-Encoding: quoted-printable\r\nContent-Type: text/plain; charset=UTF-8\r\n\r\nPlain\r\n--alt--\r\n\r\n--mixed--\r\n",
false,
},
{
Expand All @@ -343,7 +343,7 @@ func TestMailYakBuildMime(t *testing.T) {
"",
"",
"reply",
"From: \r\nMime-Version: 1.0\r\nDate: " + now + "\r\nReply-To: reply\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
"From: \r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nReply-To: reply\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
false,
},
{
Expand All @@ -355,7 +355,7 @@ func TestMailYakBuildMime(t *testing.T) {
"",
"name",
"",
"From: name <>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
"From: name <>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
false,
},
{
Expand All @@ -367,7 +367,7 @@ func TestMailYakBuildMime(t *testing.T) {
"addr",
"name",
"",
"From: name <addr>\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
"From: name <addr>\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
false,
},
{
Expand All @@ -379,7 +379,7 @@ func TestMailYakBuildMime(t *testing.T) {
"from",
"",
"",
"From: from\r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
"From: from\r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
false,
},
{
Expand All @@ -391,7 +391,7 @@ func TestMailYakBuildMime(t *testing.T) {
"",
"",
"",
"From: \r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: subject\r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
"From: \r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: subject\r\nTo: \r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
false,
},
{
Expand All @@ -403,7 +403,7 @@ func TestMailYakBuildMime(t *testing.T) {
"",
"",
"",
"From: \r\nMime-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: one,two\r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
"From: \r\nMIME-Version: 1.0\r\nDate: " + now + "\r\nSubject: \r\nTo: one,two\r\nContent-Type: multipart/mixed;\r\n\tboundary=\"mixed\"; charset=UTF-8\r\n\r\n--mixed\r\nContent-Type: multipart/alternative;\r\n\tboundary=\"alt\"\r\n\r\n\r\n--mixed--\r\n",
false,
},
}
Expand Down

0 comments on commit db61a74

Please sign in to comment.