func (m *SMTPMessage) Parse(hostname string) *Message {
	var arr []*Path
	for _, path := range m.To {
		arr = append(arr, PathFromString(path))
	}
	id, _ := NewMessageID(hostname)
	msg := &Message{
		ID:      id,
		From:    PathFromString(m.From),
		To:      arr,
		Content: ContentFromString(m.Data),
		Created: time.Now(),
		Raw:     m,
	}
	if msg.Content.IsMIME() {
		logf("Parsing MIME body")
		msg.MIME = msg.Content.ParseMIMEBody()
	}
	var hasMessageID bool
	var receivedHeaderName string
	var returnPathHeaderName string
	for k := range msg.Content.Headers {
		if strings.ToLower(k) == "message-id" {
			hasMessageID = true
			continue
		}
		if strings.ToLower(k) == "received" {
			receivedHeaderName = k
			continue
		}
		if strings.ToLower(k) == "return-path" {
			returnPathHeaderName = k
			continue
		}
	}
	if !hasMessageID {
		msg.Content.Headers["Message-ID"] = []string{string(id)}
	}
	if len(receivedHeaderName) > 0 {
		msg.Content.Headers[receivedHeaderName] = append(msg.Content.Headers[receivedHeaderName], "from "+m.Helo+" by "+hostname+" (MailHog)\r\n          id "+string(id)+"; "+time.Now().Format(time.RFC1123Z))
	} else {
		msg.Content.Headers["Received"] = []string{"from " + m.Helo + " by " + hostname + " (MailHog)\r\n          id " + string(id) + "; " + time.Now().Format(time.RFC1123Z)}
	}
	if len(returnPathHeaderName) > 0 {
		msg.Content.Headers[returnPathHeaderName] = append(msg.Content.Headers[returnPathHeaderName], "<"+m.From+">")
	} else {
		msg.Content.Headers["Return-Path"] = []string{"<" + m.From + ">"}
	}
	return msg
}
Parse converts a raw SMTP message to a parsed MIME message
package data
import (
	"bytes"
	"crypto/rand"
	"encoding/base64"
	"io"
	"log"
	"mime"
	"strings"
	"time"
)
var LogHandler func(message string, args ...interface{})
func logf(message string, args ...interface{}) {
	if LogHandler != nil {
		LogHandler(message, args...)
	} else {
		log.Printf(message, args...)
	}
}
type MessageID string
func NewMessageID(hostname string) (MessageID, error) {
	size := 32
	rb := make([]byte, size)
	_, err := rand.Read(rb)
	if err != nil {
		return MessageID(""), err
	}
	rs := base64.URLEncoding.EncodeToString(rb)
	return MessageID(rs + "@" + hostname), nil
}
type Messages []Message
type Message struct {
	ID      MessageID
	From    *Path
	To      []*Path
	Content *Content
	Created time.Time
	MIME    *MIMEBody  
	Raw     *SMTPMessage
}
type Path struct {
	Relays  []string
	Mailbox string
	Domain  string
	Params  string
}
type Content struct {
	Headers map[string][]string
	Body    string
	Size    int
	MIME    *MIMEBody
}
type SMTPMessage struct {
	From string
	To   []string
	Data string
	Helo string
}
type MIMEBody struct {
	Parts []*Content
}