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,189 +1,189 @@
<?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\Base;
/**
* @category MailSo
* @package Base
*/
class Crypt
{
/**
*
* @param string $sString
* @param string $sKey
*
* @return string
*/
public static function XxteaEncrypt($sString, $sKey)
{
if (0 === \strlen($sString))
{
return '';
}
$aV = self::str2long($sString, true);
$aK = self::str2long($sKey, false);
if (\count($aK) < 4)
{
for ($iIndex = \count($aK); $iIndex < 4; $iIndex++)
{
$aK[$iIndex] = 0;
}
}
$iN = \count($aV) - 1;
$iZ = $aV[$iN];
$iY = $aV[0];
$iDelta = 0x9E3779B9;
$iQ = \floor(6 + 52 / ($iN + 1));
$iSum = 0;
while (0 < $iQ--)
{
$iSum = self::int32($iSum + $iDelta);
$iE = $iSum >> 2 & 3;
for ($iPIndex = 0; $iPIndex < $iN; $iPIndex++)
{
$iY = $aV[$iPIndex + 1];
$iMx = self::int32((($iZ >> 5 & 0x07ffffff) ^ $iY << 2) +
(($iY >> 3 & 0x1fffffff) ^ $iZ << 4)) ^ self::int32(($iSum ^ $iY) + ($aK[$iPIndex & 3 ^ $iE] ^ $iZ));
$iZ = $aV[$iPIndex] = self::int32($aV[$iPIndex] + $iMx);
}
$iY = $aV[0];
$iMx = self::int32((($iZ >> 5 & 0x07ffffff) ^ $iY << 2) +
(($iY >> 3 & 0x1fffffff) ^ $iZ << 4)) ^ self::int32(($iSum ^ $iY) + ($aK[$iPIndex & 3 ^ $iE] ^ $iZ));
$iZ = $aV[$iN] = self::int32($aV[$iN] + $iMx);
}
return self::long2str($aV, false);
}
/**
* @param string $sEncriptedString
* @param string $sKey
*
* @return string
*/
public static function XxteaDecrypt($sEncriptedString, $sKey)
{
if (0 === \strlen($sEncriptedString))
{
return '';
}
$aV = self::str2long($sEncriptedString, false);
$aK = self::str2long($sKey, false);
if (\count($aK) < 4)
{
for ($iIndex = \count($aK); $iIndex < 4; $iIndex++)
{
$aK[$iIndex] = 0;
}
}
$iN = \count($aV) - 1;
$iZ = $aV[$iN];
$iY = $aV[0];
$iDelta = 0x9E3779B9;
$iQ = \floor(6 + 52 / ($iN + 1));
$iSum = self::int32($iQ * $iDelta);
while ($iSum != 0)
{
$iE = $iSum >> 2 & 3;
for ($iPIndex = $iN; $iPIndex > 0; $iPIndex--)
{
$iZ = $aV[$iPIndex - 1];
$iMx = self::int32((($iZ >> 5 & 0x07ffffff) ^ $iY << 2) +
(($iY >> 3 & 0x1fffffff) ^ $iZ << 4)) ^ self::int32(($iSum ^ $iY) + ($aK[$iPIndex & 3 ^ $iE] ^ $iZ));
$iY = $aV[$iPIndex] = self::int32($aV[$iPIndex] - $iMx);
}
$iZ = $aV[$iN];
$iMx = self::int32((($iZ >> 5 & 0x07ffffff) ^ $iY << 2) +
(($iY >> 3 & 0x1fffffff) ^ $iZ << 4)) ^ self::int32(($iSum ^ $iY) + ($aK[$iPIndex & 3 ^ $iE] ^ $iZ));
$iY = $aV[0] = self::int32($aV[0] - $iMx);
$iSum = self::int32($iSum - $iDelta);
}
return self::long2str($aV, true);
}
/**
* @param array $aV
* @param array $aW
*
* @return string
*/
private static function long2str($aV, $aW)
{
$iLen = \count($aV);
$iN = ($iLen - 1) << 2;
if ($aW)
{
$iM = $aV[$iLen - 1];
if (($iM < $iN - 3) || ($iM > $iN))
{
return false;
}
$iN = $iM;
}
$aS = array();
for ($iIndex = 0; $iIndex < $iLen; $iIndex++)
{
$aS[$iIndex] = \pack('V', $aV[$iIndex]);
}
if ($aW)
{
return \substr(\join('', $aS), 0, $iN);
}
else
{
return \join('', $aS);
}
}
/**
* @param string $sS
* @param string $sW
*
* @return array
*/
private static function str2long($sS, $sW)
{
$aV = \unpack('V*', $sS . \str_repeat("\0", (4 - \strlen($sS) % 4) & 3));
$aV = \array_values($aV);
if ($sW)
{
$aV[\count($aV)] = \strlen($sS);
}
return $aV;
}
/**
* @param int $iN
*
* @return int
*/
private static function int32($iN)
{
while ($iN >= 2147483648)
{
$iN -= 4294967296;
}
while ($iN <= -2147483649)
{
$iN += 4294967296;
}
return (int) $iN;
}
<?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\Base;
/**
* @category MailSo
* @package Base
*/
class Crypt
{
/**
*
* @param string $sString
* @param string $sKey
*
* @return string
*/
public static function XxteaEncrypt($sString, $sKey)
{
if (0 === \strlen($sString))
{
return '';
}
$aV = self::str2long($sString, true);
$aK = self::str2long($sKey, false);
if (\count($aK) < 4)
{
for ($iIndex = \count($aK); $iIndex < 4; $iIndex++)
{
$aK[$iIndex] = 0;
}
}
$iN = \count($aV) - 1;
$iZ = $aV[$iN];
$iY = $aV[0];
$iDelta = 0x9E3779B9;
$iQ = \floor(6 + 52 / ($iN + 1));
$iSum = 0;
while (0 < $iQ--)
{
$iSum = self::int32($iSum + $iDelta);
$iE = $iSum >> 2 & 3;
for ($iPIndex = 0; $iPIndex < $iN; $iPIndex++)
{
$iY = $aV[$iPIndex + 1];
$iMx = self::int32((($iZ >> 5 & 0x07ffffff) ^ $iY << 2) +
(($iY >> 3 & 0x1fffffff) ^ $iZ << 4)) ^ self::int32(($iSum ^ $iY) + ($aK[$iPIndex & 3 ^ $iE] ^ $iZ));
$iZ = $aV[$iPIndex] = self::int32($aV[$iPIndex] + $iMx);
}
$iY = $aV[0];
$iMx = self::int32((($iZ >> 5 & 0x07ffffff) ^ $iY << 2) +
(($iY >> 3 & 0x1fffffff) ^ $iZ << 4)) ^ self::int32(($iSum ^ $iY) + ($aK[$iPIndex & 3 ^ $iE] ^ $iZ));
$iZ = $aV[$iN] = self::int32($aV[$iN] + $iMx);
}
return self::long2str($aV, false);
}
/**
* @param string $sEncriptedString
* @param string $sKey
*
* @return string
*/
public static function XxteaDecrypt($sEncriptedString, $sKey)
{
if (0 === \strlen($sEncriptedString))
{
return '';
}
$aV = self::str2long($sEncriptedString, false);
$aK = self::str2long($sKey, false);
if (\count($aK) < 4)
{
for ($iIndex = \count($aK); $iIndex < 4; $iIndex++)
{
$aK[$iIndex] = 0;
}
}
$iN = \count($aV) - 1;
$iZ = $aV[$iN];
$iY = $aV[0];
$iDelta = 0x9E3779B9;
$iQ = \floor(6 + 52 / ($iN + 1));
$iSum = self::int32($iQ * $iDelta);
while ($iSum != 0)
{
$iE = $iSum >> 2 & 3;
for ($iPIndex = $iN; $iPIndex > 0; $iPIndex--)
{
$iZ = $aV[$iPIndex - 1];
$iMx = self::int32((($iZ >> 5 & 0x07ffffff) ^ $iY << 2) +
(($iY >> 3 & 0x1fffffff) ^ $iZ << 4)) ^ self::int32(($iSum ^ $iY) + ($aK[$iPIndex & 3 ^ $iE] ^ $iZ));
$iY = $aV[$iPIndex] = self::int32($aV[$iPIndex] - $iMx);
}
$iZ = $aV[$iN];
$iMx = self::int32((($iZ >> 5 & 0x07ffffff) ^ $iY << 2) +
(($iY >> 3 & 0x1fffffff) ^ $iZ << 4)) ^ self::int32(($iSum ^ $iY) + ($aK[$iPIndex & 3 ^ $iE] ^ $iZ));
$iY = $aV[0] = self::int32($aV[0] - $iMx);
$iSum = self::int32($iSum - $iDelta);
}
return self::long2str($aV, true);
}
/**
* @param array $aV
* @param array $aW
*
* @return string
*/
private static function long2str($aV, $aW)
{
$iLen = \count($aV);
$iN = ($iLen - 1) << 2;
if ($aW)
{
$iM = $aV[$iLen - 1];
if (($iM < $iN - 3) || ($iM > $iN))
{
return false;
}
$iN = $iM;
}
$aS = array();
for ($iIndex = 0; $iIndex < $iLen; $iIndex++)
{
$aS[$iIndex] = \pack('V', $aV[$iIndex]);
}
if ($aW)
{
return \substr(\join('', $aS), 0, $iN);
}
else
{
return \join('', $aS);
}
}
/**
* @param string $sS
* @param string $sW
*
* @return array
*/
private static function str2long($sS, $sW)
{
$aV = \unpack('V*', $sS . \str_repeat("\0", (4 - \strlen($sS) % 4) & 3));
$aV = \array_values($aV);
if ($sW)
{
$aV[\count($aV)] = \strlen($sS);
}
return $aV;
}
/**
* @param int $iN
*
* @return int
*/
private static function int32($iN)
{
while ($iN >= 2147483648)
{
$iN -= 4294967296;
}
while ($iN <= -2147483649)
{
$iN += 4294967296;
}
return (int) $iN;
}
}

View file

@ -1,154 +1,154 @@
<?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\Base;
/**
* @category MailSo
* @package Base
*/
class DateTimeHelper
{
/**
* @access private
*/
private function __construct()
{
}
/**
* @staticvar \DateTimeZone $oDateTimeZone
*
* @return \DateTimeZone
*/
public static function GetUtcTimeZoneObject()
{
static $oDateTimeZone = null;
if (null === $oDateTimeZone)
{
$oDateTimeZone = new \DateTimeZone('UTC');
}
return $oDateTimeZone;
}
/**
* Parse date string formated as "Thu, 10 Jun 2010 08:58:33 -0700 (PDT)"
* RFC2822
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseRFC2822DateString($sDateTime)
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
{
return 0;
}
$sDateTime = \trim(\preg_replace('/ \([a-zA-Z0-9]+\)$/', '', $sDateTime));
$oDateTime = \DateTime::createFromFormat('D, d M Y H:i:s O', $sDateTime, \MailSo\Base\DateTimeHelper::GetUtcTimeZoneObject());
return $oDateTime ? $oDateTime->getTimestamp() : 0;
}
/**
* Parse date string formated as "10-Jan-2012 01:58:17 -0800"
* IMAP INTERNALDATE Format
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseInternalDateString($sDateTime)
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
{
return 0;
}
if (\preg_match('/^[a-z]{2,4}, /i', $sDateTime)) // RFC2822 ~ "Thu, 10 Jun 2010 08:58:33 -0700 (PDT)"
{
return \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sDateTime);
}
$oDateTime = \DateTime::createFromFormat('d-M-Y H:i:s O', $sDateTime, \MailSo\Base\DateTimeHelper::GetUtcTimeZoneObject());
return $oDateTime ? $oDateTime->getTimestamp() : 0;
}
/**
* Parse date string formated as "2011-06-14 23:59:59 +0400"
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseDateStringType1($sDateTime)
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
{
return 0;
}
$oDateTime = \DateTime::createFromFormat('Y-m-d H:i:s O', $sDateTime, \MailSo\Base\DateTimeHelper::GetUtcTimeZoneObject());
return $oDateTime ? $oDateTime->getTimestamp() : 0;
}
/**
* Parse date string formated as "2015-05-08T14:32:18.483-07:00"
*
* @param string $sDateTime
*
* @return int
*/
public static function TryToParseSpecEtagFormat($sDateTime)
{
$sDateTime = \trim(\preg_replace('/ \([a-zA-Z0-9]+\)$/', '', \trim($sDateTime)));
$sDateTime = \trim(\preg_replace('/(:[\d]{2})\.[\d]{3}/', '$1', \trim($sDateTime)));
$sDateTime = \trim(\preg_replace('/(-[\d]{2})T([\d]{2}:)/', '$1 $2', \trim($sDateTime)));
$sDateTime = \trim(\preg_replace('/([\-+][\d]{2}):([\d]{2})$/', ' $1$2', \trim($sDateTime)));
return \MailSo\Base\DateTimeHelper::ParseDateStringType1($sDateTime);
}
/**
* @param string $sTime
*
* @return int
*/
public static function TimeToSec($sTime)
{
$iMod = 1;
$sTime = \trim($sTime);
if ('-' === \substr($sTime, 0, 1))
{
$iMod = -1;
$sTime = \substr($sTime, 1);
}
$aParts = \preg_split('/[:.,]/', (string) $sTime);
$iResult = 0;
if (isset($aParts[0]) && \is_numeric($aParts[0]))
{
$iResult += 3600 * ((int) $aParts[0]);
}
if (isset($aParts[1]) && \is_numeric($aParts[1]))
{
$iResult += 60 * ((int) $aParts[1]);
}
return $iResult * $iMod;
}
}
<?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\Base;
/**
* @category MailSo
* @package Base
*/
class DateTimeHelper
{
/**
* @access private
*/
private function __construct()
{
}
/**
* @staticvar \DateTimeZone $oDateTimeZone
*
* @return \DateTimeZone
*/
public static function GetUtcTimeZoneObject()
{
static $oDateTimeZone = null;
if (null === $oDateTimeZone)
{
$oDateTimeZone = new \DateTimeZone('UTC');
}
return $oDateTimeZone;
}
/**
* Parse date string formated as "Thu, 10 Jun 2010 08:58:33 -0700 (PDT)"
* RFC2822
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseRFC2822DateString($sDateTime)
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
{
return 0;
}
$sDateTime = \trim(\preg_replace('/ \([a-zA-Z0-9]+\)$/', '', $sDateTime));
$oDateTime = \DateTime::createFromFormat('D, d M Y H:i:s O', $sDateTime, \MailSo\Base\DateTimeHelper::GetUtcTimeZoneObject());
return $oDateTime ? $oDateTime->getTimestamp() : 0;
}
/**
* Parse date string formated as "10-Jan-2012 01:58:17 -0800"
* IMAP INTERNALDATE Format
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseInternalDateString($sDateTime)
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
{
return 0;
}
if (\preg_match('/^[a-z]{2,4}, /i', $sDateTime)) // RFC2822 ~ "Thu, 10 Jun 2010 08:58:33 -0700 (PDT)"
{
return \MailSo\Base\DateTimeHelper::ParseRFC2822DateString($sDateTime);
}
$oDateTime = \DateTime::createFromFormat('d-M-Y H:i:s O', $sDateTime, \MailSo\Base\DateTimeHelper::GetUtcTimeZoneObject());
return $oDateTime ? $oDateTime->getTimestamp() : 0;
}
/**
* Parse date string formated as "2011-06-14 23:59:59 +0400"
*
* @param string $sDateTime
*
* @return int
*/
public static function ParseDateStringType1($sDateTime)
{
$sDateTime = \trim($sDateTime);
if (empty($sDateTime))
{
return 0;
}
$oDateTime = \DateTime::createFromFormat('Y-m-d H:i:s O', $sDateTime, \MailSo\Base\DateTimeHelper::GetUtcTimeZoneObject());
return $oDateTime ? $oDateTime->getTimestamp() : 0;
}
/**
* Parse date string formated as "2015-05-08T14:32:18.483-07:00"
*
* @param string $sDateTime
*
* @return int
*/
public static function TryToParseSpecEtagFormat($sDateTime)
{
$sDateTime = \trim(\preg_replace('/ \([a-zA-Z0-9]+\)$/', '', \trim($sDateTime)));
$sDateTime = \trim(\preg_replace('/(:[\d]{2})\.[\d]{3}/', '$1', \trim($sDateTime)));
$sDateTime = \trim(\preg_replace('/(-[\d]{2})T([\d]{2}:)/', '$1 $2', \trim($sDateTime)));
$sDateTime = \trim(\preg_replace('/([\-+][\d]{2}):([\d]{2})$/', ' $1$2', \trim($sDateTime)));
return \MailSo\Base\DateTimeHelper::ParseDateStringType1($sDateTime);
}
/**
* @param string $sTime
*
* @return int
*/
public static function TimeToSec($sTime)
{
$iMod = 1;
$sTime = \trim($sTime);
if ('-' === \substr($sTime, 0, 1))
{
$iMod = -1;
$sTime = \substr($sTime, 1);
}
$aParts = \preg_split('/[:.,]/', (string) $sTime);
$iResult = 0;
if (isset($aParts[0]) && \is_numeric($aParts[0]))
{
$iResult += 3600 * ((int) $aParts[0]);
}
if (isset($aParts[1]) && \is_numeric($aParts[1]))
{
$iResult += 60 * ((int) $aParts[1]);
}
return $iResult * $iMod;
}
}

View file

@ -1,33 +1,33 @@
<?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\Base\Enumerations;
/**
* @category MailSo
* @package Base
* @subpackage Enumerations
*/
class Encoding
{
const QUOTED_PRINTABLE = 'Quoted-Printable';
const QUOTED_PRINTABLE_LOWER = 'quoted-printable';
const QUOTED_PRINTABLE_SHORT = 'Q';
const BASE64 = 'Base64';
const BASE64_LOWER = 'base64';
const BASE64_SHORT = 'B';
const SEVEN_BIT = '7bit';
const _7_BIT = '7bit';
const EIGHT_BIT = '8bit';
const _8_BIT = '8bit';
}
<?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\Base\Enumerations;
/**
* @category MailSo
* @package Base
* @subpackage Enumerations
*/
class Encoding
{
const QUOTED_PRINTABLE = 'Quoted-Printable';
const QUOTED_PRINTABLE_LOWER = 'quoted-printable';
const QUOTED_PRINTABLE_SHORT = 'Q';
const BASE64 = 'Base64';
const BASE64_LOWER = 'base64';
const BASE64_SHORT = 'B';
const SEVEN_BIT = '7bit';
const _7_BIT = '7bit';
const EIGHT_BIT = '8bit';
const _8_BIT = '8bit';
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,298 +1,298 @@
<?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\Base;
/**
* @category MailSo
* @package Base
*/
class LinkFinder
{
/**
* @const
*/
const OPEN_LINK = '@#@link{';
const CLOSE_LINK = '}link@#@';
/**
* @var array
*/
private $aPrepearPlainStringUrls;
/**
* @var string
*/
private $sText;
/**
* @var mixed
*/
private $fLinkWrapper;
/**
* @var int
*/
private $iHtmlSpecialCharsFlags;
/**
* @var mixed
*/
private $fMailWrapper;
/**
* @var int
*/
private $iOptimizationLimit;
/**
* @access private
*/
private function __construct()
{
$this->iHtmlSpecialCharsFlags = (\defined('ENT_QUOTES') && \defined('ENT_SUBSTITUTE') && \defined('ENT_HTML401'))
? ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 : ENT_QUOTES;
if (\defined('ENT_IGNORE'))
{
$this->iHtmlSpecialCharsFlags |= ENT_IGNORE;
}
$this->iOptimizationLimit = 300000;
$this->Clear();
}
/**
* @return \MailSo\Base\LinkFinder
*/
public static function NewInstance()
{
return new self();
}
/**
* @return \MailSo\Base\LinkFinder
*/
public function Clear()
{
$this->aPrepearPlainStringUrls = array();
$this->fLinkWrapper = null;
$this->fMailWrapper = null;
$this->sText = '';
return $this;
}
/**
* @param string $sText
*
* @return \MailSo\Base\LinkFinder
*/
public function Text($sText)
{
$this->sText = $sText;
return $this;
}
/**
* @param mixed $fLinkWrapper
*
* @return \MailSo\Base\LinkFinder
*/
public function LinkWrapper($fLinkWrapper)
{
$this->fLinkWrapper = $fLinkWrapper;
return $this;
}
/**
* @param mixed $fMailWrapper
*
* @return \MailSo\Base\LinkFinder
*/
public function MailWrapper($fMailWrapper)
{
$this->fMailWrapper = $fMailWrapper;
return $this;
}
/**
* @param bool $bAddTargetBlank = false
*
* @return \MailSo\Base\LinkFinder
*/
public function UseDefaultWrappers($bAddTargetBlank = false)
{
$this->fLinkWrapper = function ($sLink) use ($bAddTargetBlank) {
$sNameLink = $sLink;
if (!\preg_match('/^[a-z]{3,5}\:\/\//i', \ltrim($sLink)))
{
$sLink = 'http://'.\ltrim($sLink);
}
return '<a '.($bAddTargetBlank ? 'target="_blank" ': '').'href="'.$sLink.'">'.$sNameLink.'</a>';
};
$this->fMailWrapper = function ($sEmail) use ($bAddTargetBlank) {
return '<a '.($bAddTargetBlank ? 'target="_blank" ': '').'href="mailto:'.$sEmail.'">'.$sEmail.'</a>';
};
return $this;
}
/**
* @param bool $bUseHtmlSpecialChars = true
*
* @return string
*/
public function CompileText($bUseHtmlSpecialChars = true)
{
$sText = \substr($this->sText, 0, $this->iOptimizationLimit);
$sSubText = \substr($this->sText, $this->iOptimizationLimit);
$this->aPrepearPlainStringUrls = array();
if (null !== $this->fLinkWrapper && \is_callable($this->fLinkWrapper))
{
$sText = $this->findLinks($sText, $this->fLinkWrapper);
}
if (null !== $this->fMailWrapper && \is_callable($this->fMailWrapper))
{
$sText = $this->findMails($sText, $this->fMailWrapper);
}
$sResult = '';
if ($bUseHtmlSpecialChars)
{
$sResult = @\htmlentities($sText.$sSubText, $this->iHtmlSpecialCharsFlags, 'UTF-8');
}
else
{
$sResult = $sText.$sSubText;
}
unset($sText, $sSubText);
if (0 < \count($this->aPrepearPlainStringUrls))
{
$aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls;
$sResult = \preg_replace_callback('/'.\preg_quote(\MailSo\Base\LinkFinder::OPEN_LINK, '/').
'([\d]+)'.\preg_quote(\MailSo\Base\LinkFinder::CLOSE_LINK, '/').'/',
function ($aMatches) use ($aPrepearPlainStringUrls) {
$iIndex = (int) $aMatches[1];
return isset($aPrepearPlainStringUrls[$iIndex]) ? $aPrepearPlainStringUrls[$iIndex] : '';
}, $sResult);
$this->aPrepearPlainStringUrls = array();
}
return $sResult;
}
/**
* @param string $sText
* @param mixed $fWrapper
*
* @return string
*/
private function findLinks($sText, $fWrapper)
{
$sPattern = '/([\W]|^)((?:https?:\/\/)|(?:svn:\/\/)|(?:git:\/\/)|(?:s?ftps?:\/\/)|(?:www\.))'.
'((\S+?)(\\/)?)((?:&gt;)?|[^\w\=\\/;\(\)\[\]]*?)(?=<|\s|$)/imu';
$aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls;
$sText = \preg_replace_callback($sPattern, function ($aMatch) use ($fWrapper, &$aPrepearPlainStringUrls) {
if (\is_array($aMatch) && 6 < \count($aMatch))
{
while (\in_array($sChar = \substr($aMatch[3], -1), array(']', ')')))
{
if (\substr_count($aMatch[3], ']' === $sChar ? '[': '(') - \substr_count($aMatch[3], $sChar) < 0)
{
$aMatch[3] = \substr($aMatch[3], 0, -1);
$aMatch[6] = (']' === $sChar ? ']': ')').$aMatch[6];
}
else
{
break;
}
}
$sLinkWithWrap = \call_user_func($fWrapper, $aMatch[2].$aMatch[3]);
if (\is_string($sLinkWithWrap) && 0 < \strlen($sLinkWithWrap))
{
$aPrepearPlainStringUrls[] = \stripslashes($sLinkWithWrap);
return $aMatch[1].
\MailSo\Base\LinkFinder::OPEN_LINK.
(\count($aPrepearPlainStringUrls) - 1).
\MailSo\Base\LinkFinder::CLOSE_LINK.
$aMatch[6];
}
return $aMatch[0];
}
return '';
}, $sText);
if (0 < \count($aPrepearPlainStringUrls))
{
$this->aPrepearPlainStringUrls = $aPrepearPlainStringUrls;
}
return $sText;
}
/**
* @param string $sText
* @param mixed $fWrapper
*
* @return string
*/
private function findMails($sText, $fWrapper)
{
$sPattern = '/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/';
$aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls;
$sText = \preg_replace_callback($sPattern, function ($aMatch) use ($fWrapper, &$aPrepearPlainStringUrls) {
if (\is_array($aMatch) && isset($aMatch[1]))
{
$sMailWithWrap = \call_user_func($fWrapper, $aMatch[1]);
if (\is_string($sMailWithWrap) && 0 < \strlen($sMailWithWrap))
{
$aPrepearPlainStringUrls[] = \stripslashes($sMailWithWrap);
return \MailSo\Base\LinkFinder::OPEN_LINK.
(\count($aPrepearPlainStringUrls) - 1).
\MailSo\Base\LinkFinder::CLOSE_LINK;
}
return $aMatch[1];
}
return '';
}, $sText);
if (0 < \count($aPrepearPlainStringUrls))
{
$this->aPrepearPlainStringUrls = $aPrepearPlainStringUrls;
}
return $sText;
}
<?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\Base;
/**
* @category MailSo
* @package Base
*/
class LinkFinder
{
/**
* @const
*/
const OPEN_LINK = '@#@link{';
const CLOSE_LINK = '}link@#@';
/**
* @var array
*/
private $aPrepearPlainStringUrls;
/**
* @var string
*/
private $sText;
/**
* @var mixed
*/
private $fLinkWrapper;
/**
* @var int
*/
private $iHtmlSpecialCharsFlags;
/**
* @var mixed
*/
private $fMailWrapper;
/**
* @var int
*/
private $iOptimizationLimit;
/**
* @access private
*/
private function __construct()
{
$this->iHtmlSpecialCharsFlags = (\defined('ENT_QUOTES') && \defined('ENT_SUBSTITUTE') && \defined('ENT_HTML401'))
? ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 : ENT_QUOTES;
if (\defined('ENT_IGNORE'))
{
$this->iHtmlSpecialCharsFlags |= ENT_IGNORE;
}
$this->iOptimizationLimit = 300000;
$this->Clear();
}
/**
* @return \MailSo\Base\LinkFinder
*/
public static function NewInstance()
{
return new self();
}
/**
* @return \MailSo\Base\LinkFinder
*/
public function Clear()
{
$this->aPrepearPlainStringUrls = array();
$this->fLinkWrapper = null;
$this->fMailWrapper = null;
$this->sText = '';
return $this;
}
/**
* @param string $sText
*
* @return \MailSo\Base\LinkFinder
*/
public function Text($sText)
{
$this->sText = $sText;
return $this;
}
/**
* @param mixed $fLinkWrapper
*
* @return \MailSo\Base\LinkFinder
*/
public function LinkWrapper($fLinkWrapper)
{
$this->fLinkWrapper = $fLinkWrapper;
return $this;
}
/**
* @param mixed $fMailWrapper
*
* @return \MailSo\Base\LinkFinder
*/
public function MailWrapper($fMailWrapper)
{
$this->fMailWrapper = $fMailWrapper;
return $this;
}
/**
* @param bool $bAddTargetBlank = false
*
* @return \MailSo\Base\LinkFinder
*/
public function UseDefaultWrappers($bAddTargetBlank = false)
{
$this->fLinkWrapper = function ($sLink) use ($bAddTargetBlank) {
$sNameLink = $sLink;
if (!\preg_match('/^[a-z]{3,5}\:\/\//i', \ltrim($sLink)))
{
$sLink = 'http://'.\ltrim($sLink);
}
return '<a '.($bAddTargetBlank ? 'target="_blank" ': '').'href="'.$sLink.'">'.$sNameLink.'</a>';
};
$this->fMailWrapper = function ($sEmail) use ($bAddTargetBlank) {
return '<a '.($bAddTargetBlank ? 'target="_blank" ': '').'href="mailto:'.$sEmail.'">'.$sEmail.'</a>';
};
return $this;
}
/**
* @param bool $bUseHtmlSpecialChars = true
*
* @return string
*/
public function CompileText($bUseHtmlSpecialChars = true)
{
$sText = \substr($this->sText, 0, $this->iOptimizationLimit);
$sSubText = \substr($this->sText, $this->iOptimizationLimit);
$this->aPrepearPlainStringUrls = array();
if (null !== $this->fLinkWrapper && \is_callable($this->fLinkWrapper))
{
$sText = $this->findLinks($sText, $this->fLinkWrapper);
}
if (null !== $this->fMailWrapper && \is_callable($this->fMailWrapper))
{
$sText = $this->findMails($sText, $this->fMailWrapper);
}
$sResult = '';
if ($bUseHtmlSpecialChars)
{
$sResult = @\htmlentities($sText.$sSubText, $this->iHtmlSpecialCharsFlags, 'UTF-8');
}
else
{
$sResult = $sText.$sSubText;
}
unset($sText, $sSubText);
if (0 < \count($this->aPrepearPlainStringUrls))
{
$aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls;
$sResult = \preg_replace_callback('/'.\preg_quote(\MailSo\Base\LinkFinder::OPEN_LINK, '/').
'([\d]+)'.\preg_quote(\MailSo\Base\LinkFinder::CLOSE_LINK, '/').'/',
function ($aMatches) use ($aPrepearPlainStringUrls) {
$iIndex = (int) $aMatches[1];
return isset($aPrepearPlainStringUrls[$iIndex]) ? $aPrepearPlainStringUrls[$iIndex] : '';
}, $sResult);
$this->aPrepearPlainStringUrls = array();
}
return $sResult;
}
/**
* @param string $sText
* @param mixed $fWrapper
*
* @return string
*/
private function findLinks($sText, $fWrapper)
{
$sPattern = '/([\W]|^)((?:https?:\/\/)|(?:svn:\/\/)|(?:git:\/\/)|(?:s?ftps?:\/\/)|(?:www\.))'.
'((\S+?)(\\/)?)((?:&gt;)?|[^\w\=\\/;\(\)\[\]]*?)(?=<|\s|$)/imu';
$aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls;
$sText = \preg_replace_callback($sPattern, function ($aMatch) use ($fWrapper, &$aPrepearPlainStringUrls) {
if (\is_array($aMatch) && 6 < \count($aMatch))
{
while (\in_array($sChar = \substr($aMatch[3], -1), array(']', ')')))
{
if (\substr_count($aMatch[3], ']' === $sChar ? '[': '(') - \substr_count($aMatch[3], $sChar) < 0)
{
$aMatch[3] = \substr($aMatch[3], 0, -1);
$aMatch[6] = (']' === $sChar ? ']': ')').$aMatch[6];
}
else
{
break;
}
}
$sLinkWithWrap = \call_user_func($fWrapper, $aMatch[2].$aMatch[3]);
if (\is_string($sLinkWithWrap) && 0 < \strlen($sLinkWithWrap))
{
$aPrepearPlainStringUrls[] = \stripslashes($sLinkWithWrap);
return $aMatch[1].
\MailSo\Base\LinkFinder::OPEN_LINK.
(\count($aPrepearPlainStringUrls) - 1).
\MailSo\Base\LinkFinder::CLOSE_LINK.
$aMatch[6];
}
return $aMatch[0];
}
return '';
}, $sText);
if (0 < \count($aPrepearPlainStringUrls))
{
$this->aPrepearPlainStringUrls = $aPrepearPlainStringUrls;
}
return $sText;
}
/**
* @param string $sText
* @param mixed $fWrapper
*
* @return string
*/
private function findMails($sText, $fWrapper)
{
$sPattern = '/([\w\.!#\$%\-+.]+@[A-Za-z0-9\-]+(\.[A-Za-z0-9\-]+)+)/';
$aPrepearPlainStringUrls = $this->aPrepearPlainStringUrls;
$sText = \preg_replace_callback($sPattern, function ($aMatch) use ($fWrapper, &$aPrepearPlainStringUrls) {
if (\is_array($aMatch) && isset($aMatch[1]))
{
$sMailWithWrap = \call_user_func($fWrapper, $aMatch[1]);
if (\is_string($sMailWithWrap) && 0 < \strlen($sMailWithWrap))
{
$aPrepearPlainStringUrls[] = \stripslashes($sMailWithWrap);
return \MailSo\Base\LinkFinder::OPEN_LINK.
(\count($aPrepearPlainStringUrls) - 1).
\MailSo\Base\LinkFinder::CLOSE_LINK;
}
return $aMatch[1];
}
return '';
}, $sText);
if (0 < \count($aPrepearPlainStringUrls))
{
$this->aPrepearPlainStringUrls = $aPrepearPlainStringUrls;
}
return $sText;
}
}

File diff suppressed because it is too large Load diff

View file

@ -36,10 +36,7 @@ class CacheClient
$this->sCacheIndex = '';
}
/**
* @return \MailSo\Cache\CacheClient
*/
public static function NewInstance()
public static function NewInstance() : self
{
return new self();
}
@ -47,50 +44,40 @@ class CacheClient
/**
* @param string $sKey
* @param string $sValue
*
* @return bool
*/
public function Set($sKey, $sValue)
public function Set($sKey, $sValue) : bool
{
return $this->oDriver ? $this->oDriver->Set($sKey.$this->sCacheIndex, $sValue) : false;
}
/**
* @param string $sKey
*
* @return bool
*/
public function SetTimer($sKey)
public function SetTimer($sKey) : bool
{
return $this->Set($sKey.'/TIMER', time());
}
/**
* @param string $sKey
*
* @return bool
*/
public function SetLock($sKey)
public function SetLock($sKey) : bool
{
return $this->Set($sKey.'/LOCK', '1');
}
/**
* @param string $sKey
*
* @return bool
*/
public function RemoveLock($sKey)
public function RemoveLock($sKey) : bool
{
return $this->Set($sKey.'/LOCK', '0');
}
/**
* @param string $sKey
*
* @return bool
*/
public function GetLock($sKey)
public function GetLock($sKey) : bool
{
return '1' === $this->Get($sKey.'/LOCK');
}
@ -137,10 +124,8 @@ class CacheClient
/**
* @param string $sKey
*
* @return \MailSo\Cache\CacheClient
*/
public function Delete($sKey)
public function Delete($sKey) : self
{
if ($this->oDriver)
{
@ -152,10 +137,8 @@ class CacheClient
/**
* @param \MailSo\Cache\DriverInterface $oDriver
*
* @return \MailSo\Cache\CacheClient
*/
public function SetDriver(\MailSo\Cache\DriverInterface $oDriver)
public function SetDriver(\MailSo\Cache\DriverInterface $oDriver) : self
{
$this->oDriver = $oDriver;
@ -164,28 +147,21 @@ class CacheClient
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24)
public function GC($iTimeToClearInHours = 24) : bool
{
return $this->oDriver ? $this->oDriver->GC($iTimeToClearInHours) : false;
}
/**
* @return bool
*/
public function IsInited()
public function IsInited() : bool
{
return $this->oDriver instanceof \MailSo\Cache\DriverInterface;
}
/**
* @param string $sCacheIndex
*
* @return \MailSo\Cache\CacheClient
*/
public function SetCacheIndex($sCacheIndex)
public function SetCacheIndex($sCacheIndex) : self
{
$this->sCacheIndex = 0 < \strlen($sCacheIndex) ? "\x0".$sCacheIndex : '';
@ -194,10 +170,8 @@ class CacheClient
/**
* @param bool $bCache = false
*
* @return bool
*/
public function Verify($bCache = false)
public function Verify($bCache = false) : bool
{
if ($this->oDriver)
{

View file

@ -1,48 +1,46 @@
<?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\Cache;
/**
* @category MailSo
* @package Cache
*/
interface DriverInterface
{
/**
* @param string $sKey
* @param string $sValue
*
* @return bool
*/
public function Set($sKey, $sValue);
/**
* @param string $sKey
*
* @return string
*/
public function Get($sKey);
/**
* @param string $sKey
*
* @return void
*/
public function Delete($sKey);
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24);
}
<?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\Cache;
/**
* @category MailSo
* @package Cache
*/
interface DriverInterface
{
/**
* @param string $sKey
* @param string $sValue
*/
public function Set($sKey, $sValue) : bool;
/**
* @param string $sKey
*
* @return string
*/
public function Get($sKey);
/**
* @param string $sKey
*
* @return void
*/
public function Delete($sKey);
/**
* @param int $iTimeToClearInHours = 24
*
* @return bool
*/
public function GC($iTimeToClearInHours = 24);
}

View file

@ -51,10 +51,8 @@ class APC implements \MailSo\Cache\DriverInterface
/**
* @param string $sKey
* @param string $sValue
*
* @return bool
*/
public function Set($sKey, $sValue)
public function Set($sKey, $sValue) : bool
{
return \apc_store($this->generateCachedKey($sKey), (string) $sValue);
}

View file

@ -65,10 +65,8 @@ class File implements \MailSo\Cache\DriverInterface
/**
* @param string $sKey
* @param string $sValue
*
* @return bool
*/
public function Set($sKey, $sValue)
public function Set($sKey, $sValue) : bool
{
$sPath = $this->generateCachedFileName($sKey, true);
return '' === $sPath ? false : false !== \file_put_contents($sPath, $sValue);

View file

@ -85,10 +85,8 @@ class Memcache implements \MailSo\Cache\DriverInterface
/**
* @param string $sKey
* @param string $sValue
*
* @return bool
*/
public function Set($sKey, $sValue)
public function Set($sKey, $sValue) : bool
{
return $this->oMem ? $this->oMem->set($this->generateCachedKey($sKey), $sValue, 0, $this->iExpire) : false;
}

View file

@ -101,10 +101,8 @@ class Redis implements \MailSo\Cache\DriverInterface
/**
* @param string $sKey
* @param string $sValue
*
* @return bool
*/
public function Set($sKey, $sValue)
public function Set($sKey, $sValue) : bool
{
return $this->oRedis ? $this->oRedis->setex($this->generateCachedKey($sKey), $this->iExpire, $sValue) : false;
}

View file

@ -1,113 +1,113 @@
<?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;
/**
* @category MailSo
*/
class Config
{
/**
* @var bool
*/
public static $ICONV = true;
/**
* @var bool
*/
public static $MBSTRING = true;
/**
* @var array|null
*/
public static $HtmlStrictAllowedTags = null;
/**
* @var array|null
*/
public static $HtmlStrictAllowedAttributes = null;
/**
* @var boolean
*/
public static $HtmlStrictDebug = false;
/**
* @var bool
*/
public static $FixIconvByMbstring = true;
/**
* @var int
*/
public static $MessageListFastSimpleSearch = true;
/**
* @var int
*/
public static $MessageListCountLimitTrigger = 0;
/**
* @var bool
*/
public static $MessageListUndeletedOnly = true;
/**
* @var int
*/
public static $MessageListDateFilter = 0;
/**
* @var string
*/
public static $MessageListPermanentFilter = '';
/**
* @var int
*/
public static $LargeThreadLimit = 50;
/**
* @var bool
*/
public static $MessageAllHeaders = false;
/**
* @var bool
*/
public static $LogSimpleLiterals = false;
/**
* @var bool
*/
public static $CheckNewMessages = true;
/**
* @var bool
*/
public static $PreferStartTlsIfAutoDetect = true;
/**
* @var string
*/
public static $BoundaryPrefix = '_Part_';
/**
* @var int
*/
public static $ImapTimeout = 300;
/**
* @var \MailSo\Log\Logger|null
*/
public static $SystemLogger = null;
}
<?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;
/**
* @category MailSo
*/
class Config
{
/**
* @var bool
*/
public static $ICONV = true;
/**
* @var bool
*/
public static $MBSTRING = true;
/**
* @var array|null
*/
public static $HtmlStrictAllowedTags = null;
/**
* @var array|null
*/
public static $HtmlStrictAllowedAttributes = null;
/**
* @var boolean
*/
public static $HtmlStrictDebug = false;
/**
* @var bool
*/
public static $FixIconvByMbstring = true;
/**
* @var int
*/
public static $MessageListFastSimpleSearch = true;
/**
* @var int
*/
public static $MessageListCountLimitTrigger = 0;
/**
* @var bool
*/
public static $MessageListUndeletedOnly = true;
/**
* @var int
*/
public static $MessageListDateFilter = 0;
/**
* @var string
*/
public static $MessageListPermanentFilter = '';
/**
* @var int
*/
public static $LargeThreadLimit = 50;
/**
* @var bool
*/
public static $MessageAllHeaders = false;
/**
* @var bool
*/
public static $LogSimpleLiterals = false;
/**
* @var bool
*/
public static $CheckNewMessages = true;
/**
* @var bool
*/
public static $PreferStartTlsIfAutoDetect = true;
/**
* @var string
*/
public static $BoundaryPrefix = '_Part_';
/**
* @var int
*/
public static $ImapTimeout = 300;
/**
* @var \MailSo\Log\Logger|null
*/
public static $SystemLogger = null;
}

View file

@ -1,55 +1,55 @@
<?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;
/**
* @category MailSo
*/
class Hooks
{
/**
* @var array
*/
static $aCallbacks = array();
/**
* @param string $sName
* @param array $aArg
*/
static public function Run($sName, $aArg = array())
{
if (isset(\MailSo\Hooks::$aCallbacks[$sName]))
{
foreach (\MailSo\Hooks::$aCallbacks[$sName] as $mCallback)
{
\call_user_func_array($mCallback, $aArg);
}
}
}
/**
* @param string $sName
* @param mixed $mCallback
*/
static public function Add($sName, $mCallback)
{
if (\is_callable($mCallback))
{
if (!isset(\MailSo\Hooks::$aCallbacks[$sName]))
{
\MailSo\Hooks::$aCallbacks[$sName] = array();
}
\MailSo\Hooks::$aCallbacks[$sName][] = $mCallback;
}
}
}
<?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;
/**
* @category MailSo
*/
class Hooks
{
/**
* @var array
*/
static $aCallbacks = array();
/**
* @param string $sName
* @param array $aArg
*/
static public function Run($sName, $aArg = array())
{
if (isset(\MailSo\Hooks::$aCallbacks[$sName]))
{
foreach (\MailSo\Hooks::$aCallbacks[$sName] as $mCallback)
{
\call_user_func_array($mCallback, $aArg);
}
}
}
/**
* @param string $sName
* @param mixed $mCallback
*/
static public function Add($sName, $mCallback)
{
if (\is_callable($mCallback))
{
if (!isset(\MailSo\Hooks::$aCallbacks[$sName]))
{
\MailSo\Hooks::$aCallbacks[$sName] = array();
}
\MailSo\Hooks::$aCallbacks[$sName][] = $mCallback;
}
}
}

View file

@ -81,7 +81,7 @@ class FetchType
/**
* @param array $aFetchItems
*
*
* @return array
*/
public static function ChangeFetchItemsBefourRequest(array $aFetchItems)

View file

@ -24,7 +24,7 @@ class StoreAction
const ADD_FLAGS_SILENT = '+FLAGS.SILENT';
const REMOVE_FLAGS = '-FLAGS';
const REMOVE_FLAGS_SILENT = '-FLAGS.SILENT';
const SET_GMAIL_LABELS = 'X-GM-LABELS';
const SET_GMAIL_LABELS_SILENT = 'X-GM-LABELS.SILENT';
const ADD_GMAIL_LABELS = '+X-GM-LABELS';

View file

@ -1,273 +1,273 @@
<?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\Imap;
/**
* @category MailSo
* @package Imap
*/
class FetchResponse
{
/**
* @var \MailSo\Imap\Response
*/
private $oImapResponse;
/**
* @var array|null
*/
private $aEnvelopeCache;
/**
* @access private
*
* @param \MailSo\Imap\Response $oImapResponse
*/
private function __construct($oImapResponse)
{
$this->oImapResponse = $oImapResponse;
$this->aEnvelopeCache = null;
}
/**
* @param \MailSo\Imap\Response $oImapResponse
* @return \MailSo\Imap\FetchResponse
*/
public static function NewInstance($oImapResponse)
{
return new self($oImapResponse);
}
/**
* @param bool $bForce = false
*
* @return array|null
*/
public function GetEnvelope($bForce = false)
{
if (null === $this->aEnvelopeCache || $bForce)
{
$this->aEnvelopeCache = $this->GetFetchValue(Enumerations\FetchType::ENVELOPE);
}
return $this->aEnvelopeCache;
}
/**
* @param int $iIndex
* @param mixed $mNullResult = null
*
* @return mixed
*/
public function GetFetchEnvelopeValue($iIndex, $mNullResult)
{
return self::findEnvelopeIndex($this->GetEnvelope(), $iIndex, $mNullResult);
}
/**
* @param int $iIndex
* @param string $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1
*
* @return \MailSo\Mime\EmailCollection|null
*/
public function GetFetchEnvelopeEmailCollection($iIndex, $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1)
{
$oResult = null;
$aEmails = $this->GetFetchEnvelopeValue($iIndex, null);
if (is_array($aEmails) && 0 < count($aEmails))
{
$oResult = \MailSo\Mime\EmailCollection::NewInstance();
foreach ($aEmails as $aEmailItem)
{
if (is_array($aEmailItem) && 4 === count($aEmailItem))
{
$sDisplayName = \MailSo\Base\Utils::DecodeHeaderValue(
self::findEnvelopeIndex($aEmailItem, 0, ''), $sParentCharset);
// $sRemark = \MailSo\Base\Utils::DecodeHeaderValue(
// self::findEnvelopeIndex($aEmailItem, 1, ''), $sParentCharset);
$sLocalPart = self::findEnvelopeIndex($aEmailItem, 2, '');
$sDomainPart = self::findEnvelopeIndex($aEmailItem, 3, '');
if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart))
{
$oResult->Add(
\MailSo\Mime\Email::NewInstance($sLocalPart.'@'.$sDomainPart, $sDisplayName)
);
}
}
}
}
return $oResult;
}
/**
* @param string $sRfc822SubMimeIndex = ''
*
* @return \MailSo\Imap\BodyStructure|null
*/
public function GetFetchBodyStructure($sRfc822SubMimeIndex = '')
{
$oBodyStructure = null;
$aBodyStructureArray = $this->GetFetchValue(Enumerations\FetchType::BODYSTRUCTURE);
if (is_array($aBodyStructureArray))
{
if (0 < strlen($sRfc822SubMimeIndex))
{
$oBodyStructure = BodyStructure::NewInstanceFromRfc822SubPart($aBodyStructureArray, $sRfc822SubMimeIndex);
}
else
{
$oBodyStructure = BodyStructure::NewInstance($aBodyStructureArray);
}
}
return $oBodyStructure;
}
/**
* @param string $sFetchItemName
*
* @return mixed
*/
public function GetFetchValue($sFetchItemName)
{
$mReturn = null;
$bNextIsValue = false;
if (Enumerations\FetchType::INDEX === $sFetchItemName)
{
$mReturn = $this->oImapResponse->ResponseList[1];
}
else if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3]))
{
foreach ($this->oImapResponse->ResponseList[3] as $mItem)
{
if ($bNextIsValue)
{
$mReturn = $mItem;
break;
}
if ($sFetchItemName === $mItem)
{
$bNextIsValue = true;
}
}
}
return $mReturn;
}
/**
* @param string $sRfc822SubMimeIndex = ''
*
* @return string
*/
public function GetHeaderFieldsValue($sRfc822SubMimeIndex = '')
{
$sReturn = '';
$bNextIsValue = false;
$sRfc822SubMimeIndex = 0 < \strlen($sRfc822SubMimeIndex) ? ''.$sRfc822SubMimeIndex.'.' : '';
if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3]))
{
foreach ($this->oImapResponse->ResponseList[3] as $mItem)
{
if ($bNextIsValue)
{
$sReturn = (string) $mItem;
break;
}
if (\is_string($mItem) && (
$mItem === 'BODY['.$sRfc822SubMimeIndex.'HEADER]' ||
0 === \strpos($mItem, 'BODY['.$sRfc822SubMimeIndex.'HEADER.FIELDS') ||
$mItem === 'BODY['.$sRfc822SubMimeIndex.'MIME]'))
{
$bNextIsValue = true;
}
}
}
return $sReturn;
}
private static function findFetchUidAndSize($aList)
{
$bUid = false;
$bSize = false;
if (is_array($aList))
{
foreach ($aList as $mItem)
{
if (\MailSo\Imap\Enumerations\FetchType::UID === $mItem)
{
$bUid = true;
}
else if (\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE === $mItem)
{
$bSize = true;
}
}
}
return $bUid && $bSize;
}
/**
* @param \MailSo\Imap\Response $oImapResponse
*
* @return bool
*/
public static function IsValidFetchImapResponse($oImapResponse)
{
return (
$oImapResponse
&& true !== $oImapResponse->IsStatusResponse
&& \MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType
&& 3 < count($oImapResponse->ResponseList) && 'FETCH' === $oImapResponse->ResponseList[2]
&& is_array($oImapResponse->ResponseList[3])
);
}
/**
* @param \MailSo\Imap\Response $oImapResponse
*
* @return bool
*/
public static function IsNotEmptyFetchImapResponse($oImapResponse)
{
return (
$oImapResponse
&& self::IsValidFetchImapResponse($oImapResponse)
&& isset($oImapResponse->ResponseList[3])
&& self::findFetchUidAndSize($oImapResponse->ResponseList[3])
);
}
/**
* @param array $aEnvelope
* @param int $iIndex
* @param mixed $mNullResult = null
*
* @return mixed
*/
private static function findEnvelopeIndex($aEnvelope, $iIndex, $mNullResult)
{
return (isset($aEnvelope[$iIndex]) && 'NIL' !== $aEnvelope[$iIndex] && '' !== $aEnvelope[$iIndex])
? $aEnvelope[$iIndex] : $mNullResult;
}
}
<?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\Imap;
/**
* @category MailSo
* @package Imap
*/
class FetchResponse
{
/**
* @var \MailSo\Imap\Response
*/
private $oImapResponse;
/**
* @var array|null
*/
private $aEnvelopeCache;
/**
* @access private
*
* @param \MailSo\Imap\Response $oImapResponse
*/
private function __construct($oImapResponse)
{
$this->oImapResponse = $oImapResponse;
$this->aEnvelopeCache = null;
}
/**
* @param \MailSo\Imap\Response $oImapResponse
* @return \MailSo\Imap\FetchResponse
*/
public static function NewInstance($oImapResponse)
{
return new self($oImapResponse);
}
/**
* @param bool $bForce = false
*
* @return array|null
*/
public function GetEnvelope($bForce = false)
{
if (null === $this->aEnvelopeCache || $bForce)
{
$this->aEnvelopeCache = $this->GetFetchValue(Enumerations\FetchType::ENVELOPE);
}
return $this->aEnvelopeCache;
}
/**
* @param int $iIndex
* @param mixed $mNullResult = null
*
* @return mixed
*/
public function GetFetchEnvelopeValue($iIndex, $mNullResult)
{
return self::findEnvelopeIndex($this->GetEnvelope(), $iIndex, $mNullResult);
}
/**
* @param int $iIndex
* @param string $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1
*
* @return \MailSo\Mime\EmailCollection|null
*/
public function GetFetchEnvelopeEmailCollection($iIndex, $sParentCharset = \MailSo\Base\Enumerations\Charset::ISO_8859_1)
{
$oResult = null;
$aEmails = $this->GetFetchEnvelopeValue($iIndex, null);
if (is_array($aEmails) && 0 < count($aEmails))
{
$oResult = \MailSo\Mime\EmailCollection::NewInstance();
foreach ($aEmails as $aEmailItem)
{
if (is_array($aEmailItem) && 4 === count($aEmailItem))
{
$sDisplayName = \MailSo\Base\Utils::DecodeHeaderValue(
self::findEnvelopeIndex($aEmailItem, 0, ''), $sParentCharset);
// $sRemark = \MailSo\Base\Utils::DecodeHeaderValue(
// self::findEnvelopeIndex($aEmailItem, 1, ''), $sParentCharset);
$sLocalPart = self::findEnvelopeIndex($aEmailItem, 2, '');
$sDomainPart = self::findEnvelopeIndex($aEmailItem, 3, '');
if (0 < strlen($sLocalPart) && 0 < strlen($sDomainPart))
{
$oResult->Add(
\MailSo\Mime\Email::NewInstance($sLocalPart.'@'.$sDomainPart, $sDisplayName)
);
}
}
}
}
return $oResult;
}
/**
* @param string $sRfc822SubMimeIndex = ''
*
* @return \MailSo\Imap\BodyStructure|null
*/
public function GetFetchBodyStructure($sRfc822SubMimeIndex = '')
{
$oBodyStructure = null;
$aBodyStructureArray = $this->GetFetchValue(Enumerations\FetchType::BODYSTRUCTURE);
if (is_array($aBodyStructureArray))
{
if (0 < strlen($sRfc822SubMimeIndex))
{
$oBodyStructure = BodyStructure::NewInstanceFromRfc822SubPart($aBodyStructureArray, $sRfc822SubMimeIndex);
}
else
{
$oBodyStructure = BodyStructure::NewInstance($aBodyStructureArray);
}
}
return $oBodyStructure;
}
/**
* @param string $sFetchItemName
*
* @return mixed
*/
public function GetFetchValue($sFetchItemName)
{
$mReturn = null;
$bNextIsValue = false;
if (Enumerations\FetchType::INDEX === $sFetchItemName)
{
$mReturn = $this->oImapResponse->ResponseList[1];
}
else if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3]))
{
foreach ($this->oImapResponse->ResponseList[3] as $mItem)
{
if ($bNextIsValue)
{
$mReturn = $mItem;
break;
}
if ($sFetchItemName === $mItem)
{
$bNextIsValue = true;
}
}
}
return $mReturn;
}
/**
* @param string $sRfc822SubMimeIndex = ''
*
* @return string
*/
public function GetHeaderFieldsValue($sRfc822SubMimeIndex = '')
{
$sReturn = '';
$bNextIsValue = false;
$sRfc822SubMimeIndex = 0 < \strlen($sRfc822SubMimeIndex) ? ''.$sRfc822SubMimeIndex.'.' : '';
if (isset($this->oImapResponse->ResponseList[3]) && \is_array($this->oImapResponse->ResponseList[3]))
{
foreach ($this->oImapResponse->ResponseList[3] as $mItem)
{
if ($bNextIsValue)
{
$sReturn = (string) $mItem;
break;
}
if (\is_string($mItem) && (
$mItem === 'BODY['.$sRfc822SubMimeIndex.'HEADER]' ||
0 === \strpos($mItem, 'BODY['.$sRfc822SubMimeIndex.'HEADER.FIELDS') ||
$mItem === 'BODY['.$sRfc822SubMimeIndex.'MIME]'))
{
$bNextIsValue = true;
}
}
}
return $sReturn;
}
private static function findFetchUidAndSize($aList)
{
$bUid = false;
$bSize = false;
if (is_array($aList))
{
foreach ($aList as $mItem)
{
if (\MailSo\Imap\Enumerations\FetchType::UID === $mItem)
{
$bUid = true;
}
else if (\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE === $mItem)
{
$bSize = true;
}
}
}
return $bUid && $bSize;
}
/**
* @param \MailSo\Imap\Response $oImapResponse
*
* @return bool
*/
public static function IsValidFetchImapResponse($oImapResponse)
{
return (
$oImapResponse
&& true !== $oImapResponse->IsStatusResponse
&& \MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType
&& 3 < count($oImapResponse->ResponseList) && 'FETCH' === $oImapResponse->ResponseList[2]
&& is_array($oImapResponse->ResponseList[3])
);
}
/**
* @param \MailSo\Imap\Response $oImapResponse
*
* @return bool
*/
public static function IsNotEmptyFetchImapResponse($oImapResponse)
{
return (
$oImapResponse
&& self::IsValidFetchImapResponse($oImapResponse)
&& isset($oImapResponse->ResponseList[3])
&& self::findFetchUidAndSize($oImapResponse->ResponseList[3])
);
}
/**
* @param array $aEnvelope
* @param int $iIndex
* @param mixed $mNullResult = null
*
* @return mixed
*/
private static function findEnvelopeIndex($aEnvelope, $iIndex, $mNullResult)
{
return (isset($aEnvelope[$iIndex]) && 'NIL' !== $aEnvelope[$iIndex] && '' !== $aEnvelope[$iIndex])
? $aEnvelope[$iIndex] : $mNullResult;
}
}

