Added a new encoding: Unencoded
This commit is contained in:
parent
4fcb155d12
commit
b4e3113e2d
|
@ -29,11 +29,7 @@ func (msg *Message) Export() *mail.Message {
|
||||||
for _, part := range msg.parts {
|
for _, part := range msg.parts {
|
||||||
h := make(map[string][]string)
|
h := make(map[string][]string)
|
||||||
h["Content-Type"] = []string{part.contentType + "; charset=" + msg.charset}
|
h["Content-Type"] = []string{part.contentType + "; charset=" + msg.charset}
|
||||||
if msg.encoding == Base64 {
|
h["Content-Transfer-Encoding"] = []string{string(msg.encoding)}
|
||||||
h["Content-Transfer-Encoding"] = []string{string(Base64)}
|
|
||||||
} else {
|
|
||||||
h["Content-Transfer-Encoding"] = []string{string(QuotedPrintable)}
|
|
||||||
}
|
|
||||||
|
|
||||||
w.write(h, part.body.Bytes(), msg.encoding)
|
w.write(h, part.body.Bytes(), msg.encoding)
|
||||||
}
|
}
|
||||||
|
@ -166,6 +162,8 @@ func (w *messageWriter) writeBody(body []byte, enc Encoding) {
|
||||||
writer := base64.NewEncoder(base64.StdEncoding, newBase64LineWriter(subWriter))
|
writer := base64.NewEncoder(base64.StdEncoding, newBase64LineWriter(subWriter))
|
||||||
writer.Write(body)
|
writer.Write(body)
|
||||||
writer.Close()
|
writer.Close()
|
||||||
|
} else if enc == Unencoded {
|
||||||
|
subWriter.Write(body)
|
||||||
} else {
|
} else {
|
||||||
writer := quotedprintable.NewEncoder(newQpLineWriter(subWriter))
|
writer := quotedprintable.NewEncoder(newQpLineWriter(subWriter))
|
||||||
writer.Write(body)
|
writer.Write(body)
|
||||||
|
|
|
@ -95,6 +95,9 @@ const (
|
||||||
QuotedPrintable Encoding = "quoted-printable"
|
QuotedPrintable Encoding = "quoted-printable"
|
||||||
// Base64 represents the base64 encoding as defined in RFC 2045.
|
// Base64 represents the base64 encoding as defined in RFC 2045.
|
||||||
Base64 Encoding = "base64"
|
Base64 Encoding = "base64"
|
||||||
|
// Unencoded can be used to avoid encoding the body of an email. The headers
|
||||||
|
// will still be encoded using quoted-printable encoding.
|
||||||
|
Unencoded Encoding = "8bit"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetHeader sets a value to the given header field.
|
// SetHeader sets a value to the given header field.
|
||||||
|
|
|
@ -95,6 +95,30 @@ func TestCustomMessage(t *testing.T) {
|
||||||
testMessage(t, msg, 0, want)
|
testMessage(t, msg, 0, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUnencodedMessage(t *testing.T) {
|
||||||
|
msg := NewMessage(SetEncoding(Unencoded))
|
||||||
|
msg.SetHeaders(map[string][]string{
|
||||||
|
"From": {"from@example.com"},
|
||||||
|
"To": {"to@example.com"},
|
||||||
|
"Subject": {"Café"},
|
||||||
|
})
|
||||||
|
msg.SetBody("text/html", "¡Hola, señor!")
|
||||||
|
|
||||||
|
want := message{
|
||||||
|
from: "from@example.com",
|
||||||
|
to: []string{"to@example.com"},
|
||||||
|
content: "From: from@example.com\r\n" +
|
||||||
|
"To: to@example.com\r\n" +
|
||||||
|
"Subject: =?UTF-8?Q?Caf=C3=A9?=\r\n" +
|
||||||
|
"Content-Type: text/html; charset=UTF-8\r\n" +
|
||||||
|
"Content-Transfer-Encoding: 8bit\r\n" +
|
||||||
|
"\r\n" +
|
||||||
|
"¡Hola, señor!",
|
||||||
|
}
|
||||||
|
|
||||||
|
testMessage(t, msg, 0, want)
|
||||||
|
}
|
||||||
|
|
||||||
func TestRecipients(t *testing.T) {
|
func TestRecipients(t *testing.T) {
|
||||||
msg := NewMessage()
|
msg := NewMessage()
|
||||||
msg.SetHeaders(map[string][]string{
|
msg.SetHeaders(map[string][]string{
|
||||||
|
|
Loading…
Reference in New Issue