getAddressBaseConsumer(); } /** * Overridden to extract all addresses into addresses array. * * @return static */ protected function setParseHeaderValue(AbstractConsumer $consumer) { parent::setParseHeaderValue($consumer); foreach ($this->parts as $part) { if ($part instanceof AddressPart) { $this->addresses[] = $part; } elseif ($part instanceof AddressGroupPart) { $this->addresses = \array_merge($this->addresses, $part->getAddresses()); $this->groups[] = $part; } } return $this; } /** * Returns all address parts in the header including any addresses that are * in groups (lists). * * @return AddressPart[] The addresses. */ public function getAddresses(): array { return $this->addresses; } /** * Returns all group parts (lists) in the header. * * @return AddressGroupPart[] */ public function getGroups(): array { return $this->groups; } /** * Returns true if an address exists with the passed email address. * * Comparison is done case insensitively. * */ public function hasAddress(string $email): bool { foreach ($this->addresses as $addr) { if (\strcasecmp($addr->getEmail(), $email) === 0) { return true; } } return false; } /** * Returns the first email address in the header. * * @return ?string The email address */ public function getEmail(): ?string { return $this->getValue(); } /** * Returns the name associated with the first email address to complement * getValue()/getEmail() if one is set, or null if not. * * @return string|null The person name. */ public function getPersonName(): ?string { if (!empty($this->parts)) { return $this->parts[0]->getName(); } return null; } }