Privacy/GDPR friendly version (removed: Social, Gravatar, Facebook, Google, Twitter, DropBox, OwnCloud)

Also removed: POP3, OAuth2 and update feature
Added: admin password_hash/password_verify
Requires: PHP 7.3+
Replaced: CRLF with LF
Replaced: pclZip with ZipArchive
This commit is contained in:
djmaze 2020-03-09 17:04:17 +01:00
parent 15ceddc202
commit 2cada68f41
293 changed files with 23728 additions and 85420 deletions

View file

@ -1,197 +1,197 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @category MailSo
* @package Mime
*/
class Attachment
{
/**
* @var resource
*/
private $rResource;
/**
* @var string
*/
private $sFileName;
/**
* @var int
*/
private $iFileSize;
/**
* @var string
*/
private $sCID;
/**
* @var bool
*/
private $bIsInline;
/**
* @var bool
*/
private $bIsLinked;
/**
* @var array
*/
private $aCustomContentTypeParams;
/**
* @var string
*/
private $sContentLocation;
/**
* @access private
*/
private function __construct($rResource, $sFileName, $iFileSize, $bIsInline, $bIsLinked, $sCID,
$aCustomContentTypeParams = array(), $sContentLocation = '')
{
$this->rResource = $rResource;
$this->sFileName = $sFileName;
$this->iFileSize = $iFileSize;
$this->bIsInline = $bIsInline;
$this->bIsLinked = $bIsLinked;
$this->sCID = $sCID;
$this->aCustomContentTypeParams = $aCustomContentTypeParams;
$this->sContentLocation = $sContentLocation;
}
/**
* @param resource $rResource
* @param string $sFileName = ''
* @param int $iFileSize = 0
* @param bool $bIsInline = false
* @param bool $bIsLinked = false
* @param string $sCID = ''
* @param array $aCustomContentTypeParams = array()
* @param string $sContentLocation = ''
*
* @return \MailSo\Mime\Attachment
*/
public static function NewInstance($rResource, $sFileName = '', $iFileSize = 0, $bIsInline = false,
$bIsLinked = false, $sCID = '', $aCustomContentTypeParams = array(), $sContentLocation = '')
{
return new self($rResource, $sFileName, $iFileSize, $bIsInline, $bIsLinked, $sCID, $aCustomContentTypeParams, $sContentLocation);
}
/**
* @return resource
*/
public function Resource()
{
return $this->rResource;
}
/**
* @return string
*/
public function ContentType()
{
return \MailSo\Base\Utils::MimeContentType($this->sFileName);
}
/**
* @return array
*/
public function CustomContentTypeParams()
{
return $this->aCustomContentTypeParams;
}
/**
* @return string
*/
public function CID()
{
return $this->sCID;
}
/**
* @return string
*/
public function ContentLocation()
{
return $this->sContentLocation;
}
/**
* @return string
*/
public function FileName()
{
return $this->sFileName;
}
/**
* @return int
*/
public function FileSize()
{
return $this->iFileSize;
}
/**
* @return bool
*/
public function IsInline()
{
return $this->bIsInline;
}
/**
* @return bool
*/
public function IsImage()
{
return 'image' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}
/**
* @return bool
*/
public function IsArchive()
{
return 'archive' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}
/**
* @return bool
*/
public function IsPdf()
{
return 'pdf' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}
/**
* @return bool
*/
public function IsDoc()
{
return 'doc' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}
/**
* @return bool
*/
public function IsLinked()
{
return $this->bIsLinked && 0 < \strlen($this->sCID);
}
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @category MailSo
* @package Mime
*/
class Attachment
{
/**
* @var resource
*/
private $rResource;
/**
* @var string
*/
private $sFileName;
/**
* @var int
*/
private $iFileSize;
/**
* @var string
*/
private $sCID;
/**
* @var bool
*/
private $bIsInline;
/**
* @var bool
*/
private $bIsLinked;
/**
* @var array
*/
private $aCustomContentTypeParams;
/**
* @var string
*/
private $sContentLocation;
/**
* @access private
*/
private function __construct($rResource, $sFileName, $iFileSize, $bIsInline, $bIsLinked, $sCID,
$aCustomContentTypeParams = array(), $sContentLocation = '')
{
$this->rResource = $rResource;
$this->sFileName = $sFileName;
$this->iFileSize = $iFileSize;
$this->bIsInline = $bIsInline;
$this->bIsLinked = $bIsLinked;
$this->sCID = $sCID;
$this->aCustomContentTypeParams = $aCustomContentTypeParams;
$this->sContentLocation = $sContentLocation;
}
/**
* @param resource $rResource
* @param string $sFileName = ''
* @param int $iFileSize = 0
* @param bool $bIsInline = false
* @param bool $bIsLinked = false
* @param string $sCID = ''
* @param array $aCustomContentTypeParams = array()
* @param string $sContentLocation = ''
*
* @return \MailSo\Mime\Attachment
*/
public static function NewInstance($rResource, $sFileName = '', $iFileSize = 0, $bIsInline = false,
$bIsLinked = false, $sCID = '', $aCustomContentTypeParams = array(), $sContentLocation = '')
{
return new self($rResource, $sFileName, $iFileSize, $bIsInline, $bIsLinked, $sCID, $aCustomContentTypeParams, $sContentLocation);
}
/**
* @return resource
*/
public function Resource()
{
return $this->rResource;
}
/**
* @return string
*/
public function ContentType()
{
return \MailSo\Base\Utils::MimeContentType($this->sFileName);
}
/**
* @return array
*/
public function CustomContentTypeParams()
{
return $this->aCustomContentTypeParams;
}
/**
* @return string
*/
public function CID()
{
return $this->sCID;
}
/**
* @return string
*/
public function ContentLocation()
{
return $this->sContentLocation;
}
/**
* @return string
*/
public function FileName()
{
return $this->sFileName;
}
/**
* @return int
*/
public function FileSize()
{
return $this->iFileSize;
}
/**
* @return bool
*/
public function IsInline()
{
return $this->bIsInline;
}
/**
* @return bool
*/
public function IsImage()
{
return 'image' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}
/**
* @return bool
*/
public function IsArchive()
{
return 'archive' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}
/**
* @return bool
*/
public function IsPdf()
{
return 'pdf' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}
/**
* @return bool
*/
public function IsDoc()
{
return 'doc' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}
/**
* @return bool
*/
public function IsLinked()
{
return $this->bIsLinked && 0 < \strlen($this->sCID);
}
}

View file

@ -1,315 +1,315 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @category MailSo
* @package Mime
*/
class Email
{
/**
* @var string
*/
private $sDisplayName;
/**
* @var string
*/
private $sEmail;
/**
* @var string
*/
private $sDkimStatus;
/**
* @var string
*/
private $sDkimValue;
/**
* @access private
*
* @param string $sEmail
* @param string $sDisplayName = ''
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct($sEmail, $sDisplayName = '')
{
if (!\MailSo\Base\Validator::NotEmptyString($sEmail, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sEmail), true);
$this->sDisplayName = \MailSo\Base\Utils::Trim($sDisplayName);
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
$this->sDkimValue = '';
}
/**
* @param string $sEmail
* @param string $sDisplayName = ''
*
* @return \MailSo\Mime\Email
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance($sEmail, $sDisplayName = '')
{
return new self($sEmail, $sDisplayName);
}
/**
* @param string $sEmailAddress
* @return \MailSo\Mime\Email
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function Parse($sEmailAddress)
{
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$sName = '';
$sEmail = '';
$sComment = '';
$bInName = false;
$bInAddress = false;
$bInComment = false;
$iStartIndex = 0;
$iEndIndex = 0;
$iCurrentIndex = 0;
while ($iCurrentIndex < \strlen($sEmailAddress))
{
switch ($sEmailAddress{$iCurrentIndex})
{
// case '\'':
case '"':
// $sQuoteChar = $sEmailAddress{$iCurrentIndex};
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInName = true;
$iStartIndex = $iCurrentIndex;
}
else if ((!$bInAddress) && (!$bInComment))
{
$iEndIndex = $iCurrentIndex;
$sName = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInName = false;
}
break;
case '<':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
if ($iCurrentIndex > 0 && \strlen($sName) === 0)
{
$sName = \substr($sEmailAddress, 0, $iCurrentIndex);
}
$bInAddress = true;
$iStartIndex = $iCurrentIndex;
}
break;
case '>':
if ($bInAddress)
{
$iEndIndex = $iCurrentIndex;
$sEmail = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInAddress = false;
}
break;
case '(':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInComment = true;
$iStartIndex = $iCurrentIndex;
}
break;
case ')':
if ($bInComment)
{
$iEndIndex = $iCurrentIndex;
$sComment = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInComment = false;
}
break;
case '\\':
$iCurrentIndex++;
break;
}
$iCurrentIndex++;
}
if (\strlen($sEmail) === 0)
{
$aRegs = array('');
if (\preg_match('/[^@\s]+@\S+/i', $sEmailAddress, $aRegs) && isset($aRegs[0]))
{
$sEmail = $aRegs[0];
}
else
{
$sName = $sEmailAddress;
}
}
if ((\strlen($sEmail) > 0) && (\strlen($sName) == 0) && (\strlen($sComment) == 0))
{
$sName = \str_replace($sEmail, '', $sEmailAddress);
}
$sEmail = \trim(\trim($sEmail), '<>');
$sEmail = \rtrim(\trim($sEmail), '.');
$sEmail = \trim($sEmail);
$sName = \trim(\trim($sName), '"');
$sName = \trim($sName, '\'');
$sComment = \trim(\trim($sComment), '()');
// Remove backslash
$sName = \preg_replace('/\\\\(.)/s', '$1', $sName);
$sComment = \preg_replace('/\\\\(.)/s', '$1', $sComment);
return Email::NewInstance($sEmail, $sName);
}
/**
* @param bool $bIdn = false
*
* @return string
*/
public function GetEmail($bIdn = false)
{
return $bIdn ? \MailSo\Base\Utils::IdnToUtf8($this->sEmail) : $this->sEmail;
}
/**
* @return string
*/
public function GetDisplayName()
{
return $this->sDisplayName;
}
/**
* @return string
*/
public function GetDkimStatus()
{
return $this->sDkimStatus;
}
/**
* @return string
*/
public function GetDkimValue()
{
return $this->sDkimValue;
}
/**
* @return string
*/
public function GetAccountName()
{
return \MailSo\Base\Utils::GetAccountNameFromEmail($this->GetEmail(false));
}
/**
* @param bool $bIdn = false
*
* @return string
*/
public function GetDomain($bIdn = false)
{
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
}
/**
* @param string $sDkimStatus
* @param string $sDkimValue = ''
*/
public function SetDkimStatusAndValue($sDkimStatus, $sDkimValue = '')
{
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
$this->sDkimValue = $sDkimValue;
}
/**
* @param bool $bIdn = false
* @param bool $bDkim = true
*
* @return array
*/
public function ToArray($bIdn = false, $bDkim = true)
{
return $bDkim ?
array($this->sDisplayName, $this->GetEmail($bIdn), $this->sDkimStatus, $this->sDkimValue) :
array($this->sDisplayName, $this->GetEmail($bIdn));
}
/**
* @param bool $bConvertSpecialsName = false
* @param bool $bIdn = false
*
* @return string
*/
public function ToString($bConvertSpecialsName = false, $bIdn = false)
{
$sReturn = '';
$sDisplayName = \str_replace('"', '\"', $this->sDisplayName);
if ($bConvertSpecialsName)
{
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
$sDisplayName);
}
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : '"'.$sDisplayName.'"';
if (0 < \strlen($this->sEmail))
{
$sReturn = $this->GetEmail($bIdn);
if (0 < \strlen($sDisplayName))
{
$sReturn = $sDisplayName.' <'.$sReturn.'>';
}
}
return \trim($sReturn);
}
}
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @category MailSo
* @package Mime
*/
class Email
{
/**
* @var string
*/
private $sDisplayName;
/**
* @var string
*/
private $sEmail;
/**
* @var string
*/
private $sDkimStatus;
/**
* @var string
*/
private $sDkimValue;
/**
* @access private
*
* @param string $sEmail
* @param string $sDisplayName = ''
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct($sEmail, $sDisplayName = '')
{
if (!\MailSo\Base\Validator::NotEmptyString($sEmail, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sEmail), true);
$this->sDisplayName = \MailSo\Base\Utils::Trim($sDisplayName);
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
$this->sDkimValue = '';
}
/**
* @param string $sEmail
* @param string $sDisplayName = ''
*
* @return \MailSo\Mime\Email
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance($sEmail, $sDisplayName = '')
{
return new self($sEmail, $sDisplayName);
}
/**
* @param string $sEmailAddress
* @return \MailSo\Mime\Email
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function Parse($sEmailAddress)
{
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$sName = '';
$sEmail = '';
$sComment = '';
$bInName = false;
$bInAddress = false;
$bInComment = false;
$iStartIndex = 0;
$iEndIndex = 0;
$iCurrentIndex = 0;
while ($iCurrentIndex < \strlen($sEmailAddress))
{
switch ($sEmailAddress{$iCurrentIndex})
{
// case '\'':
case '"':
// $sQuoteChar = $sEmailAddress{$iCurrentIndex};
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInName = true;
$iStartIndex = $iCurrentIndex;
}
else if ((!$bInAddress) && (!$bInComment))
{
$iEndIndex = $iCurrentIndex;
$sName = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInName = false;
}
break;
case '<':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
if ($iCurrentIndex > 0 && \strlen($sName) === 0)
{
$sName = \substr($sEmailAddress, 0, $iCurrentIndex);
}
$bInAddress = true;
$iStartIndex = $iCurrentIndex;
}
break;
case '>':
if ($bInAddress)
{
$iEndIndex = $iCurrentIndex;
$sEmail = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInAddress = false;
}
break;
case '(':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInComment = true;
$iStartIndex = $iCurrentIndex;
}
break;
case ')':
if ($bInComment)
{
$iEndIndex = $iCurrentIndex;
$sComment = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInComment = false;
}
break;
case '\\':
$iCurrentIndex++;
break;
}
$iCurrentIndex++;
}
if (\strlen($sEmail) === 0)
{
$aRegs = array('');
if (\preg_match('/[^@\s]+@\S+/i', $sEmailAddress, $aRegs) && isset($aRegs[0]))
{
$sEmail = $aRegs[0];
}
else
{
$sName = $sEmailAddress;
}
}
if ((\strlen($sEmail) > 0) && (\strlen($sName) == 0) && (\strlen($sComment) == 0))
{
$sName = \str_replace($sEmail, '', $sEmailAddress);
}
$sEmail = \trim(\trim($sEmail), '<>');
$sEmail = \rtrim(\trim($sEmail), '.');
$sEmail = \trim($sEmail);
$sName = \trim(\trim($sName), '"');
$sName = \trim($sName, '\'');
$sComment = \trim(\trim($sComment), '()');
// Remove backslash
$sName = \preg_replace('/\\\\(.)/s', '$1', $sName);
$sComment = \preg_replace('/\\\\(.)/s', '$1', $sComment);
return Email::NewInstance($sEmail, $sName);
}
/**
* @param bool $bIdn = false
*
* @return string
*/
public function GetEmail($bIdn = false)
{
return $bIdn ? \MailSo\Base\Utils::IdnToUtf8($this->sEmail) : $this->sEmail;
}
/**
* @return string
*/
public function GetDisplayName()
{
return $this->sDisplayName;
}
/**
* @return string
*/
public function GetDkimStatus()
{
return $this->sDkimStatus;
}
/**
* @return string
*/
public function GetDkimValue()
{
return $this->sDkimValue;
}
/**
* @return string
*/
public function GetAccountName()
{
return \MailSo\Base\Utils::GetAccountNameFromEmail($this->GetEmail(false));
}
/**
* @param bool $bIdn = false
*
* @return string
*/
public function GetDomain($bIdn = false)
{
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
}
/**
* @param string $sDkimStatus
* @param string $sDkimValue = ''
*/
public function SetDkimStatusAndValue($sDkimStatus, $sDkimValue = '')
{
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
$this->sDkimValue = $sDkimValue;
}
/**
* @param bool $bIdn = false
* @param bool $bDkim = true
*
* @return array
*/
public function ToArray($bIdn = false, $bDkim = true)
{
return $bDkim ?
array($this->sDisplayName, $this->GetEmail($bIdn), $this->sDkimStatus, $this->sDkimValue) :
array($this->sDisplayName, $this->GetEmail($bIdn));
}
/**
* @param bool $bConvertSpecialsName = false
* @param bool $bIdn = false
*
* @return string
*/
public function ToString($bConvertSpecialsName = false, $bIdn = false)
{
$sReturn = '';
$sDisplayName = \str_replace('"', '\"', $this->sDisplayName);
if ($bConvertSpecialsName)
{
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
$sDisplayName);
}
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : '"'.$sDisplayName.'"';
if (0 < \strlen($this->sEmail))
{
$sReturn = $this->GetEmail($bIdn);
if (0 < \strlen($sDisplayName))
{
$sReturn = $sDisplayName.' <'.$sReturn.'>';
}
}
return \trim($sReturn);
}
}

