Split splits a email address (as defined by RFC 5321 as a forward-path token) into local part (mailbox) and domain. Note that definition of the forward-path token includes the special postmaster address without the domain part. Split will return domain == "" in this case. Split does almost no sani
(addr string)
| 34 | // If this is a concern, ValidMailbox and ValidDomain should be used on the |
| 35 | // output. |
| 36 | func Split(addr string) (mailbox, domain string, err error) { |
| 37 | if strings.EqualFold(addr, "postmaster") { |
| 38 | return addr, "", nil |
| 39 | } |
| 40 | |
| 41 | indx := strings.LastIndexByte(addr, '@') |
| 42 | if indx == -1 { |
| 43 | return "", "", errors.New("address: missing at-sign") |
| 44 | } |
| 45 | mailbox = addr[:indx] |
| 46 | domain = addr[indx+1:] |
| 47 | if mailbox == "" { |
| 48 | return "", "", errors.New("address: empty local-part") |
| 49 | } |
| 50 | if domain == "" { |
| 51 | return "", "", errors.New("address: empty domain") |
| 52 | } |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | // UnquoteMbox undoes escaping and quoting of the local-part. That is, for |
| 57 | // local-part `"test\" @ test"` it will return `test" @test`. |
no outgoing calls