From 3346e955b2d7998f7627b49ecbbc839eca25204b Mon Sep 17 00:00:00 2001 From: Alexandre Cesaro Date: Thu, 16 Jul 2015 19:33:38 +0200 Subject: [PATCH] Lowered Go version requirement from 1.5 to 1.2 --- README.md | 2 +- message.go | 9 ++++----- mime.go | 19 +++++++++++++++++++ mime_go14.go | 16 ++++++++++++++++ writeto.go | 3 +-- 5 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 mime.go create mode 100644 mime_go14.go diff --git a/README.md b/README.md index 70f7acf..8c1f3bf 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/message.go b/message.go index 20c3b9b..dd50d85 100644 --- a/message.go +++ b/message.go @@ -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) } diff --git a/mime.go b/mime.go new file mode 100644 index 0000000..51cba72 --- /dev/null +++ b/mime.go @@ -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} +) diff --git a/mime_go14.go b/mime_go14.go new file mode 100644 index 0000000..246e2e5 --- /dev/null +++ b/mime_go14.go @@ -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} +) diff --git a/writeto.go b/writeto.go index 68213a3..efe4123 100644 --- a/writeto.go +++ b/writeto.go @@ -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() }