Bugfix: application/pgp-encrypted attachments not listed

This commit is contained in:
the-djmaze 2024-08-30 00:39:00 +02:00
parent ed7a2bd239
commit 366ca05200

View file

@ -172,9 +172,10 @@ class BodyStructure implements \JsonSerializable
); );
} }
public function IsAttachment() : bool protected function IsAttachment(/*BodyStructure*/ $oParent) : bool
{ {
return 'application/pgp-encrypted' !== $this->sContentType // return 'application/pgp-encrypted' !== $this->sContentType
return (!$oParent || !$oParent->isPgpEncrypted())
&& ( && (
'attachment' === $this->sDisposition || ( 'attachment' === $this->sDisposition || (
!\str_starts_with($this->sContentType, 'multipart/') !\str_starts_with($this->sContentType, 'multipart/')
@ -194,8 +195,8 @@ class BodyStructure implements \JsonSerializable
{ {
$aParts = []; $aParts = [];
$gParts = $this->SearchByCallback(function ($oItem) { $gParts = $this->SearchByCallback(function ($oItem, $oParent) {
return $oItem->isText() && !$oItem->IsAttachment(); return $oItem->isText() && !$oItem->IsAttachment($oParent);
}); });
foreach ($gParts as $oPart) { foreach ($gParts as $oPart) {
$aParts[] = $oPart; $aParts[] = $oPart;
@ -232,13 +233,13 @@ class BodyStructure implements \JsonSerializable
public function SearchCharset() : string public function SearchCharset() : string
{ {
$gParts = $this->SearchByCallback(function ($oPart) { $gParts = $this->SearchByCallback(function ($oPart, $oParent) {
return $oPart->Charset() && $oPart->isText() && !$oPart->IsAttachment(); return $oPart->Charset() && $oPart->isText() && !$oPart->IsAttachment($oParent);
}); });
if (!$gParts->valid()) { if (!$gParts->valid()) {
$gParts = $this->SearchByCallback(function ($oPart) { $gParts = $this->SearchByCallback(function ($oPart, $oParent) {
return $oPart->Charset() && $oPart->IsAttachment(); return $oPart->Charset() && $oPart->IsAttachment($oParent);
}); });
} }
@ -259,7 +260,7 @@ class BodyStructure implements \JsonSerializable
{ {
return $this->SearchByCallback(function ($oItem, $oParent) { return $this->SearchByCallback(function ($oItem, $oParent) {
// return $oItem->IsAttachment(); // return $oItem->IsAttachment();
return $oItem->IsAttachment() && (!$oParent || !$oParent->isPgpEncrypted()); return $oItem->IsAttachment($oParent) && (!$oParent || !$oParent->isPgpEncrypted());
}); });
} }