func ParseBodyPart(raw, boundary []byte) (mime *MIME, rest []byte, err error) {
	if len(raw) == 0 {
		return nil, raw, nil
	}
	if len(boundary) == 0 {
		return nil, raw, errors.New("ParseBodyPart: boundary parameter is empty")
	}
	r := &libio.Reader{}
	r.Init(raw)
	var (
		line   []byte
		minlen = len(boundary) + 2
	)
	r.SkipSpaces()
	line = r.ReadLine()
	if len(line) == 0 {
		rest = r.Rest()
		return nil, rest, nil
	}
	if len(line) < minlen {
		return nil, raw, errors.New("ParseBodyPart: missing boundary line")
	}
	if line[len(line)-2] != cr {
		return nil, raw, errors.New("ParseBodyPart: invalid boundary line: missing CR")
	}
	if !bytes.Equal(line[:2], boundSeps) {
		return nil, raw, errors.New("ParseBodyPart: invalid boundary line: missing '--'")
	}
	if !bytes.Equal(line[2:minlen], boundary) {
		return nil, raw, errors.New("ParseBodyPart: boundary mismatch")
	}
	if bytes.Equal(line[minlen:len(line)-2], boundSeps) {
		return nil, r.Rest(), nil
	}
	mime = &MIME{}
	mime.Header, rest, err = ParseHeader(r.Rest())
	if err != nil {
		return nil, raw, err
	}
	r.Init(rest)
	for {
		line = r.ReadLine()
		if len(line) == 0 {
			break
		}
		if len(line) < minlen {
			mime.Content = append(mime.Content, line...)
			continue
		}
		if line[len(line)-2] != cr {
			mime.Content = append(mime.Content, line...)
			continue
		}
		if !bytes.Equal(line[:2], boundSeps) {
			mime.Content = append(mime.Content, line...)
			continue
		}
		if !bytes.Equal(line[2:minlen], boundary) {
			mime.Content = append(mime.Content, line...)
			continue
		}
		r.UnreadN(len(line))
		break
	}
	rest = r.Rest()
	return mime, rest, err
}
ParseBodyPart parse one body part using boundary and return the rest of
body.
package email
import (
	"bytes"
	"errors"
	"mime/quotedprintable"
	"strings"
	libio "github.com/shuLhan/share/lib/io"
)
type MIME struct {
	Header  *Header
	Content []byte
}
func newMIME(contentType, content []byte) (mime *MIME, err error) {
	mime = &MIME{
		Header: &Header{},
	}
	err = mime.Header.Set(FieldTypeContentType, contentType)
	if err != nil {
		return nil, err
	}
	err = mime.Header.Set(FieldTypeMIMEVersion, []byte(mimeVersion1))
	if err != nil {
		return nil, err
	}
	err = mime.Header.Set(FieldTypeContentTransferEncoding,
		[]byte(encodingQuotedPrintable))
	if err != nil {
		return nil, err
	}
	var buf bytes.Buffer
	content = append(content, []byte("\r\n")...)
	w := quotedprintable.NewWriter(&buf)
	_, err = w.Write(content)
	if err != nil {
		return nil, err
	}
	w.Close()
	mime.Content = buf.Bytes()
	return mime, nil
}