Lowered Go version requirement from 1.5 to 1.2

This commit is contained in:
Alexandre Cesaro 2015-07-16 19:33:38 +02:00
parent b01506efc6
commit 3346e955b2
5 changed files with 41 additions and 8 deletions

View File

@ -4,7 +4,7 @@
Gomail is a very simple and powerful package to send emails. Gomail is a very simple and powerful package to send emails.
It requires Go 1.3 or newer. It requires Go 1.2 or newer.
## Features ## Features

View File

@ -6,7 +6,6 @@ package gomail
import ( import (
"bytes" "bytes"
"io" "io"
"mime"
"os" "os"
"path/filepath" "path/filepath"
"time" "time"
@ -20,7 +19,7 @@ type Message struct {
embedded []*File embedded []*File
charset string charset string
encoding Encoding encoding Encoding
hEncoder mime.WordEncoder hEncoder mimeEncoder
buf bytes.Buffer buf bytes.Buffer
} }
@ -43,9 +42,9 @@ func NewMessage(settings ...MessageSetting) *Message {
m.applySettings(settings) m.applySettings(settings)
if m.encoding == Base64 { if m.encoding == Base64 {
m.hEncoder = mime.BEncoding m.hEncoder = bEncoding
} else { } else {
m.hEncoder = mime.QEncoding m.hEncoder = qEncoding
} }
return m return m
@ -150,7 +149,7 @@ func (m *Message) FormatAddress(address, name string) string {
} }
m.buf.WriteByte('"') m.buf.WriteByte('"')
} else if hasSpecials(name) { } else if hasSpecials(name) {
m.buf.WriteString(mime.BEncoding.Encode(m.charset, name)) m.buf.WriteString(bEncoding.Encode(m.charset, name))
} else { } else {
m.buf.WriteString(enc) m.buf.WriteString(enc)
} }

19
mime.go Normal file
View File

@ -0,0 +1,19 @@
// +build go1.5
package gomail
import (
"mime"
"mime/quotedprintable"
)
var newQPWriter = quotedprintable.NewWriter
type mimeEncoder struct {
mime.WordEncoder
}
var (
bEncoding = mimeEncoder{mime.BEncoding}
qEncoding = mimeEncoder{mime.QEncoding}
)

16
mime_go14.go Normal file
View File

@ -0,0 +1,16 @@
// +build !go1.5
package gomail
import "gopkg.in/alexcesaro/quotedprintable.v3"
var newQPWriter = quotedprintable.NewWriter
type mimeEncoder struct {
quotedprintable.WordEncoder
}
var (
bEncoding = mimeEncoder{quotedprintable.BEncoding}
qEncoding = mimeEncoder{quotedprintable.QEncoding}
)

View File

@ -6,7 +6,6 @@ import (
"io" "io"
"mime" "mime"
"mime/multipart" "mime/multipart"
"mime/quotedprintable"
"path/filepath" "path/filepath"
"time" "time"
) )
@ -207,7 +206,7 @@ func (w *messageWriter) writeBody(f func(io.Writer) error, enc Encoding) {
} else if enc == Unencoded { } else if enc == Unencoded {
w.err = f(subWriter) w.err = f(subWriter)
} else { } else {
wc := quotedprintable.NewWriter(subWriter) wc := newQPWriter(subWriter)
w.err = f(wc) w.err = f(wc)
wc.Close() wc.Close()
} }