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

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

	message, err := mail.ReadMessage(m.fd)
	if err != nil {
		return
	}

	m.subject, err = ParseSubject(message)
	if err != nil {
		return
	}

	m.from, err = ParseFromAddress(message)
	if err != nil {
		return
	}

	m.to, err = ParseToAddress(message)
	if err != nil {
		return
	}

	m.content, err = ParseBoby(message)
	if err != nil {
		return
	}

	return
}
示例#2
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
}