func (p *ParsedMessage) Unlink() error {
	if _, err := os.Stat(p.FileName()); os.IsNotExist(err) {
		return nil
	}
	return os.Remove(p.FileName())
}
Unlink message data from disk if present.
package lib
import (
	"bufio"
	"bytes"
	"crypto/sha256"
	"encoding/hex"
	"errors"
	"io"
	"log"
	"net/mail"
	"os"
	"path"
	"strings"
	"github.com/spf13/viper"
)
func splitAddress(email string) (account, host string) {
	i := strings.LastIndexByte(email, '@')
	account = email[:i]
	host = email[i+1:]
	return
}
func joinAddresses(addresses []*mail.Address) string {
	out := ""
	for _, addr := range addresses {
		if addr != nil {
			if out != "" {
				out = out + ", " + addr.String()
			} else {
				out = addr.String()
			}
		}
	}
	return out
}
func ReadMessage(reader io.Reader) []byte {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanBytes)
	mailMsg := make([]byte, 0)
	for scanner.Scan() {
		mailMsg = append(mailMsg, scanner.Bytes()...)
	}
	if err := scanner.Err(); err != nil && err != io.EOF {
		log.Fatalf("reading message: %v", err)
	}
	return mailMsg
}
type ParsedMessage struct {
	Sender       string
	SourceDomain string
	Rcpt         map[string][]string
	DestDomain   []string
	Bytes        *[]byte
	*mail.Message
}
func (p ParsedMessage) Hash() string {
	hasher := sha256.New()
	m, err := mail.ReadMessage(bytes.NewReader(*p.Bytes))
	if err != nil {
		return ""
	}
	io.Copy(hasher, m.Body)
	return hex.EncodeToString(hasher.Sum(nil))
}
func (p ParsedMessage) FileName() string {
	return path.Join(path.Dir(viper.ConfigFileUsed()), p.Hash()+".eml")
}
func (p *ParsedMessage) UnmarshalText(b []byte) error {
	hash := bytes.Index(b, []byte(" "))
	if hash == -1 {
		return errors.New("invalid cache line")
	}
	filename := path.Join(path.Dir(viper.ConfigFileUsed()), string(b[0:hash])+".eml")
	dat, err := ParseDiskInput(filename)
	if err != nil {
		return err
	}
	msg := ParseMessage(&dat)
	p.Bytes = &dat
	p.Sender = msg.Sender
	p.SourceDomain = msg.SourceDomain
	p.Message = msg.Message
	return p.SetRecipients(string(b[hash+1:]))
}
func (p ParsedMessage) MarshalText() ([]byte, error) {
	return []byte(p.Hash() + " " + p.Recipients()), nil
}
func (p *ParsedMessage) Save() error {
	return WriteDiskOutput(p.FileName(), *p.Bytes)
}