You are here

public static function HTMLMailMime::parse in HTML Mail 8

Same name and namespace in other branches
  1. 8.3 src/Utility/HtmlMailMime.php \Drupal\htmlmail\Utility\HtmlMailMime::parse()

Parse a complete message and return a MailMIME object.

Parameters

string $message: The complete message, including headers and body.

\Drupal\Core\Logger\LoggerChannelFactoryInterface $logger: The logger service.

\Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface $mimeTypeGuesser: The mime type guesser service.

\Drupal\Core\File\FileSystemInterface $fileSystem: The file system service.

Return value

bool|\Drupal\htmlmail\Utility\HTMLMailMime FALSE if an error occured; otherwise a new MailMIME object containing the parsed message and its attachments, if any.

1 call to HTMLMailMime::parse()
HTMLMailSystem::formatMailMime in src/Plugin/Mail/HTMLMailSystem.php
Use the MailMime class to format the message body.

File

src/Utility/HTMLMailMime.php, line 467
Provides the MailMIME class for creating MIME-formatted email messages.

Class

HTMLMailMime
Class HTMLMailMime.

Namespace

Drupal\htmlmail\Utility

Code

public static function &parse($message, LoggerChannelFactoryInterface $logger, MimeTypeGuesserInterface $mimeTypeGuesser, FileSystemInterface $fileSystem) {
  $decoder = new \Mail_mimeDecode($message);
  $decoded = $decoder
    ->decode([
    'decode_headers' => TRUE,
    'decode_bodies' => TRUE,
    'include_bodies' => TRUE,
    'rfc822_bodies' => TRUE,
  ]);
  if (!self::successful($decoded)) {
    return FALSE;
  }
  $parsed = new HTMLMailMime($logger, $mimeTypeGuesser, $fileSystem);
  self::parseDecoded($parsed, $decoded);
  return $parsed;
}