$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)));
} private static function createEmailFromTextPart(Message
$message, TextPart
$part): Email
{ if ('text' ===
$part->
getMediaType() && 'plain' ===
$part->
getMediaSubtype()) { return (new Email(clone $message->
getHeaders()))->
text($part->
getBody(),
$part->
getPreparedHeaders()->
getHeaderParameter('Content-Type', 'charset'
) ?: 'utf-8'
);
} if ('text' ===
$part->
getMediaType() && 'html' ===
$part->
getMediaSubtype()) {