summaryrefslogtreecommitdiffstats
path: root/utils/mail.go
diff options
context:
space:
mode:
authorMelvi Ts <layzerar@gmail.com>2015-10-15 21:17:52 +0800
committerzenglei <zenglei@6xia.net>2015-10-16 14:52:31 +0800
commit830c6b3f1ebdfc38ca8ee0e6c672301fbe884e21 (patch)
tree57410ef095cea103f4d02aa4a5e4e8247b1c8af7 /utils/mail.go
parente9e2bd6e3d5ab451e7b74d1f9b0ff256f973f5b8 (diff)
downloadchat-830c6b3f1ebdfc38ca8ee0e6c672301fbe884e21.tar.gz
chat-830c6b3f1ebdfc38ca8ee0e6c672301fbe884e21.tar.bz2
chat-830c6b3f1ebdfc38ca8ee0e6c672301fbe884e21.zip
Fix email encoding issue
Diffstat (limited to 'utils/mail.go')
-rw-r--r--utils/mail.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/utils/mail.go b/utils/mail.go
index c91c15a6a..07a79eeb2 100644
--- a/utils/mail.go
+++ b/utils/mail.go
@@ -6,15 +6,22 @@ package utils
import (
l4g "code.google.com/p/log4go"
"crypto/tls"
+ "encoding/base64"
"fmt"
"github.com/mattermost/platform/model"
- "html"
"net"
"net/mail"
"net/smtp"
"time"
)
+func encodeRFC2047Word(s string) string {
+ // TODO: use `mime.BEncoding.Encode` instead when `go` >= 1.5
+ // return mime.BEncoding.Encode("utf-8", s)
+ dst := base64.StdEncoding.EncodeToString([]byte(s))
+ return "=?utf-8?b?" + dst + "?="
+}
+
func connectToSMTPServer(config *model.Config) (net.Conn, *model.AppError) {
var conn net.Conn
var err error
@@ -102,9 +109,10 @@ func SendMailUsingConfig(to, subject, body string, config *model.Config) *model.
headers := make(map[string]string)
headers["From"] = fromMail.String()
headers["To"] = toMail.String()
- headers["Subject"] = html.UnescapeString(subject)
+ headers["Subject"] = encodeRFC2047Word(subject)
headers["MIME-version"] = "1.0"
- headers["Content-Type"] = "text/html"
+ headers["Content-Type"] = "text/html; charset=\"utf-8\""
+ headers["Content-Transfer-Encoding"] = "8bit"
headers["Date"] = time.Now().Format(time.RFC1123Z)
message := ""