signMessage looks up a DKIM keypair for the given domain and returns a signed copy of the message. Returns (nil, false) when no key is stored for the domain or when signing fails — callers proceed with the unsigned message rather than failing the send.
(message []byte, domain string)
| 313 | // stored for the domain or when signing fails — callers proceed with |
| 314 | // the unsigned message rather than failing the send. |
| 315 | func (s *Sender) signMessage(message []byte, domain string) ([]byte, bool) { |
| 316 | if s.dkimLookup == nil || domain == "" { |
| 317 | return nil, false |
| 318 | } |
| 319 | selector, privKey, err := s.dkimLookup.GetDKIMKeyInternal(context.Background(), domain) |
| 320 | if err != nil { |
| 321 | log.Printf("[sender] dkim key lookup for %s: %v", domain, err) |
| 322 | return nil, false |
| 323 | } |
| 324 | if selector == "" || len(privKey) == 0 { |
| 325 | return nil, false |
| 326 | } |
| 327 | signed, err := dkim.Sign(message, domain, selector, privKey) |
| 328 | if err != nil { |
| 329 | log.Printf("[sender] dkim sign for %s failed (sending unsigned): %v", domain, err) |
| 330 | return nil, false |
| 331 | } |
| 332 | return signed, true |
| 333 | } |
| 334 | |
| 335 | // normalizeAddrs parses and lowercases a list of email addresses. |
| 336 | // Returns an error if any address is unparseable. |