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 }
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 }
func ParseFromAddress(message *mail.Message) (*mail.Address, error) { return mail.ParseAddress(message.Header.Get("From")) }