func (msg *message) closeMultipart() {
	if msg.parts > 0 {
		msg.writers[msg.parts-1].Close()
		msg.parts--
	}
}
closeMultipart closes a part of a multipart message
package mail
import (
	"bytes"
	"encoding/base64"
	"io"
	"mime/multipart"
	"mime/quotedprintable"
	"net/textproto"
	"regexp"
	"strconv"
	"strings"
	"time"
)
type message struct {
	headers  textproto.MIMEHeader
	body     *bytes.Buffer
	writers  []*multipart.Writer
	parts    uint8
	cids     map[string]string
	charset  string
	encoding encoding
}
func newMessage(email *Email) *message {
	return &message{
		headers:  email.headers,
		body:     new(bytes.Buffer),
		cids:     make(map[string]string),
		charset:  email.Charset,
		encoding: email.Encoding}
}
func encodeHeader(text string, charset string, usedChars int) string {
	buf := new(bytes.Buffer)
	encoder := newEncoder(buf, charset, usedChars)
	encoder.encode([]byte(text))
	return buf.String()
}
func (msg *message) getHeaders() (headers string) {
	if date := msg.headers.Get("Date"); date == "" {
		msg.headers.Set("Date", time.Now().Format(time.RFC1123Z))
	}
	for header, values := range msg.headers {
		headers += header + ": " + encodeHeader(strings.Join(values, ", "), msg.charset, len(header)+2) + "\r\n"
	}
	headers = headers + "\r\n"
	return
}
func (msg *message) getCID(text string) (cid string) {
	const dateFormat = "20060102.150405"
	cid, exists := msg.cids[text]
	if !exists {
		cid = time.Now().Format(dateFormat) + "." + strconv.Itoa(len(msg.cids)+1) + "@mail.0"
		msg.cids[text] = cid
	}
	return
}
func (msg *message) replaceCIDs(text string) string {
	re := regexp.MustCompile(`(src|href)="cid:(.*?)"`)
	for _, matches := range re.FindAllStringSubmatch(text, -1) {
		cid := msg.getCID(matches[2])
		text = strings.Replace(text, "cid:"+matches[2], "cid:"+cid, -1)
	}
	return text
}
func (msg *message) openMultipart(multipartType string) {
	msg.writers = append(msg.writers, multipart.NewWriter(msg.body))
	contentType := "multipart/" + multipartType + ";\n \tboundary=" + msg.writers[msg.parts].Boundary()
	if msg.parts == 0 {
		msg.headers.Set("Content-Type", contentType)
	} else {  
		header := make(textproto.MIMEHeader)
		header.Set("Content-Type", contentType)
		msg.writers[msg.parts-1].CreatePart(header)
	}
	msg.parts++
}