You are here

protected static function HtmlMailMime::parseDecoded in HTML Mail 8.3

Same name and namespace in other branches
  1. 8 src/Utility/HTMLMailMime.php \Drupal\htmlmail\Utility\HTMLMailMime::parseDecoded()

Recursively copies message parts into a HtmlMailMime object.

Copies the MIME parts from an object returned by \Mail_mimeDecode->decode() into a HtmlMailMime object, including subparts of any 'multipart' parts.

Parameters

\Drupal\htmlmail\Utility\HtmlMailMime $parsed: The target HtmlMailMime object.

object $decoded: The object returned by \Mail_mimeDecode->decode() whose MIME parts are being copied.

string $parent_subtype: The content-type subtype of the parent multipart MIME part. This should be either 'mixed', 'related', or 'alternative'. Defaults to an empty string, signifying the root of the MIME tree.

1 call to HtmlMailMime::parseDecoded()
HtmlMailMime::parse in src/Utility/HtmlMailMime.php
Parse a complete message and return a HtmlMailMime object.

File

src/Utility/HtmlMailMime.php, line 538

Class

HtmlMailMime
Class HtmlMailMime.

Namespace

Drupal\htmlmail\Utility

Code

protected static function parseDecoded(HtmlMailMime &$parsed, &$decoded, $parent_subtype = '') {
  if ($decoded->ctype_primary == 'multipart') {
    if (!empty($decoded->parts)) {
      foreach (array_keys($decoded->parts) as $key) {
        self::parseDecoded($parsed, $decoded->parts[$key], $decoded->ctype_secondary);
      }
    }
    return;
  }
  if (empty($decoded->body)) {
    return;
  }
  switch ($decoded->ctype_primary) {
    case 'text':
      if ($parent_subtype == '' || $parent_subtype == 'alternative' || $parent_subtype == 'related') {
        if ($decoded->ctype_secondary == 'plain') {
          $parsed
            ->setTxtBody($decoded->body);
          return;
        }
        elseif ($decoded->ctype_secondary == 'html') {
          $parsed
            ->setHtmlBody($decoded->body);
          return;
        }
      }
      break;
    case 'image':
      if ($parent_subtype == 'related') {
        $cid = isset($decoded->headers['content-id']) ? $decoded->headers['content-id'] : NULL;
        return;
      }
      break;
    default:
      $type = $decoded->ctype_primary . '/' . $decoded->ctype_secondary;
      $name = isset($decoded->d_parameters['name']) ? $decoded->d_parameters['name'] : (isset($decoded->d_parameters['filename']) ? $decoded->d_parameters['filename'] : '');
      if (!empty($name) && !empty($cid)) {
        $parsed
          ->addHtmlImage($decoded->body, $type, $name, FALSE, $cid);
        return;
      }
      $parsed
        ->addAttachment($decoded->body, $type, $name, FALSE);
  }
}