mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Code refactoring
This commit is contained in:
parent
58d8e92902
commit
1de1ecc9c4
4 changed files with 220 additions and 127 deletions
|
|
@ -736,6 +736,10 @@ class Utils
|
||||||
$sValue = \MailSo\Base\Utils::AttributeRfc2231Encode($sAttrName, $sValue);
|
$sValue = \MailSo\Base\Utils::AttributeRfc2231Encode($sAttrName, $sValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$sValue = $sAttrName.'="'.\str_replace('"', '\\"', $sValue).'"';
|
||||||
|
}
|
||||||
|
|
||||||
return \trim($sValue);
|
return \trim($sValue);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,7 @@ class BodyStructure
|
||||||
public function EstimatedSize()
|
public function EstimatedSize()
|
||||||
{
|
{
|
||||||
$fCoefficient = 1;
|
$fCoefficient = 1;
|
||||||
switch (strtolower($this->MailEncodingName()))
|
switch (\strtolower($this->MailEncodingName()))
|
||||||
{
|
{
|
||||||
case 'base64':
|
case 'base64':
|
||||||
$fCoefficient = 0.75;
|
$fCoefficient = 0.75;
|
||||||
|
|
@ -213,7 +213,7 @@ class BodyStructure
|
||||||
public function IsInline()
|
public function IsInline()
|
||||||
{
|
{
|
||||||
return (null === $this->sDisposition) ?
|
return (null === $this->sDisposition) ?
|
||||||
(0 < strlen($this->ContentID())) : ('inline' === strtolower($this->sDisposition));
|
(0 < \strlen($this->ContentID())) : ('inline' === strtolower($this->sDisposition));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -256,6 +256,25 @@ class BodyStructure
|
||||||
return 'application/pgp-signature' === \strtolower($this->ContentType());
|
return 'application/pgp-signature' === \strtolower($this->ContentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsAttachBodyPart()
|
||||||
|
{
|
||||||
|
$bResult = (
|
||||||
|
(null !== $this->sDisposition && 'attachment' === \strtolower($this->sDisposition))
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$bResult && null !== $this->sContentType)
|
||||||
|
{
|
||||||
|
$sContentType = \strtolower($this->sContentType);
|
||||||
|
$bResult = false === \strpos($sContentType, 'multipart/') &&
|
||||||
|
'text/html' !== $sContentType && 'text/plain' !== $sContentType;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $bResult;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array|null
|
* @return array|null
|
||||||
*/
|
*/
|
||||||
|
|
@ -265,7 +284,7 @@ class BodyStructure
|
||||||
$aParts = $this->SearchByContentType('text/plain');
|
$aParts = $this->SearchByContentType('text/plain');
|
||||||
foreach ($aParts as $oPart)
|
foreach ($aParts as $oPart)
|
||||||
{
|
{
|
||||||
if (!$oPart->isAttachBodyPart())
|
if (!$oPart->IsAttachBodyPart())
|
||||||
{
|
{
|
||||||
$aReturn[] = $oPart;
|
$aReturn[] = $oPart;
|
||||||
}
|
}
|
||||||
|
|
@ -283,7 +302,7 @@ class BodyStructure
|
||||||
|
|
||||||
foreach ($aParts as $oPart)
|
foreach ($aParts as $oPart)
|
||||||
{
|
{
|
||||||
if (!$oPart->isAttachBodyPart())
|
if (!$oPart->IsAttachBodyPart())
|
||||||
{
|
{
|
||||||
$aReturn[] = $oPart;
|
$aReturn[] = $oPart;
|
||||||
}
|
}
|
||||||
|
|
@ -298,7 +317,7 @@ class BodyStructure
|
||||||
public function SearchHtmlOrPlainParts()
|
public function SearchHtmlOrPlainParts()
|
||||||
{
|
{
|
||||||
$mResult = $this->SearchHtmlParts();
|
$mResult = $this->SearchHtmlParts();
|
||||||
if (null === $mResult || (is_array($mResult) && 0 === count($mResult)))
|
if (null === $mResult || (\is_array($mResult) && 0 === count($mResult)))
|
||||||
{
|
{
|
||||||
$mResult = $this->SearchPlainParts();
|
$mResult = $this->SearchPlainParts();
|
||||||
}
|
}
|
||||||
|
|
@ -312,18 +331,19 @@ class BodyStructure
|
||||||
public function SearchCharset()
|
public function SearchCharset()
|
||||||
{
|
{
|
||||||
$sResult = '';
|
$sResult = '';
|
||||||
|
$mParts = array();
|
||||||
|
|
||||||
$mHtmlParts = $this->SearchHtmlParts();
|
$mHtmlParts = $this->SearchHtmlParts();
|
||||||
$mPlainParts = $this->SearchPlainParts();
|
$mPlainParts = $this->SearchPlainParts();
|
||||||
$mParts = array();
|
|
||||||
if (is_array($mHtmlParts) && 0 < count($mHtmlParts))
|
if (\is_array($mHtmlParts) && 0 < \count($mHtmlParts))
|
||||||
{
|
{
|
||||||
$mParts = array_merge($mParts, $mHtmlParts);
|
$mParts = \array_merge($mParts, $mHtmlParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($mPlainParts) && 0 < count($mPlainParts))
|
if (\is_array($mPlainParts) && 0 < \count($mPlainParts))
|
||||||
{
|
{
|
||||||
$mParts = array_merge($mParts, $mPlainParts);
|
$mParts = \array_merge($mParts, $mPlainParts);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($mParts as $oPart)
|
foreach ($mParts as $oPart)
|
||||||
|
|
@ -340,7 +360,7 @@ class BodyStructure
|
||||||
$aParts = $this->SearchAttachmentsParts();
|
$aParts = $this->SearchAttachmentsParts();
|
||||||
foreach ($aParts as $oPart)
|
foreach ($aParts as $oPart)
|
||||||
{
|
{
|
||||||
if (0 === strlen($sResult))
|
if (0 === \strlen($sResult))
|
||||||
{
|
{
|
||||||
$sResult = $oPart ? $oPart->Charset() : '';
|
$sResult = $oPart ? $oPart->Charset() : '';
|
||||||
}
|
}
|
||||||
|
|
@ -355,22 +375,27 @@ class BodyStructure
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return bool
|
* @param mixed $fCallback
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
protected function isAttachBodyPart()
|
public function SearchByCallback($fCallback)
|
||||||
{
|
{
|
||||||
$bResult = (
|
$aReturn = array();
|
||||||
(null !== $this->sDisposition && 'attachment' === strtolower($this->sDisposition))
|
if (\call_user_func($fCallback, $this))
|
||||||
);
|
|
||||||
|
|
||||||
if (!$bResult && null !== $this->sContentType)
|
|
||||||
{
|
{
|
||||||
$sContentType = strtolower($this->sContentType);
|
$aReturn[] = $this;
|
||||||
$bResult = false === strpos($sContentType, 'multipart/') &&
|
|
||||||
'text/html' !== $sContentType && 'text/plain' !== $sContentType;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $bResult;
|
if (\is_array($this->aSubParts) && 0 < \count($this->aSubParts))
|
||||||
|
{
|
||||||
|
foreach ($this->aSubParts as /* @var $oSubPart \MailSo\Imap\BodyStructure */ &$oSubPart)
|
||||||
|
{
|
||||||
|
$aReturn = \array_merge($aReturn, $oSubPart->SearchByCallback($fCallback));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aReturn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -378,22 +403,9 @@ class BodyStructure
|
||||||
*/
|
*/
|
||||||
public function SearchAttachmentsParts()
|
public function SearchAttachmentsParts()
|
||||||
{
|
{
|
||||||
$aReturn = array();
|
return $this->SearchByCallback(function ($oItem) {
|
||||||
if ($this->isAttachBodyPart())
|
return $oItem->IsAttachBodyPart();
|
||||||
{
|
});
|
||||||
$aReturn[] = $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($this->aSubParts) && 0 < count($this->aSubParts))
|
|
||||||
{
|
|
||||||
foreach ($this->aSubParts as /* @var $oSubPart \MailSo\Imap\BodyStructure */ &$oSubPart)
|
|
||||||
{
|
|
||||||
$aReturn = array_merge($aReturn, $oSubPart->SearchAttachmentsParts());
|
|
||||||
unset($oSubPart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $aReturn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -403,21 +415,10 @@ class BodyStructure
|
||||||
*/
|
*/
|
||||||
public function SearchByContentType($sContentType)
|
public function SearchByContentType($sContentType)
|
||||||
{
|
{
|
||||||
$aReturn = array();
|
$sContentType = \strtolower($sContentType);
|
||||||
if (strtolower($sContentType) === $this->sContentType)
|
return $this->SearchByCallback(function ($oItem) use ($sContentType) {
|
||||||
{
|
return $sContentType === $oItem->ContentType();
|
||||||
$aReturn[] = $this;
|
});
|
||||||
}
|
|
||||||
|
|
||||||
if (is_array($this->aSubParts) && 0 < count($this->aSubParts))
|
|
||||||
{
|
|
||||||
foreach ($this->aSubParts as /* @var $oSubPart \MailSo\Imap\BodyStructure */ &$oSubPart)
|
|
||||||
{
|
|
||||||
$aReturn = array_merge($aReturn, $oSubPart->SearchByContentType($sContentType));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $aReturn;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -428,7 +429,7 @@ class BodyStructure
|
||||||
public function GetPartByMimeIndex($sMimeIndex)
|
public function GetPartByMimeIndex($sMimeIndex)
|
||||||
{
|
{
|
||||||
$oPart = null;
|
$oPart = null;
|
||||||
if (0 < strlen($sMimeIndex))
|
if (0 < \strlen($sMimeIndex))
|
||||||
{
|
{
|
||||||
if ($sMimeIndex === $this->sPartID)
|
if ($sMimeIndex === $this->sPartID)
|
||||||
{
|
{
|
||||||
|
|
@ -467,17 +468,17 @@ class BodyStructure
|
||||||
}
|
}
|
||||||
else if (isset($aParams[$sParamName.'*']))
|
else if (isset($aParams[$sParamName.'*']))
|
||||||
{
|
{
|
||||||
$aValueParts = explode('\'\'', $aParams[$sParamName.'*'], 2);
|
$aValueParts = \explode('\'\'', $aParams[$sParamName.'*'], 2);
|
||||||
if (is_array($aValueParts) && 2 === count($aValueParts))
|
if (\is_array($aValueParts) && 2 === \count($aValueParts))
|
||||||
{
|
{
|
||||||
$sCharset = isset($aValueParts[0]) ? $aValueParts[0] : \MailSo\Base\Enumerations\Charset::UTF_8;
|
$sCharset = isset($aValueParts[0]) ? $aValueParts[0] : \MailSo\Base\Enumerations\Charset::UTF_8;
|
||||||
|
|
||||||
$sResult = \MailSo\Base\Utils::ConvertEncoding(
|
$sResult = \MailSo\Base\Utils::ConvertEncoding(
|
||||||
urldecode($aValueParts[1]), $sCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
\urldecode($aValueParts[1]), $sCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sResult = urldecode($aParams[$sParamName.'*']);
|
$sResult = \urldecode($aParams[$sParamName.'*']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (isset($aParams[$sParamName.'*0*']))
|
else if (isset($aParams[$sParamName.'*0*']))
|
||||||
|
|
@ -489,10 +490,10 @@ class BodyStructure
|
||||||
$aMatches = array();
|
$aMatches = array();
|
||||||
if ($sParamName.'*0*' === $sName)
|
if ($sParamName.'*0*' === $sName)
|
||||||
{
|
{
|
||||||
if (0 === strlen($sCharset))
|
if (0 === \strlen($sCharset))
|
||||||
{
|
{
|
||||||
$aValueParts = explode('\'\'', $sValue, 2);
|
$aValueParts = \explode('\'\'', $sValue, 2);
|
||||||
if (is_array($aValueParts) && 2 === count($aValueParts) && 0 < strlen($aValueParts[0]))
|
if (\is_array($aValueParts) && 2 === \count($aValueParts) && 0 < \strlen($aValueParts[0]))
|
||||||
{
|
{
|
||||||
$sCharset = $aValueParts[0];
|
$sCharset = $aValueParts[0];
|
||||||
$sValue = $aValueParts[1];
|
$sValue = $aValueParts[1];
|
||||||
|
|
@ -501,19 +502,19 @@ class BodyStructure
|
||||||
|
|
||||||
$aFileNames[0] = $sValue;
|
$aFileNames[0] = $sValue;
|
||||||
}
|
}
|
||||||
else if ($sParamName.'*0*' !== $sName && preg_match('/^'.preg_quote($sParamName, '/').'\*([0-9]+)\*$/i', $sName, $aMatches) && 0 < strlen($aMatches[1]))
|
else if ($sParamName.'*0*' !== $sName && \preg_match('/^'.\preg_quote($sParamName, '/').'\*([0-9]+)\*$/i', $sName, $aMatches) && 0 < \strlen($aMatches[1]))
|
||||||
{
|
{
|
||||||
$aFileNames[(int) $aMatches[1]] = $sValue;
|
$aFileNames[(int) $aMatches[1]] = $sValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 < count($aFileNames))
|
if (0 < \count($aFileNames))
|
||||||
{
|
{
|
||||||
ksort($aFileNames, SORT_NUMERIC);
|
\ksort($aFileNames, SORT_NUMERIC);
|
||||||
$sResult = implode(array_values($aFileNames));
|
$sResult = \implode(\array_values($aFileNames));
|
||||||
$sResult = urldecode($sResult);
|
$sResult = \urldecode($sResult);
|
||||||
|
|
||||||
if (0 < strlen($sCharset))
|
if (0 < \strlen($sCharset))
|
||||||
{
|
{
|
||||||
$sResult = \MailSo\Base\Utils::ConvertEncoding($sResult,
|
$sResult = \MailSo\Base\Utils::ConvertEncoding($sResult,
|
||||||
$sCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
$sCharset, \MailSo\Base\Enumerations\Charset::UTF_8);
|
||||||
|
|
@ -532,14 +533,14 @@ class BodyStructure
|
||||||
*/
|
*/
|
||||||
public static function NewInstance(array $aBodyStructure, $sPartID = '')
|
public static function NewInstance(array $aBodyStructure, $sPartID = '')
|
||||||
{
|
{
|
||||||
if (!is_array($aBodyStructure) || 2 > count($aBodyStructure))
|
if (!\is_array($aBodyStructure) || 2 > \count($aBodyStructure))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sBodyMainType = null;
|
$sBodyMainType = null;
|
||||||
if (is_string($aBodyStructure[0]) && 'NIL' !== $aBodyStructure[0])
|
if (\is_string($aBodyStructure[0]) && 'NIL' !== $aBodyStructure[0])
|
||||||
{
|
{
|
||||||
$sBodyMainType = $aBodyStructure[0];
|
$sBodyMainType = $aBodyStructure[0];
|
||||||
}
|
}
|
||||||
|
|
@ -560,7 +561,7 @@ class BodyStructure
|
||||||
if (null === $sBodyMainType)
|
if (null === $sBodyMainType)
|
||||||
{
|
{
|
||||||
// Process multipart body structure
|
// Process multipart body structure
|
||||||
if (!is_array($aBodyStructure[0]))
|
if (!\is_array($aBodyStructure[0]))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -568,13 +569,13 @@ class BodyStructure
|
||||||
{
|
{
|
||||||
$sBodyMainType = 'multipart';
|
$sBodyMainType = 'multipart';
|
||||||
$sSubPartIDPrefix = '';
|
$sSubPartIDPrefix = '';
|
||||||
if (0 === strlen($sPartID) || '.' === $sPartID[strlen($sPartID) - 1])
|
if (0 === \strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1])
|
||||||
{
|
{
|
||||||
// This multi-part is root part of message.
|
// This multi-part is root part of message.
|
||||||
$sSubPartIDPrefix = $sPartID;
|
$sSubPartIDPrefix = $sPartID;
|
||||||
$sPartID .= 'TEXT';
|
$sPartID .= 'TEXT';
|
||||||
}
|
}
|
||||||
else if (0 < strlen($sPartID))
|
else if (0 < \strlen($sPartID))
|
||||||
{
|
{
|
||||||
// This multi-part is a part of another multi-part.
|
// This multi-part is a part of another multi-part.
|
||||||
$sSubPartIDPrefix = $sPartID.'.';
|
$sSubPartIDPrefix = $sPartID.'.';
|
||||||
|
|
@ -583,7 +584,7 @@ class BodyStructure
|
||||||
$aSubParts = array();
|
$aSubParts = array();
|
||||||
$iIndex = 1;
|
$iIndex = 1;
|
||||||
|
|
||||||
while ($iExtraItemPos < count($aBodyStructure) && is_array($aBodyStructure[$iExtraItemPos]))
|
while ($iExtraItemPos < \count($aBodyStructure) && \is_array($aBodyStructure[$iExtraItemPos]))
|
||||||
{
|
{
|
||||||
$oPart = self::NewInstance($aBodyStructure[$iExtraItemPos], $sSubPartIDPrefix.$iIndex);
|
$oPart = self::NewInstance($aBodyStructure[$iExtraItemPos], $sSubPartIDPrefix.$iIndex);
|
||||||
if (null === $oPart)
|
if (null === $oPart)
|
||||||
|
|
@ -606,45 +607,46 @@ class BodyStructure
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($iExtraItemPos < count($aBodyStructure))
|
if ($iExtraItemPos < \count($aBodyStructure))
|
||||||
{
|
{
|
||||||
if (!is_string($aBodyStructure[$iExtraItemPos]) || 'NIL' === $aBodyStructure[$iExtraItemPos])
|
if (!\is_string($aBodyStructure[$iExtraItemPos]) || 'NIL' === $aBodyStructure[$iExtraItemPos])
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sBodySubType = strtolower($aBodyStructure[$iExtraItemPos]);
|
$sBodySubType = \strtolower($aBodyStructure[$iExtraItemPos]);
|
||||||
$iExtraItemPos++;
|
$iExtraItemPos++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($iExtraItemPos < count($aBodyStructure))
|
if ($iExtraItemPos < \count($aBodyStructure))
|
||||||
{
|
{
|
||||||
$sBodyParamList = $aBodyStructure[$iExtraItemPos];
|
$sBodyParamList = $aBodyStructure[$iExtraItemPos];
|
||||||
if (is_array($sBodyParamList))
|
if (\is_array($sBodyParamList))
|
||||||
{
|
{
|
||||||
$aBodyParams = self::getKeyValueListFromArrayList($sBodyParamList);
|
$aBodyParams = self::getKeyValueListFromArrayList($sBodyParamList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$iExtraItemPos++;
|
$iExtraItemPos++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Process simple (singlepart) body structure
|
// Process simple (singlepart) body structure
|
||||||
if (7 > count($aBodyStructure))
|
if (7 > \count($aBodyStructure))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sBodyMainType = strtolower($sBodyMainType);
|
$sBodyMainType = \strtolower($sBodyMainType);
|
||||||
if (!is_string($aBodyStructure[1]) || 'NIL' === $aBodyStructure[1])
|
if (!\is_string($aBodyStructure[1]) || 'NIL' === $aBodyStructure[1])
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sBodySubType = strtolower($aBodyStructure[1]);
|
$sBodySubType = \strtolower($aBodyStructure[1]);
|
||||||
|
|
||||||
$aBodyParamList = $aBodyStructure[2];
|
$aBodyParamList = $aBodyStructure[2];
|
||||||
if (is_array($aBodyParamList))
|
if (\is_array($aBodyParamList))
|
||||||
{
|
{
|
||||||
$aBodyParams = self::getKeyValueListFromArrayList($aBodyParamList);
|
$aBodyParams = self::getKeyValueListFromArrayList($aBodyParamList);
|
||||||
if (isset($aBodyParams['charset']))
|
if (isset($aBodyParams['charset']))
|
||||||
|
|
@ -652,7 +654,7 @@ class BodyStructure
|
||||||
$sCharset = $aBodyParams['charset'];
|
$sCharset = $aBodyParams['charset'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_array($aBodyParams))
|
if (\is_array($aBodyParams))
|
||||||
{
|
{
|
||||||
$sName = self::decodeAttrParamenter($aBodyParams, 'name', $sContentType);
|
$sName = self::decodeAttrParamenter($aBodyParams, 'name', $sContentType);
|
||||||
}
|
}
|
||||||
|
|
@ -660,7 +662,7 @@ class BodyStructure
|
||||||
|
|
||||||
if (null !== $aBodyStructure[3] && 'NIL' !== $aBodyStructure[3])
|
if (null !== $aBodyStructure[3] && 'NIL' !== $aBodyStructure[3])
|
||||||
{
|
{
|
||||||
if (!is_string($aBodyStructure[3]))
|
if (!\is_string($aBodyStructure[3]))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -670,7 +672,7 @@ class BodyStructure
|
||||||
|
|
||||||
if (null !== $aBodyStructure[4] && 'NIL' !== $aBodyStructure[4])
|
if (null !== $aBodyStructure[4] && 'NIL' !== $aBodyStructure[4])
|
||||||
{
|
{
|
||||||
if (!is_string($aBodyStructure[4]))
|
if (!\is_string($aBodyStructure[4]))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
@ -680,14 +682,14 @@ class BodyStructure
|
||||||
|
|
||||||
if (null !== $aBodyStructure[5] && 'NIL' !== $aBodyStructure[5])
|
if (null !== $aBodyStructure[5] && 'NIL' !== $aBodyStructure[5])
|
||||||
{
|
{
|
||||||
if (!is_string($aBodyStructure[5]))
|
if (!\is_string($aBodyStructure[5]))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$sMailEncodingName = $aBodyStructure[5];
|
$sMailEncodingName = $aBodyStructure[5];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_numeric($aBodyStructure[6]))
|
if (\is_numeric($aBodyStructure[6]))
|
||||||
{
|
{
|
||||||
$iSize = (int) $aBodyStructure[6];
|
$iSize = (int) $aBodyStructure[6];
|
||||||
}
|
}
|
||||||
|
|
@ -696,7 +698,7 @@ class BodyStructure
|
||||||
$iSize = -1;
|
$iSize = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 === strlen($sPartID) || '.' === $sPartID[strlen($sPartID) - 1])
|
if (0 === \strlen($sPartID) || '.' === $sPartID[\strlen($sPartID) - 1])
|
||||||
{
|
{
|
||||||
// This is the only sub-part of the message (otherwise, it would be
|
// This is the only sub-part of the message (otherwise, it would be
|
||||||
// one of sub-parts of a multi-part, and partID would already be fully set up).
|
// one of sub-parts of a multi-part, and partID would already be fully set up).
|
||||||
|
|
@ -706,9 +708,9 @@ class BodyStructure
|
||||||
$iExtraItemPos = 7;
|
$iExtraItemPos = 7;
|
||||||
if ('text' === $sBodyMainType)
|
if ('text' === $sBodyMainType)
|
||||||
{
|
{
|
||||||
if ($iExtraItemPos < count($aBodyStructure))
|
if ($iExtraItemPos < \count($aBodyStructure))
|
||||||
{
|
{
|
||||||
if (is_numeric($aBodyStructure[$iExtraItemPos]))
|
if (\is_numeric($aBodyStructure[$iExtraItemPos]))
|
||||||
{
|
{
|
||||||
$iTextLineCount = (int) $aBodyStructure[$iExtraItemPos];
|
$iTextLineCount = (int) $aBodyStructure[$iExtraItemPos];
|
||||||
}
|
}
|
||||||
|
|
@ -721,13 +723,14 @@ class BodyStructure
|
||||||
{
|
{
|
||||||
$iTextLineCount = -1;
|
$iTextLineCount = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$iExtraItemPos++;
|
$iExtraItemPos++;
|
||||||
}
|
}
|
||||||
else if ('message' === $sBodyMainType && 'rfc822' === $sBodySubType)
|
else if ('message' === $sBodyMainType && 'rfc822' === $sBodySubType)
|
||||||
{
|
{
|
||||||
if ($iExtraItemPos + 2 < count($aBodyStructure))
|
if ($iExtraItemPos + 2 < \count($aBodyStructure))
|
||||||
{
|
{
|
||||||
if (is_numeric($aBodyStructure[$iExtraItemPos + 2]))
|
if (\is_numeric($aBodyStructure[$iExtraItemPos + 2]))
|
||||||
{
|
{
|
||||||
$iTextLineCount = (int) $aBodyStructure[$iExtraItemPos + 2];
|
$iTextLineCount = (int) $aBodyStructure[$iExtraItemPos + 2];
|
||||||
}
|
}
|
||||||
|
|
@ -753,14 +756,14 @@ class BodyStructure
|
||||||
$aDispositionParams = null;
|
$aDispositionParams = null;
|
||||||
$sFileName = null;
|
$sFileName = null;
|
||||||
|
|
||||||
if ($iExtraItemPos < count($aBodyStructure))
|
if ($iExtraItemPos < \count($aBodyStructure))
|
||||||
{
|
{
|
||||||
$aDispList = $aBodyStructure[$iExtraItemPos];
|
$aDispList = $aBodyStructure[$iExtraItemPos];
|
||||||
if (is_array($aDispList) && 1 < count($aDispList))
|
if (\is_array($aDispList) && 1 < \count($aDispList))
|
||||||
{
|
{
|
||||||
if (null !== $aDispList[0])
|
if (null !== $aDispList[0])
|
||||||
{
|
{
|
||||||
if (is_string($aDispList[0]) && 'NIL' !== $aDispList[0])
|
if (\is_string($aDispList[0]) && 'NIL' !== $aDispList[0])
|
||||||
{
|
{
|
||||||
$sDisposition = $aDispList[0];
|
$sDisposition = $aDispList[0];
|
||||||
}
|
}
|
||||||
|
|
@ -772,15 +775,16 @@ class BodyStructure
|
||||||
}
|
}
|
||||||
|
|
||||||
$aDispParamList = $aDispList[1];
|
$aDispParamList = $aDispList[1];
|
||||||
if (is_array($aDispParamList))
|
if (\is_array($aDispParamList))
|
||||||
{
|
{
|
||||||
$aDispositionParams = self::getKeyValueListFromArrayList($aDispParamList);
|
$aDispositionParams = self::getKeyValueListFromArrayList($aDispParamList);
|
||||||
if (is_array($aDispositionParams))
|
if (\is_array($aDispositionParams))
|
||||||
{
|
{
|
||||||
$sFileName = self::decodeAttrParamenter($aDispositionParams, 'filename', $sCharset);
|
$sFileName = self::decodeAttrParamenter($aDispositionParams, 'filename', $sCharset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$iExtraItemPos++;
|
$iExtraItemPos++;
|
||||||
|
|
||||||
$sLanguage = null;
|
$sLanguage = null;
|
||||||
|
|
@ -788,11 +792,11 @@ class BodyStructure
|
||||||
{
|
{
|
||||||
if (null !== $aBodyStructure[$iExtraItemPos] && 'NIL' !== $aBodyStructure[$iExtraItemPos])
|
if (null !== $aBodyStructure[$iExtraItemPos] && 'NIL' !== $aBodyStructure[$iExtraItemPos])
|
||||||
{
|
{
|
||||||
if (is_array($aBodyStructure[$iExtraItemPos]))
|
if (\is_array($aBodyStructure[$iExtraItemPos]))
|
||||||
{
|
{
|
||||||
$sLanguage = implode(',', $aBodyStructure[$iExtraItemPos]);
|
$sLanguage = \implode(',', $aBodyStructure[$iExtraItemPos]);
|
||||||
}
|
}
|
||||||
else if (is_string($aBodyStructure[$iExtraItemPos]))
|
else if (\is_string($aBodyStructure[$iExtraItemPos]))
|
||||||
{
|
{
|
||||||
$sLanguage = $aBodyStructure[$iExtraItemPos];
|
$sLanguage = $aBodyStructure[$iExtraItemPos];
|
||||||
}
|
}
|
||||||
|
|
@ -801,11 +805,11 @@ class BodyStructure
|
||||||
}
|
}
|
||||||
|
|
||||||
$sLocation = null;
|
$sLocation = null;
|
||||||
if ($iExtraItemPos < count($aBodyStructure))
|
if ($iExtraItemPos < \count($aBodyStructure))
|
||||||
{
|
{
|
||||||
if (null !== $aBodyStructure[$iExtraItemPos] && 'NIL' !== $aBodyStructure[$iExtraItemPos])
|
if (null !== $aBodyStructure[$iExtraItemPos] && 'NIL' !== $aBodyStructure[$iExtraItemPos])
|
||||||
{
|
{
|
||||||
if (is_string($aBodyStructure[$iExtraItemPos]))
|
if (\is_string($aBodyStructure[$iExtraItemPos]))
|
||||||
{
|
{
|
||||||
$sLocation = $aBodyStructure[$iExtraItemPos];
|
$sLocation = $aBodyStructure[$iExtraItemPos];
|
||||||
}
|
}
|
||||||
|
|
@ -822,8 +826,7 @@ class BodyStructure
|
||||||
$sMailEncodingName,
|
$sMailEncodingName,
|
||||||
$sDisposition,
|
$sDisposition,
|
||||||
$aDispositionParams,
|
$aDispositionParams,
|
||||||
\MailSo\Base\Utils::Utf8Clear(
|
\MailSo\Base\Utils::Utf8Clear((null === $sFileName || 0 === \strlen($sFileName)) ? $sName : $sFileName),
|
||||||
null === $sFileName || 0 === strlen($sFileName) ? $sName : $sFileName),
|
|
||||||
$sLanguage,
|
$sLanguage,
|
||||||
$sLocation,
|
$sLocation,
|
||||||
$iSize,
|
$iSize,
|
||||||
|
|
@ -836,7 +839,7 @@ class BodyStructure
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $aBodyStructure
|
* @param array $aBodyStructure
|
||||||
* @param string $sPartID
|
* @param string $sSubPartID
|
||||||
*
|
*
|
||||||
* @return \MailSo\Imap\BodyStructure|null
|
* @return \MailSo\Imap\BodyStructure|null
|
||||||
*/
|
*/
|
||||||
|
|
@ -844,7 +847,7 @@ class BodyStructure
|
||||||
{
|
{
|
||||||
$oBody = null;
|
$oBody = null;
|
||||||
$aBodySubStructure = self::findPartByIndexInArray($aBodyStructure, $sSubPartID);
|
$aBodySubStructure = self::findPartByIndexInArray($aBodyStructure, $sSubPartID);
|
||||||
if ($aBodySubStructure && is_array($aBodySubStructure) && isset($aBodySubStructure[8]))
|
if ($aBodySubStructure && \is_array($aBodySubStructure) && isset($aBodySubStructure[8]))
|
||||||
{
|
{
|
||||||
$oBody = self::NewInstance($aBodySubStructure[8], $sSubPartID);
|
$oBody = self::NewInstance($aBodySubStructure[8], $sSubPartID);
|
||||||
}
|
}
|
||||||
|
|
@ -861,11 +864,12 @@ class BodyStructure
|
||||||
private static function findPartByIndexInArray(array $aList, $sPartID)
|
private static function findPartByIndexInArray(array $aList, $sPartID)
|
||||||
{
|
{
|
||||||
$bFind = false;
|
$bFind = false;
|
||||||
$aPath = explode('.', ''.$sPartID);
|
$aPath = \explode('.', ''.$sPartID);
|
||||||
$aCurrentPart = $aList;
|
$aCurrentPart = $aList;
|
||||||
|
|
||||||
foreach ($aPath as $iPos => $iNum)
|
foreach ($aPath as $iPos => $iNum)
|
||||||
{
|
{
|
||||||
$iIndex = intval($iNum) - 1;
|
$iIndex = \intval($iNum) - 1;
|
||||||
if (0 <= $iIndex && 0 < $iPos ? isset($aCurrentPart[8][$iIndex]) : isset($aCurrentPart[$iIndex]))
|
if (0 <= $iIndex && 0 < $iPos ? isset($aCurrentPart[8][$iIndex]) : isset($aCurrentPart[$iIndex]))
|
||||||
{
|
{
|
||||||
$aCurrentPart = 0 < $iPos ? $aCurrentPart[8][$iIndex] : $aCurrentPart[$iIndex];
|
$aCurrentPart = 0 < $iPos ? $aCurrentPart[8][$iIndex] : $aCurrentPart[$iIndex];
|
||||||
|
|
@ -887,14 +891,14 @@ class BodyStructure
|
||||||
private static function getKeyValueListFromArrayList(array $aList)
|
private static function getKeyValueListFromArrayList(array $aList)
|
||||||
{
|
{
|
||||||
$aDict = null;
|
$aDict = null;
|
||||||
if (0 === count($aList) % 2)
|
if (0 === \count($aList) % 2)
|
||||||
{
|
{
|
||||||
$aDict = array();
|
$aDict = array();
|
||||||
for ($iIndex = 0, $iLen = count($aList); $iIndex < $iLen; $iIndex += 2)
|
for ($iIndex = 0, $iLen = \count($aList); $iIndex < $iLen; $iIndex += 2)
|
||||||
{
|
{
|
||||||
if (is_string($aList[$iIndex]) && isset($aList[$iIndex + 1]) && is_string($aList[$iIndex + 1]))
|
if (\is_string($aList[$iIndex]) && isset($aList[$iIndex + 1]) && \is_string($aList[$iIndex + 1]))
|
||||||
{
|
{
|
||||||
$aDict[strtolower($aList[$iIndex])] = $aList[$iIndex + 1];
|
$aDict[\strtolower($aList[$iIndex])] = $aList[$iIndex + 1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1757,6 +1757,64 @@ class Actions
|
||||||
return $aIdentities;
|
return $aIdentities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \RainLoop\Account $oAccount
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function GetIdentitiesNew($oAccount)
|
||||||
|
{
|
||||||
|
$aIdentities = array();
|
||||||
|
if ($oAccount)
|
||||||
|
{
|
||||||
|
$oAccountIdentity = \RainLoop\Identity::NewInstance('', $oAccount->Email());
|
||||||
|
|
||||||
|
$aSubIdentities = array();
|
||||||
|
$oSettings = $this->SettingsProvider()->Load($oAccount);
|
||||||
|
if ($oSettings)
|
||||||
|
{
|
||||||
|
$sData = $oSettings->GetConf('Identities', '');
|
||||||
|
if ('' !== $sData && '[' === \substr($sData, 0, 1))
|
||||||
|
{
|
||||||
|
$aSubIdentities = @\json_decode($sData, true);
|
||||||
|
$aSubIdentities = \is_array($aSubIdentities) ? $aSubIdentities : array();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (0 < \count($aSubIdentities))
|
||||||
|
{
|
||||||
|
foreach ($aSubIdentities as $aItem)
|
||||||
|
{
|
||||||
|
if (isset($aItem['Id'], $aItem['Email']))
|
||||||
|
{
|
||||||
|
if (0 < \strlen($aItem['Id']))
|
||||||
|
{
|
||||||
|
$oItem = \RainLoop\Identity::NewInstance($aItem['Id'], $aItem['Email']);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$oItem = $oAccountIdentity;
|
||||||
|
}
|
||||||
|
|
||||||
|
$oItem->SetName(isset($aItem['Name']) ? $aItem['Name'] : '');
|
||||||
|
$oItem->SetReplyTo(isset($aItem['ReplyTo']) ? $aItem['ReplyTo'] : '');
|
||||||
|
$oItem->SetBcc(isset($aItem['Bcc']) ? $aItem['Bcc'] : '');
|
||||||
|
$oItem->SetSignature(isset($aItem['Signature']) ? $aItem['Signature'] : '');
|
||||||
|
|
||||||
|
if ('' !== $oItem->Id())
|
||||||
|
{
|
||||||
|
\array_push($aIdentities, $oItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
\array_unshift($aIdentities, $oAccountIdentity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aIdentities;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \RainLoop\Account $oAccount
|
* @param \RainLoop\Account $oAccount
|
||||||
* @param array $aAccounts = array()
|
* @param array $aAccounts = array()
|
||||||
|
|
@ -2024,6 +2082,33 @@ class Actions
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @throws \MailSo\Base\Exceptions\Exception
|
||||||
|
*/
|
||||||
|
public function DoAccountsAndIdentitiesNew()
|
||||||
|
{
|
||||||
|
$oAccount = $this->getAccountFromToken();
|
||||||
|
|
||||||
|
$mAccounts = false;
|
||||||
|
if ($this->Config()->Get('webmail', 'allow_additional_accounts', true))
|
||||||
|
{
|
||||||
|
$mAccounts = $this->GetAccounts($oAccount);
|
||||||
|
$mAccounts = \array_keys($mAccounts);
|
||||||
|
|
||||||
|
foreach ($mAccounts as $iIndex => $sName)
|
||||||
|
{
|
||||||
|
$mAccounts[$iIndex] = \MailSo\Base\Utils::IdnToUtf8($sName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->DefaultResponse(__FUNCTION__, array(
|
||||||
|
'Accounts' => $mAccounts,
|
||||||
|
'Identities' => $this->GetIdentitiesNew($oAccount)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \RainLoop\Account $oAccount
|
* @param \RainLoop\Account $oAccount
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,16 @@ class KeyPathHelper
|
||||||
return 'TwoFactorAuth/User/'.$sEmail.'/Data/';
|
return 'TwoFactorAuth/User/'.$sEmail.'/Data/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sEmail
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
static public function WebmailAccounts($sEmail)
|
||||||
|
{
|
||||||
|
return 'Webmail/Accounts/'.$sEmail.'/Array';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sSsoHash
|
* @param string $sSsoHash
|
||||||
*
|
*
|
||||||
|
|
@ -44,16 +54,6 @@ class KeyPathHelper
|
||||||
return '/SignMe/UserToken/'.$sSignMeToken;
|
return '/SignMe/UserToken/'.$sSignMeToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $sEmail
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
static public function WebmailAccounts($sEmail)
|
|
||||||
{
|
|
||||||
return 'Webmail/Accounts/'.$sEmail.'/Array';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $sDomain
|
* @param string $sDomain
|
||||||
*
|
*
|
||||||
|
|
@ -61,7 +61,7 @@ class KeyPathHelper
|
||||||
*/
|
*/
|
||||||
static public function LicensingDomainKeyValue($sDomain)
|
static public function LicensingDomainKeyValue($sDomain)
|
||||||
{
|
{
|
||||||
return 'Licensing/DomainKey/Value/'.$sDomain;
|
return '/Licensing/DomainKey/Value/'.$sDomain;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -72,7 +72,7 @@ class KeyPathHelper
|
||||||
*/
|
*/
|
||||||
static public function RepositoryCacheFile($sRepo, $sRepoFile)
|
static public function RepositoryCacheFile($sRepo, $sRepoFile)
|
||||||
{
|
{
|
||||||
return 'RepositoryCache/Repo/'.$sRepo.'/File/'.$sRepoFile;
|
return '/RepositoryCache/Repo/'.$sRepo.'/File/'.$sRepoFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -82,7 +82,7 @@ class KeyPathHelper
|
||||||
*/
|
*/
|
||||||
static public function RepositoryCacheCore($sRepo)
|
static public function RepositoryCacheCore($sRepo)
|
||||||
{
|
{
|
||||||
return 'RepositoryCache/CoreRepo/'.$sRepo;
|
return '/RepositoryCache/CoreRepo/'.$sRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue