generated from Nodarx/template
refactor: message properties
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -82,36 +82,16 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
}
|
||||
|
||||
if ($message->bodyStructure() !== null) {
|
||||
$this->data[static::PROPERTY_BODY] = $message->bodyStructure()->toArray();
|
||||
$body = $message->bodyStructure()->withInjectedSections($message->bodySections() ?? [])->toArray();
|
||||
$this->data[static::PROPERTY_BODY] = $body;
|
||||
|
||||
$attachments = [];
|
||||
$this->collectAttachments($message->bodyStructure(), $attachments);
|
||||
$this->collectAttachments($body, $attachments);
|
||||
if ($attachments !== []) {
|
||||
$this->data[static::PROPERTY_ATTACHMENTS] = $attachments;
|
||||
}
|
||||
}
|
||||
|
||||
if ($message->bodyStructure() !== null) {
|
||||
$this->data[static::PROPERTY_BODY] = $message->bodyStructure()->toArray();
|
||||
// Recursively add content from bodyValues to matching parts
|
||||
if (is_array($message->bodySections())) {
|
||||
$addContentToParts = function(&$structure, $bodyValues) use (&$addContentToParts) {
|
||||
// If this part has a partId and matching bodyValue, add content
|
||||
if (isset($structure['partId']) && isset($bodyValues[$structure['partId']])) {
|
||||
$structure['content'] = $bodyValues[$structure['partId']] ?? null;
|
||||
}
|
||||
// Recursively process subParts
|
||||
if (isset($structure['subParts']) && is_array($structure['subParts'])) {
|
||||
foreach ($structure['subParts'] as &$subPart) {
|
||||
$addContentToParts($subPart, $bodyValues);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$addContentToParts($this->data[static::PROPERTY_BODY], $message->bodySections());
|
||||
}
|
||||
}
|
||||
|
||||
$this->data[static::PROPERTY_FLAGS] = [];
|
||||
foreach ($message->flags() as $flag) {
|
||||
$flag = ltrim($flag, '\\');
|
||||
@@ -132,9 +112,9 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
/**
|
||||
* Recursively collect attachment parts from body structure
|
||||
*/
|
||||
private function collectAttachments(ClientMessagePart $part, array &$attachments): void
|
||||
private function collectAttachments(array $part, array &$attachments): void
|
||||
{
|
||||
$children = $part->parts();
|
||||
$children = $part['subParts'] ?? [];
|
||||
if ($children !== []) {
|
||||
foreach ($children as $childPart) {
|
||||
$this->collectAttachments($childPart, $attachments);
|
||||
@@ -142,9 +122,9 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
return;
|
||||
}
|
||||
|
||||
$mimeType = strtolower($part->mimeType());
|
||||
$disposition = strtolower($part->disposition() ?? '');
|
||||
$name = $part->parameters()['name'] ?? $part->dispositionParameters()['filename'] ?? null;
|
||||
$mimeType = strtolower((string)($part['type'] ?? ''));
|
||||
$disposition = strtolower((string)($part['disposition'] ?? ''));
|
||||
$name = $part['name'] ?? null;
|
||||
$isInlineText = str_starts_with($mimeType, 'text/')
|
||||
&& in_array($mimeType, ['text/plain', 'text/html'], true)
|
||||
&& $disposition !== 'attachment';
|
||||
@@ -153,7 +133,7 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
return;
|
||||
}
|
||||
|
||||
$attachments[] = $part->toArray();
|
||||
$attachments[] = $part;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user