View file

@ -1,339 +1,339 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @deprecated
* @category MailSo
* @package Mime
*/
class EmailDep
{
/**
* @var string
*/
private $sDisplayName;
/**
* @var string
*/
private $sEmail;
/**
* @var string
*/
private $sRemark;
/**
* @var string
*/
private $sDkimStatus;
/**
* @var string
*/
private $sDkimValue;
/**
* @access private
*
* @param string $sEmail
* @param string $sDisplayName = ''
* @param string $sRemark = ''
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct($sEmail, $sDisplayName = '', $sRemark = '')
{
if (!\MailSo\Base\Validator::NotEmptyString($sEmail, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sEmail), true);
$this->sDisplayName = \MailSo\Base\Utils::Trim($sDisplayName);
$this->sRemark = \MailSo\Base\Utils::Trim($sRemark);
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
$this->sDkimValue = '';
}
/**
* @param string $sEmail
* @param string $sDisplayName = ''
* @param string $sRemark = ''
*
* @return \MailSo\Mime\Email
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance($sEmail, $sDisplayName = '', $sRemark = '')
{
return new self($sEmail, $sDisplayName, $sRemark);
}
/**
* @param string $sEmailAddress
* @return \MailSo\Mime\Email
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function Parse($sEmailAddress)
{
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$sName = '';
$sEmail = '';
$sComment = '';
$bInName = false;
$bInAddress = false;
$bInComment = false;
$iStartIndex = 0;
$iEndIndex = 0;
$iCurrentIndex = 0;
while ($iCurrentIndex < \strlen($sEmailAddress))
{
switch ($sEmailAddress{$iCurrentIndex})
{
// case '\'':
case '"':
// $sQuoteChar = $sEmailAddress{$iCurrentIndex};
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInName = true;
$iStartIndex = $iCurrentIndex;
}
else if ((!$bInAddress) && (!$bInComment))
{
$iEndIndex = $iCurrentIndex;
$sName = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInName = false;
}
break;
case '<':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
if ($iCurrentIndex > 0 && \strlen($sName) === 0)
{
$sName = \substr($sEmailAddress, 0, $iCurrentIndex);
}
$bInAddress = true;
$iStartIndex = $iCurrentIndex;
}
break;
case '>':
if ($bInAddress)
{
$iEndIndex = $iCurrentIndex;
$sEmail = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInAddress = false;
}
break;
case '(':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInComment = true;
$iStartIndex = $iCurrentIndex;
}
break;
case ')':
if ($bInComment)
{
$iEndIndex = $iCurrentIndex;
$sComment = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInComment = false;
}
break;
case '\\':
$iCurrentIndex++;
break;
}
$iCurrentIndex++;
}
if (\strlen($sEmail) === 0)
{
$aRegs = array('');
if (\preg_match('/[^@\s]+@\S+/i', $sEmailAddress, $aRegs) && isset($aRegs[0]))
{
$sEmail = $aRegs[0];
}
else
{
$sName = $sEmailAddress;
}
}
if ((\strlen($sEmail) > 0) && (\strlen($sName) == 0) && (\strlen($sComment) == 0))
{
$sName = \str_replace($sEmail, '', $sEmailAddress);
}
$sEmail = \trim(\trim($sEmail), '<>');
$sEmail = \rtrim(\trim($sEmail), '.');
$sEmail = \trim($sEmail);
$sName = \trim(\trim($sName), '"');
$sName = \trim($sName, '\'');
$sComment = \trim(\trim($sComment), '()');
// Remove backslash
$sName = \preg_replace('/\\\\(.)/s', '$1', $sName);
$sComment = \preg_replace('/\\\\(.)/s', '$1', $sComment);
return Email::NewInstance($sEmail, $sName, $sComment);
}
/**
* @param bool $bIdn = false
*
* @return string
*/
public function GetEmail($bIdn = false)
{
return $bIdn ? \MailSo\Base\Utils::IdnToUtf8($this->sEmail) : $this->sEmail;
}
/**
* @return string
*/
public function GetDisplayName()
{
return $this->sDisplayName;
}
/**
* @return string
*/
public function GetRemark()
{
return $this->sRemark;
}
/**
* @return string
*/
public function GetDkimStatus()
{
return $this->sDkimStatus;
}
/**
* @return string
*/
public function GetDkimValue()
{
return $this->sDkimValue;
}
/**
* @return string
*/
public function GetAccountName()
{
return \MailSo\Base\Utils::GetAccountNameFromEmail($this->GetEmail(false));
}
/**
* @param bool $bIdn = false
*
* @return string
*/
public function GetDomain($bIdn = false)
{
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
}
/**
* @param string $sDkimStatus
* @param string $sDkimValue = ''
*/
public function SetDkimStatusAndValue($sDkimStatus, $sDkimValue = '')
{
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
$this->sDkimValue = $sDkimValue;
}
/**
* @param bool $bIdn = false
* @param bool $bDkim = true
*
* @return array
*/
public function ToArray($bIdn = false, $bDkim = true)
{
return $bDkim ? array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark, $this->sDkimStatus, $this->sDkimValue) :
array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark);
}
/**
* @param bool $bConvertSpecialsName = false
* @param bool $bIdn = false
*
* @return string
*/
public function ToString($bConvertSpecialsName = false, $bIdn = false)
{
$sReturn = '';
$sRemark = \str_replace(')', '\)', $this->sRemark);
$sDisplayName = \str_replace('"', '\"', $this->sDisplayName);
if ($bConvertSpecialsName)
{
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
$sDisplayName);
$sRemark = 0 === \strlen($sRemark) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
$sRemark);
}
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : '"'.$sDisplayName.'"';
$sRemark = 0 === \strlen($sRemark) ? '' : '('.$sRemark.')';
if (0 < \strlen($this->sEmail))
{
$sReturn = $this->GetEmail($bIdn);
if (0 < \strlen($sDisplayName.$sRemark))
{
$sReturn = $sDisplayName.' <'.$sReturn.'> '.$sRemark;
}
}
return \trim($sReturn);
}
}
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @deprecated
* @category MailSo
* @package Mime
*/
class EmailDep
{
/**
* @var string
*/
private $sDisplayName;
/**
* @var string
*/
private $sEmail;
/**
* @var string
*/
private $sRemark;
/**
* @var string
*/
private $sDkimStatus;
/**
* @var string
*/
private $sDkimValue;
/**
* @access private
*
* @param string $sEmail
* @param string $sDisplayName = ''
* @param string $sRemark = ''
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
private function __construct($sEmail, $sDisplayName = '', $sRemark = '')
{
if (!\MailSo\Base\Validator::NotEmptyString($sEmail, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$this->sEmail = \MailSo\Base\Utils::IdnToAscii(
\MailSo\Base\Utils::Trim($sEmail), true);
$this->sDisplayName = \MailSo\Base\Utils::Trim($sDisplayName);
$this->sRemark = \MailSo\Base\Utils::Trim($sRemark);
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::NONE;
$this->sDkimValue = '';
}
/**
* @param string $sEmail
* @param string $sDisplayName = ''
* @param string $sRemark = ''
*
* @return \MailSo\Mime\Email
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function NewInstance($sEmail, $sDisplayName = '', $sRemark = '')
{
return new self($sEmail, $sDisplayName, $sRemark);
}
/**
* @param string $sEmailAddress
* @return \MailSo\Mime\Email
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public static function Parse($sEmailAddress)
{
$sEmailAddress = \MailSo\Base\Utils::Trim($sEmailAddress);
if (!\MailSo\Base\Validator::NotEmptyString($sEmailAddress, true))
{
throw new \MailSo\Base\Exceptions\InvalidArgumentException();
}
$sName = '';
$sEmail = '';
$sComment = '';
$bInName = false;
$bInAddress = false;
$bInComment = false;
$iStartIndex = 0;
$iEndIndex = 0;
$iCurrentIndex = 0;
while ($iCurrentIndex < \strlen($sEmailAddress))
{
switch ($sEmailAddress{$iCurrentIndex})
{
// case '\'':
case '"':
// $sQuoteChar = $sEmailAddress{$iCurrentIndex};
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInName = true;
$iStartIndex = $iCurrentIndex;
}
else if ((!$bInAddress) && (!$bInComment))
{
$iEndIndex = $iCurrentIndex;
$sName = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInName = false;
}
break;
case '<':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
if ($iCurrentIndex > 0 && \strlen($sName) === 0)
{
$sName = \substr($sEmailAddress, 0, $iCurrentIndex);
}
$bInAddress = true;
$iStartIndex = $iCurrentIndex;
}
break;
case '>':
if ($bInAddress)
{
$iEndIndex = $iCurrentIndex;
$sEmail = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInAddress = false;
}
break;
case '(':
if ((!$bInName) && (!$bInAddress) && (!$bInComment))
{
$bInComment = true;
$iStartIndex = $iCurrentIndex;
}
break;
case ')':
if ($bInComment)
{
$iEndIndex = $iCurrentIndex;
$sComment = \substr($sEmailAddress, $iStartIndex + 1, $iEndIndex - $iStartIndex - 1);
$sEmailAddress = \substr_replace($sEmailAddress, '', $iStartIndex, $iEndIndex - $iStartIndex + 1);
$iEndIndex = 0;
$iCurrentIndex = 0;
$iStartIndex = 0;
$bInComment = false;
}
break;
case '\\':
$iCurrentIndex++;
break;
}
$iCurrentIndex++;
}
if (\strlen($sEmail) === 0)
{
$aRegs = array('');
if (\preg_match('/[^@\s]+@\S+/i', $sEmailAddress, $aRegs) && isset($aRegs[0]))
{
$sEmail = $aRegs[0];
}
else
{
$sName = $sEmailAddress;
}
}
if ((\strlen($sEmail) > 0) && (\strlen($sName) == 0) && (\strlen($sComment) == 0))
{
$sName = \str_replace($sEmail, '', $sEmailAddress);
}
$sEmail = \trim(\trim($sEmail), '<>');
$sEmail = \rtrim(\trim($sEmail), '.');
$sEmail = \trim($sEmail);
$sName = \trim(\trim($sName), '"');
$sName = \trim($sName, '\'');
$sComment = \trim(\trim($sComment), '()');
// Remove backslash
$sName = \preg_replace('/\\\\(.)/s', '$1', $sName);
$sComment = \preg_replace('/\\\\(.)/s', '$1', $sComment);
return Email::NewInstance($sEmail, $sName, $sComment);
}
/**
* @param bool $bIdn = false
*
* @return string
*/
public function GetEmail($bIdn = false)
{
return $bIdn ? \MailSo\Base\Utils::IdnToUtf8($this->sEmail) : $this->sEmail;
}
/**
* @return string
*/
public function GetDisplayName()
{
return $this->sDisplayName;
}
/**
* @return string
*/
public function GetRemark()
{
return $this->sRemark;
}
/**
* @return string
*/
public function GetDkimStatus()
{
return $this->sDkimStatus;
}
/**
* @return string
*/
public function GetDkimValue()
{
return $this->sDkimValue;
}
/**
* @return string
*/
public function GetAccountName()
{
return \MailSo\Base\Utils::GetAccountNameFromEmail($this->GetEmail(false));
}
/**
* @param bool $bIdn = false
*
* @return string
*/
public function GetDomain($bIdn = false)
{
return \MailSo\Base\Utils::GetDomainFromEmail($this->GetEmail($bIdn));
}
/**
* @param string $sDkimStatus
* @param string $sDkimValue = ''
*/
public function SetDkimStatusAndValue($sDkimStatus, $sDkimValue = '')
{
$this->sDkimStatus = \MailSo\Mime\Enumerations\DkimStatus::normalizeValue($sDkimStatus);
$this->sDkimValue = $sDkimValue;
}
/**
* @param bool $bIdn = false
* @param bool $bDkim = true
*
* @return array
*/
public function ToArray($bIdn = false, $bDkim = true)
{
return $bDkim ? array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark, $this->sDkimStatus, $this->sDkimValue) :
array($this->sDisplayName, $this->GetEmail($bIdn), $this->sRemark);
}
/**
* @param bool $bConvertSpecialsName = false
* @param bool $bIdn = false
*
* @return string
*/
public function ToString($bConvertSpecialsName = false, $bIdn = false)
{
$sReturn = '';
$sRemark = \str_replace(')', '\)', $this->sRemark);
$sDisplayName = \str_replace('"', '\"', $this->sDisplayName);
if ($bConvertSpecialsName)
{
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
$sDisplayName);
$sRemark = 0 === \strlen($sRemark) ? '' : \MailSo\Base\Utils::EncodeUnencodedValue(
\MailSo\Base\Enumerations\Encoding::BASE64_SHORT,
$sRemark);
}
$sDisplayName = 0 === \strlen($sDisplayName) ? '' : '"'.$sDisplayName.'"';
$sRemark = 0 === \strlen($sRemark) ? '' : '('.$sRemark.')';
if (0 < \strlen($this->sEmail))
{
$sReturn = $this->GetEmail($bIdn);
if (0 < \strlen($sDisplayName.$sRemark))
{
$sReturn = $sDisplayName.' <'.$sReturn.'> '.$sRemark;
}
}
return \trim($sReturn);
}
}

