Merge branch 'master' of https://github.com/itsthewall/parsemail into itsthewall-master
diff --git a/go.mod b/go.mod
index 0b7ccf2..5b91a53 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,3 @@
 module github.com/DusanKasan/parsemail
 
-go 1.12
+go 1.12
\ No newline at end of file
diff --git a/parsemail.go b/parsemail.go
index a8f84e8..42e0170 100644
--- a/parsemail.go
+++ b/parsemail.go
@@ -42,6 +42,8 @@
 		email.TextBody, email.HTMLBody, email.Attachments, email.EmbeddedFiles, err = parseMultipartMixed(msg.Body, params["boundary"])
 	case contentTypeMultipartAlternative:
 		email.TextBody, email.HTMLBody, email.EmbeddedFiles, err = parseMultipartAlternative(msg.Body, params["boundary"])
+	case contentTypeMultipartRelated:
+		email.TextBody, email.HTMLBody, email.EmbeddedFiles, err = parseMultipartRelated(msg.Body, params["boundary"])
 	case contentTypeTextPlain:
 		message, _ := ioutil.ReadAll(msg.Body)
 		email.TextBody = strings.TrimSuffix(string(message[:]), "\n")
diff --git a/parsemail_test.go b/parsemail_test.go
index 5cc106a..add111a 100644
--- a/parsemail_test.go
+++ b/parsemail_test.go
@@ -540,6 +540,27 @@
 	}
 }
 
+func TestMultiPartRelatedEmail(t *testing.T) {
+	email, err := Parse(strings.NewReader(multipartRelatedExample))
+	if err != nil {
+		t.Errorf("[Test Multipart Related] Emailed failed to parse: %v", err)
+	}
+
+	if len(email.TextBody) == 0 {
+		t.Errorf("[Test Multipart Related] Failed to parse multipart related at the top level.")
+	}
+	body := "Time for the egg."
+	fmt.Println(email.TextBody)
+	if email.TextBody != body {
+		t.Errorf("Test Multipart Related] Body didn't match. \nExpected: %v,\nbut got: %v", body, email.TextBody)
+	}
+
+	html := "<div dir=\"ltr\"><div>Time for the egg.</div><div><br></div><div><br><br></div></div>"
+	if email.HTMLBody !=  html {
+		t.Errorf("Test Multipart Related] HTML didn't match. \nExpected: %v,\nbut got: %v", html, email.TextBody)
+	}
+}
+
 func parseDate(in string) time.Time {
 	out, err := time.Parse(time.RFC1123Z, in)
 	if err != nil {
@@ -824,6 +845,35 @@
 
 R0lGODlhAQE7`
 
+var multipartRelatedExample = `MIME-Version: 1.0
+From: John Doe <jdoe@machine.example>
+Sender: Michael Jones <mjones@machine.example>
+To: Mary Smith <mary@example.net>
+Subject: Saying Hello
+Date: Fri, 21 Nov 1997 09:55:06 -0600
+Message-ID: <1234@local.machine.example>
+Subject: ooops
+To: test@example.rocks
+Content-Type: multipart/related; boundary="000000000000ab2e2205a26de587"
+
+--000000000000ab2e2205a26de587
+Content-Type: multipart/alternative; boundary="000000000000ab2e1f05a26de586"
+
+--000000000000ab2e1f05a26de586
+Content-Type: text/plain; charset="UTF-8"
+
+Time for the egg.
+
+--000000000000ab2e1f05a26de586
+Content-Type: text/html; charset="UTF-8"
+
+<div dir="ltr"><div>Time for the egg.</div><div><br></div><div><br><br></div></div>
+
+--000000000000ab2e1f05a26de586--
+
+
+--000000000000ab2e2205a26de587--
+`
 var attachment7bit = `From: =?UTF-8?Q?Peter_Foobar?= <peter.foobar@gmail.com>
 Date: Tue, 2 Apr 2019 11:12:26 +0000
 Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com>