Cleanup message attachments collections

This commit is contained in:
djmaze 2021-12-16 15:54:43 +01:00
parent eb669715ca
commit 94bfe09f63
6 changed files with 28 additions and 34 deletions

View file

@ -23,32 +23,20 @@ class AttachmentCollection extends \MailSo\Base\Collection
parent::append($oAttachment, $bToTop);
}
public function InlineCount() : int
{
$iCount = 0;
foreach ($this as $oAttachment) {
if ($oAttachment && $oAttachment->IsInline()) {
++$iCount;
}
}
return $iCount;
}
public function SpecData() : array
{
$aResult = array();
foreach ($this as $oAttachment) {
$aResult[] = $oAttachment
? array($oAttachment->FileName(true), $oAttachment->MimeType())
: null;
$aResult[] = array(
'@Object' => 'Object/Attachment',
'FileName' => $oAttachment->FileName(true),
'MimeType' => $oAttachment->MimeType(),
'IsInline' => $oAttachment->IsInline()
);
}
return $aResult;
}
public function jsonSerialize()
{
return array_merge(parent::jsonSerialize(), array(
'InlineCount' => $this->InlineCount()
));
return array(
'@Object' => 'Collection/AttachmentCollection',
'@Collection' => $aResult
);
}
}

View file

@ -654,8 +654,7 @@ class Message implements \JsonSerializable
'UnsubsribeLinks' => $this->aUnsubsribeLinks,
'ReadReceipt' => '',
'HasAttachments' => $this->oAttachments && 0 < $this->oAttachments->count(),
'AttachmentsSpecData' => $this->oAttachments ? $this->oAttachments->SpecData() : array(),
'Attachments' => $this->oAttachments ? $this->oAttachments->SpecData() : null,
'Flags' => $this->aFlagsLowerCase
);

View file

@ -202,13 +202,12 @@ trait Response
if ('Message' === $sParent)
{
$oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments();
$bHasExternals = false;
$mFoundCIDs = array();
$aContentLocationUrls = array();
$mFoundContentLocationUrls = array();
$oAttachments = /* @var \MailSo\Mail\AttachmentCollection */ $mResponse->Attachments();
if ($oAttachments && 0 < $oAttachments->count())
{
foreach ($oAttachments as /* @var \MailSo\Mail\Attachment */ $oAttachment)
@ -218,7 +217,7 @@ trait Response
$sContentLocation = $oAttachment->ContentLocation();
if ($sContentLocation && \strlen($sContentLocation))
{
$aContentLocationUrls[] = $oAttachment->ContentLocation();
$aContentLocationUrls[] = $sContentLocation;
}
}
}
@ -273,12 +272,14 @@ trait Response
$mResult['HasExternals'] = $bHasExternals;
$mResult['HasInternals'] = (\is_array($mFoundCIDs) && \count($mFoundCIDs)) ||
(\is_array($mFoundContentLocationUrls) && \count($mFoundContentLocationUrls));
$mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, $aParameters);
/*
// $mResult['FoundCIDs'] = $mFoundCIDs;
$mResult['Attachments'] = $this->responseObject($oAttachments, $sParent, \array_merge($aParameters, array(
'FoundCIDs' => $mFoundCIDs,
'FoundContentLocationUrls' => $mFoundContentLocationUrls
)));
*/
$mResult['ReadReceipt'] = $mResponse->ReadReceipt();
if (\strlen($mResult['ReadReceipt']) && !\in_array('$forwarded', $mResult['Flags']))