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 }
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 }