View file

@ -1,112 +1,112 @@
<?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\Imap;
/**
* @category MailSo
* @package Imap
*/
class FolderInformation
{
/**
* @var string
*/
public $FolderName;
/**
* @var bool
*/
public $IsWritable;
/**
* @var array
*/
public $Flags;
/**
* @var array
*/
public $PermanentFlags;
/**
* @var int
*/
public $Exists;
/**
* @var int
*/
public $Recent;
/**
* @var string
*/
public $Uidvalidity;
/**
* @var int
*/
public $Unread;
/**
* @var string
*/
public $Uidnext;
/**
* @var string
*/
public $HighestModSeq;
/**
* @access private
*
* @param string $sFolderName
* @param bool $bIsWritable
*/
private function __construct($sFolderName, $bIsWritable)
{
$this->FolderName = $sFolderName;
$this->IsWritable = $bIsWritable;
$this->Exists = null;
$this->Recent = null;
$this->Flags = array();
$this->PermanentFlags = array();
$this->Unread = null;
$this->Uidnext = null;
$this->HighestModSeq = null;
}
/**
* @param string $sFolderName
* @param bool $bIsWritable
*
* @return \MailSo\Imap\FolderInformation
*/
public static function NewInstance($sFolderName, $bIsWritable)
{
return new self($sFolderName, $bIsWritable);
}
/**
* @param string $sFlag
*
* @return bool
*/
public function IsFlagSupported($sFlag)
{
return \in_array('\\*', $this->PermanentFlags) ||
\in_array($sFlag, $this->PermanentFlags) ||
\in_array($sFlag, $this->Flags);
}
}
<?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\Imap;
/**
* @category MailSo
* @package Imap
*/
class FolderInformation
{
/**
* @var string
*/
public $FolderName;
/**
* @var bool
*/
public $IsWritable;
/**
* @var array
*/
public $Flags;
/**
* @var array
*/
public $PermanentFlags;
/**
* @var int
*/
public $Exists;
/**
* @var int
*/
public $Recent;
/**
* @var string
*/
public $Uidvalidity;
/**
* @var int
*/
public $Unread;
/**
* @var string
*/
public $Uidnext;
/**
* @var string
*/
public $HighestModSeq;
/**
* @access private
*
* @param string $sFolderName
* @param bool $bIsWritable
*/
private function __construct($sFolderName, $bIsWritable)
{
$this->FolderName = $sFolderName;
$this->IsWritable = $bIsWritable;
$this->Exists = null;
$this->Recent = null;
$this->Flags = array();
$this->PermanentFlags = array();
$this->Unread = null;
$this->Uidnext = null;
$this->HighestModSeq = null;
}
/**
* @param string $sFolderName
* @param bool $bIsWritable
*
* @return \MailSo\Imap\FolderInformation
*/
public static function NewInstance($sFolderName, $bIsWritable)
{
return new self($sFolderName, $bIsWritable);
}
/**
* @param string $sFlag
*
* @return bool
*/
public function IsFlagSupported($sFlag)
{
return \in_array('\\*', $this->PermanentFlags) ||
\in_array($sFlag, $this->PermanentFlags) ||
\in_array($sFlag, $this->Flags);
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,132 +1,132 @@
<?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\Imap;
/**
* @category MailSo
* @package Imap
*/
class NamespaceResult
{
/**
* @var string
*/
private $sPersonal;
/**
* @var string
*/
private $sPersonalDelimiter;
/**
* @var string
*/
private $sOtherUser;
/**
* @var string
*/
private $sOtherUserDelimiter;
/**
* @var string
*/
private $sShared;
/**
* @var string
*/
private $sSharedDelimiter;
/**
* @access private
*/
private function __construct()
{
$this->sPersonal = '';
$this->sPersonalDelimiter = '';
$this->sOtherUser = '';
$this->sOtherUserDelimiter = '';
$this->sShared = '';
$this->sSharedDelimiter = '';
}
/**
* @return \MailSo\Imap\NamespaceResult
*/
public static function NewInstance()
{
return new self();
}
/**
* @param \MailSo\Imap\Response $oImapResponse
*
* @return \MailSo\Imap\NamespaceResult
*/
public function InitByImapResponse($oImapResponse)
{
if ($oImapResponse && $oImapResponse instanceof \MailSo\Imap\Response)
{
if (isset($oImapResponse->ResponseList[2][0]) &&
\is_array($oImapResponse->ResponseList[2][0]) &&
2 <= \count($oImapResponse->ResponseList[2][0]))
{
$this->sPersonal = $oImapResponse->ResponseList[2][0][0];
$this->sPersonalDelimiter = $oImapResponse->ResponseList[2][0][1];
$this->sPersonal = 'INBOX'.$this->sPersonalDelimiter === \substr(\strtoupper($this->sPersonal), 0, 6) ?
'INBOX'.$this->sPersonalDelimiter.\substr($this->sPersonal, 6) : $this->sPersonal;
}
if (isset($oImapResponse->ResponseList[3][0]) &&
\is_array($oImapResponse->ResponseList[3][0]) &&
2 <= \count($oImapResponse->ResponseList[3][0]))
{
$this->sOtherUser = $oImapResponse->ResponseList[3][0][0];
$this->sOtherUserDelimiter = $oImapResponse->ResponseList[3][0][1];
$this->sOtherUser = 'INBOX'.$this->sOtherUserDelimiter === \substr(\strtoupper($this->sOtherUser), 0, 6) ?
'INBOX'.$this->sOtherUserDelimiter.\substr($this->sOtherUser, 6) : $this->sOtherUser;
}
if (isset($oImapResponse->ResponseList[4][0]) &&
\is_array($oImapResponse->ResponseList[4][0]) &&
2 <= \count($oImapResponse->ResponseList[4][0]))
{
$this->sShared = $oImapResponse->ResponseList[4][0][0];
$this->sSharedDelimiter = $oImapResponse->ResponseList[4][0][1];
$this->sShared = 'INBOX'.$this->sSharedDelimiter === \substr(\strtoupper($this->sShared), 0, 6) ?
'INBOX'.$this->sSharedDelimiter.\substr($this->sShared, 6) : $this->sShared;
}
}
return $this;
}
/**
* @return string
*/
public function GetPersonalNamespace()
{
return $this->sPersonal;
}
/**
* @return string
*/
public function GetPersonalNamespaceDelimiter()
{
return $this->sPersonalDelimiter;
}
}
<?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\Imap;
/**
* @category MailSo
* @package Imap
*/
class NamespaceResult
{
/**
* @var string
*/
private $sPersonal;
/**
* @var string
*/
private $sPersonalDelimiter;
/**
* @var string
*/
private $sOtherUser;
/**
* @var string
*/
private $sOtherUserDelimiter;
/**
* @var string
*/
private $sShared;
/**
* @var string
*/
private $sSharedDelimiter;
/**
* @access private
*/
private function __construct()
{
$this->sPersonal = '';
$this->sPersonalDelimiter = '';
$this->sOtherUser = '';
$this->sOtherUserDelimiter = '';
$this->sShared = '';
$this->sSharedDelimiter = '';
}
/**
* @return \MailSo\Imap\NamespaceResult
*/
public static function NewInstance()
{
return new self();
}
/**
* @param \MailSo\Imap\Response $oImapResponse
*
* @return \MailSo\Imap\NamespaceResult
*/
public function InitByImapResponse($oImapResponse)
{
if ($oImapResponse && $oImapResponse instanceof \MailSo\Imap\Response)
{
if (isset($oImapResponse->ResponseList[2][0]) &&
\is_array($oImapResponse->ResponseList[2][0]) &&
2 <= \count($oImapResponse->ResponseList[2][0]))
{
$this->sPersonal = $oImapResponse->ResponseList[2][0][0];
$this->sPersonalDelimiter = $oImapResponse->ResponseList[2][0][1];
$this->sPersonal = 'INBOX'.$this->sPersonalDelimiter === \substr(\strtoupper($this->sPersonal), 0, 6) ?
'INBOX'.$this->sPersonalDelimiter.\substr($this->sPersonal, 6) : $this->sPersonal;
}
if (isset($oImapResponse->ResponseList[3][0]) &&
\is_array($oImapResponse->ResponseList[3][0]) &&
2 <= \count($oImapResponse->ResponseList[3][0]))
{
$this->sOtherUser = $oImapResponse->ResponseList[3][0][0];
$this->sOtherUserDelimiter = $oImapResponse->ResponseList[3][0][1];
$this->sOtherUser = 'INBOX'.$this->sOtherUserDelimiter === \substr(\strtoupper($this->sOtherUser), 0, 6) ?
'INBOX'.$this->sOtherUserDelimiter.\substr($this->sOtherUser, 6) : $this->sOtherUser;
}
if (isset($oImapResponse->ResponseList[4][0]) &&
\is_array($oImapResponse->ResponseList[4][0]) &&
2 <= \count($oImapResponse->ResponseList[4][0]))
{
$this->sShared = $oImapResponse->ResponseList[4][0][0];
$this->sSharedDelimiter = $oImapResponse->ResponseList[4][0][1];
$this->sShared = 'INBOX'.$this->sSharedDelimiter === \substr(\strtoupper($this->sShared), 0, 6) ?
'INBOX'.$this->sSharedDelimiter.\substr($this->sShared, 6) : $this->sShared;
}
}
return $this;
}
/**
* @return string
*/
public function GetPersonalNamespace()
{
return $this->sPersonal;
}
/**
* @return string
*/
public function GetPersonalNamespaceDelimiter()
{
return $this->sPersonalDelimiter;
}
}

View file

@ -76,7 +76,7 @@ class Response
/**
* @param string $aList
*
*
* @return string
*/
private function recToLine($aList)
@ -92,7 +92,7 @@ class Response
return \implode(' ', $aResult);
}
/**
* @return string

View file

@ -1,408 +1,408 @@
<?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\Log;
/**
* @category MailSo
* @package Log
*/
abstract class Driver
{
/**
* @var string
*/
protected $sDatePattern;
/**
* @var string
*/
protected $sName;
/**
* @var array
*/
protected $aPrefixes;
/**
* @var bool
*/
protected $bGuidPrefix;
/**
* @var string
*/
protected $sTimeOffset;
/**
* @var bool
*/
protected $bTimePrefix;
/**
* @var bool
*/
protected $bTypedPrefix;
/**
* @var string
*/
protected $sNewLine;
/**
* @var int
*/
private $iWriteOnTimeoutOnly;
/**
* @var bool
*/
private $bWriteOnErrorOnly;
/**
* @var bool
*/
private $bWriteOnPhpErrorOnly;
/**
* @var bool
*/
private $bFlushCache;
/**
* @var array
*/
private $aCache;
/**
* @access protected
*/
protected function __construct()
{
$this->sDatePattern = 'H:i:s';
$this->sName = 'INFO';
$this->sNewLine = "\r\n";
$this->bTimePrefix = true;
$this->bTypedPrefix = true;
$this->bGuidPrefix = true;
$this->sTimeOffset = '0';
$this->iWriteOnTimeoutOnly = 0;
$this->bWriteOnErrorOnly = false;
$this->bWriteOnPhpErrorOnly = false;
$this->bFlushCache = false;
$this->aCache = array();
$this->aPrefixes = array(
\MailSo\Log\Enumerations\Type::INFO => '[DATA]',
\MailSo\Log\Enumerations\Type::SECURE => '[SECURE]',
\MailSo\Log\Enumerations\Type::NOTE => '[NOTE]',
\MailSo\Log\Enumerations\Type::TIME => '[TIME]',
\MailSo\Log\Enumerations\Type::TIME_DELTA => '[TIME]',
\MailSo\Log\Enumerations\Type::MEMORY => '[MEMORY]',
\MailSo\Log\Enumerations\Type::NOTICE => '[NOTICE]',
\MailSo\Log\Enumerations\Type::WARNING => '[WARNING]',
\MailSo\Log\Enumerations\Type::ERROR => '[ERROR]',
\MailSo\Log\Enumerations\Type::NOTICE_PHP => '[NOTICE]',
\MailSo\Log\Enumerations\Type::WARNING_PHP => '[WARNING]',
\MailSo\Log\Enumerations\Type::ERROR_PHP => '[ERROR]',
);
}
/**
* @param string $sTimeOffset
*
* @return \MailSo\Log\Driver
*/
public function SetTimeOffset($sTimeOffset)
{
$this->sTimeOffset = (string) $sTimeOffset;
return $this;
}
/**
* @return \MailSo\Log\Driver
*/
public function DisableGuidPrefix()
{
$this->bGuidPrefix = false;
return $this;
}
/**
* @return \MailSo\Log\Driver
*/
public function DisableTimePrefix()
{
$this->bTimePrefix = false;
return $this;
}
/**
* @param bool $bValue
*
* @return \MailSo\Log\Driver
*/
public function WriteOnErrorOnly($bValue)
{
$this->bWriteOnErrorOnly = !!$bValue;
return $this;
}
/**
* @param bool $bValue
*
* @return \MailSo\Log\Driver
*/
public function WriteOnPhpErrorOnly($bValue)
{
$this->bWriteOnPhpErrorOnly = !!$bValue;
return $this;
}
/**
* @param int $iTimeout
*
* @return \MailSo\Log\Driver
*/
public function WriteOnTimeoutOnly($iTimeout)
{
$this->iWriteOnTimeoutOnly = (int) $iTimeout;
if (0 > $this->iWriteOnTimeoutOnly)
{
$this->iWriteOnTimeoutOnly = 0;
}
return $this;
}
/**
* @return \MailSo\Log\Driver
*/
public function DisableTypedPrefix()
{
$this->bTypedPrefix = false;
return $this;
}
/**
* @param string|array $mDesc
* @return bool
*/
abstract protected function writeImplementation($mDesc);
/**
* @return bool
*/
protected function writeEmptyLineImplementation()
{
return $this->writeImplementation('');
}
/**
* @param string $sTimePrefix
* @param string $sDesc
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param array $sName = ''
*
* @return string
*/
protected function loggerLineImplementation($sTimePrefix, $sDesc,
$iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
{
return \ltrim(
($this->bTimePrefix ? '['.$sTimePrefix.']' : '').
($this->bGuidPrefix ? '['.\MailSo\Log\Logger::Guid().']' : '').
($this->bTypedPrefix ? ' '.$this->getTypedPrefix($iType, $sName) : '')
).$sDesc;
}
/**
* @return bool
*/
protected function clearImplementation()
{
return true;
}
/**
* @return string
*/
protected function getTimeWithMicroSec()
{
$aMicroTimeItems = \explode(' ', \microtime());
return \MailSo\Log\Logger::DateHelper($this->sDatePattern, $this->sTimeOffset, $aMicroTimeItems[1]).'.'.
\str_pad((int) ($aMicroTimeItems[0] * 1000), 3, '0', STR_PAD_LEFT);
}
/**
* @param int $iType
* @param string $sName = ''
*
* @return string
*/
protected function getTypedPrefix($iType, $sName = '')
{
$sName = 0 < \strlen($sName) ? $sName : $this->sName;
return isset($this->aPrefixes[$iType]) ? $sName.$this->aPrefixes[$iType].': ' : '';
}
/**
* @param string|array $mDesc
* @param bool $bDiplayCrLf = false
*
* @return string
*/
protected function localWriteImplementation($mDesc, $bDiplayCrLf = false)
{
if ($bDiplayCrLf)
{
if (\is_array($mDesc))
{
foreach ($mDesc as &$sLine)
{
$sLine = \strtr($sLine, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
$sLine = \rtrim($sLine);
}
}
else
{
$mDesc = \strtr($mDesc, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
$mDesc = \rtrim($mDesc);
}
}
return $this->writeImplementation($mDesc);
}
/**
* @final
* @param string $sDesc
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
final public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bDiplayCrLf = false)
{
$bResult = true;
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || 0 < $this->iWriteOnTimeoutOnly))
{
$bErrorPhp = false;
$bError = $this->bWriteOnErrorOnly && \in_array($iType, array(
\MailSo\Log\Enumerations\Type::NOTICE,
\MailSo\Log\Enumerations\Type::NOTICE_PHP,
\MailSo\Log\Enumerations\Type::WARNING,
\MailSo\Log\Enumerations\Type::WARNING_PHP,
\MailSo\Log\Enumerations\Type::ERROR,
\MailSo\Log\Enumerations\Type::ERROR_PHP
));
if (!$bError)
{
$bErrorPhp = $this->bWriteOnPhpErrorOnly && \in_array($iType, array(
\MailSo\Log\Enumerations\Type::NOTICE_PHP,
\MailSo\Log\Enumerations\Type::WARNING_PHP,
\MailSo\Log\Enumerations\Type::ERROR_PHP
));
}
if ($bError || $bErrorPhp)
{
$sFlush = '--- FlushLogCache: '.($bError ? 'WriteOnErrorOnly' : 'WriteOnPhpErrorOnly');
if (isset($this->aCache[0]) && empty($this->aCache[0]))
{
$this->aCache[0] = $sFlush;
\array_unshift($this->aCache, '');
}
else
{
\array_unshift($this->aCache, $sFlush);
}
$this->aCache[] = '--- FlushLogCache: Trigger';
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
$this->bFlushCache = true;
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
$this->aCache = array();
}
else if (0 < $this->iWriteOnTimeoutOnly && \time() - APP_START_TIME > $this->iWriteOnTimeoutOnly)
{
$sFlush = '--- FlushLogCache: WriteOnTimeoutOnly ['.(\time() - APP_START_TIME).'sec]';
if (isset($this->aCache[0]) && empty($this->aCache[0]))
{
$this->aCache[0] = $sFlush;
\array_unshift($this->aCache, '');
}
else
{
\array_unshift($this->aCache, $sFlush);
}
$this->aCache[] = '--- FlushLogCache: Trigger';
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
$this->bFlushCache = true;
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
$this->aCache = array();
}
else
{
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
}
}
else
{
$bResult = $this->localWriteImplementation(
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName), $bDiplayCrLf);
}
return $bResult;
}
/**
* @return string
*/
public function GetNewLine()
{
return $this->sNewLine;
}
/**
* @final
* @return bool
*/
final public function Clear()
{
return $this->clearImplementation();
}
/**
* @final
* @return void
*/
final public function WriteEmptyLine()
{
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || 0 < $this->iWriteOnTimeoutOnly))
{
$this->aCache[] = '';
}
else
{
$this->writeEmptyLineImplementation();
}
}
}
<?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\Log;
/**
* @category MailSo
* @package Log
*/
abstract class Driver
{
/**
* @var string
*/
protected $sDatePattern;
/**
* @var string
*/
protected $sName;
/**
* @var array
*/
protected $aPrefixes;
/**
* @var bool
*/
protected $bGuidPrefix;
/**
* @var string
*/
protected $sTimeOffset;
/**
* @var bool
*/
protected $bTimePrefix;
/**
* @var bool
*/
protected $bTypedPrefix;
/**
* @var string
*/
protected $sNewLine;
/**
* @var int
*/
private $iWriteOnTimeoutOnly;
/**
* @var bool
*/
private $bWriteOnErrorOnly;
/**
* @var bool
*/
private $bWriteOnPhpErrorOnly;
/**
* @var bool
*/
private $bFlushCache;
/**
* @var array
*/
private $aCache;
/**
* @access protected
*/
protected function __construct()
{
$this->sDatePattern = 'H:i:s';
$this->sName = 'INFO';
$this->sNewLine = "\r\n";
$this->bTimePrefix = true;
$this->bTypedPrefix = true;
$this->bGuidPrefix = true;
$this->sTimeOffset = '0';
$this->iWriteOnTimeoutOnly = 0;
$this->bWriteOnErrorOnly = false;
$this->bWriteOnPhpErrorOnly = false;
$this->bFlushCache = false;
$this->aCache = array();
$this->aPrefixes = array(
\MailSo\Log\Enumerations\Type::INFO => '[DATA]',
\MailSo\Log\Enumerations\Type::SECURE => '[SECURE]',
\MailSo\Log\Enumerations\Type::NOTE => '[NOTE]',
\MailSo\Log\Enumerations\Type::TIME => '[TIME]',
\MailSo\Log\Enumerations\Type::TIME_DELTA => '[TIME]',
\MailSo\Log\Enumerations\Type::MEMORY => '[MEMORY]',
\MailSo\Log\Enumerations\Type::NOTICE => '[NOTICE]',
\MailSo\Log\Enumerations\Type::WARNING => '[WARNING]',
\MailSo\Log\Enumerations\Type::ERROR => '[ERROR]',
\MailSo\Log\Enumerations\Type::NOTICE_PHP => '[NOTICE]',
\MailSo\Log\Enumerations\Type::WARNING_PHP => '[WARNING]',
\MailSo\Log\Enumerations\Type::ERROR_PHP => '[ERROR]',
);
}
/**
* @param string $sTimeOffset
*
* @return \MailSo\Log\Driver
*/
public function SetTimeOffset($sTimeOffset)
{
$this->sTimeOffset = (string) $sTimeOffset;
return $this;
}
/**
* @return \MailSo\Log\Driver
*/
public function DisableGuidPrefix()
{
$this->bGuidPrefix = false;
return $this;
}
/**
* @return \MailSo\Log\Driver
*/
public function DisableTimePrefix()
{
$this->bTimePrefix = false;
return $this;
}
/**
* @param bool $bValue
*
* @return \MailSo\Log\Driver
*/
public function WriteOnErrorOnly($bValue)
{
$this->bWriteOnErrorOnly = !!$bValue;
return $this;
}
/**
* @param bool $bValue
*
* @return \MailSo\Log\Driver
*/
public function WriteOnPhpErrorOnly($bValue)
{
$this->bWriteOnPhpErrorOnly = !!$bValue;
return $this;
}
/**
* @param int $iTimeout
*
* @return \MailSo\Log\Driver
*/
public function WriteOnTimeoutOnly($iTimeout)
{
$this->iWriteOnTimeoutOnly = (int) $iTimeout;
if (0 > $this->iWriteOnTimeoutOnly)
{
$this->iWriteOnTimeoutOnly = 0;
}
return $this;
}
/**
* @return \MailSo\Log\Driver
*/
public function DisableTypedPrefix()
{
$this->bTypedPrefix = false;
return $this;
}
/**
* @param string|array $mDesc
* @return bool
*/
abstract protected function writeImplementation($mDesc);
/**
* @return bool
*/
protected function writeEmptyLineImplementation()
{
return $this->writeImplementation('');
}
/**
* @param string $sTimePrefix
* @param string $sDesc
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param array $sName = ''
*
* @return string
*/
protected function loggerLineImplementation($sTimePrefix, $sDesc,
$iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '')
{
return \ltrim(
($this->bTimePrefix ? '['.$sTimePrefix.']' : '').
($this->bGuidPrefix ? '['.\MailSo\Log\Logger::Guid().']' : '').
($this->bTypedPrefix ? ' '.$this->getTypedPrefix($iType, $sName) : '')
).$sDesc;
}
/**
* @return bool
*/
protected function clearImplementation()
{
return true;
}
/**
* @return string
*/
protected function getTimeWithMicroSec()
{
$aMicroTimeItems = \explode(' ', \microtime());
return \MailSo\Log\Logger::DateHelper($this->sDatePattern, $this->sTimeOffset, $aMicroTimeItems[1]).'.'.
\str_pad((int) ($aMicroTimeItems[0] * 1000), 3, '0', STR_PAD_LEFT);
}
/**
* @param int $iType
* @param string $sName = ''
*
* @return string
*/
protected function getTypedPrefix($iType, $sName = '')
{
$sName = 0 < \strlen($sName) ? $sName : $this->sName;
return isset($this->aPrefixes[$iType]) ? $sName.$this->aPrefixes[$iType].': ' : '';
}
/**
* @param string|array $mDesc
* @param bool $bDiplayCrLf = false
*
* @return string
*/
protected function localWriteImplementation($mDesc, $bDiplayCrLf = false)
{
if ($bDiplayCrLf)
{
if (\is_array($mDesc))
{
foreach ($mDesc as &$sLine)
{
$sLine = \strtr($sLine, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
$sLine = \rtrim($sLine);
}
}
else
{
$mDesc = \strtr($mDesc, array("\r" => '\r', "\n" => '\n'.$this->sNewLine));
$mDesc = \rtrim($mDesc);
}
}
return $this->writeImplementation($mDesc);
}
/**
* @final
* @param string $sDesc
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
final public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '', $bDiplayCrLf = false)
{
$bResult = true;
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || 0 < $this->iWriteOnTimeoutOnly))
{
$bErrorPhp = false;
$bError = $this->bWriteOnErrorOnly && \in_array($iType, array(
\MailSo\Log\Enumerations\Type::NOTICE,
\MailSo\Log\Enumerations\Type::NOTICE_PHP,
\MailSo\Log\Enumerations\Type::WARNING,
\MailSo\Log\Enumerations\Type::WARNING_PHP,
\MailSo\Log\Enumerations\Type::ERROR,
\MailSo\Log\Enumerations\Type::ERROR_PHP
));
if (!$bError)
{
$bErrorPhp = $this->bWriteOnPhpErrorOnly && \in_array($iType, array(
\MailSo\Log\Enumerations\Type::NOTICE_PHP,
\MailSo\Log\Enumerations\Type::WARNING_PHP,
\MailSo\Log\Enumerations\Type::ERROR_PHP
));
}
if ($bError || $bErrorPhp)
{
$sFlush = '--- FlushLogCache: '.($bError ? 'WriteOnErrorOnly' : 'WriteOnPhpErrorOnly');
if (isset($this->aCache[0]) && empty($this->aCache[0]))
{
$this->aCache[0] = $sFlush;
\array_unshift($this->aCache, '');
}
else
{
\array_unshift($this->aCache, $sFlush);
}
$this->aCache[] = '--- FlushLogCache: Trigger';
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
$this->bFlushCache = true;
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
$this->aCache = array();
}
else if (0 < $this->iWriteOnTimeoutOnly && \time() - APP_START_TIME > $this->iWriteOnTimeoutOnly)
{
$sFlush = '--- FlushLogCache: WriteOnTimeoutOnly ['.(\time() - APP_START_TIME).'sec]';
if (isset($this->aCache[0]) && empty($this->aCache[0]))
{
$this->aCache[0] = $sFlush;
\array_unshift($this->aCache, '');
}
else
{
\array_unshift($this->aCache, $sFlush);
}
$this->aCache[] = '--- FlushLogCache: Trigger';
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
$this->bFlushCache = true;
$bResult = $this->localWriteImplementation($this->aCache, $bDiplayCrLf);
$this->aCache = array();
}
else
{
$this->aCache[] = $this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName);
}
}
else
{
$bResult = $this->localWriteImplementation(
$this->loggerLineImplementation($this->getTimeWithMicroSec(), $sDesc, $iType, $sName), $bDiplayCrLf);
}
return $bResult;
}
/**
* @return string
*/
public function GetNewLine()
{
return $this->sNewLine;
}
/**
* @final
* @return bool
*/
final public function Clear()
{
return $this->clearImplementation();
}
/**
* @final
* @return void
*/
final public function WriteEmptyLine()
{
if (!$this->bFlushCache && ($this->bWriteOnErrorOnly || $this->bWriteOnPhpErrorOnly || 0 < $this->iWriteOnTimeoutOnly))
{
$this->aCache[] = '';
}
else
{
$this->writeEmptyLineImplementation();
}
}
}

View file

@ -1,83 +1,83 @@
<?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\Log\Drivers;
/**
* @category MailSo
* @package Log
* @subpackage Drivers
*/
class Callback extends \MailSo\Log\Driver
{
/**
* @var mixed
*/
private $fWriteCallback;
/**
* @var mixed
*/
private $fClearCallback;
/**
* @access protected
*
* @param mixed $fWriteCallback
* @param mixed $fClearCallback
*/
protected function __construct($fWriteCallback, $fClearCallback)
{
parent::__construct();
$this->fWriteCallback = \is_callable($fWriteCallback) ? $fWriteCallback : null;
$this->fClearCallback = \is_callable($fClearCallback) ? $fClearCallback : null;
}
/**
* @param mixed $fWriteCallback
* @param mixed $fClearCallback = null
*
* @return \MailSo\Log\Drivers\Callback
*/
public static function NewInstance($fWriteCallback, $fClearCallback = null)
{
return new self($fWriteCallback, $fClearCallback);
}
/**
* @param string|array $mDesc
*
* @return bool
*/
protected function writeImplementation($mDesc)
{
if ($this->fWriteCallback)
{
\call_user_func_array($this->fWriteCallback, array($mDesc));
}
return true;
}
/**
* @return bool
*/
protected function clearImplementation()
{
if ($this->fClearCallback)
{
\call_user_func($this->fClearCallback);
}
return true;
}
}
<?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\Log\Drivers;
/**
* @category MailSo
* @package Log
* @subpackage Drivers
*/
class Callback extends \MailSo\Log\Driver
{
/**
* @var mixed
*/
private $fWriteCallback;
/**
* @var mixed
*/
private $fClearCallback;
/**
* @access protected
*
* @param mixed $fWriteCallback
* @param mixed $fClearCallback
*/
protected function __construct($fWriteCallback, $fClearCallback)
{
parent::__construct();
$this->fWriteCallback = \is_callable($fWriteCallback) ? $fWriteCallback : null;
$this->fClearCallback = \is_callable($fClearCallback) ? $fClearCallback : null;
}
/**
* @param mixed $fWriteCallback
* @param mixed $fClearCallback = null
*
* @return \MailSo\Log\Drivers\Callback
*/
public static function NewInstance($fWriteCallback, $fClearCallback = null)
{
return new self($fWriteCallback, $fClearCallback);
}
/**
* @param string|array $mDesc
*
* @return bool
*/
protected function writeImplementation($mDesc)
{
if ($this->fWriteCallback)
{
\call_user_func_array($this->fWriteCallback, array($mDesc));
}
return true;
}
/**
* @return bool
*/
protected function clearImplementation()
{
if ($this->fClearCallback)
{
\call_user_func($this->fClearCallback);
}
return true;
}
}

View file

@ -1,431 +1,431 @@
<?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\Log;
/**
* @category MailSo
* @package Log
*/
class Logger extends \MailSo\Base\Collection
{
/**
* @var bool
*/
private $bUsed;
/**
* @var array
*/
private $aForbiddenTypes;
/**
* @var array
*/
private $aSecretWords;
/**
* @var bool
*/
private $bShowSecter;
/**
* @var bool
*/
private $bHideErrorNotices;
/**
* @access protected
*
* @param bool $bRegPhpErrorHandler = false
*/
protected function __construct($bRegPhpErrorHandler = true)
{
parent::__construct();
$this->bUsed = false;
$this->aForbiddenTypes = array();
$this->aSecretWords = array();
$this->bShowSecter = false;
$this->bHideErrorNotices = false;
if ($bRegPhpErrorHandler)
{
\set_error_handler(array(&$this, '__phpErrorHandler'));
}
\register_shutdown_function(array(&$this, '__loggerShutDown'));
}
/**
* @param bool $bRegPhpErrorHandler = false
*
* @return \MailSo\Log\Logger
*/
public static function NewInstance($bRegPhpErrorHandler = false)
{
return new self($bRegPhpErrorHandler);
}
/**
* @staticvar \MailSo\Log\Logger $oInstance;
*
* @return \MailSo\Log\Logger
*/
public static function SingletonInstance()
{
static $oInstance = null;
if (null === $oInstance)
{
$oInstance = self::NewInstance();
}
return $oInstance;
}
/**
* @param string $sFormat
* @param string $sTimeOffset = '0'
* @param int $iTimestamp = 0
*
* @return string
*/
public static function DateHelper($sFormat, $sTimeOffset = '0', $iTimestamp = null)
{
$iTimestamp = null === $iTimestamp ? \time() : (int) $iTimestamp;
return \gmdate($sFormat, $iTimestamp + \MailSo\Base\DateTimeHelper::TimeToSec((string) $sTimeOffset));
}
/**
* @return bool
*/
public static function IsSystemEnabled()
{
return !!(\MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger);
}
/**
* @param mixed $mData
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
*/
public static function SystemLog($mData, $iType = \MailSo\Log\Enumerations\Type::INFO)
{
if (\MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger)
{
\MailSo\Config::$SystemLogger->WriteMixed($mData, $iType);
}
}
/**
* @staticvar string $sCache;
*
* @return string
*/
public static function Guid()
{
static $sCache = null;
if (null === $sCache)
{
$sCache = \substr(\MailSo\Base\Utils::Md5Rand(), -8);
}
return $sCache;
}
/**
* @return bool
*/
public function Ping()
{
return true;
}
/**
* @return bool
*/
public function IsEnabled()
{
return 0 < $this->Count();
}
/**
* @param string $sWord
*
* @return bool
*/
public function AddSecret($sWord)
{
if (\is_string($sWord) && 0 < \strlen(\trim($sWord)))
{
$this->aSecretWords[] = $sWord;
$this->aSecretWords = \array_unique($this->aSecretWords);
}
}
/**
* @param bool $bShow
*
* @return \MailSo\Log\Logger
*/
public function SetShowSecter($bShow)
{
$this->bShowSecter = !!$bShow;
return $this;
}
/**
* @param bool $bValue
*
* @return \MailSo\Log\Logger
*/
public function HideErrorNotices($bValue)
{
$this->bHideErrorNotices = !!$bValue;
return $this;
}
/**
* @return bool
*/
public function IsShowSecter()
{
return $this->bShowSecter;
}
/**
* @param int $iType
*
* @return \MailSo\Log\Logger
*/
public function AddForbiddenType($iType)
{
$this->aForbiddenTypes[$iType] = true;
return $this;
}
/**
* @param int $iType
*
* @return \MailSo\Log\Logger
*/
public function RemoveForbiddenType($iType)
{
$this->aForbiddenTypes[$iType] = false;
return $this;
}
/**
* @param int $iErrNo
* @param string $sErrStr
* @param string $sErrFile
* @param int $iErrLine
*
* @return bool
*/
public function __phpErrorHandler($iErrNo, $sErrStr, $sErrFile, $iErrLine)
{
$iType = \MailSo\Log\Enumerations\Type::NOTICE_PHP;
switch ($iErrNo)
{
case E_USER_ERROR:
$iType = \MailSo\Log\Enumerations\Type::ERROR_PHP;
break;
case E_USER_WARNING:
$iType = \MailSo\Log\Enumerations\Type::WARNING_PHP;
break;
}
$this->Write($sErrFile.' [line:'.$iErrLine.', code:'.$iErrNo.']', $iType, 'PHP');
$this->Write('Error: '.$sErrStr, $iType, 'PHP');
return !!(\MailSo\Log\Enumerations\Type::NOTICE === $iType && $this->bHideErrorNotices);
}
/**
* @return void
*/
public function __loggerShutDown()
{
if ($this->bUsed)
{
$aStatistic = \MailSo\Base\Loader::Statistic();
if (\is_array($aStatistic))
{
if (isset($aStatistic['php']['memory_get_peak_usage']))
{
$this->Write('Memory peak usage: '.$aStatistic['php']['memory_get_peak_usage'],
\MailSo\Log\Enumerations\Type::MEMORY);
}
if (isset($aStatistic['time']))
{
$this->Write('Time delta: '.$aStatistic['time'], \MailSo\Log\Enumerations\Type::TIME_DELTA);
}
}
}
}
/**
* @return bool
*/
public function WriteEmptyLine()
{
$iResult = 1;
$aLoggers =& $this->GetAsArray();
foreach ($aLoggers as /* @var $oLogger \MailSo\Log\Driver */ &$oLogger)
{
$iResult &= $oLogger->WriteEmptyLine();
}
return (bool) $iResult;
}
/**
* @param string $sDesc
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO,
$sName = '', $bSearchSecretWords = true, $bDiplayCrLf = false)
{
if (isset($this->aForbiddenTypes[$iType]) && true === $this->aForbiddenTypes[$iType])
{
return true;
}
$this->bUsed = true;
$oLogger = null;
$aLoggers = array();
$iResult = 1;
if ($bSearchSecretWords && !$this->bShowSecter && 0 < \count($this->aSecretWords))
{
$sDesc = \str_replace($this->aSecretWords, '*******', $sDesc);
}
$aLoggers =& $this->GetAsArray();
foreach ($aLoggers as /* @var $oLogger \MailSo\Log\Driver */ $oLogger)
{
$iResult &= $oLogger->Write($sDesc, $iType, $sName, $bDiplayCrLf);
}
return (bool) $iResult;
}
/**
* @param mixed $oValue
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bSearchSecretWords = false
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteDump($oValue, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '',
$bSearchSecretWords = false, $bDiplayCrLf = false)
{
return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
/**
* @param \Exception $oException
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteException($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '',
$bSearchSecretWords = true, $bDiplayCrLf = false)
{
if ($oException instanceof \Exception)
{
if (isset($oException->__LOGINNED__))
{
return true;
}
$oException->__LOGINNED__ = true;
return $this->Write((string) $oException, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
return false;
}
/**
* @param \Exception $oException
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteExceptionShort($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '',
$bSearchSecretWords = true, $bDiplayCrLf = false)
{
if ($oException instanceof \Exception)
{
if (isset($oException->__LOGINNED__))
{
return true;
}
$oException->__LOGINNED__ = true;
return $this->Write($oException->getMessage(), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
return false;
}
/**
* @param mixed $mData
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteMixed($mData, $iType = null, $sName = '',
$bSearchSecretWords = true, $bDiplayCrLf = false)
{
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::INFO : $iType;
if (\is_array($mData) || \is_object($mData))
{
if ($mData instanceof \Exception)
{
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::NOTICE : $iType;
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
else
{
return $this->WriteDump($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
}
else
{
return $this->Write($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
return false;
}
}
<?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\Log;
/**
* @category MailSo
* @package Log
*/
class Logger extends \MailSo\Base\Collection
{
/**
* @var bool
*/
private $bUsed;
/**
* @var array
*/
private $aForbiddenTypes;
/**
* @var array
*/
private $aSecretWords;
/**
* @var bool
*/
private $bShowSecter;
/**
* @var bool
*/
private $bHideErrorNotices;
/**
* @access protected
*
* @param bool $bRegPhpErrorHandler = false
*/
protected function __construct($bRegPhpErrorHandler = true)
{
parent::__construct();
$this->bUsed = false;
$this->aForbiddenTypes = array();
$this->aSecretWords = array();
$this->bShowSecter = false;
$this->bHideErrorNotices = false;
if ($bRegPhpErrorHandler)
{
\set_error_handler(array(&$this, '__phpErrorHandler'));
}
\register_shutdown_function(array(&$this, '__loggerShutDown'));
}
/**
* @param bool $bRegPhpErrorHandler = false
*
* @return \MailSo\Log\Logger
*/
public static function NewInstance($bRegPhpErrorHandler = false)
{
return new self($bRegPhpErrorHandler);
}
/**
* @staticvar \MailSo\Log\Logger $oInstance;
*
* @return \MailSo\Log\Logger
*/
public static function SingletonInstance()
{
static $oInstance = null;
if (null === $oInstance)
{
$oInstance = self::NewInstance();
}
return $oInstance;
}
/**
* @param string $sFormat
* @param string $sTimeOffset = '0'
* @param int $iTimestamp = 0
*
* @return string
*/
public static function DateHelper($sFormat, $sTimeOffset = '0', $iTimestamp = null)
{
$iTimestamp = null === $iTimestamp ? \time() : (int) $iTimestamp;
return \gmdate($sFormat, $iTimestamp + \MailSo\Base\DateTimeHelper::TimeToSec((string) $sTimeOffset));
}
/**
* @return bool
*/
public static function IsSystemEnabled()
{
return !!(\MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger);
}
/**
* @param mixed $mData
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
*/
public static function SystemLog($mData, $iType = \MailSo\Log\Enumerations\Type::INFO)
{
if (\MailSo\Config::$SystemLogger instanceof \MailSo\Log\Logger)
{
\MailSo\Config::$SystemLogger->WriteMixed($mData, $iType);
}
}
/**
* @staticvar string $sCache;
*
* @return string
*/
public static function Guid()
{
static $sCache = null;
if (null === $sCache)
{
$sCache = \substr(\MailSo\Base\Utils::Md5Rand(), -8);
}
return $sCache;
}
/**
* @return bool
*/
public function Ping()
{
return true;
}
/**
* @return bool
*/
public function IsEnabled()
{
return 0 < $this->Count();
}
/**
* @param string $sWord
*
* @return bool
*/
public function AddSecret($sWord)
{
if (\is_string($sWord) && 0 < \strlen(\trim($sWord)))
{
$this->aSecretWords[] = $sWord;
$this->aSecretWords = \array_unique($this->aSecretWords);
}
}
/**
* @param bool $bShow
*
* @return \MailSo\Log\Logger
*/
public function SetShowSecter($bShow)
{
$this->bShowSecter = !!$bShow;
return $this;
}
/**
* @param bool $bValue
*
* @return \MailSo\Log\Logger
*/
public function HideErrorNotices($bValue)
{
$this->bHideErrorNotices = !!$bValue;
return $this;
}
/**
* @return bool
*/
public function IsShowSecter()
{
return $this->bShowSecter;
}
/**
* @param int $iType
*
* @return \MailSo\Log\Logger
*/
public function AddForbiddenType($iType)
{
$this->aForbiddenTypes[$iType] = true;
return $this;
}
/**
* @param int $iType
*
* @return \MailSo\Log\Logger
*/
public function RemoveForbiddenType($iType)
{
$this->aForbiddenTypes[$iType] = false;
return $this;
}
/**
* @param int $iErrNo
* @param string $sErrStr
* @param string $sErrFile
* @param int $iErrLine
*
* @return bool
*/
public function __phpErrorHandler($iErrNo, $sErrStr, $sErrFile, $iErrLine)
{
$iType = \MailSo\Log\Enumerations\Type::NOTICE_PHP;
switch ($iErrNo)
{
case E_USER_ERROR:
$iType = \MailSo\Log\Enumerations\Type::ERROR_PHP;
break;
case E_USER_WARNING:
$iType = \MailSo\Log\Enumerations\Type::WARNING_PHP;
break;
}
$this->Write($sErrFile.' [line:'.$iErrLine.', code:'.$iErrNo.']', $iType, 'PHP');
$this->Write('Error: '.$sErrStr, $iType, 'PHP');
return !!(\MailSo\Log\Enumerations\Type::NOTICE === $iType && $this->bHideErrorNotices);
}
/**
* @return void
*/
public function __loggerShutDown()
{
if ($this->bUsed)
{
$aStatistic = \MailSo\Base\Loader::Statistic();
if (\is_array($aStatistic))
{
if (isset($aStatistic['php']['memory_get_peak_usage']))
{
$this->Write('Memory peak usage: '.$aStatistic['php']['memory_get_peak_usage'],
\MailSo\Log\Enumerations\Type::MEMORY);
}
if (isset($aStatistic['time']))
{
$this->Write('Time delta: '.$aStatistic['time'], \MailSo\Log\Enumerations\Type::TIME_DELTA);
}
}
}
}
/**
* @return bool
*/
public function WriteEmptyLine()
{
$iResult = 1;
$aLoggers =& $this->GetAsArray();
foreach ($aLoggers as /* @var $oLogger \MailSo\Log\Driver */ &$oLogger)
{
$iResult &= $oLogger->WriteEmptyLine();
}
return (bool) $iResult;
}
/**
* @param string $sDesc
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function Write($sDesc, $iType = \MailSo\Log\Enumerations\Type::INFO,
$sName = '', $bSearchSecretWords = true, $bDiplayCrLf = false)
{
if (isset($this->aForbiddenTypes[$iType]) && true === $this->aForbiddenTypes[$iType])
{
return true;
}
$this->bUsed = true;
$oLogger = null;
$aLoggers = array();
$iResult = 1;
if ($bSearchSecretWords && !$this->bShowSecter && 0 < \count($this->aSecretWords))
{
$sDesc = \str_replace($this->aSecretWords, '*******', $sDesc);
}
$aLoggers =& $this->GetAsArray();
foreach ($aLoggers as /* @var $oLogger \MailSo\Log\Driver */ $oLogger)
{
$iResult &= $oLogger->Write($sDesc, $iType, $sName, $bDiplayCrLf);
}
return (bool) $iResult;
}
/**
* @param mixed $oValue
* @param int $iType = \MailSo\Log\Enumerations\Type::INFO
* @param string $sName = ''
* @param bool $bSearchSecretWords = false
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteDump($oValue, $iType = \MailSo\Log\Enumerations\Type::INFO, $sName = '',
$bSearchSecretWords = false, $bDiplayCrLf = false)
{
return $this->Write(\print_r($oValue, true), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
/**
* @param \Exception $oException
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteException($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '',
$bSearchSecretWords = true, $bDiplayCrLf = false)
{
if ($oException instanceof \Exception)
{
if (isset($oException->__LOGINNED__))
{
return true;
}
$oException->__LOGINNED__ = true;
return $this->Write((string) $oException, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
return false;
}
/**
* @param \Exception $oException
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteExceptionShort($oException, $iType = \MailSo\Log\Enumerations\Type::NOTICE, $sName = '',
$bSearchSecretWords = true, $bDiplayCrLf = false)
{
if ($oException instanceof \Exception)
{
if (isset($oException->__LOGINNED__))
{
return true;
}
$oException->__LOGINNED__ = true;
return $this->Write($oException->getMessage(), $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
return false;
}
/**
* @param mixed $mData
* @param int $iType = \MailSo\Log\Enumerations\Type::NOTICE
* @param string $sName = ''
* @param bool $bSearchSecretWords = true
* @param bool $bDiplayCrLf = false
*
* @return bool
*/
public function WriteMixed($mData, $iType = null, $sName = '',
$bSearchSecretWords = true, $bDiplayCrLf = false)
{
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::INFO : $iType;
if (\is_array($mData) || \is_object($mData))
{
if ($mData instanceof \Exception)
{
$iType = null === $iType ? \MailSo\Log\Enumerations\Type::NOTICE : $iType;
return $this->WriteException($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
else
{
return $this->WriteDump($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
}
else
{
return $this->Write($mData, $iType, $sName, $bSearchSecretWords, $bDiplayCrLf);
}
return false;
}
}

File diff suppressed because it is too large Load diff

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);

View file

@ -63,7 +63,7 @@ class ConnectionSecurityType
public static function UseStartTLS($bSupported, $iSecurityType, $bHasSupportedAuth = true)
{
return ($bSupported &&
(self::STARTTLS === $iSecurityType ||
(self::STARTTLS === $iSecurityType ||
(self::AUTO_DETECT === $iSecurityType && (!$bHasSupportedAuth || \MailSo\Config::$PreferStartTlsIfAutoDetect))) &&
\defined('STREAM_CRYPTO_METHOD_TLS_CLIENT') && \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_socket_enable_crypto'));
}

View file

@ -1,19 +0,0 @@
<?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\Pop3\Exceptions;
/**
* @category MailSo
* @package Pop3
* @subpackage Exceptions
*/
class Exception extends \MailSo\Base\Exceptions\Exception {}

View file

@ -1,19 +0,0 @@
<?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\Pop3\Exceptions;
/**
* @category MailSo
* @package Pop3
* @subpackage Exceptions
*/
class LoginBadCredentialsException extends \MailSo\Pop3\Exceptions\NegativeResponseException {}

View file

@ -1,19 +0,0 @@
<?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\Pop3\Exceptions;
/**
* @category MailSo
* @package Pop3
* @subpackage Exceptions
*/
class NegativeResponseException extends \MailSo\Pop3\Exceptions\ResponseException {}

View file

@ -1,57 +0,0 @@
<?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\Pop3\Exceptions;
/**
* @category MailSo
* @package Pop3
* @subpackage Exceptions
*/
class ResponseException extends \MailSo\Pop3\Exceptions\Exception
{
/**
* @var array
*/
private $aResponses;
/**
* @param array $aResponses = array
* @param string $sMessage = ''
* @param int $iCode = 0
* @param \Exception $oPrevious = null
*/
public function __construct($aResponses = array(), $sMessage = '', $iCode = 0, $oPrevious = null)
{
parent::__construct($sMessage, $iCode, $oPrevious);
if (is_array($aResponses))
{
$this->aResponses = $aResponses;
}
}
/**
* @return array
*/
public function GetResponses()
{
return $this->aResponses;
}
/**
* @return \MailSo\Pop3\Response | null
*/
public function GetLastResponse()
{
return 0 < count($this->aResponses) ? $this->aResponses[count($this->aResponses) - 1] : null;
}
}

View file

@ -1,19 +0,0 @@
<?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\Pop3\Exceptions;
/**
* @category MailSo
* @package Pop3
* @subpackage Exceptions
*/
class RuntimeException extends \MailSo\Pop3\Exceptions\Exception {}

View file

@ -1,373 +0,0 @@
<?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\Pop3;
/**
* @category MailSo
* @package Pop3
*/
class Pop3Client extends \MailSo\Net\NetClient
{
/**
* @var bool
*/
private $bIsLoggined;
/**
* @var int
*/
private $iRequestTime;
/**
* @var array
*/
private $aCapa;
/**
* @var string
*/
private $sLastMessage;
/**
* @access protected
*/
protected function __construct()
{
parent::__construct();
$this->bIsLoggined = false;
$this->iRequestTime = 0;
$this->aCapa = null;
$this->sLastMessage = '';
}
/**
* @return \MailSo\Pop3\Pop3Client
*/
public static function NewInstance()
{
return new self();
}
/**
* @param string $sServerName
* @param int $iPort = 110
* @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
* @param bool $bVerifySsl = false
* @param bool $bAllowSelfSigned = null
*
* @return \MailSo\Pop3\Pop3Client
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Pop3\Exceptions\ResponseException
*/
public function Connect($sServerName, $iPort = 110,
$iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT,
$bVerifySsl = false, $bAllowSelfSigned = null)
{
$this->iRequestTime = microtime(true);
parent::Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned);
$this->validateResponse();
if (\MailSo\Net\Enumerations\ConnectionSecurityType::UseStartTLS(
in_array('STLS', $this->Capa()), $this->iSecurityType))
{
$this->sendRequestWithCheck('STLS');
$this->EnableCrypto();
$this->aCapa = null;
}
else if (\MailSo\Net\Enumerations\ConnectionSecurityType::STARTTLS === $this->iSecurityType)
{
$this->writeLogException(
new \MailSo\Net\Exceptions\SocketUnsuppoterdSecureConnectionException('STARTTLS is not supported'),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
return $this;
}
/**
* @param string $sLogin = ''
* @param string $sPassword = ''
*
* @return \MailSo\Pop3\Pop3Client
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Pop3\Exceptions\ResponseException
*/
public function Login($sLogin, $sPassword)
{
if ($this->bIsLoggined)
{
$this->writeLogException(
new Exceptions\RuntimeException('Already authenticated for this session'),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$sLogin = trim($sLogin);
$sPassword = $sPassword;
try
{
$this->sendRequestWithCheck('USER', $sLogin);
$this->sendRequestWithCheck('PASS', $sPassword);
}
catch (\MailSo\Pop3\Exceptions\NegativeResponseException $oException)
{
$this->writeLogException(
new \MailSo\Pop3\Exceptions\LoginBadCredentialsException(
$oException->GetResponses(), '', 0, $oException),
\MailSo\Log\Enumerations\Type::NOTICE, true);
}
$this->bIsLoggined = true;
$this->aCapa = null;
return $this;
}
/**
* @return bool
*/
public function IsLoggined()
{
return $this->IsConnected() && $this->bIsLoggined;
}
/**
* @return \MailSo\Pop3\Pop3Client
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Pop3\Exceptions\Exception
*/
public function Noop()
{
$this->sendRequestWithCheck('NOOP');
return $this;
}
/**
* @return array [MessagesCount, Size]
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Pop3\Exceptions\Exception
*/
public function Status()
{
$this->sendRequestWithCheck('STAT');
$iMessageCount = $iSize = 0;
sscanf($this->sLastMessage, '%d %d', $iMessageCount, $iSize);
return array((int) $iMessageCount, (int) $iSize);
}
/**
* @return \MailSo\Pop3\Pop3Client
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Pop3\Exceptions\Exception
*/
public function Capa()
{
if (null === $this->aCapa)
{
$this->sendRequestWithCheck('CAPA');
$this->aCapa = array_filter(explode("\n", $this->readMultilineResponse()), function (&$sCapa) {
return 0 < strlen(trim($sCapa));
});
$this->aCapa = array_map('trim', $this->aCapa);
}
return $this->aCapa;
}
/**
* @return \MailSo\Pop3\Pop3Client
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Pop3\Exceptions\Exception
*/
public function Logout()
{
if ($this->bIsLoggined)
{
$this->sendRequestWithCheck('QUIT');
}
$this->bIsLoggined = false;
return $this;
}
/**
* @param string $sCommand
* @param string $sAddToCommand = ''
*
* @return \MailSo\Pop3\Pop3Client
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
*/
protected function sendRequest($sCommand, $sAddToCommand = '')
{
if (0 === strlen(trim($sCommand)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$this->IsConnected(true);
$sCommand = trim($sCommand);
$sRealCommand = $sCommand.(0 === strlen($sAddToCommand) ? '' : ' '.$sAddToCommand);
$sFakeCommand = '';
$sFakeAddToCommand = $this->secureRequestParams($sCommand, $sAddToCommand);
if (0 < strlen($sFakeAddToCommand))
{
$sFakeCommand = $sCommand.' '.$sFakeAddToCommand;
}
$this->iRequestTime = microtime(true);
$this->sendRaw($sRealCommand, true, $sFakeCommand);
return $this;
}
/**
* @param string $sCommand
* @param string $sAddToCommand
*
* @return string
*/
private function secureRequestParams($sCommand, $sAddToCommand)
{
$sResult = null;
if (0 < strlen($sAddToCommand))
{
switch ($sCommand)
{
case 'PASS':
$sResult = '********';
break;
}
}
return $sResult;
}
/**
* @param string $sCommand
* @param string $sAddToCommand = ''
*
* @return \MailSo\Pop3\Pop3Client
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Pop3\Exceptions\Exception
*/
private function sendRequestWithCheck($sCommand, $sAddToCommand = '')
{
$this->sendRequest($sCommand, $sAddToCommand);
return $this->validateResponse();
}
/**
* @return string
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Pop3\Exceptions\ResponseException
*/
private function validateResponse()
{
$this->getNextBuffer();
$this->sLastMessage = '';
$sStatus = $sMessage = '';
$sBuffer = trim($this->sResponseBuffer);
$sStatus = $sBuffer;
if (false !== strpos($sBuffer, ' '))
{
list($sStatus, $sMessage) = explode(' ', $sBuffer, 2);
}
$this->sLastMessage = $sMessage;
if ($sStatus != '+OK')
{
$this->writeLogException(
new Exceptions\NegativeResponseException(),
\MailSo\Log\Enumerations\Type::WARNING, true);
}
$this->writeLog((microtime(true) - $this->iRequestTime),
\MailSo\Log\Enumerations\Type::TIME);
}
/**
* @return string
*
* @throws \MailSo\Net\Exceptions\Exception
*/
private function readMultilineResponse()
{
$this->iRequestTime = microtime(true);
$sResult = '';
do
{
$this->getNextBuffer();
if (0 === strpos($this->sResponseBuffer, '.'))
{
$sResult .= substr($this->sResponseBuffer, 1);
}
else
{
$sResult .= $this->sResponseBuffer;
}
}
while ('.' !== rtrim($this->sResponseBuffer, "\r\n"));
$this->writeLog((microtime(true) - $this->iRequestTime),
\MailSo\Log\Enumerations\Type::TIME);
return $sResult;
}
/**
* @return string
*/
protected function getLogName()
{
return 'POP3';
}
/**
* @param \MailSo\Log\Logger $oLogger
* @return \MailSo\Pop3\Pop3Client
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function SetLogger($oLogger)
{
parent::SetLogger($oLogger);
return $this;
}
}

View file

@ -1,19 +0,0 @@
<?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\Poppassd\Exceptions;
/**
* @category MailSo
* @package Poppassd
* @subpackage Exceptions
*/
class Exception extends \MailSo\Base\Exceptions\Exception {}

View file

@ -1,19 +0,0 @@
<?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\Poppassd\Exceptions;
/**
* @category MailSo
* @package Poppassd
* @subpackage Exceptions
*/
class LoginBadCredentialsException extends \MailSo\Poppassd\Exceptions\NegativeResponseException {}

View file

@ -1,19 +0,0 @@
<?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\Poppassd\Exceptions;
/**
* @category MailSo
* @package Poppassd
* @subpackage Exceptions
*/
class NegativeResponseException extends \MailSo\Poppassd\Exceptions\ResponseException {}

View file

@ -1,57 +0,0 @@
<?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\Poppassd\Exceptions;
/**
* @category MailSo
* @package Poppassd
* @subpackage Exceptions
*/
class ResponseException extends \MailSo\Poppassd\Exceptions\Exception
{
/**
* @var array
*/
private $aResponses;
/**
* @param array $aResponses = array
* @param string $sMessage = ''
* @param int $iCode = 0
* @param \Exception $oPrevious = null
*/
public function __construct($aResponses = array(), $sMessage = '', $iCode = 0, $oPrevious = null)
{
parent::__construct($sMessage, $iCode, $oPrevious);
if (\is_array($aResponses))
{
$this->aResponses = $aResponses;
}
}
/**
* @return array
*/
public function GetResponses()
{
return $this->aResponses;
}
/**
* @return \MailSo\Poppassd\Response | null
*/
public function GetLastResponse()
{
return 0 < \count($this->aResponses) ? $this->aResponses[count($this->aResponses) - 1] : null;
}
}

View file

@ -1,19 +0,0 @@
<?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\Poppassd\Exceptions;
/**
* @category MailSo
* @package Poppassd
* @subpackage Exceptions
*/
class RuntimeException extends \MailSo\Poppassd\Exceptions\Exception {}

View file

@ -1,296 +0,0 @@
<?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\Poppassd;
/**
* @category MailSo
* @package Poppassd
*/
class PoppassdClient extends \MailSo\Net\NetClient
{
/**
* @var bool
*/
private $bIsLoggined;
/**
* @var int
*/
private $iRequestTime;
/**
* @access protected
*/
protected function __construct()
{
$this->bIsLoggined = false;
$this->iRequestTime = 0;
parent::__construct();
}
/**
* @return \MailSo\Poppassd\PoppassdClient
*/
public static function NewInstance()
{
return new self();
}
/**
* @param string $sServerName
* @param int $iPort = 106
* @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
* @param bool $bVerifySsl = false
* @param bool $bAllowSelfSigned = true
*
* @return \MailSo\Poppassd\PoppassdClient
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Poppassd\Exceptions\ResponseException
*/
public function Connect($sServerName, $iPort = 106,
$iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT,
$bVerifySsl = false, $bAllowSelfSigned = true)
{
$this->iRequestTime = \microtime(true);
parent::Connect($sServerName, $iPort, $iSecurityType, $bVerifySsl, $bAllowSelfSigned);
$this->validateResponse();
return $this;
}
/**
* @param string $sLogin = ''
* @param string $sPassword = ''
*
* @return \MailSo\Poppassd\PoppassdClient
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Poppassd\Exceptions\ResponseException
*/
public function Login($sLogin, $sPassword)
{
if ($this->bIsLoggined)
{
$this->writeLogException(
new Exceptions\RuntimeException('Already authenticated for this session'),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$sLogin = \trim($sLogin);
$sPassword = $sPassword;
try
{
$this->sendRequestWithCheck('user', $sLogin, true);
$this->sendRequestWithCheck('pass', $sPassword, true);
}
catch (\MailSo\Poppassd\Exceptions\NegativeResponseException $oException)
{
$this->writeLogException(
new \MailSo\Poppassd\Exceptions\LoginBadCredentialsException(
$oException->GetResponses(), '', 0, $oException),
\MailSo\Log\Enumerations\Type::NOTICE, true);
}
$this->bIsLoggined = true;
return $this;
}
/**
* @return \MailSo\Poppassd\PoppassdClient
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Poppassd\Exceptions\Exception
*/
public function Logout()
{
if ($this->bIsLoggined)
{
$this->sendRequestWithCheck('quit');
}
$this->bIsLoggined = false;
return $this;
}
/**
* @param string $sNewPassword
*
* @return \MailSo\Poppassd\PoppassdClient
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Poppassd\Exceptions\Exception
*/
public function NewPass($sNewPassword)
{
if ($this->bIsLoggined)
{
$this->sendRequestWithCheck('newpass', $sNewPassword);
}
else
{
$this->writeLogException(
new \MailSo\Poppassd\Exceptions\RuntimeException('Required login'),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
return $this;
}
/**
* @param string $sCommand
* @param string $sAddToCommand
*
* @return string
*/
private function secureRequestParams($sCommand, $sAddToCommand)
{
$sResult = null;
if (0 < \strlen($sAddToCommand))
{
switch (\strtolower($sCommand))
{
case 'pass':
case 'newpass':
$sResult = '********';
break;
}
}
return $sResult;
}
/**
* @param string $sCommand
* @param string $sAddToCommand = ''
*
* @return \MailSo\Poppassd\PoppassdClient
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
*/
private function sendRequest($sCommand, $sAddToCommand = '')
{
if (0 === \strlen(\trim($sCommand)))
{
$this->writeLogException(
new \MailSo\Base\Exceptions\InvalidArgumentException(),
\MailSo\Log\Enumerations\Type::ERROR, true);
}
$this->IsConnected(true);
$sCommand = \trim($sCommand);
$sRealCommand = $sCommand.(0 === \strlen($sAddToCommand) ? '' : ' '.$sAddToCommand);
$sFakeCommand = '';
$sFakeAddToCommand = $this->secureRequestParams($sCommand, $sAddToCommand);
if (0 < \strlen($sFakeAddToCommand))
{
$sFakeCommand = $sCommand.' '.$sFakeAddToCommand;
}
$this->iRequestTime = \microtime(true);
$this->sendRaw($sRealCommand, true, $sFakeCommand);
return $this;
}
/**
* @param string $sCommand
* @param string $sAddToCommand = ''
* @param bool $bAuthRequestValidate = false
*
* @return \MailSo\Poppassd\PoppassdClient
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Poppassd\Exceptions\Exception
*/
private function sendRequestWithCheck($sCommand, $sAddToCommand = '', $bAuthRequestValidate = false)
{
$this->sendRequest($sCommand, $sAddToCommand);
$this->validateResponse($bAuthRequestValidate);
return $this;
}
/**
* @param bool $bAuthRequestValidate = false
*
* @return \MailSo\Poppassd\PoppassdClient
*
* @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Poppassd\Exceptions\ResponseException
*/
private function validateResponse($bAuthRequestValidate = false)
{
$this->getNextBuffer();
$bResult = false;
if ($bAuthRequestValidate)
{
$bResult = (bool) \preg_match('/^[23]\d\d/', trim($this->sResponseBuffer));
}
else
{
$bResult = (bool) \preg_match('/^2\d\d/', \trim($this->sResponseBuffer));
}
if (!$bResult)
{
// POP3 validation hack
$bResult = '+OK ' === \substr(\trim($this->sResponseBuffer), 0, 4);
}
if (!$bResult)
{
$this->writeLogException(
new Exceptions\NegativeResponseException(),
\MailSo\Log\Enumerations\Type::WARNING, true);
}
$this->writeLog((\microtime(true) - $this->iRequestTime),
\MailSo\Log\Enumerations\Type::TIME);
return $this;
}
/**
* @return string
*/
protected function getLogName()
{
return 'POPPASSD';
}
/**
* @param \MailSo\Log\Logger $oLogger
*
* @return \MailSo\Poppassd\PoppassdClient
*
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
*/
public function SetLogger($oLogger)
{
parent::SetLogger($oLogger);
return $this;
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,59 +1,59 @@
<?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;
/**
* @category MailSo
*/
final class Version
{
/**
* @var string
*/
const APP_VERSION = '2.0.1';
/**
* @var string
*/
const MIME_X_MAILER = 'MailSo';
/**
* @return string
*/
public static function AppVersion()
{
return \MailSo\Version::APP_VERSION;
}
/**
* @return string
*/
public static function XMailer()
{
return \MailSo\Version::MIME_X_MAILER.'/'.\MailSo\Version::APP_VERSION;
}
/**
* @return string
*/
public static function Signature()
{
$sSignature = '';
if (\defined('MAILSO_LIBRARY_USE_PHAR'))
{
$oPhar = new \Phar('mailso.phar');
$sSignature = $oPhar->getSignature();
}
return $sSignature;
}
}
<?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;
/**
* @category MailSo
*/
final class Version
{
/**
* @var string
*/
const APP_VERSION = '2.0.1';
/**
* @var string
*/
const MIME_X_MAILER = 'MailSo';
/**
* @return string
*/
public static function AppVersion()
{
return \MailSo\Version::APP_VERSION;
}
/**
* @return string
*/
public static function XMailer()
{
return \MailSo\Version::MIME_X_MAILER.'/'.\MailSo\Version::APP_VERSION;
}
/**
* @return string
*/
public static function Signature()
{
$sSignature = '';
if (\defined('MAILSO_LIBRARY_USE_PHAR'))
{
$oPhar = new \Phar('mailso.phar');
$sSignature = $oPhar->getSignature();
}
return $sSignature;
}
}