package mailparser import ( "net/mail" "strings" ) // Only the topmost Return-Path counts: it is added by the final delivering // mailserver; lower ones stem from earlier hops or the sender. func returnPath(h mail.Header) string { values := h["Return-Path"] if len(values) == 0 { return "" } v := strings.TrimSpace(values[0]) if v == "" || v == "<>" { return "" } a, err := mail.ParseAddress(v) if err != nil { return "" } return strings.ToLower(strings.TrimSpace(a.Address)) }