Пример #1
0
func getFromAddress(rawMailContent []byte) (string, error) {
	var message *mail.Message
	message, err := mail.ReadMessage(bytes.NewReader(rawMailContent))
	if err != nil {
		return "", err
	}

	address, err := mail.ParseAddress(message.Header.Get("From"))
	if err != nil {
		log.Printf("parse from address failure, Err:%v, Raw:%s", err, message.Header.Get("From"))
		return "", err
	}

	return address.Address, nil
}
Пример #2
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
}
Пример #3
0
func ParseFromAddress(message *mail.Message) (*mail.Address, error) {
	return mail.ParseAddress(message.Header.Get("From"))
}