Cleanup & Speedup *Collection objects

This commit is contained in:
djmaze 2020-03-19 15:21:00 +01:00
parent f6fdb69c65
commit ebfde6e360
12 changed files with 169 additions and 209 deletions

View file

@ -15,7 +15,7 @@ namespace MailSo\Base;
* @category MailSo * @category MailSo
* @package Base * @package Base
*/ */
abstract class Collection extends \ArrayObject /*implements \ArrayAccess, \Traversable, \Countable, \Ds\Collection */ abstract class Collection extends \ArrayObject
{ {
/** /**
* @param mixed $mItem * @param mixed $mItem
@ -37,16 +37,6 @@ abstract class Collection extends \ArrayObject /*implements \ArrayAccess, \Trave
return $this; return $this;
} }
public function AddArray(array $aItems) : self
{
foreach ($aItems as $mItem)
{
$this->append($mItem);
}
return $this;
}
public function Clear() : void public function Clear() : void
{ {
$this->exchangeArray([]); $this->exchangeArray([]);
@ -59,45 +49,11 @@ abstract class Collection extends \ArrayObject /*implements \ArrayAccess, \Trave
); );
} }
public function MapList(callable $cCallback) : array public function Crop(int $length = null, int $offset = 0, bool $preserve_keys = false)
{ {
$aResult = array(); $this->exchangeArray(
if (\is_callable($cCallback)) array_slice($this->getArrayCopy(), $offset, $length, $preserve_keys)
{ );
foreach ($this as $oItem) return $this;
{
$aResult[] = \call_user_func($cCallback, $oItem);
}
}
return $aResult;
}
public function FilterList(callable $cCallback) : array
{
$aResult = array();
if (\is_callable($cCallback))
{
foreach ($this as $oItem)
{
if (\call_user_func($cCallback, $oItem))
{
$aResult[] = $oItem;
}
}
}
return $aResult;
}
public function ForeachList(callable $cCallback) : void
{
if (\is_callable($cCallback))
{
foreach ($this as $oItem)
{
\call_user_func($cCallback, $oItem);
}
}
} }
} }

View file

@ -27,33 +27,41 @@ class AttachmentCollection extends \MailSo\Base\Collection
return new self(); return new self();
} }
public function append(Attachment $oFolder, bool $bToTop = false) : void
{
parent::append($oFolder, $bToTop);
}
public function InlineCount() : int public function InlineCount() : int
{ {
$aList = $this->FilterList(function ($oAttachment) { $iCount = 0;
return $oAttachment && $oAttachment->IsInline(); foreach ($this as $oAttachment) {
}); if ($oAttachment && $oAttachment->IsInline()) {
++$iCount;
return \is_array($aList) ? \count($aList) : 0; }
}
return $iCount;
} }
public function NonInlineCount() : int public function NonInlineCount() : int
{ {
$aList = $this->FilterList(function ($oAttachment) { $iCount = 0;
return $oAttachment && !$oAttachment->IsInline(); foreach ($this as $oAttachment) {
}); if ($oAttachment && !$oAttachment->IsInline()) {
++$iCount;
return \is_array($aList) ? \count($aList) : 0; }
}
return $iCount;
} }
public function SpecData() : array public function SpecData() : array
{ {
return $this->MapList(function ($oAttachment) { $aResult = array();
if ($oAttachment) foreach ($this as $oAttachment) {
{ $aResult[] = $oAttachment
return array($oAttachment->FileName(true), $oAttachment->MimeType()); ? array($oAttachment->FileName(true), $oAttachment->MimeType())
: null;
} }
return $aResult;
return null;
});
} }
} }

View file

@ -155,15 +155,14 @@ class Folder
public function HasVisibleSubFolders() : bool public function HasVisibleSubFolders() : bool
{ {
$sList = array(); if ($this->oSubFolders) {
if ($this->oSubFolders) foreach ($this->oSubFolders as $oFolder) {
{ if ($oFolder->IsSubscribed()) {
$sList = $this->oSubFolders->FilterList(function (\MailSo\Mail\Folder $oFolder) { return true;
return $oFolder->IsSubscribed();
});
} }
}
return 0 < \count($sList); }
return false;
} }
public function IsSubscribed() : bool public function IsSubscribed() : bool

View file

@ -58,10 +58,15 @@ class FolderCollection extends \MailSo\Base\Collection
return new self(); return new self();
} }
public function GetByFullNameRaw(string $sFullNameRaw) : ?\MailSo\Mail\Folder public function append(Folder $oFolder, bool $bToTop = false) : void
{
parent::append($oFolder, $bToTop);
}
public function GetByFullNameRaw(string $sFullNameRaw) : ?Folder
{ {
$mResult = null; $mResult = null;
foreach ($this as /* @var $oFolder \MailSo\Mail\Folder */ $oFolder) foreach ($this as $oFolder)
{ {
if ($oFolder->FullNameRaw() === $sFullNameRaw) if ($oFolder->FullNameRaw() === $sFullNameRaw)
{ {
@ -75,10 +80,6 @@ class FolderCollection extends \MailSo\Base\Collection
{ {
break; break;
} }
else
{
$mResult = null;
}
} }
} }
@ -88,7 +89,7 @@ class FolderCollection extends \MailSo\Base\Collection
public function CountRec() : int public function CountRec() : int
{ {
$iResult = $this->Count(); $iResult = $this->Count();
foreach ($this as /* @var $oFolder \MailSo\Mail\Folder */ $oFolder) foreach ($this as $oFolder)
{ {
if ($oFolder) if ($oFolder)
{ {
@ -135,7 +136,7 @@ class FolderCollection extends \MailSo\Base\Collection
$this->Clear(); $this->Clear();
$aSortedByLenImapFolders = array(); $aSortedByLenImapFolders = array();
foreach ($aUnsortedMailFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ $oMailFolder) foreach ($aUnsortedMailFolders as /* @var $oMailFolder Folder */ $oMailFolder)
{ {
$aSortedByLenImapFolders[$oMailFolder->FullNameRaw()] =& $oMailFolder; $aSortedByLenImapFolders[$oMailFolder->FullNameRaw()] =& $oMailFolder;
unset($oMailFolder); unset($oMailFolder);
@ -143,7 +144,7 @@ class FolderCollection extends \MailSo\Base\Collection
unset($aUnsortedMailFolders); unset($aUnsortedMailFolders);
$aAddedFolders = array(); $aAddedFolders = array();
foreach ($aSortedByLenImapFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ $oMailFolder) foreach ($aSortedByLenImapFolders as /* @var $oMailFolder Folder */ $oMailFolder)
{ {
$sDelimiter = $oMailFolder->Delimiter(); $sDelimiter = $oMailFolder->Delimiter();
$aFolderExplode = \explode($sDelimiter, $oMailFolder->FullNameRaw()); $aFolderExplode = \explode($sDelimiter, $oMailFolder->FullNameRaw());
@ -181,7 +182,7 @@ class FolderCollection extends \MailSo\Base\Collection
return \strnatcmp($oFolderA->FullNameRaw(), $oFolderB->FullNameRaw()); return \strnatcmp($oFolderA->FullNameRaw(), $oFolderB->FullNameRaw());
}); });
foreach ($aSortedByLenImapFolders as /* @var $oMailFolder \MailSo\Mail\Folder */ $oMailFolder) foreach ($aSortedByLenImapFolders as $oMailFolder)
{ {
$this->AddWithPositionSearch($oMailFolder); $this->AddWithPositionSearch($oMailFolder);
unset($oMailFolder); unset($oMailFolder);
@ -190,14 +191,14 @@ class FolderCollection extends \MailSo\Base\Collection
unset($aSortedByLenImapFolders); unset($aSortedByLenImapFolders);
} }
public function AddWithPositionSearch(\MailSo\Mail\Folder $oMailFolder) : bool public function AddWithPositionSearch(Folder $oMailFolder) : bool
{ {
$oItemFolder = null; $oItemFolder = null;
$bIsAdded = false; $bIsAdded = false;
foreach ($this as /* @var $oItemFolder \MailSo\Mail\Folder */ $oItemFolder) foreach ($this as $oItemFolder)
{ {
if ($oMailFolder instanceof \MailSo\Mail\Folder && if ($oMailFolder instanceof Folder &&
0 === \strpos($oMailFolder->FullNameRaw(), $oItemFolder->FullNameRaw().$oItemFolder->Delimiter())) 0 === \strpos($oMailFolder->FullNameRaw(), $oItemFolder->FullNameRaw().$oItemFolder->Delimiter()))
{ {
if ($oItemFolder->SubFolders(true)->AddWithPositionSearch($oMailFolder)) if ($oItemFolder->SubFolders(true)->AddWithPositionSearch($oMailFolder))
@ -209,7 +210,7 @@ class FolderCollection extends \MailSo\Base\Collection
} }
} }
if (!$bIsAdded && $oMailFolder instanceof \MailSo\Mail\Folder) if (!$bIsAdded && $oMailFolder instanceof Folder)
{ {
$bIsAdded = true; $bIsAdded = true;
$this->append($oMailFolder); $this->append($oMailFolder);

View file

@ -1842,8 +1842,7 @@ class MailClient
if ($bUseThreadSortIfSupported && 0 === $iThreadUid && \is_array($mAllThreads) && 0 < \count($mAllThreads)) if ($bUseThreadSortIfSupported && 0 === $iThreadUid && \is_array($mAllThreads) && 0 < \count($mAllThreads))
{ {
$oMessageCollection->ForeachList(function (/* @var $oMessage \MailSo\Mail\Message */ $oMessage) use ($mAllThreads) { foreach ($oMessageCollection as $oMessage) {
$iUid = $oMessage->Uid(); $iUid = $oMessage->Uid();
if (isset($mAllThreads[$iUid]) && \is_array($mAllThreads[$iUid]) && 0 < \count($mAllThreads[$iUid])) if (isset($mAllThreads[$iUid]) && \is_array($mAllThreads[$iUid]) && 0 < \count($mAllThreads[$iUid]))
{ {
@ -1853,7 +1852,7 @@ class MailClient
$oMessage->SetThreads(\array_map('trim', $aSubThreads)); $oMessage->SetThreads(\array_map('trim', $aSubThreads));
unset($aSubThreads); unset($aSubThreads);
} }
}); }
} }
return $oMessageCollection; return $oMessageCollection;

View file

@ -491,7 +491,9 @@ class Message
$this->oCc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::CC, $bCharsetAutoDetect); $this->oCc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::CC, $bCharsetAutoDetect);
$this->oBcc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::BCC, $bCharsetAutoDetect); $this->oBcc = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::BCC, $bCharsetAutoDetect);
if ($this->oFrom) {
$oHeaders->PopulateEmailColectionByDkim($this->oFrom); $oHeaders->PopulateEmailColectionByDkim($this->oFrom);
}
$this->oSender = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::SENDER, $bCharsetAutoDetect); $this->oSender = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::SENDER, $bCharsetAutoDetect);
$this->oReplyTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::REPLY_TO, $bCharsetAutoDetect); $this->oReplyTo = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::REPLY_TO, $bCharsetAutoDetect);
@ -582,15 +584,13 @@ class Message
} }
$sDraftInfo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO); $sDraftInfo = $oHeaders->ValueByName(\MailSo\Mime\Enumerations\Header::X_DRAFT_INFO);
if (0 < \strlen($sDraftInfo)) if (0 < \strlen($sDraftInfo)) {
{
$sType = ''; $sType = '';
$sFolder = ''; $sFolder = '';
$sUid = ''; $sUid = '';
\MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo) $oParameters = \MailSo\Mime\ParameterCollection::NewInstance($sDraftInfo);
->ForeachList(function ($oParameter) use (&$sType, &$sFolder, &$sUid) { foreach ($oParameters as $oParameter) {
switch (\strtolower($oParameter->Name())) switch (\strtolower($oParameter->Name()))
{ {
case 'type': case 'type':
@ -603,11 +603,9 @@ class Message
$sFolder = \base64_decode($oParameter->Value()); $sFolder = \base64_decode($oParameter->Value());
break; break;
} }
}) }
;
if (0 < \strlen($sType) && 0 < \strlen($sFolder) && 0 < \strlen($sUid)) if (0 < \strlen($sType) && 0 < \strlen($sFolder) && 0 < \strlen($sUid)) {
{
$this->aDraftInfo = array($sType, $sUid, $sFolder); $this->aDraftInfo = array($sType, $sUid, $sFolder);
} }
} }

