From be50d776d2a72dd2b6143e8f3a0859ee88965382 Mon Sep 17 00:00:00 2001 From: William Ryan Date: Wed, 23 Nov 2022 09:22:31 +0200 Subject: [PATCH] allow nested attachments allow nested attachments in attached emails of email --- src/Fetch/Message.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Fetch/Message.php b/src/Fetch/Message.php index 7faee6d..6d0fa7a 100755 --- a/src/Fetch/Message.php +++ b/src/Fetch/Message.php @@ -573,15 +573,21 @@ protected function processStructure($structure, $partIdentifier = null) } } - if (isset($structure->parts)) { // multipart: iterate through each part + if (! empty($structure->parts)) { - foreach ($structure->parts as $partIndex => $part) { - $partId = $partIndex + 1; + if (isset($structure->subtype) && strtolower($structure->subtype) === 'rfc822') { + // rfc822: The root part is processed with the current part identifier + $this->processStructure($structure->parts[0], $partIdentifier); + } else { + // multipart: iterate through each part + foreach ($structure->parts as $partIndex => $part) { + $partId = $partIndex + 1; - if (isset($partIdentifier)) - $partId = $partIdentifier . '.' . $partId; + if (isset($partIdentifier)) + $partId = $partIdentifier . '.' . $partId; - $this->processStructure($part, $partId); + $this->processStructure($part, $partId); + } } } }