NormalizeAndValidateLabelList runs each entry through normalizeAndValidateLabel, dedups within the slice, and rejects if the slice is empty after trimming or exceeds the per-op cap. The `op` argument is used only to shape the error message.
(raw []string, op string)
| 1483 | // the slice is empty after trimming or exceeds the per-op cap. The |
| 1484 | // `op` argument is used only to shape the error message. |
| 1485 | func NormalizeAndValidateLabelList(raw []string, op string) ([]string, error) { |
| 1486 | if len(raw) > MaxLabelsPerOp { |
| 1487 | return nil, fmt.Errorf("%s_labels exceeds per-request cap of %d", op, MaxLabelsPerOp) |
| 1488 | } |
| 1489 | seen := map[string]struct{}{} |
| 1490 | out := make([]string, 0, len(raw)) |
| 1491 | for _, r := range raw { |
| 1492 | l, err := normalizeAndValidateLabel(r, false) |
| 1493 | if err != nil { |
| 1494 | return nil, err |
| 1495 | } |
| 1496 | if _, dup := seen[l]; dup { |
| 1497 | continue |
| 1498 | } |
| 1499 | seen[l] = struct{}{} |
| 1500 | out = append(out, l) |
| 1501 | } |
| 1502 | return out, nil |
| 1503 | } |
| 1504 | |
| 1505 | // validateRecipients ensures every entry in the joined To/CC/BCC slices |
| 1506 | // is a syntactically valid RFC 5322 address. We use net/mail.ParseAddress |
no test coverage detected