View file

@ -1,25 +1,25 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime\Enumerations;
/**
* @category MailSo
* @package Mime
* @subpackage Enumerations
*/
class Constants
{
const TAB = "\t";
const CRLF = "\r\n";
const LINE_LENGTH = 74;
}
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime\Enumerations;
/**
* @category MailSo
* @package Mime
* @subpackage Enumerations
*/
class Constants
{
const TAB = "\t";
const CRLF = "\r\n";
const LINE_LENGTH = 74;
}

View file

@ -46,7 +46,7 @@ class DkimStatus
/**
* @param string $sStatus
*
*
* @return string
*/
public static function normalizeValue($sStatus)

View file

@ -1,36 +1,36 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime\Enumerations;
/**
* @category MailSo
* @package Mime
* @subpackage Enumerations
*/
class MimeType
{
const TEXT_PLAIN = 'text/plain';
const TEXT_HTML = 'text/html';
const MULTIPART_ALTERNATIVE = 'multipart/alternative';
const MULTIPART_RELATED = 'multipart/related';
const MULTIPART_MIXED = 'multipart/mixed';
const MULTIPART_SIGNED = 'multipart/signed';
const MESSAGE_RFC822 = 'message/rfc822';
const MESSAGE_PARTIAL = 'message/partial';
const MESSAGE_REPORT = 'message/report';
const APPLICATION_MS_TNEF = 'application/ms-tnef';
const APPLICATION_PKCS7_MIME = 'application/pkcs7-mime';
const APPLICATION_PKCS7_SIGNATURE = 'application/pkcs7-signature';
}
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime\Enumerations;
/**
* @category MailSo
* @package Mime
* @subpackage Enumerations
*/
class MimeType
{
const TEXT_PLAIN = 'text/plain';
const TEXT_HTML = 'text/html';
const MULTIPART_ALTERNATIVE = 'multipart/alternative';
const MULTIPART_RELATED = 'multipart/related';
const MULTIPART_MIXED = 'multipart/mixed';
const MULTIPART_SIGNED = 'multipart/signed';
const MESSAGE_RFC822 = 'message/rfc822';
const MESSAGE_PARTIAL = 'message/partial';
const MESSAGE_REPORT = 'message/report';
const APPLICATION_MS_TNEF = 'application/ms-tnef';
const APPLICATION_PKCS7_MIME = 'application/pkcs7-mime';
const APPLICATION_PKCS7_SIGNATURE = 'application/pkcs7-signature';
}

