UTF-8 subject now decoded properly
diff --git a/parsemail.go b/parsemail.go
index b86f294..6ee0624 100644
--- a/parsemail.go
+++ b/parsemail.go
@@ -57,7 +57,7 @@
func createEmailFromHeader(header mail.Header) (email Email, err error) {
hp := headerParser{header: &header}
- email.Subject = header.Get("Subject")
+ email.Subject = decodeMimeSentence(header.Get("Subject"))
email.From = hp.parseAddressList(header.Get("From"))
email.Sender = hp.parseAddress(header.Get("Sender"))
email.ReplyTo = hp.parseAddressList(header.Get("Reply-To"))
@@ -192,7 +192,7 @@
return textBody, htmlBody, attachments, embeddedFiles, err
}
-func decodeMimeSentence(s string) (string, error) {
+func decodeMimeSentence(s string) string {
result := []string{}
ss := strings.Split(s, " ")
@@ -210,7 +210,7 @@
result = append(result, w)
}
- return strings.Join(result, ""), nil
+ return strings.Join(result, "")
}
func decodeHeaderMime(header mail.Header) (mail.Header, error) {
@@ -220,11 +220,7 @@
parsedHeaderData := []string{}
for _, headerValue := range headerData {
- decodedHeaderValue, err := decodeMimeSentence(headerValue)
- if err != nil {
- return mail.Header{}, err
- }
- parsedHeaderData = append(parsedHeaderData, decodedHeaderValue)
+ parsedHeaderData = append(parsedHeaderData, decodeMimeSentence(headerValue))
}
parsedHeader[headerName] = parsedHeaderData
@@ -254,11 +250,7 @@
}
func decodeEmbeddedFile(part *multipart.Part) (ef EmbeddedFile, err error) {
- cid, err := decodeMimeSentence(part.Header.Get("Content-Id"))
- if err != nil {
- return
- }
-
+ cid := decodeMimeSentence(part.Header.Get("Content-Id"))
decoded, err := decodePartData(part)
if err != nil {
return
@@ -276,11 +268,7 @@
}
func decodeAttachment(part *multipart.Part) (at Attachment, err error) {
- filename, err := decodeMimeSentence(part.FileName())
- if err != nil {
- return
- }
-
+ filename := decodeMimeSentence(part.FileName())
decoded, err := decodePartData(part)
if err != nil {
return
diff --git a/parsemail_test.go b/parsemail_test.go
index 622003e..809aad8 100644
--- a/parsemail_test.go
+++ b/parsemail_test.go
@@ -182,7 +182,7 @@
},
6: {
mailData: data1,
- subject: "Test Subject 1",
+ subject: "Peter Paholík",
from: []mail.Address{
{
Name: "Peter Paholík",
@@ -499,7 +499,7 @@
var data1 = `From: =?UTF-8?Q?Peter_Pahol=C3=ADk?= <peter.paholik@gmail.com>
Date: Fri, 7 Apr 2017 09:17:26 +0200
Message-ID: <CACtgX4kNXE7T5XKSKeH_zEcfUUmf2vXVASxYjaaK9cCn-3zb_g@mail.gmail.com>
-Subject: Test Subject 1
+Subject: =?UTF-8?Q?Peter_Pahol=C3=ADk?=
To: dusan@kasan.sk
Content-Type: multipart/mixed; boundary=f403045f1dcc043a44054c8e6bbf