View file

@ -89,6 +89,11 @@ class MessageCollection extends \MailSo\Base\Collection
return new self(); return new self();
} }
public function append(Message $oMessage, bool $bToTop = false) : void
{
parent::append($oMessage, $bToTop);
}
public function Clear() : void public function Clear() : void
{ {
parent::Clear(); parent::Clear();

View file

@ -17,43 +17,49 @@ namespace MailSo\Mime;
*/ */
class AttachmentCollection extends \MailSo\Base\Collection class AttachmentCollection extends \MailSo\Base\Collection
{ {
/**
* @access protected
*/
protected function __construct() protected function __construct()
{ {
parent::__construct(); parent::__construct();
} }
public static function NewInstance() : \MailSo\Mime\AttachmentCollection public static function NewInstance() : self
{ {
return new self(); return new self();
} }
public function append(Attachment $oFolder, bool $bToTop = false) : void
{
parent::append($oFolder, $bToTop);
}
public function LinkedAttachments() : array public function LinkedAttachments() : array
{ {
return $this->FilterList(function ($oItem) { $aResult = array();
return $oItem && $oItem->IsLinked(); foreach ($this as $oAttachment) {
}); if ($oAttachment->IsLinked()) {
$aResult[] = $oAttachment;
}
}
return $aResult;
} }
public function UnlinkedAttachments() : array public function UnlinkedAttachments() : array
{ {
return $this->FilterList(function ($oItem) { $aResult = array();
return $oItem && !$oItem->IsLinked(); foreach ($this as $oAttachment) {
}); if (!$oAttachment->IsLinked()) {
$aResult[] = $oAttachment;
}
}
return $aResult;
} }
public function SizeOfAttachments() : int public function SizeOfAttachments() : int
{ {
$iResult = 0; $iResult = 0;
$this->ForeachList(function ($oItem) use (&$iResult) { foreach ($this as $oAttachment) {
if ($oItem) $iResult += $oAttachment->FileSize();
{
$iResult += $oItem->FileSize();
} }
});
return $iResult; return $iResult;
} }
} }

View file

@ -33,6 +33,11 @@ class EmailCollection extends \MailSo\Base\Collection
return new self($sEmailAddresses); return new self($sEmailAddresses);
} }
public function append(Email $oEmail, bool $bToTop = false) : void
{
parent::append($oEmail, $bToTop);
}
public static function Parse(string $sEmailAddresses) : self public static function Parse(string $sEmailAddresses) : self
{ {
return self::NewInstance($sEmailAddresses); return self::NewInstance($sEmailAddresses);
@ -41,7 +46,7 @@ class EmailCollection extends \MailSo\Base\Collection
public function ToArray() : array public function ToArray() : array
{ {
$aReturn = array(); $aReturn = array();
foreach ($this as /* @var $oEmail \MailSo\Mime\Email */ $oEmail) foreach ($this as $oEmail)
{ {
$aReturn[] = $oEmail->ToArray(); $aReturn[] = $oEmail->ToArray();
} }
@ -51,7 +56,7 @@ class EmailCollection extends \MailSo\Base\Collection
public function MergeWithOtherCollection(EmailCollection $oEmails) : self public function MergeWithOtherCollection(EmailCollection $oEmails) : self
{ {
foreach ($oEmails as /* @var $oEmail \MailSo\Mime\Email */ $oEmail) foreach ($oEmails as $oEmail)
{ {
$this->append($oEmail); $this->append($oEmail);
} }
@ -63,7 +68,7 @@ class EmailCollection extends \MailSo\Base\Collection
{ {
$aReturn = array(); $aReturn = array();
foreach ($this as /* @var $oEmail \MailSo\Mime\Email */ $oEmail) foreach ($this as $oEmail)
{ {
$sEmail = $oEmail->GetEmail(); $sEmail = $oEmail->GetEmail();
if (!isset($aReturn[$sEmail])) if (!isset($aReturn[$sEmail]))
@ -80,7 +85,7 @@ class EmailCollection extends \MailSo\Base\Collection
public function ToString(bool $bConvertSpecialsName = false, bool $bIdn = false) : string public function ToString(bool $bConvertSpecialsName = false, bool $bIdn = false) : string
{ {
$aReturn = array(); $aReturn = array();
foreach ($this as /* @var $oEmail \MailSo\Mime\Email */ $oEmail) foreach ($this as $oEmail)
{ {
$aReturn[] = $oEmail->ToString($bConvertSpecialsName, $bIdn); $aReturn[] = $oEmail->ToString($bConvertSpecialsName, $bIdn);
} }
@ -169,7 +174,7 @@ class EmailCollection extends \MailSo\Base\Collection
try try
{ {
$this->append( $this->append(
\MailSo\Mime\Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iEmailEndPos - $iEmailStartPos)) Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iEmailEndPos - $iEmailStartPos))
); );
$iEmailStartPos = $iCurrentPos + 1; $iEmailStartPos = $iCurrentPos + 1;
@ -189,7 +194,7 @@ class EmailCollection extends \MailSo\Base\Collection
try try
{ {
$this->append( $this->append(
\MailSo\Mime\Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iCurrentPos - $iEmailStartPos)) Email::Parse(\substr($sWorkingRecipients, $iEmailStartPos, $iCurrentPos - $iEmailStartPos))
); );
} }
catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException) {} catch (\MailSo\Base\Exceptions\InvalidArgumentException $oException) {}

View file

@ -18,22 +18,18 @@ namespace MailSo\Mime;
class HeaderCollection extends \MailSo\Base\Collection class HeaderCollection extends \MailSo\Base\Collection
{ {
protected $sRawHeaders; protected $sRawHeaders = '';
/** /**
* @var string * @var string
*/ */
protected $sParentCharset; protected $sParentCharset = '';
protected function __construct(string $sRawHeaders = '', bool $bStoreRawHeaders = true) protected function __construct(string $sRawHeaders = '', bool $bStoreRawHeaders = true)
{ {
parent::__construct(); parent::__construct();
$this->sRawHeaders = ''; if (0 < \strlen($sRawHeaders)) {
$this->sParentCharset = '';
if (0 < \strlen($sRawHeaders))
{
$this->Parse($sRawHeaders, $bStoreRawHeaders); $this->Parse($sRawHeaders, $bStoreRawHeaders);
} }
} }
@ -43,6 +39,11 @@ class HeaderCollection extends \MailSo\Base\Collection
return new self($sRawHeaders, $bStoreRawHeaders); return new self($sRawHeaders, $bStoreRawHeaders);
} }
public function append(Header $oHeader, bool $bToTop = false) : void
{
parent::append($oHeader, $bToTop);
}
public function AddByName(string $sName, string $sValue, bool $bToTop = false) : self public function AddByName(string $sName, string $sValue, bool $bToTop = false) : self
{ {
$this->append(Header::NewInstance($sName, $sValue), $bToTop); $this->append(Header::NewInstance($sName, $sValue), $bToTop);
@ -63,16 +64,12 @@ class HeaderCollection extends \MailSo\Base\Collection
public function ValuesByName(string $sHeaderName, bool $bCharsetAutoDetect = false) : array public function ValuesByName(string $sHeaderName, bool $bCharsetAutoDetect = false) : array
{ {
$aResult = array(); $aResult = array();
$sHeaderNameLower = \strtolower($sHeaderName); $sHeaderNameLower = \strtolower($sHeaderName);
foreach ($this as /* @var $oHeader \MailSo\Mime\Header */ $oHeader) foreach ($this as $oHeader) {
{ if ($sHeaderNameLower === \strtolower($oHeader->Name())) {
if ($sHeaderNameLower === \strtolower($oHeader->Name()))
{
$aResult[] = $bCharsetAutoDetect ? $oHeader->ValueWithCharsetAutoDetect() : $oHeader->Value(); $aResult[] = $bCharsetAutoDetect ? $oHeader->ValueWithCharsetAutoDetect() : $oHeader->Value();
} }
} }
return $aResult; return $aResult;
} }
@ -85,19 +82,17 @@ class HeaderCollection extends \MailSo\Base\Collection
return $this; return $this;
} }
public function GetAsEmailCollection(string $sHeaderName, bool $bCharsetAutoDetect = false) : ?\MailSo\Mime\EmailCollection public function GetAsEmailCollection(string $sHeaderName, bool $bCharsetAutoDetect = false) : ?EmailCollection
{ {
$oResult = null; $oResult = null;
$sValue = $this->ValueByName($sHeaderName, $bCharsetAutoDetect); $sValue = $this->ValueByName($sHeaderName, $bCharsetAutoDetect);
if (0 < \strlen($sValue)) if (0 < \strlen($sValue)) {
{ $oResult = EmailCollection::NewInstance($sValue);
$oResult = \MailSo\Mime\EmailCollection::NewInstance($sValue);
} }
return $oResult && 0 < $oResult->Count() ? $oResult : null; return $oResult && 0 < $oResult->Count() ? $oResult : null;
} }
public function ParametersByName(string $sHeaderName) : ?\MailSo\Mime\ParameterCollection public function ParametersByName(string $sHeaderName) : ?ParameterCollection
{ {
$oHeader = $this->GetByName($sHeaderName); $oHeader = $this->GetByName($sHeaderName);
return $oHeader ? $oHeader->Parameters() : null; return $oHeader ? $oHeader->Parameters() : null;
@ -109,35 +104,27 @@ class HeaderCollection extends \MailSo\Base\Collection
return (null !== $oParameters) ? $oParameters->ParameterValueByName($sParamName) : ''; return (null !== $oParameters) ? $oParameters->ParameterValueByName($sParamName) : '';
} }
public function GetByName(string $sHeaderName) : ?\MailSo\Mime\Header public function GetByName(string $sHeaderName) : ?Header
{ {
$sHeaderNameLower = \strtolower($sHeaderName); $sHeaderNameLower = \strtolower($sHeaderName);
foreach ($this as /* @var $oHeader \MailSo\Mime\Header */ $oHeader) foreach ($this as $oHeader) {
{ if ($sHeaderNameLower === \strtolower($oHeader->Name())) {
if ($sHeaderNameLower === \strtolower($oHeader->Name()))
{
return $oHeader; return $oHeader;
} }
} }
return null; return null;
} }
public function SetParentCharset(string $sParentCharset) : self public function SetParentCharset(string $sParentCharset) : self
{ {
if (0 < \strlen($sParentCharset)) if (0 < \strlen($sParentCharset)){
{ if ($this->sParentCharset !== $sParentCharset) {
if ($this->sParentCharset !== $sParentCharset) foreach ($this as $oHeader) {
{
foreach ($this as /* @var $oHeader \MailSo\Mime\Header */ $oHeader)
{
$oHeader->SetParentCharset($sParentCharset); $oHeader->SetParentCharset($sParentCharset);
} }
$this->sParentCharset = $sParentCharset; $this->sParentCharset = $sParentCharset;
} }
} }
return $this; return $this;
} }
@ -151,13 +138,11 @@ class HeaderCollection extends \MailSo\Base\Collection
{ {
$this->Clear(); $this->Clear();
if ($bStoreRawHeaders) if ($bStoreRawHeaders) {
{
$this->sRawHeaders = $sRawHeaders; $this->sRawHeaders = $sRawHeaders;
} }
if (0 === \strlen($this->sParentCharset)) if (0 === \strlen($this->sParentCharset)) {
{
$this->sParentCharset = $sParentCharset; $this->sParentCharset = $sParentCharset;
} }
@ -165,10 +150,8 @@ class HeaderCollection extends \MailSo\Base\Collection
$sName = null; $sName = null;
$sValue = null; $sValue = null;
foreach ($aHeaders as $sHeadersValue) foreach ($aHeaders as $sHeadersValue) {
{ if (0 === strlen($sHeadersValue)) {
if (0 === strlen($sHeadersValue))
{
continue; continue;
} }
@ -241,7 +224,7 @@ class HeaderCollection extends \MailSo\Base\Collection
{ {
$aResult = array(); $aResult = array();
$aHeaders = $this->ValuesByName(\MailSo\Mime\Enumerations\Header::AUTHENTICATION_RESULTS); $aHeaders = $this->ValuesByName(Enumerations\Header::AUTHENTICATION_RESULTS);
if (\is_array($aHeaders) && 0 < \count($aHeaders)) if (\is_array($aHeaders) && 0 < \count($aHeaders))
{ {
foreach ($aHeaders as $sHeaderValue) foreach ($aHeaders as $sHeaderValue)
@ -280,7 +263,7 @@ class HeaderCollection extends \MailSo\Base\Collection
else else
{ {
// X-DKIM-Authentication-Results: signer="hostinger.com" status="pass" // X-DKIM-Authentication-Results: signer="hostinger.com" status="pass"
$aHeaders = $this->ValuesByName(\MailSo\Mime\Enumerations\Header::X_DKIM_AUTHENTICATION_RESULTS); $aHeaders = $this->ValuesByName(Enumerations\Header::X_DKIM_AUTHENTICATION_RESULTS);
if (\is_array($aHeaders) && 0 < \count($aHeaders)) if (\is_array($aHeaders) && 0 < \count($aHeaders))
{ {
foreach ($aHeaders as $sHeaderValue) foreach ($aHeaders as $sHeaderValue)
@ -313,39 +296,29 @@ class HeaderCollection extends \MailSo\Base\Collection
return $aResult; return $aResult;
} }
public function PopulateEmailColectionByDkim($oEmails) : void public function PopulateEmailColectionByDkim(EmailCollection $oEmails) : void
{
if ($oEmails && $oEmails instanceof \MailSo\Mime\EmailCollection)
{ {
$aDkimStatuses = $this->DkimStatuses(); $aDkimStatuses = $this->DkimStatuses();
if (\is_array($aDkimStatuses) && 0 < \count($aDkimStatuses)) if (\is_array($aDkimStatuses) && 0 < \count($aDkimStatuses)) {
{ foreach ($oEmails as $oEmail) {
$oEmails->ForeachList(function (/* @var $oItem \MailSo\Mime\Email */ $oItem) use ($aDkimStatuses) { $sEmail = $oEmail->GetEmail();
if ($oItem && $oItem instanceof \MailSo\Mime\Email) foreach ($aDkimStatuses as $aDkimData) {
{
$sEmail = $oItem->GetEmail();
foreach ($aDkimStatuses as $aDkimData)
{
if (isset($aDkimData[0], $aDkimData[1]) && if (isset($aDkimData[0], $aDkimData[1]) &&
$aDkimData[1] === \strstr($sEmail, $aDkimData[1])) $aDkimData[1] === \strstr($sEmail, $aDkimData[1]))
{ {
$oItem->SetDkimStatusAndValue($aDkimData[0], empty($aDkimData[2]) ? '' : $aDkimData[2]); $oEmail->SetDkimStatusAndValue($aDkimData[0], empty($aDkimData[2]) ? '' : $aDkimData[2]);
} }
} }
} }
});
}
} }
} }
public function ToEncodedString() : string public function ToEncodedString() : string
{ {
$aResult = array(); $aResult = array();
foreach ($this as /* @var $oHeader \MailSo\Mime\Header */ $oHeader) foreach ($this as $oHeader) {
{
$aResult[] = $oHeader->EncodedValue(); $aResult[] = $oHeader->EncodedValue();
} }
return \implode(Enumerations\Constants::CRLF, $aResult);
return \implode(\MailSo\Mime\Enumerations\Constants::CRLF, $aResult);
} }
} }

View file

@ -32,11 +32,16 @@ class ParameterCollection extends \MailSo\Base\Collection
return new self($sRawParams); return new self($sRawParams);
} }
public function append(Parameter $oHeader, bool $bToTop = false) : void
{
parent::append($oHeader, $bToTop);
}
public function ParameterValueByName(string $sName) : string public function ParameterValueByName(string $sName) : string
{ {
$sName = \strtolower(\trim($sName)); $sName = \strtolower(\trim($sName));
foreach ($this as /* @var $oParam \MailSo\Mime\ParameterCollection */ $oParam) foreach ($this as $oParam)
{ {
if ($sName === \strtolower($oParam->Name())) if ($sName === \strtolower($oParam->Name()))
{ {
@ -66,7 +71,7 @@ class ParameterCollection extends \MailSo\Base\Collection
public function ToString(bool $bConvertSpecialsName = false) : string public function ToString(bool $bConvertSpecialsName = false) : string
{ {
$aResult = array(); $aResult = array();
foreach ($this as /* @var $oParam \MailSo\Mime\Parameter */ $oParam) foreach ($this as $oParam)
{ {
$sLine = $oParam->ToString($bConvertSpecialsName); $sLine = $oParam->ToString($bConvertSpecialsName);
if (0 < \strlen($sLine)) if (0 < \strlen($sLine))
@ -86,7 +91,7 @@ class ParameterCollection extends \MailSo\Base\Collection
$this->Clear(); $this->Clear();
$aPreParams = array(); $aPreParams = array();
foreach ($aDataToReParse as /* @var $oParam \MailSo\Mime\Parameter */ $oParam) foreach ($aDataToReParse as $oParam)
{ {
$aMatch = array(); $aMatch = array();
$sParamName = $oParam->Name(); $sParamName = $oParam->Name();

View file

@ -27,6 +27,11 @@ class PartCollection extends \MailSo\Base\Collection
return new self(); return new self();
} }
public function append(Part $oPart, bool $bToTop = false) : void
{
parent::append($oPart, $bToTop);
}
/** /**
* @return resource * @return resource
*/ */
@ -37,12 +42,12 @@ class PartCollection extends \MailSo\Base\Collection
{ {
$aResult = array(); $aResult = array();
foreach ($this as /* @var $oPart \MailSo\Mime\Part */ $oPart) foreach ($this as $oPart)
{ {
if (0 < count($aResult)) if (0 < count($aResult))
{ {
$aResult[] = \MailSo\Mime\Enumerations\Constants::CRLF. $aResult[] = Enumerations\Constants::CRLF.
'--'.$sBoundary.\MailSo\Mime\Enumerations\Constants::CRLF; '--'.$sBoundary.Enumerations\Constants::CRLF;
} }
$aResult[] = $oPart->ToStream(); $aResult[] = $oPart->ToStream();