View file

@ -221,7 +221,7 @@ class Header
if ($this->IsSubject())
{
if (!\MailSo\Base\Utils::IsAscii($sResult) &&
if (!\MailSo\Base\Utils::IsAscii($sResult) &&
\MailSo\Base\Utils::IsIconvSupported() &&
\function_exists('iconv_mime_encode'))
{

View file

@ -1,480 +1,480 @@
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @category MailSo
* @package Mime
*/
class HeaderCollection extends \MailSo\Base\Collection
{
/**
* @return string
*/
protected $sRawHeaders;
/**
* @var strign
*/
protected $sParentCharset;
/**
* @access protected
*
* @param string $sRawHeaders = ''
* @param bool $bStoreRawHeaders = true
*/
protected function __construct($sRawHeaders = '', $bStoreRawHeaders = true)
{
parent::__construct();
$this->sRawHeaders = '';
$this->sParentCharset = '';
if (0 < \strlen($sRawHeaders))
{
$this->Parse($sRawHeaders, $bStoreRawHeaders);
}
}
/**
* @param string $sRawHeaders = ''
* @param bool $bStoreRawHeaders = true
*
* @return \MailSo\Mime\HeaderCollection
*/
public static function NewInstance($sRawHeaders = '', $bStoreRawHeaders = true)
{
return new self($sRawHeaders, $bStoreRawHeaders);
}
/**
* @param string $sName
* @param string $sValue
* @param bool $bToTop = false
*
* @return \MailSo\Mime\HeaderCollection
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function AddByName($sName, $sValue, $bToTop = false)
{
return $this->Add(Header::NewInstance($sName, $sValue), $bToTop);
}
/**
* @param string $sName
* @param string $sValue
* @param bool $bToTop = false
*
* @return \MailSo\Mime\HeaderCollection
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function SetByName($sName, $sValue, $bToTop = false)
{
return $this->RemoveByName($sName)->Add(Header::NewInstance($sName, $sValue), $bToTop);
}
/**
* @return \MailSo\Mime\Header | null
*/
public function &GetByIndex($iIndex)
{
$mResult = null;
$mResult =& parent::GetByIndex($iIndex);
return $mResult;
}
/**
* @param string $sHeaderName
* @param bool $bCharsetAutoDetect = false
* @return string
*/
public function ValueByName($sHeaderName, $bCharsetAutoDetect = false)
{
$oHeader = null;
$oHeader =& $this->GetByName($sHeaderName);
return (null !== $oHeader) ? ($bCharsetAutoDetect ? $oHeader->ValueWithCharsetAutoDetect() : $oHeader->Value()) : '';
}
/**
* @param string $sHeaderName
* @param bool $bCharsetAutoDetect = false
* @return array
*/
public function ValuesByName($sHeaderName, $bCharsetAutoDetect = false)
{
$aResult = array();
$oHeader = null;
$sHeaderNameLower = \strtolower($sHeaderName);
$aHeaders =& $this->GetAsArray();
foreach ($aHeaders as /* @var $oHeader \MailSo\Mime\Header */ &$oHeader)
{
if ($sHeaderNameLower === \strtolower($oHeader->Name()))
{
$aResult[] = $bCharsetAutoDetect ? $oHeader->ValueWithCharsetAutoDetect() : $oHeader->Value();
}
}
return $aResult;
}
/**
* @param string $sHeaderName
*
* @return \MailSo\Mime\HeaderCollection
*/
public function RemoveByName($sHeaderName)
{
$aResult = $this->FilterList(function ($oHeader) use ($sHeaderName) {
return $oHeader && \strtolower($oHeader->Name()) !== \strtolower($sHeaderName);
});
return $this->SetAsArray($aResult);
}
/**
* @param string $sHeaderName
* @param bool $bCharsetAutoDetect = false
*
* @return \MailSo\Mime\EmailCollection|null
*/
public function GetAsEmailCollection($sHeaderName, $bCharsetAutoDetect = false)
{
$oResult = null;
$sValue = $this->ValueByName($sHeaderName, $bCharsetAutoDetect);
if (0 < \strlen($sValue))
{
$oResult = \MailSo\Mime\EmailCollection::NewInstance($sValue);
}
return $oResult && 0 < $oResult->Count() ? $oResult : null;
}
/**
* @param string $sHeaderName
* @return \MailSo\Mime\ParameterCollection|null
*/
public function ParametersByName($sHeaderName)
{
$oParameters = $oHeader = null;
$oHeader =& $this->GetByName($sHeaderName);
if ($oHeader)
{
$oParameters = $oHeader->Parameters();
}
return $oParameters;
}
/**
* @param string $sHeaderName
* @param string $sParamName
* @return string
*/
public function ParameterValue($sHeaderName, $sParamName)
{
$oParameters = $this->ParametersByName($sHeaderName);
return (null !== $oParameters) ? $oParameters->ParameterValueByName($sParamName) : '';
}
/**
* @param string $sHeaderName
* @return \MailSo\Mime\Header | false
*/
public function &GetByName($sHeaderName)
{
$oResult = $oHeader = null;
$sHeaderNameLower = \strtolower($sHeaderName);
$aHeaders =& $this->GetAsArray();
foreach ($aHeaders as /* @var $oHeader \MailSo\Mime\Header */ &$oHeader)
{
if ($sHeaderNameLower === \strtolower($oHeader->Name()))
{
$oResult =& $oHeader;
break;
}
}
return $oResult;
}
/**
* @param array $aList
* @return \MailSo\Mime\HeaderCollection
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function SetAsArray($aList)
{
parent::SetAsArray($aList);
return $this;
}
/**
* @param string $sParentCharset
* @return \MailSo\Mime\HeaderCollection
*/
public function SetParentCharset($sParentCharset)
{
if (0 < \strlen($sParentCharset))
{
if ($this->sParentCharset !== $sParentCharset)
{
$oHeader = null;
$aHeaders =& $this->GetAsArray();
foreach ($aHeaders as /* @var $oHeader \MailSo\Mime\Header */ &$oHeader)
{
$oHeader->SetParentCharset($sParentCharset);
}
$this->sParentCharset = $sParentCharset;
}
}
return $this;
}
/**
* @return void
*/
public function Clear()
{
parent::Clear();
$this->sRawHeaders = '';
}
/**
* @param string $sRawHeaders
* @param bool $bStoreRawHeaders = false
* @param string $sParentCharset = ''
*
* @return \MailSo\Mime\HeaderCollection
*/
public function Parse($sRawHeaders, $bStoreRawHeaders = false, $sParentCharset = '')
{
$this->Clear();
if ($bStoreRawHeaders)
{
$this->sRawHeaders = $sRawHeaders;
}
if (0 === \strlen($this->sParentCharset))
{
$this->sParentCharset = $sParentCharset;
}
$aHeaders = \explode("\n", \str_replace("\r", '', $sRawHeaders));
$sName = null;
$sValue = null;
foreach ($aHeaders as $sHeadersValue)
{
if (0 === strlen($sHeadersValue))
{
continue;
}
$sFirstChar = \substr($sHeadersValue, 0, 1);
if ($sFirstChar !== ' ' && $sFirstChar !== "\t" && false === \strpos($sHeadersValue, ':'))
{
continue;
}
else if (null !== $sName && ($sFirstChar === ' ' || $sFirstChar === "\t"))
{
$sValue = \is_null($sValue) ? '' : $sValue;
if ('?=' === \substr(\rtrim($sHeadersValue), -2))
{
$sHeadersValue = \rtrim($sHeadersValue);
}
if ('=?' === \substr(\ltrim($sHeadersValue), 0, 2))
{
$sHeadersValue = \ltrim($sHeadersValue);
}
if ('=?' === \substr($sHeadersValue, 0, 2))
{
$sValue .= $sHeadersValue;
}
else
{
$sValue .= "\n".$sHeadersValue;
}
}
else
{
if (null !== $sName)
{
$oHeader = Header::NewInstanceFromEncodedString($sName.': '.$sValue, $this->sParentCharset);
if ($oHeader)
{
$this->Add($oHeader);
}
$sName = null;
$sValue = null;
}
$aHeaderParts = \explode(':', $sHeadersValue, 2);
$sName = $aHeaderParts[0];
$sValue = isset($aHeaderParts[1]) ? $aHeaderParts[1] : '';
if ('?=' === \substr(\rtrim($sValue), -2))
{
$sValue = \rtrim($sValue);
}
}
}
if (null !== $sName)
{
$oHeader = Header::NewInstanceFromEncodedString($sName.': '.$sValue, $this->sParentCharset);
if ($oHeader)
{
$this->Add($oHeader);
}
}
return $this;
}
/**
* @return int
*/
public function DkimStatuses()
{
$aResult = array();
$aHeaders = $this->ValuesByName(\MailSo\Mime\Enumerations\Header::AUTHENTICATION_RESULTS);
if (\is_array($aHeaders) && 0 < \count($aHeaders))
{
foreach ($aHeaders as $sHeaderValue)
{
$sStatus = '';
$sHeader = '';
$sDkimLine = '';
$aMatch = array();
$sHeaderValue = \preg_replace('/[\r\n\t\s]+/', ' ', $sHeaderValue);
if (\preg_match('/dkim=.+/i', $sHeaderValue, $aMatch) && !empty($aMatch[0]))
{
$sDkimLine = $aMatch[0];
$aMatch = array();
if (\preg_match('/dkim=([a-zA-Z0-9]+)/i', $sDkimLine, $aMatch) && !empty($aMatch[1]))
{
$sStatus = $aMatch[1];
}
$aMatch = array();
if (\preg_match('/header\.(d|i|from)=([^\s;]+)/i', $sDkimLine, $aMatch) && !empty($aMatch[2]))
{
$sHeader = \trim($aMatch[2]);
}
if (!empty($sStatus) && !empty($sHeader))
{
$aResult[] = array($sStatus, $sHeader, $sDkimLine);
}
}
}
}
else
{
// X-DKIM-Authentication-Results: signer="hostinger.com" status="pass"
$aHeaders = $this->ValuesByName(\MailSo\Mime\Enumerations\Header::X_DKIM_AUTHENTICATION_RESULTS);
if (\is_array($aHeaders) && 0 < \count($aHeaders))
{
foreach ($aHeaders as $sHeaderValue)
{
$sStatus = '';
$sHeader = '';
$aMatch = array();
$sHeaderValue = \preg_replace('/[\r\n\t\s]+/', ' ', $sHeaderValue);
if (\preg_match('/status[\s]?=[\s]?"([a-zA-Z0-9]+)"/i', $sHeaderValue, $aMatch) && !empty($aMatch[1]))
{
$sStatus = $aMatch[1];
}
if (\preg_match('/signer[\s]?=[\s]?"([^";]+)"/i', $sHeaderValue, $aMatch) && !empty($aMatch[1]))
{
$sHeader = \trim($aMatch[1]);
}
if (!empty($sStatus) && !empty($sHeader))
{
$aResult[] = array($sStatus, $sHeader, $sHeaderValue);
}
}
}
}
return $aResult;
}
/**
* @return int
*/
public function PopulateEmailColectionByDkim($oEmails)
{
if ($oEmails && $oEmails instanceof \MailSo\Mime\EmailCollection)
{
$aDkimStatuses = $this->DkimStatuses();
if (\is_array($aDkimStatuses) && 0 < \count($aDkimStatuses))
{
$oEmails->ForeachList(function (/* @var $oItem \MailSo\Mime\Email */ $oItem) use ($aDkimStatuses) {
if ($oItem && $oItem instanceof \MailSo\Mime\Email)
{
$sEmail = $oItem->GetEmail();
foreach ($aDkimStatuses as $aDkimData)
{
if (isset($aDkimData[0], $aDkimData[1]) &&
$aDkimData[1] === \strstr($sEmail, $aDkimData[1]))
{
$oItem->SetDkimStatusAndValue($aDkimData[0], empty($aDkimData[2]) ? '' : $aDkimData[2]);
}
}
}
});
}
}
}
/**
* @return string
*/
public function ToEncodedString()
{
$aResult = array();
$aHeaders =& $this->GetAsArray();
foreach ($aHeaders as /* @var $oHeader \MailSo\Mime\Header */ &$oHeader)
{
$aResult[] = $oHeader->EncodedValue();
}
return \implode(\MailSo\Mime\Enumerations\Constants::CRLF, $aResult);
}
}
<?php
/*
* This file is part of MailSo.
*
* (c) 2014 Usenko Timur
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MailSo\Mime;
/**
* @category MailSo
* @package Mime
*/
class HeaderCollection extends \MailSo\Base\Collection
{
/**
* @return string
*/
protected $sRawHeaders;
/**
* @var strign
*/
protected $sParentCharset;
/**
* @access protected
*
* @param string $sRawHeaders = ''
* @param bool $bStoreRawHeaders = true
*/
protected function __construct($sRawHeaders = '', $bStoreRawHeaders = true)
{
parent::__construct();
$this->sRawHeaders = '';
$this->sParentCharset = '';
if (0 < \strlen($sRawHeaders))
{
$this->Parse($sRawHeaders, $bStoreRawHeaders);
}
}
/**
* @param string $sRawHeaders = ''
* @param bool $bStoreRawHeaders = true
*
* @return \MailSo\Mime\HeaderCollection
*/
public static function NewInstance($sRawHeaders = '', $bStoreRawHeaders = true)
{
return new self($sRawHeaders, $bStoreRawHeaders);
}
/**
* @param string $sName
* @param string $sValue
* @param bool $bToTop = false
*
* @return \MailSo\Mime\HeaderCollection
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function AddByName($sName, $sValue, $bToTop = false)
{
return $this->Add(Header::NewInstance($sName, $sValue), $bToTop);
}
/**
* @param string $sName
* @param string $sValue
* @param bool $bToTop = false
*
* @return \MailSo\Mime\HeaderCollection
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function SetByName($sName, $sValue, $bToTop = false)
{
return $this->RemoveByName($sName)->Add(Header::NewInstance($sName, $sValue), $bToTop);
}
/**
* @return \MailSo\Mime\Header | null
*/
public function &GetByIndex($iIndex)
{
$mResult = null;
$mResult =& parent::GetByIndex($iIndex);
return $mResult;
}
/**
* @param string $sHeaderName
* @param bool $bCharsetAutoDetect = false
* @return string
*/
public function ValueByName($sHeaderName, $bCharsetAutoDetect = false)
{
$oHeader = null;
$oHeader =& $this->GetByName($sHeaderName);
return (null !== $oHeader) ? ($bCharsetAutoDetect ? $oHeader->ValueWithCharsetAutoDetect() : $oHeader->Value()) : '';
}
/**
* @param string $sHeaderName
* @param bool $bCharsetAutoDetect = false
* @return array
*/
public function ValuesByName($sHeaderName, $bCharsetAutoDetect = false)
{
$aResult = array();
$oHeader = null;
$sHeaderNameLower = \strtolower($sHeaderName);
$aHeaders =& $this->GetAsArray();
foreach ($aHeaders as /* @var $oHeader \MailSo\Mime\Header */ &$oHeader)
{
if ($sHeaderNameLower === \strtolower($oHeader->Name()))
{
$aResult[] = $bCharsetAutoDetect ? $oHeader->ValueWithCharsetAutoDetect() : $oHeader->Value();
}
}
return $aResult;
}
/**
* @param string $sHeaderName
*
* @return \MailSo\Mime\HeaderCollection
*/
public function RemoveByName($sHeaderName)
{
$aResult = $this->FilterList(function ($oHeader) use ($sHeaderName) {
return $oHeader && \strtolower($oHeader->Name()) !== \strtolower($sHeaderName);
});
return $this->SetAsArray($aResult);
}
/**
* @param string $sHeaderName
* @param bool $bCharsetAutoDetect = false
*
* @return \MailSo\Mime\EmailCollection|null
*/
public function GetAsEmailCollection($sHeaderName, $bCharsetAutoDetect = false)
{
$oResult = null;
$sValue = $this->ValueByName($sHeaderName, $bCharsetAutoDetect);
if (0 < \strlen($sValue))
{
$oResult = \MailSo\Mime\EmailCollection::NewInstance($sValue);
}
return $oResult && 0 < $oResult->Count() ? $oResult : null;
}
/**
* @param string $sHeaderName
* @return \MailSo\Mime\ParameterCollection|null
*/
public function ParametersByName($sHeaderName)
{
$oParameters = $oHeader = null;
$oHeader =& $this->GetByName($sHeaderName);
if ($oHeader)
{
$oParameters = $oHeader->Parameters();
}
return $oParameters;
}
/**
* @param string $sHeaderName
* @param string $sParamName
* @return string
*/
public function ParameterValue($sHeaderName, $sParamName)
{
$oParameters = $this->ParametersByName($sHeaderName);
return (null !== $oParameters) ? $oParameters->ParameterValueByName($sParamName) : '';
}
/**
* @param string $sHeaderName
* @return \MailSo\Mime\Header | false
*/
public function &GetByName($sHeaderName)
{
$oResult = $oHeader = null;
$sHeaderNameLower = \strtolower($sHeaderName);
$aHeaders =& $this->GetAsArray();
foreach ($aHeaders as /* @var $oHeader \MailSo\Mime\Header */ &$oHeader)
{
if ($sHeaderNameLower === \strtolower($oHeader->Name()))
{
$oResult =& $oHeader;
break;
}
}
return $oResult;
}
/**
* @param array $aList
* @return \MailSo\Mime\HeaderCollection
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function SetAsArray($aList)
{
parent::SetAsArray($aList);
return $this;
}
/**
* @param string $sParentCharset
* @return \MailSo\Mime\HeaderCollection
*/
public function SetParentCharset($sParentCharset)
{
if (0 < \strlen($sParentCharset))
{
if ($this->sParentCharset !== $sParentCharset)
{
$oHeader = null;
$aHeaders =& $this->GetAsArray();
foreach ($aHeaders as /* @var $oHeader \MailSo\Mime\Header */ &$oHeader)
{
$oHeader->SetParentCharset($sParentCharset);
}
$this->sParentCharset = $sParentCharset;
}
}
return $this;
}
/**
* @return void
*/
public function Clear()
{
parent::Clear();
$this->sRawHeaders = '';
}
/**
* @param string $sRawHeaders
* @param bool $bStoreRawHeaders = false
* @param string $sParentCharset = ''
*
* @return \MailSo\Mime\HeaderCollection
*/
public function Parse($sRawHeaders, $bStoreRawHeaders = false, $sParentCharset = '')
{
$this->Clear();
if ($bStoreRawHeaders)
{
$this->sRawHeaders = $sRawHeaders;
}
if (0 === \strlen($this->sParentCharset))
{
$this->sParentCharset = $sParentCharset;
}
$aHeaders = \explode("\n", \str_replace("\r", '', $sRawHeaders));
$sName = null;
$sValue = null;
foreach ($aHeaders as $sHeadersValue)
{
if (0 === strlen($sHeadersValue))
{
continue;
}
$sFirstChar = \substr($sHeadersValue, 0, 1);
if ($sFirstChar !== ' ' && $sFirstChar !== "\t" && false === \strpos($sHeadersValue, ':'))
{
continue;
}
else if (null !== $sName && ($sFirstChar === ' ' || $sFirstChar === "\t"))
{
$sValue = \is_null($sValue) ? '' : $sValue;
if ('?=' === \substr(\rtrim($sHeadersValue), -2))
{
$sHeadersValue = \rtrim($sHeadersValue);
}
if ('=?' === \substr(\ltrim($sHeadersValue), 0, 2))
{
$sHeadersValue = \ltrim($sHeadersValue);
}
if ('=?' === \substr($sHeadersValue, 0, 2))
{
$sValue .= $sHeadersValue;
}
else
{
$sValue .= "\n".$sHeadersValue;
}
}
else
{
if (null !== $sName)
{
$oHeader = Header::NewInstanceFromEncodedString($sName.': '.$sValue, $this->sParentCharset);
if ($oHeader)
{
$this->Add($oHeader);
}
$sName = null;
$sValue = null;
}
$aHeaderParts = \explode(':', $sHeadersValue, 2);
$sName = $aHeaderParts[0];
$sValue = isset($aHeaderParts[1]) ? $aHeaderParts[1] : '';
if ('?=' === \substr(\rtrim($sValue), -2))
{
$sValue = \rtrim($sValue);
}
}
}
if (null !== $sName)
{
$oHeader = Header::NewInstanceFromEncodedString($sName.': '.$sValue, $this->sParentCharset);
if ($oHeader)
{
$this->Add($oHeader);
}
}
return $this;
}
/**
* @return int
*/
public function DkimStatuses()
{
$aResult = array();
$aHeaders = $this->ValuesByName(\MailSo\Mime\Enumerations\Header::AUTHENTICATION_RESULTS);
if (\is_array($aHeaders) && 0 < \count($aHeaders))
{
foreach ($aHeaders as $sHeaderValue)
{
$sStatus = '';
$sHeader = '';
$sDkimLine = '';
$aMatch = array();
$sHeaderValue = \preg_replace('/[\r\n\t\s]+/', ' ', $sHeaderValue);
if (\preg_match('/dkim=.+/i', $sHeaderValue, $aMatch) && !empty($aMatch[0]))
{
$sDkimLine = $aMatch[0];
$aMatch = array();
if (\preg_match('/dkim=([a-zA-Z0-9]+)/i', $sDkimLine, $aMatch) && !empty($aMatch[1]))
{
$sStatus = $aMatch[1];
}
$aMatch = array();
if (\preg_match('/header\.(d|i|from)=([^\s;]+)/i', $sDkimLine, $aMatch) && !empty($aMatch[2]))
{
$sHeader = \trim($aMatch[2]);
}
if (!empty($sStatus) && !empty($sHeader))
{
$aResult[] = array($sStatus, $sHeader, $sDkimLine);
}
}
}
}
else
{
// X-DKIM-Authentication-Results: signer="hostinger.com" status="pass"
$aHeaders = $this->ValuesByName(\MailSo\Mime\Enumerations\Header::X_DKIM_AUTHENTICATION_RESULTS);
if (\is_array($aHeaders) && 0 < \count($aHeaders))
{
foreach ($aHeaders as $sHeaderValue)
{
$sStatus = '';
$sHeader = '';
$aMatch = array();
$sHeaderValue = \preg_replace('/[\r\n\t\s]+/', ' ', $sHeaderValue);
if (\preg_match('/status[\s]?=[\s]?"([a-zA-Z0-9]+)"/i', $sHeaderValue, $aMatch) && !empty($aMatch[1]))
{
$sStatus = $aMatch[1];
}
if (\preg_match('/signer[\s]?=[\s]?"([^";]+)"/i', $sHeaderValue, $aMatch) && !empty($aMatch[1]))
{
$sHeader = \trim($aMatch[1]);
}
if (!empty($sStatus) && !empty($sHeader))
{
$aResult[] = array($sStatus, $sHeader, $sHeaderValue);
}
}
}
}
return $aResult;
}
/**
* @return int
*/
public function PopulateEmailColectionByDkim($oEmails)
{
if ($oEmails && $oEmails instanceof \MailSo\Mime\EmailCollection)
{
$aDkimStatuses = $this->DkimStatuses();
if (\is_array($aDkimStatuses) && 0 < \count($aDkimStatuses))
{
$oEmails->ForeachList(function (/* @var $oItem \MailSo\Mime\Email */ $oItem) use ($aDkimStatuses) {
if ($oItem && $oItem instanceof \MailSo\Mime\Email)
{
$sEmail = $oItem->GetEmail();
foreach ($aDkimStatuses as $aDkimData)
{
if (isset($aDkimData[0], $aDkimData[1]) &&
$aDkimData[1] === \strstr($sEmail, $aDkimData[1]))
{
$oItem->SetDkimStatusAndValue($aDkimData[0], empty($aDkimData[2]) ? '' : $aDkimData[2]);
}
}
}
});
}
}
}
/**
* @return string
*/
public function ToEncodedString()
{
$aResult = array();
$aHeaders =& $this->GetAsArray();
foreach ($aHeaders as /* @var $oHeader \MailSo\Mime\Header */ &$oHeader)
{
$aResult[] = $oHeader->EncodedValue();
}
return \implode(\MailSo\Mime\Enumerations\Constants::CRLF, $aResult);
}
}

View file

@ -53,7 +53,7 @@ interface ParserInterface
/**
* @param string $sBuffer
*
*
* @return void
*/
public function ReadBuffer($sBuffer);