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

Breadcrumb

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

function MessageConverter::toEmail

Throws

RuntimeException when unable to convert the message to an email

1 call to MessageConverter::toEmail()
AbstractApiTransport::doSendHttp in vendor/symfony/mailer/Transport/AbstractApiTransport.php

File

vendor/symfony/mime/MessageConverter.php, line 29

Class

MessageConverter
@author Fabien Potencier <fabien@symfony.com>

Namespace

Symfony\Component\Mime

Code

public static function toEmail(Message $message) : Email {
    if ($message instanceof Email) {
        return $message;
    }
    // try to convert to a "simple" Email instance
    $body = $message->getBody();
    if ($body instanceof TextPart) {
        return self::createEmailFromTextPart($message, $body);
    }
    if ($body instanceof AlternativePart) {
        return self::createEmailFromAlternativePart($message, $body);
    }
    if ($body instanceof RelatedPart) {
        return self::createEmailFromRelatedPart($message, $body);
    }
    if ($body instanceof MixedPart) {
        $parts = $body->getParts();
        if ($parts[0] instanceof RelatedPart) {
            $email = self::createEmailFromRelatedPart($message, $parts[0]);
        }
        elseif ($parts[0] instanceof AlternativePart) {
            $email = self::createEmailFromAlternativePart($message, $parts[0]);
        }
        elseif ($parts[0] instanceof TextPart) {
            $email = self::createEmailFromTextPart($message, $parts[0]);
        }
        else {
            throw new RuntimeException(\sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
        }
        return self::addParts($email, \array_slice($parts, 1));
    }
    throw new RuntimeException(\sprintf('Unable to create an Email from an instance of "%s" as the body is too complex.', get_debug_type($message)));
}

API Navigation

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