示例#1
0
func (m *plainTextMail) Parse() (err error) {

	m.fd, err = os.Open(m.filePath)
	if err != nil {
		return
	}

	r := bufio.NewReader(m.fd)

	m.subject, err = r.ReadString('\n')
	if err != nil {
		return
	}
	m.subject = strings.TrimSpace(m.subject)

	fromText, err := r.ReadString('\n')
	if err != nil {
		return
	}
	m.from, err = mail.ParseAddress(strings.TrimSpace(fromText))
	if err != nil {
		return
	}

	toTextList, err := r.ReadString('\n')
	if err != nil {
		return
	}
	m.to, err = mail.ParseAddressList(strings.TrimSpace(toTextList))
	if err != nil {
		return
	}

	m.content = r
	return
}
示例#2
0
func ParseToAddress(message *mail.Message) ([]*mail.Address, error) {
	return mail.ParseAddressList(message.Header.Get("To"))
}