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

Breadcrumb

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

class Message

Same name in this branch
  1. 11.1.x vendor/guzzlehttp/psr7/src/Message.php \GuzzleHttp\Psr7\Message
  2. 11.1.x vendor/google/protobuf/src/Google/Protobuf/Internal/Message.php \Google\Protobuf\Internal\Message
  3. 11.1.x composer/Plugin/ProjectMessage/Message.php \Drupal\Composer\Plugin\ProjectMessage\Message
  4. 11.1.x core/modules/contact/src/Entity/Message.php \Drupal\contact\Entity\Message

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

  • class \Symfony\Component\Mime\RawMessage
    • class \Symfony\Component\Mime\Message extends \Symfony\Component\Mime\RawMessage

Expanded class hierarchy of Message

14 files declare their use of Message
DelayedEnvelope.php in vendor/symfony/mailer/DelayedEnvelope.php
DkimSigner.php in vendor/symfony/mime/Crypto/DkimSigner.php
EmailAttachmentCount.php in vendor/symfony/mime/Test/Constraint/EmailAttachmentCount.php
EmailHtmlBodyContains.php in vendor/symfony/mime/Test/Constraint/EmailHtmlBodyContains.php
EmailTextBodyContains.php in vendor/symfony/mime/Test/Constraint/EmailTextBodyContains.php

... See full list

33 string references to 'Message'
AbstractWebDriver::curl in vendor/lullabot/php-webdriver/lib/WebDriver/AbstractWebDriver.php
Curl request to webdriver server.
Checkstyle::generateFileReport in vendor/squizlabs/php_codesniffer/src/Reports/Checkstyle.php
Generate a partial report for a single processed file.
Compiler::compile in vendor/symfony/dependency-injection/Compiler/Compiler.php
Run the Compiler and process all Passes.
ContactFormEditForm::form in core/modules/contact/src/ContactFormEditForm.php
Gets the actual form array to be built.
core.entity.schema.yml in core/config/schema/core.entity.schema.yml
core/config/schema/core.entity.schema.yml

... See full list

File

vendor/symfony/mime/Message.php, line 22

Namespace

Symfony\Component\Mime
View source
class Message extends RawMessage {
    private Headers $headers;
    public function __construct(?Headers $headers = null, ?AbstractPart $body = null) {
        $this->headers = $headers ? clone $headers : new Headers();
    }
    public function __clone() {
        $this->headers = clone $this->headers;
        if (null !== $this->body) {
            $this->body = clone $this->body;
        }
    }
    
    /**
     * @return $this
     */
    public function setBody(?AbstractPart $body) : static {
        $this->body = $body;
        return $this;
    }
    public function getBody() : ?AbstractPart {
        return $this->body;
    }
    
    /**
     * @return $this
     */
    public function setHeaders(Headers $headers) : static {
        $this->headers = $headers;
        return $this;
    }
    public function getHeaders() : Headers {
        return $this->headers;
    }
    public function getPreparedHeaders() : Headers {
        $headers = clone $this->headers;
        if (!$headers->has('From')) {
            if (!$headers->has('Sender')) {
                throw new LogicException('An email must have a "From" or a "Sender" header.');
            }
            $headers->addMailboxListHeader('From', [
                $headers->get('Sender')
                    ->getAddress(),
            ]);
        }
        if (!$headers->has('MIME-Version')) {
            $headers->addTextHeader('MIME-Version', '1.0');
        }
        if (!$headers->has('Date')) {
            $headers->addDateHeader('Date', new \DateTimeImmutable());
        }
        // determine the "real" sender
        if (!$headers->has('Sender') && \count($froms = $headers->get('From')
            ->getAddresses()) > 1) {
            $headers->addMailboxHeader('Sender', $froms[0]);
        }
        if (!$headers->has('Message-ID')) {
            $headers->addIdHeader('Message-ID', $this->generateMessageId());
        }
        // remove the Bcc field which should NOT be part of the sent message
        $headers->remove('Bcc');
        return $headers;
    }
    public function toString() : string {
        if (null === ($body = $this->getBody())) {
            $body = new TextPart('');
        }
        return $this->getPreparedHeaders()
            ->toString() . $body->toString();
    }
    public function toIterable() : iterable {
        if (null === ($body = $this->getBody())) {
            $body = new TextPart('');
        }
        (yield $this->getPreparedHeaders()
            ->toString());
        yield from $body->toIterable();
    }
    public function ensureValidity() : void {
        if (!$this->headers
            ->get('To')?->getBody() && !$this->headers
            ->get('Cc')?->getBody() && !$this->headers
            ->get('Bcc')?->getBody()) {
            throw new LogicException('An email must have a "To", "Cc", or "Bcc" header.');
        }
        if (!$this->headers
            ->get('From')?->getBody() && !$this->headers
            ->get('Sender')?->getBody()) {
            throw new LogicException('An email must have a "From" or a "Sender" header.');
        }
        parent::ensureValidity();
    }
    public function generateMessageId() : string {
        if ($this->headers
            ->has('Sender')) {
            $sender = $this->headers
                ->get('Sender')
                ->getAddress();
        }
        elseif ($this->headers
            ->has('From')) {
            if (!($froms = $this->headers
                ->get('From')
                ->getAddresses())) {
                throw new LogicException('A "From" header must have at least one email address.');
            }
            $sender = $froms[0];
        }
        else {
            throw new LogicException('An email must have a "From" or a "Sender" header.');
        }
        return bin2hex(random_bytes(16)) . strstr($sender->getAddress(), '@');
    }
    public function __serialize() : array {
        return [
            $this->headers,
            $this->body,
        ];
    }
    public function __unserialize(array $data) : void {
        [
            $this->headers,
            $this->body,
        ] = $data;
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
Message::$headers private property
Message::ensureValidity public function Overrides RawMessage::ensureValidity 1
Message::generateMessageId public function
Message::getBody public function 1
Message::getHeaders public function
Message::getPreparedHeaders public function 1
Message::setBody public function
Message::setHeaders public function
Message::toIterable public function Overrides RawMessage::toIterable
Message::toString public function Overrides RawMessage::toString
Message::__clone public function
Message::__construct public function Overrides RawMessage::__construct 1
Message::__serialize public function Overrides RawMessage::__serialize 1
Message::__unserialize public function Overrides RawMessage::__unserialize 1
RawMessage::$isGeneratorClosed private property
RawMessage::__destruct public function
RSS feed
Powered by Drupal