generated from VLADIMIR/template
fix email
This commit is contained in:
@@ -133,7 +133,7 @@ func buildMessage(from, fromName, to, subject, replyTo, body, html string) []byt
|
||||
b.Grow(len(from) + len(fromName) + len(to) + len(subject) + len(body) + len(html) + 512)
|
||||
b.WriteString("From: ")
|
||||
if fromName != "" {
|
||||
b.WriteString(mime.QEncoding.Encode("utf-8", fromName))
|
||||
b.WriteString(mime.BEncoding.Encode("utf-8", fromName))
|
||||
b.WriteString(" <")
|
||||
b.WriteString(from)
|
||||
b.WriteString(">\r\n")
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"crypto/x509/pkix"
|
||||
"math/big"
|
||||
"net"
|
||||
"net/mail"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -183,7 +184,7 @@ func TestSendSuccess(t *testing.T) {
|
||||
raw := string(data)
|
||||
for _, want := range []string{
|
||||
// From с отображаемым именем (RFC 2047).
|
||||
"From: =?utf-8?q?",
|
||||
"From: =?utf-8?b?",
|
||||
"<sender@example.com>",
|
||||
"To: user@example.com",
|
||||
"Subject: =?utf-8?q?",
|
||||
@@ -270,7 +271,7 @@ func TestBuildMessage(t *testing.T) {
|
||||
"текст", "<html><body>текст</body></html>",
|
||||
))
|
||||
for _, want := range []string{
|
||||
"From: =?utf-8?q?",
|
||||
"From: =?utf-8?b?",
|
||||
"<sender@example.com>",
|
||||
"To: user@example.com",
|
||||
"Subject: =?utf-8?q?",
|
||||
@@ -354,3 +355,19 @@ func TestValidateMessage(t *testing.T) {
|
||||
t.Error("пустая тема принята")
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildMessageSenderNameRoundTrip(t *testing.T) {
|
||||
const name = "Вечерний детектив"
|
||||
raw := buildMessage("sender@example.com", name, "user@example.com", "Привет", "", "текст", "")
|
||||
message, err := mail.ReadMessage(strings.NewReader(string(raw)))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
from, err := message.Header.AddressList("From")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(from) != 1 || from[0].Name != name || from[0].Address != "sender@example.com" {
|
||||
t.Fatalf("неверный отправитель: %+v", from)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user