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.
It requires Go 1.3 or newer.
It requires Go 1.2 or newer.
## Features

View File

@ -6,7 +6,6 @@ package gomail
import (
"bytes"
"io"
"mime"
"os"
"path/filepath"
"time"
@ -20,7 +19,7 @@ type Message struct {
embedded []*File
charset string
encoding Encoding
hEncoder mime.WordEncoder
hEncoder mimeEncoder
buf bytes.Buffer
}
@ -43,9 +42,9 @@ func NewMessage(settings ...MessageSetting) *Message {
m.applySettings(settings)
if m.encoding == Base64 {
m.hEncoder = mime.BEncoding
m.hEncoder = bEncoding
} else {
m.hEncoder = mime.QEncoding
m.hEncoder = qEncoding
}
return m
@ -150,7 +149,7 @@ func (m *Message) FormatAddress(address, name string) string {
}
m.buf.WriteByte('"')
} else if hasSpecials(name) {
m.buf.WriteString(mime.BEncoding.Encode(m.charset, name))
m.buf.WriteString(bEncoding.Encode(m.charset, name))
} else {
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"
"mime"
"mime/multipart"
"mime/quotedprintable"
"path/filepath"
"time"
)
@ -207,7 +206,7 @@ func (w *messageWriter) writeBody(f func(io.Writer) error, enc Encoding) {
} else if enc == Unencoded {
w.err = f(subWriter)
} else {
wc := quotedprintable.NewWriter(subWriter)
wc := newQPWriter(subWriter)
w.err = f(wc)
wc.Close()
}