mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-03-14 00:36:17 +08:00
Cleanup Collections
This commit is contained in:
parent
7afbc05d18
commit
9218cc4785
6 changed files with 47 additions and 126 deletions
|
@ -34,17 +34,6 @@ class AttachmentCollection extends \MailSo\Base\Collection
|
|||
return $iCount;
|
||||
}
|
||||
|
||||
public function NonInlineCount() : int
|
||||
{
|
||||
$iCount = 0;
|
||||
foreach ($this as $oAttachment) {
|
||||
if ($oAttachment && !$oAttachment->IsInline()) {
|
||||
++$iCount;
|
||||
}
|
||||
}
|
||||
return $iCount;
|
||||
}
|
||||
|
||||
public function SpecData() : array
|
||||
{
|
||||
$aResult = array();
|
||||
|
|
|
@ -678,7 +678,7 @@ class Message implements \JsonSerializable
|
|||
'UnsubsribeLinks' => $this->aUnsubsribeLinks,
|
||||
'ReadReceipt' => '',
|
||||
|
||||
'HasAttachments' => $this->oAttachments && 0 < $this->oAttachments->Count(),
|
||||
'HasAttachments' => $this->oAttachments && 0 < $this->oAttachments->count(),
|
||||
'AttachmentsSpecData' => $this->oAttachments ? $this->oAttachments->SpecData() : array(),
|
||||
|
||||
// Flags
|
||||
|
|
|
@ -20,69 +20,62 @@ class MessageCollection extends \MailSo\Base\Collection
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $FolderHash;
|
||||
public $FolderHash = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $MessageCount;
|
||||
public $MessageCount = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $MessageUnseenCount;
|
||||
public $MessageUnseenCount = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $MessageResultCount;
|
||||
public $MessageResultCount = 0;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $FolderName;
|
||||
public $FolderName = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $Offset;
|
||||
public $Offset = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $Limit;
|
||||
public $Limit = 0;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $Search;
|
||||
public $Search = '';
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $UidNext;
|
||||
public $UidNext = 0;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $ThreadUid;
|
||||
public $ThreadUid = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $NewMessages;
|
||||
public $NewMessages = array();
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $Filtered;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->Clear();
|
||||
}
|
||||
public $Filtered = false;
|
||||
|
||||
public function append($oMessage, bool $bToTop = false) : void
|
||||
{
|
||||
|
@ -92,23 +85,7 @@ class MessageCollection extends \MailSo\Base\Collection
|
|||
|
||||
public function Clear() : void
|
||||
{
|
||||
parent::Clear();
|
||||
|
||||
$this->FolderHash = '';
|
||||
|
||||
$this->MessageCount = 0;
|
||||
$this->MessageUnseenCount = 0;
|
||||
$this->MessageResultCount = 0;
|
||||
|
||||
$this->FolderName = '';
|
||||
$this->Offset = 0;
|
||||
$this->Limit = 0;
|
||||
$this->Search = '';
|
||||
$this->UidNext = 0;
|
||||
$this->ThreadUid = 0;
|
||||
$this->NewMessages = array();
|
||||
|
||||
$this->Filtered = false;
|
||||
throw new \BadMethodCallException('disallowed');
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
|
|
|
@ -22,35 +22,4 @@ class AttachmentCollection extends \MailSo\Base\Collection
|
|||
assert($oAttachment instanceof Attachment);
|
||||
parent::append($oAttachment, $bToTop);
|
||||
}
|
||||
|
||||
public function LinkedAttachments() : array
|
||||
{
|
||||
$aResult = array();
|
||||
foreach ($this as $oAttachment) {
|
||||
if ($oAttachment->IsLinked()) {
|
||||
$aResult[] = $oAttachment;
|
||||
}
|
||||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
public function UnlinkedAttachments() : array
|
||||
{
|
||||
$aResult = array();
|
||||
foreach ($this as $oAttachment) {
|
||||
if (!$oAttachment->IsLinked()) {
|
||||
$aResult[] = $oAttachment;
|
||||
}
|
||||
}
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
public function SizeOfAttachments() : int
|
||||
{
|
||||
$iResult = 0;
|
||||
foreach ($this as $oAttachment) {
|
||||
$iResult += $oAttachment->FileSize();
|
||||
}
|
||||
return $iResult;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -593,68 +593,54 @@ class Message
|
|||
{
|
||||
$oResultPart = null;
|
||||
|
||||
$aAttachments = $this->oAttachmentCollection->LinkedAttachments();
|
||||
if (\count($aAttachments))
|
||||
{
|
||||
$oResultPart = new Part;
|
||||
foreach ($this->oAttachmentCollection as $oAttachment) {
|
||||
if ($oAttachment->IsLinked()) {
|
||||
if (!$oResultPart) {
|
||||
$oResultPart = new Part;
|
||||
$oResultPart->Headers->append(
|
||||
new Header(Enumerations\Header::CONTENT_TYPE,
|
||||
Enumerations\MimeType::MULTIPART_RELATED.'; '.
|
||||
(new ParameterCollection)->Add(
|
||||
new Parameter(
|
||||
Enumerations\Parameter::BOUNDARY,
|
||||
$this->generateNewBoundary())
|
||||
)->ToString()
|
||||
)
|
||||
);
|
||||
$oResultPart->SubParts->append($oIncPart);
|
||||
}
|
||||
|
||||
$oResultPart->Headers->append(
|
||||
new Header(Enumerations\Header::CONTENT_TYPE,
|
||||
Enumerations\MimeType::MULTIPART_RELATED.'; '.
|
||||
(new ParameterCollection)->Add(
|
||||
new Parameter(
|
||||
Enumerations\Parameter::BOUNDARY,
|
||||
$this->generateNewBoundary())
|
||||
)->ToString()
|
||||
)
|
||||
);
|
||||
|
||||
$oResultPart->SubParts->append($oIncPart);
|
||||
|
||||
foreach ($aAttachments as $oAttachment)
|
||||
{
|
||||
$oResultPart->SubParts->append($this->createNewMessageAttachmentBody($oAttachment));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$oResultPart = $oIncPart;
|
||||
}
|
||||
|
||||
return $oResultPart;
|
||||
return $oResultPart ?: $oIncPart;
|
||||
}
|
||||
|
||||
private function createNewMessageMixedBody(Part $oIncPart) : Part
|
||||
{
|
||||
$oResultPart = null;
|
||||
|
||||
$aAttachments = $this->oAttachmentCollection->UnlinkedAttachments();
|
||||
if (\count($aAttachments))
|
||||
{
|
||||
$oResultPart = new Part;
|
||||
foreach ($this->oAttachmentCollection as $oAttachment) {
|
||||
if (!$oAttachment->IsLinked()) {
|
||||
if (!$oResultPart) {
|
||||
$oResultPart = new Part;
|
||||
$oResultPart->Headers->AddByName(Enumerations\Header::CONTENT_TYPE,
|
||||
Enumerations\MimeType::MULTIPART_MIXED.'; '.
|
||||
(new ParameterCollection)->Add(
|
||||
new Parameter(
|
||||
Enumerations\Parameter::BOUNDARY,
|
||||
$this->generateNewBoundary())
|
||||
)->ToString()
|
||||
);
|
||||
$oResultPart->SubParts->append($oIncPart);
|
||||
}
|
||||
|
||||
$oResultPart->Headers->AddByName(Enumerations\Header::CONTENT_TYPE,
|
||||
Enumerations\MimeType::MULTIPART_MIXED.'; '.
|
||||
(new ParameterCollection)->Add(
|
||||
new Parameter(
|
||||
Enumerations\Parameter::BOUNDARY,
|
||||
$this->generateNewBoundary())
|
||||
)->ToString()
|
||||
);
|
||||
|
||||
$oResultPart->SubParts->append($oIncPart);
|
||||
|
||||
foreach ($aAttachments as $oAttachment)
|
||||
{
|
||||
$oResultPart->SubParts->append($this->createNewMessageAttachmentBody($oAttachment));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$oResultPart = $oIncPart;
|
||||
}
|
||||
|
||||
return $oResultPart;
|
||||
return $oResultPart ?: $oIncPart;
|
||||
}
|
||||
|
||||
private function setDefaultHeaders(Part $oIncPart, bool $bWithoutBcc = false) : Part
|
||||
|
|
|
@ -221,7 +221,7 @@ trait Response
|
|||
$aContentLocationUrls = array();
|
||||
$mFoundedContentLocationUrls = array();
|
||||
|
||||
if ($oAttachments && 0 < $oAttachments->Count())
|
||||
if ($oAttachments && 0 < $oAttachments->count())
|
||||
{
|
||||
foreach ($oAttachments as /* @var \MailSo\Mail\Attachment */ $oAttachment)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue