Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. MailboxListHeader.php

class MailboxListHeader

A Mailbox list MIME Header for something like From, To, Cc, and Bcc (one or more named addresses).

@author Chris Corbyn

Hierarchy

  • class \Symfony\Component\Mime\Header\AbstractHeader implements \Symfony\Component\Mime\Header\HeaderInterface
    • class \Symfony\Component\Mime\Header\MailboxListHeader extends \Symfony\Component\Mime\Header\AbstractHeader

Expanded class hierarchy of MailboxListHeader

2 files declare their use of MailboxListHeader
EmailAddressContains.php in vendor/symfony/mime/Test/Constraint/EmailAddressContains.php
MessageListener.php in vendor/symfony/mailer/EventListener/MessageListener.php

File

vendor/symfony/mime/Header/MailboxListHeader.php, line 22

Namespace

Symfony\Component\Mime\Header
View source
final class MailboxListHeader extends AbstractHeader {
    private array $addresses = [];
    
    /**
     * @param Address[] $addresses
     */
    public function __construct(string $name, array $addresses) {
        parent::__construct($name);
        $this->setAddresses($addresses);
    }
    
    /**
     * @param Address[] $body
     *
     * @throws RfcComplianceException
     */
    public function setBody(mixed $body) : void {
        $this->setAddresses($body);
    }
    
    /**
     * @return Address[]
     *
     * @throws RfcComplianceException
     */
    public function getBody() : array {
        return $this->getAddresses();
    }
    
    /**
     * Sets a list of addresses to be shown in this Header.
     *
     * @param Address[] $addresses
     *
     * @throws RfcComplianceException
     */
    public function setAddresses(array $addresses) : void {
        $this->addresses = [];
        $this->addAddresses($addresses);
    }
    
    /**
     * Sets a list of addresses to be shown in this Header.
     *
     * @param Address[] $addresses
     *
     * @throws RfcComplianceException
     */
    public function addAddresses(array $addresses) : void {
        foreach ($addresses as $address) {
            $this->addAddress($address);
        }
    }
    
    /**
     * @throws RfcComplianceException
     */
    public function addAddress(Address $address) : void {
        $this->addresses[] = $address;
    }
    
    /**
     * @return Address[]
     */
    public function getAddresses() : array {
        return $this->addresses;
    }
    
    /**
     * Gets the full mailbox list of this Header as an array of valid RFC 2822 strings.
     *
     * @return string[]
     *
     * @throws RfcComplianceException
     */
    public function getAddressStrings() : array {
        $strings = [];
        foreach ($this->addresses as $address) {
            $str = $address->getEncodedAddress();
            if ($name = $address->getName()) {
                $str = $this->createPhrase($this, $name, $this->getCharset(), !$strings) . ' <' . $str . '>';
            }
            $strings[] = $str;
        }
        return $strings;
    }
    public function getBodyAsString() : string {
        return implode(', ', $this->getAddressStrings());
    }
    
    /**
     * Redefine the encoding requirements for addresses.
     *
     * All "specials" must be encoded as the full header value will not be quoted
     *
     * @see RFC 2822 3.2.1
     */
    protected function tokenNeedsEncoding(string $token) : bool {
        return preg_match('/[()<>\\[\\]:;@\\,."]/', $token) || parent::tokenNeedsEncoding($token);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AbstractHeader::$charset private property
AbstractHeader::$encoder private static property 1
AbstractHeader::$lang private property
AbstractHeader::$lineLength private property
AbstractHeader::$name private property
AbstractHeader::createPhrase protected function Produces a compliant, formatted RFC 2822 &#039;phrase&#039; based on the string given.
AbstractHeader::encodeWords protected function Encode needed word tokens within a string of input.
AbstractHeader::generateTokenLines protected function Generates tokens from the given string which include CRLF as individual tokens.
AbstractHeader::getCharset public function Overrides HeaderInterface::getCharset
AbstractHeader::getEncodableWordTokens protected function Splits a string into tokens in blocks of words which can be encoded quickly.
AbstractHeader::getLanguage public function Overrides HeaderInterface::getLanguage
AbstractHeader::getMaxLineLength public function Overrides HeaderInterface::getMaxLineLength
AbstractHeader::getName public function Overrides HeaderInterface::getName
AbstractHeader::getTokenAsEncodedWord protected function Get a token as an encoded word for safe insertion into headers.
AbstractHeader::PHRASE_PATTERN public constant
AbstractHeader::setCharset public function Overrides HeaderInterface::setCharset
AbstractHeader::setLanguage public function Set the language used in this Header. Overrides HeaderInterface::setLanguage
AbstractHeader::setMaxLineLength public function Overrides HeaderInterface::setMaxLineLength
AbstractHeader::tokensToString private function Takes an array of tokens which appear in the header and turns them into
an RFC 2822 compliant string, adding FWSP where needed.
AbstractHeader::toString public function Gets this Header rendered as a compliant string. Overrides HeaderInterface::toString
AbstractHeader::toTokens protected function Generate a list of all tokens in the final header. 1
MailboxListHeader::$addresses private property
MailboxListHeader::addAddress public function
MailboxListHeader::addAddresses public function Sets a list of addresses to be shown in this Header.
MailboxListHeader::getAddresses public function
MailboxListHeader::getAddressStrings public function Gets the full mailbox list of this Header as an array of valid RFC 2822 strings.
MailboxListHeader::getBody public function Overrides HeaderInterface::getBody
MailboxListHeader::getBodyAsString public function Gets the header&#039;s body, prepared for folding into a final header value. Overrides HeaderInterface::getBodyAsString
MailboxListHeader::setAddresses public function Sets a list of addresses to be shown in this Header.
MailboxListHeader::setBody public function Overrides HeaderInterface::setBody
MailboxListHeader::tokenNeedsEncoding protected function Redefine the encoding requirements for addresses. Overrides AbstractHeader::tokenNeedsEncoding
MailboxListHeader::__construct public function Overrides AbstractHeader::__construct

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal