protected function AmazonSesHandler::getParts in Amazon SES 2.0.x
Get the plain text and HTML parts of a multipart MIME message.
Parameters
string $message: The message body.
Return value
array|false An array of the part contents, or FALSE if it could not be parsed.
1 call to AmazonSesHandler::getParts()
- AmazonSesHandler::send in src/
AmazonSesHandler.php - Send an email using the AWS SDK.
File
- src/
AmazonSesHandler.php, line 144
Class
- AmazonSesHandler
- Amazon SES service.
Namespace
Drupal\amazon_sesCode
protected function getParts($message) {
$message_parts = [];
// Parse the Content-Type header to find the boundary string.
$content_type_parts = explode(';', $message['headers']['Content-Type']);
foreach ($content_type_parts as $part) {
if (strpos($part, 'boundary') !== FALSE) {
$boundary_parts = explode('=', $part);
$boundary = trim($boundary_parts[1], '"');
}
}
// Exit if no boundary string is found.
if (!$boundary) {
return FALSE;
}
$body_parts = explode($boundary, $message['body']);
foreach ($body_parts as $part) {
if (strpos($part, 'multipart/alternative') !== FALSE) {
$boundary_start = strpos($part, 'boundary') + 10;
if ($boundary_start !== FALSE) {
$boundary_end = strpos($part, '"', $boundary_start);
$boundary_length = $boundary_end - $boundary_start;
$alternative_boundary = substr($part, $boundary_start, $boundary_length);
$alternative_parts = explode($alternative_boundary, $part);
foreach ($alternative_parts as $part) {
if (strpos($part, 'text/plain') !== FALSE) {
$message_parts['plain'] = $this
->getPartContent($part);
}
elseif (strpos($part, 'text/html') !== FALSE) {
$message_parts['html'] = $this
->getPartContent($part);
}
}
}
}
}
return $message_parts;
}