remove imap_message_list_hide_deleted_messages setting (it's a bad idea to use it)

fixed uid cacher
certificate validatetion on test connection (first look)
This commit is contained in:
RainLoop Team 2014-10-01 01:26:23 +04:00
parent 1fee4d35f9
commit 60b449b9f8
8 changed files with 168 additions and 170 deletions

View file

@ -2,7 +2,7 @@
"name": "RainLoop", "name": "RainLoop",
"title": "RainLoop Webmail", "title": "RainLoop Webmail",
"version": "1.6.9", "version": "1.6.9",
"release": "169", "release": "170",
"description": "Simple, modern & fast web-based email client", "description": "Simple, modern & fast web-based email client",
"homepage": "http://rainloop.net", "homepage": "http://rainloop.net",
"main": "gulpfile.js", "main": "gulpfile.js",

View file

@ -1,60 +1,55 @@
<?php <?php
namespace MailSo; namespace MailSo;
/** /**
* @category MailSo * @category MailSo
* @package Base * @package Base
*/ */
class Config class Config
{ {
/** /**
* @var bool * @var bool
*/ */
public static $ICONV = true; public static $ICONV = true;
/** /**
* @var bool * @var bool
*/ */
public static $MBSTRING = true; public static $MBSTRING = true;
/** /**
* @var bool * @var bool
*/ */
public static $FixIconvByMbstring = true; public static $FixIconvByMbstring = true;
/** /**
* @var int * @var int
*/ */
public static $MessageListFastSimpleSearch = true; public static $MessageListFastSimpleSearch = true;
/** /**
* @var int * @var int
*/ */
public static $MessageListCountLimitTrigger = 0; public static $MessageListCountLimitTrigger = 0;
/** /**
* @var bool * @var int
*/ */
public static $MessageListUndeletedFilter = false; public static $MessageListDateFilter = 0;
/** /**
* @var int * @var bool
*/ */
public static $MessageListDateFilter = 0; public static $LogSimpleLiterals = false;
/** /**
* @var bool * @var bool
*/ */
public static $LogSimpleLiterals = false; public static $PreferStartTlsIfAutoDetect = true;
/** /**
* @var bool * @var \MailSo\Log\Logger|null
*/ */
public static $PreferStartTlsIfAutoDetect = true; public static $SystemLogger = null;
}
/**
* @var \MailSo\Log\Logger|null
*/
public static $SystemLogger = null;
}

View file

@ -126,6 +126,7 @@ class ImapClient extends \MailSo\Net\NetClient
* @param string $sServerName * @param string $sServerName
* @param int $iPort = 143 * @param int $iPort = 143
* @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT * @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
* @param bool $bCapturePeerCertIfSsl = false
* *
* @return \MailSo\Imap\ImapClient * @return \MailSo\Imap\ImapClient
* *
@ -134,11 +135,11 @@ class ImapClient extends \MailSo\Net\NetClient
* @throws \MailSo\Imap\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception
*/ */
public function Connect($sServerName, $iPort = 143, public function Connect($sServerName, $iPort = 143,
$iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT) $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT, $bCapturePeerCertIfSsl = false)
{ {
$this->aTagTimeouts['*'] = \microtime(true); $this->aTagTimeouts['*'] = \microtime(true);
parent::Connect($sServerName, $iPort, $iSecurityType); parent::Connect($sServerName, $iPort, $iSecurityType, $bCapturePeerCertIfSsl);
$this->parseResponseWithValidation('*', true); $this->parseResponseWithValidation('*', true);
@ -628,19 +629,19 @@ class ImapClient extends \MailSo\Net\NetClient
} }
} }
} }
if ($bUseListStatus) if ($bUseListStatus)
{ {
foreach ($aResult as /* @var $oImapResponse \MailSo\Imap\Response */ $oImapResponse) foreach ($aResult as /* @var $oImapResponse \MailSo\Imap\Response */ $oImapResponse)
{ {
if (\MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType && if (\MailSo\Imap\Enumerations\ResponseType::UNTAGGED === $oImapResponse->ResponseType &&
'STATUS' === $oImapResponse->StatusOrIndex && 'STATUS' === $oImapResponse->StatusOrIndex &&
isset($oImapResponse->ResponseList[2]) && isset($oImapResponse->ResponseList[2]) &&
isset($oImapResponse->ResponseList[3]) && isset($oImapResponse->ResponseList[3]) &&
\is_array($oImapResponse->ResponseList[3])) \is_array($oImapResponse->ResponseList[3]))
{ {
$sFolderNameRaw = $oImapResponse->ResponseList[2]; $sFolderNameRaw = $oImapResponse->ResponseList[2];
$oCurrentFolder = null; $oCurrentFolder = null;
foreach ($aReturn as &$oFolder) foreach ($aReturn as &$oFolder)
{ {
@ -650,7 +651,7 @@ class ImapClient extends \MailSo\Net\NetClient
break; break;
} }
} }
if (null !== $oCurrentFolder) if (null !== $oCurrentFolder)
{ {
$sName = null; $sName = null;
@ -667,13 +668,13 @@ class ImapClient extends \MailSo\Net\NetClient
$sName = null; $sName = null;
} }
} }
if (0 < count($aStatus)) if (0 < count($aStatus))
{ {
$oCurrentFolder->SetExtended('STATUS', $aStatus); $oCurrentFolder->SetExtended('STATUS', $aStatus);
} }
} }
unset($oCurrentFolder); unset($oCurrentFolder);
} }
} }
@ -700,9 +701,9 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$sCmd = 'LIST'; $sCmd = 'LIST';
} }
$sListPattern = 0 === strlen(trim($sListPattern)) ? '*' : $sListPattern; $sListPattern = 0 === strlen(trim($sListPattern)) ? '*' : $sListPattern;
$aParameters = array( $aParameters = array(
$this->EscapeString($sParentFolderName), $this->EscapeString($sParentFolderName),
$this->EscapeString($sListPattern) $this->EscapeString($sListPattern)
@ -724,7 +725,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$bUseListStatus = false; $bUseListStatus = false;
} }
$this->SendRequest($sCmd, $aParameters); $this->SendRequest($sCmd, $aParameters);
return $this->getFoldersFromResult( return $this->getFoldersFromResult(
@ -1085,7 +1086,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$iStart = 3; $iStart = 3;
} }
for ($iIndex = $iStart, $iLen = \count($oImapResponse->ResponseList); $iIndex < $iLen; $iIndex++) for ($iIndex = $iStart, $iLen = \count($oImapResponse->ResponseList); $iIndex < $iLen; $iIndex++)
{ {
$aReturn[] = (int) $oImapResponse->ResponseList[$iIndex]; $aReturn[] = (int) $oImapResponse->ResponseList[$iIndex];
@ -1142,7 +1143,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$aRequest[] = 'RETURN'; $aRequest[] = 'RETURN';
$aRequest[] = $aSearchOrSortReturn; $aRequest[] = $aSearchOrSortReturn;
$aRequest[] = $aSortTypes; $aRequest[] = $aSortTypes;
$aRequest[] = \MailSo\Base\Utils::IsAscii($sSearchCriterias) ? 'US-ASCII' : 'UTF-8'; $aRequest[] = \MailSo\Base\Utils::IsAscii($sSearchCriterias) ? 'US-ASCII' : 'UTF-8';
} }
@ -1415,7 +1416,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$iStart = 3; $iStart = 3;
} }
for ($iIndex = $iStart, $iLen = \count($oImapResponse->ResponseList); $iIndex < $iLen; $iIndex++) for ($iIndex = $iStart, $iLen = \count($oImapResponse->ResponseList); $iIndex < $iLen; $iIndex++)
{ {
$aNewValue = $this->validateThreadItem($oImapResponse->ResponseList[$iIndex]); $aNewValue = $this->validateThreadItem($oImapResponse->ResponseList[$iIndex]);
@ -1454,7 +1455,7 @@ class ImapClient extends \MailSo\Net\NetClient
return $this->SendRequestWithCheck($sCommandPrefix.'COPY', return $this->SendRequestWithCheck($sCommandPrefix.'COPY',
array($sIndexRange, $this->EscapeString($sToFolder))); array($sIndexRange, $this->EscapeString($sToFolder)));
} }
/** /**
* @param string $sToFolder * @param string $sToFolder
* @param string $sIndexRange * @param string $sIndexRange
@ -1488,21 +1489,23 @@ class ImapClient extends \MailSo\Net\NetClient
} }
/** /**
* @param string $sUidRangeIfSupported * @param string $sUidRangeIfSupported = ''
* @param bool $bForceUidExpunge = false
* @param bool $bExpungeAll = false
* *
* @return \MailSo\Imap\ImapClient * @return \MailSo\Imap\ImapClient
* *
* @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception
*/ */
public function MessageExpunge($sUidRangeIfSupported = '', $bForceUidExpunge = false) public function MessageExpunge($sUidRangeIfSupported = '', $bForceUidExpunge = false, $bExpungeAll = false)
{ {
$sUidRangeIfSupported = \trim($sUidRangeIfSupported); $sUidRangeIfSupported = \trim($sUidRangeIfSupported);
$sCmd = 'EXPUNGE'; $sCmd = 'EXPUNGE';
$aArguments = array(); $aArguments = array();
if ($bForceUidExpunge && 0 < \strlen($sUidRangeIfSupported) && $this->IsSupported('UIDPLUS')) if (!$bExpungeAll && $bForceUidExpunge && 0 < \strlen($sUidRangeIfSupported) && $this->IsSupported('UIDPLUS'))
{ {
$sCmd = 'UID '.$sCmd; $sCmd = 'UID '.$sCmd;
$aArguments = array($sUidRangeIfSupported); $aArguments = array($sUidRangeIfSupported);
@ -1737,7 +1740,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$oImapResponse = null; $oImapResponse = null;
$sEndTag = (null === $sEndTag) ? $this->getCurrentTag() : $sEndTag; $sEndTag = (null === $sEndTag) ? $this->getCurrentTag() : $sEndTag;
while (true) while (true)
{ {
$oImapResponse = Response::NewInstance(); $oImapResponse = Response::NewInstance();
@ -1929,11 +1932,11 @@ class ImapClient extends \MailSo\Net\NetClient
$this->writeLog('Literal stream read warning "read '.$iLiteralSize.' of '. $this->writeLog('Literal stream read warning "read '.$iLiteralSize.' of '.
$iLiteralLen.'" bytes', \MailSo\Log\Enumerations\Type::WARNING); $iLiteralLen.'" bytes', \MailSo\Log\Enumerations\Type::WARNING);
} }
if (!$bTreatAsAtom) if (!$bTreatAsAtom)
{ {
$aList[] = $sLiteral; $aList[] = $sLiteral;
if (\MailSo\Config::$LogSimpleLiterals) if (\MailSo\Config::$LogSimpleLiterals)
{ {
$this->writeLog('{'.\strlen($sLiteral).'} '.$sLiteral, \MailSo\Log\Enumerations\Type::INFO); $this->writeLog('{'.\strlen($sLiteral).'} '.$sLiteral, \MailSo\Log\Enumerations\Type::INFO);
@ -1965,7 +1968,7 @@ class ImapClient extends \MailSo\Net\NetClient
{ {
$sAtomBlock = $this->partialParseResponseBranch($mNull, $iStackIndex, true, $sAtomBlock = $this->partialParseResponseBranch($mNull, $iStackIndex, true,
null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase)); null === $sPreviousAtomUpperCase ? '' : \strtoupper($sPreviousAtomUpperCase));
$sAtomBuilder .= $sAtomBlock; $sAtomBuilder .= $sAtomBlock;
$iPos = $this->iResponseBufParsedPos; $iPos = $this->iResponseBufParsedPos;
$sAtomBuilder .= ($bIsClosingBracketSquare) ? ']' : ')'; $sAtomBuilder .= ($bIsClosingBracketSquare) ? ']' : ')';
@ -1987,7 +1990,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (null !== $oImapResponse && $oImapResponse->IsStatusResponse) if (null !== $oImapResponse && $oImapResponse->IsStatusResponse)
{ {
$oImapResponse->OptionalResponse = $aSubItems; $oImapResponse->OptionalResponse = $aSubItems;
$bIsGotoDefault = true; $bIsGotoDefault = true;
$bIsGotoNotAtomBracket = false; $bIsGotoNotAtomBracket = false;
continue; continue;
@ -2350,7 +2353,7 @@ class ImapClient extends \MailSo\Net\NetClient
if (\is_resource($rImapLiteralStream)) if (\is_resource($rImapLiteralStream))
{ {
$iNotReadLiteralLen = 0; $iNotReadLiteralLen = 0;
$bFeof = \feof($rImapLiteralStream); $bFeof = \feof($rImapLiteralStream);
$this->writeLog('End Callback for '.$sParent.' / '.$sLiteralAtomUpperCase. $this->writeLog('End Callback for '.$sParent.' / '.$sLiteralAtomUpperCase.
' - feof = '.($bFeof ? 'good' : 'BAD'), $bFeof ? ' - feof = '.($bFeof ? 'good' : 'BAD'), $bFeof ?

View file

@ -495,6 +495,7 @@ class MailClient
* @param array $aIndexRange * @param array $aIndexRange
* @param bool $bIndexIsUid * @param bool $bIndexIsUid
* @param bool $bUseExpunge = true * @param bool $bUseExpunge = true
* @param bool $bExpungeAll = false
* *
* @return \MailSo\Mail\MailClient * @return \MailSo\Mail\MailClient
* *
@ -502,7 +503,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception
*/ */
public function MessageDelete($sFolder, $aIndexRange, $bIndexIsUid, $bUseExpunge = true) public function MessageDelete($sFolder, $aIndexRange, $bIndexIsUid, $bUseExpunge = true, $bExpungeAll = false)
{ {
if (0 === \strlen($sFolder) || !\is_array($aIndexRange) || 0 === \count($aIndexRange)) if (0 === \strlen($sFolder) || !\is_array($aIndexRange) || 0 === \count($aIndexRange))
{ {
@ -520,7 +521,7 @@ class MailClient
if ($bUseExpunge) if ($bUseExpunge)
{ {
$this->oImapClient->MessageExpunge($bIndexIsUid ? $sIndexRange : '', $bIndexIsUid); $this->oImapClient->MessageExpunge($bIndexIsUid ? $sIndexRange : '', $bIndexIsUid, $bExpungeAll);
} }
return $this; return $this;
@ -532,6 +533,7 @@ class MailClient
* @param array $aIndexRange * @param array $aIndexRange
* @param bool $bIndexIsUid * @param bool $bIndexIsUid
* @param bool $bUseMoveSupported = false * @param bool $bUseMoveSupported = false
* @param bool $bExpungeAll = false
* *
* @return \MailSo\Mail\MailClient * @return \MailSo\Mail\MailClient
* *
@ -539,7 +541,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception
*/ */
public function MessageMove($sFromFolder, $sToFolder, $aIndexRange, $bIndexIsUid, $bUseMoveSupported = false) public function MessageMove($sFromFolder, $sToFolder, $aIndexRange, $bIndexIsUid, $bUseMoveSupported = false, $bExpungeAll = false)
{ {
if (0 === \strlen($sFromFolder) || 0 === \strlen($sToFolder) || if (0 === \strlen($sFromFolder) || 0 === \strlen($sToFolder) ||
!\is_array($aIndexRange) || 0 === \count($aIndexRange)) !\is_array($aIndexRange) || 0 === \count($aIndexRange))
@ -559,7 +561,7 @@ class MailClient
$this->oImapClient->MessageCopy($sToFolder, $this->oImapClient->MessageCopy($sToFolder,
\MailSo\Base\Utils::PrepearFetchSequence($aIndexRange), $bIndexIsUid); \MailSo\Base\Utils::PrepearFetchSequence($aIndexRange), $bIndexIsUid);
$this->MessageDelete($sFromFolder, $aIndexRange, $bIndexIsUid, true); $this->MessageDelete($sFromFolder, $aIndexRange, $bIndexIsUid, true, $bExpungeAll);
} }
return $this; return $this;
@ -647,11 +649,10 @@ class MailClient
* @param int $iCount * @param int $iCount
* @param int $iUnseenCount * @param int $iUnseenCount
* @param string $sUidNext * @param string $sUidNext
* @param \MailSo\Cache\CacheClient|null $oCacher = null
* *
* @return void * @return void
*/ */
protected function initFolderValues($sFolderName, &$iCount, &$iUnseenCount, &$sUidNext, $oCacher = null) protected function initFolderValues($sFolderName, &$iCount, &$iUnseenCount, &$sUidNext)
{ {
$aFolderStatus = $this->oImapClient->FolderStatus($sFolderName, array( $aFolderStatus = $this->oImapClient->FolderStatus($sFolderName, array(
\MailSo\Imap\Enumerations\FolderResponseStatus::MESSAGES, \MailSo\Imap\Enumerations\FolderResponseStatus::MESSAGES,
@ -668,36 +669,7 @@ class MailClient
$sUidNext = isset($aFolderStatus[\MailSo\Imap\Enumerations\FolderResponseStatus::UIDNEXT]) $sUidNext = isset($aFolderStatus[\MailSo\Imap\Enumerations\FolderResponseStatus::UIDNEXT])
? (string) $aFolderStatus[\MailSo\Imap\Enumerations\FolderResponseStatus::UIDNEXT] : '0'; ? (string) $aFolderStatus[\MailSo\Imap\Enumerations\FolderResponseStatus::UIDNEXT] : '0';
if (\MailSo\Config::$MessageListUndeletedFilter) if ($this->IsGmail())
{
$oFolder = $this->oImapClient->FolderCurrentInformation();
if (!$oFolder || $oFolder->FolderName !== $sFolderName)
{
$this->oImapClient->FolderExamine($sFolderName);
}
$aUids = $this->getSearchUidsResult('',
$sFolderName, false, false, false, $oCacher);
$iNewCount = \count($aUids);
if (0 < $iNewCount && $iNewCount !== $iCount)
{
$iCount = $iNewCount;
$aUids = $this->getSearchUidsResult('is:unread',
$sFolderName, false, false, false, $oCacher);
$iUnseenCount = \count($aUids);
}
else if (0 === $iNewCount)
{
$iCount = 0;
$iUnseenCount = 0;
}
unset($aUids);
}
else if ($this->IsGmail())
{ {
$oFolder = $this->oImapClient->FolderCurrentInformation(); $oFolder = $this->oImapClient->FolderCurrentInformation();
if ($oFolder && null !== $oFolder->Exists && $oFolder->FolderName === $sFolderName) if ($oFolder && null !== $oFolder->Exists && $oFolder->FolderName === $sFolderName)
@ -800,7 +772,6 @@ class MailClient
* @param string $sFolderName * @param string $sFolderName
* @param string $sPrevUidNext = '' * @param string $sPrevUidNext = ''
* @param array $aUids = '' * @param array $aUids = ''
* @param \MailSo\Cache\CacheClient|null $oCacher = null
* *
* @return string * @return string
* *
@ -808,7 +779,7 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception
*/ */
public function FolderInformation($sFolderName, $sPrevUidNext = '', $aUids = array(), $oCacher = null) public function FolderInformation($sFolderName, $sPrevUidNext = '', $aUids = array())
{ {
$aFlags = array(); $aFlags = array();
@ -847,7 +818,7 @@ class MailClient
$iUnseenCount = 0; $iUnseenCount = 0;
$sUidNext = '0'; $sUidNext = '0';
$this->initFolderValues($sFolderName, $iCount, $iUnseenCount, $sUidNext, $oCacher); $this->initFolderValues($sFolderName, $iCount, $iUnseenCount, $sUidNext);
$aResult = array( $aResult = array(
'Folder' => $sFolderName, 'Folder' => $sFolderName,
@ -865,7 +836,6 @@ class MailClient
/** /**
* @param string $sFolderName * @param string $sFolderName
* @param \MailSo\Cache\CacheClient|null $oCacher = null
* *
* @return string * @return string
* *
@ -873,13 +843,13 @@ class MailClient
* @throws \MailSo\Net\Exceptions\Exception * @throws \MailSo\Net\Exceptions\Exception
* @throws \MailSo\Imap\Exceptions\Exception * @throws \MailSo\Imap\Exceptions\Exception
*/ */
public function FolderHash($sFolderName, $oCacher = null) public function FolderHash($sFolderName)
{ {
$iCount = 0; $iCount = 0;
$iUnseenCount = 0; $iUnseenCount = 0;
$sUidNext = '0'; $sUidNext = '0';
$this->initFolderValues($sFolderName, $iCount, $iUnseenCount, $sUidNext, $oCacher); $this->initFolderValues($sFolderName, $iCount, $iUnseenCount, $sUidNext);
return self::GenerateHash($sFolderName, $iCount, $iUnseenCount, $sUidNext); return self::GenerateHash($sFolderName, $iCount, $iUnseenCount, $sUidNext);
} }
@ -1327,10 +1297,6 @@ class MailClient
} }
$sCriteriasResult = \trim(\implode(' ', $aCriteriasResult)); $sCriteriasResult = \trim(\implode(' ', $aCriteriasResult));
if (\MailSo\Config::$MessageListUndeletedFilter)
{
$sCriteriasResult .= ' UNDELETED';
}
if (0 < $iTimeFilter) if (0 < $iTimeFilter)
{ {
@ -1420,11 +1386,6 @@ class MailClient
public function MessageListThreadsMap($sFolderName, $sFolderHash, $oCacher) public function MessageListThreadsMap($sFolderName, $sFolderHash, $oCacher)
{ {
$sSearchHash = ''; $sSearchHash = '';
if (\MailSo\Config::$MessageListUndeletedFilter)
{
$sSearchHash .= ' UNDELETED';
}
if (0 < \MailSo\Config::$MessageListDateFilter) if (0 < \MailSo\Config::$MessageListDateFilter)
{ {
$iD = \time() - 3600 * 24 * 30 * \MailSo\Config::$MessageListDateFilter; $iD = \time() - 3600 * 24 * 30 * \MailSo\Config::$MessageListDateFilter;
@ -1608,7 +1569,7 @@ class MailClient
$aSerialized = @\unserialize($sSerialized); $aSerialized = @\unserialize($sSerialized);
if (\is_array($aSerialized) && isset($aSerialized['FolderHash'], $aSerialized['Uids']) && if (\is_array($aSerialized) && isset($aSerialized['FolderHash'], $aSerialized['Uids']) &&
\is_array($aSerialized['Uids']) && \is_array($aSerialized['Uids']) &&
($sFolderHash === $aSerialized['FolderHash'] || false === $sFolderHash)) ($sFolderHash === $aSerialized['FolderHash']))
{ {
if ($this->oLogger) if ($this->oLogger)
{ {
@ -1762,7 +1723,7 @@ class MailClient
$oCacher = null; $oCacher = null;
} }
$this->initFolderValues($sFolderName, $iMessageRealCount, $iMessageUnseenCount, $sUidNext, $oCacher); $this->initFolderValues($sFolderName, $iMessageRealCount, $iMessageUnseenCount, $sUidNext);
$iMessageCount = $iMessageRealCount; $iMessageCount = $iMessageRealCount;
$oMessageCollection->FolderHash = self::GenerateHash($sFolderName, $iMessageRealCount, $iMessageUnseenCount, $sUidNext); $oMessageCollection->FolderHash = self::GenerateHash($sFolderName, $iMessageRealCount, $iMessageUnseenCount, $sUidNext);
@ -1860,8 +1821,7 @@ class MailClient
if (1 < $iMessageCount) if (1 < $iMessageCount)
{ {
if ($bMessageListOptimization || if ($bMessageListOptimization || 0 === \MailSo\Config::$MessageListDateFilter)
(!\MailSo\Config::$MessageListUndeletedFilter && 0 === \MailSo\Config::$MessageListDateFilter))
{ {
$aIndexOrUids = \array_reverse(\range(1, $iMessageCount)); $aIndexOrUids = \array_reverse(\range(1, $iMessageCount));
} }

View file

@ -172,6 +172,7 @@ abstract class NetClient
* @param string $sServerName * @param string $sServerName
* @param int $iPort * @param int $iPort
* @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT * @param int $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT
* @param bool $bCapturePeerCertIfSsl = false
* *
* @return void * @return void
* *
@ -180,7 +181,7 @@ abstract class NetClient
* @throws \MailSo\Net\Exceptions\SocketCanNotConnectToHostException * @throws \MailSo\Net\Exceptions\SocketCanNotConnectToHostException
*/ */
public function Connect($sServerName, $iPort, public function Connect($sServerName, $iPort,
$iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT) $iSecurityType = \MailSo\Net\Enumerations\ConnectionSecurityType::AUTO_DETECT, $bCapturePeerCertIfSsl = false)
{ {
if (!\MailSo\Base\Validator::NotEmptyString($sServerName, true) || !\MailSo\Base\Validator::PortInt($iPort)) if (!\MailSo\Base\Validator::NotEmptyString($sServerName, true) || !\MailSo\Base\Validator::PortInt($iPort))
{ {
@ -206,6 +207,8 @@ abstract class NetClient
$this->bSecure = \MailSo\Net\Enumerations\ConnectionSecurityType::UseSSL($iPort, $iSecurityType); $this->bSecure = \MailSo\Net\Enumerations\ConnectionSecurityType::UseSSL($iPort, $iSecurityType);
$this->sConnectedHost = $this->bSecure ? 'ssl://'.$sServerName : $sServerName; $this->sConnectedHost = $this->bSecure ? 'ssl://'.$sServerName : $sServerName;
$bCapturePeerCertIfSsl = !!($bCapturePeerCertIfSsl && $this->bSecure);
if (!$this->bSecure && \MailSo\Net\Enumerations\ConnectionSecurityType::SSL === $this->iSecurityType) if (!$this->bSecure && \MailSo\Net\Enumerations\ConnectionSecurityType::SSL === $this->iSecurityType)
{ {
$this->writeLogException( $this->writeLogException(
@ -217,8 +220,24 @@ abstract class NetClient
$this->writeLog('Start connection to "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"', $this->writeLog('Start connection to "'.$this->sConnectedHost.':'.$this->iConnectedPort.'"',
\MailSo\Log\Enumerations\Type::NOTE); \MailSo\Log\Enumerations\Type::NOTE);
$this->rConnect = @\fsockopen($this->sConnectedHost, $this->iConnectedPort, if ($bCapturePeerCertIfSsl && \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_context_create') &&
$iErrorNo, $sErrorStr, $this->iConnectTimeOut); \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_socket_client') && defined('STREAM_CLIENT_CONNECT'))
{
$rStreamContext = \stream_context_create(array('ssl' => array('capture_peer_cert' => true)));
$sRemoteSocket = (0 === \strpos($this->sConnectedHost, 'ssl://')
? $this->sConnectedHost : 'tcp://'.$this->sConnectedHost).':'.$this->iConnectedPort;
if ($rStreamContext)
{
$this->rConnect = @\stream_socket_client($sRemoteSocket, $iErrorNo, $sErrorStr,
$this->iConnectTimeOut, STREAM_CLIENT_CONNECT, $rStreamContext);
}
}
else
{
$this->rConnect = @\fsockopen($this->sConnectedHost, $this->iConnectedPort,
$iErrorNo, $sErrorStr, $this->iConnectTimeOut);
}
if (!\is_resource($this->rConnect)) if (!\is_resource($this->rConnect))
{ {
@ -308,6 +327,15 @@ abstract class NetClient
$this->IsConnected(true); $this->IsConnected(true);
} }
/**
* @return array|bool
*/
public function StreamContextParams()
{
return \is_resource($this->rConnect) && \MailSo\Base\Utils::FunctionExistsAndEnabled('stream_context_get_options')
? \stream_context_get_params($this->rConnect) : false;
}
/** /**
* @param string $sRaw * @param string $sRaw
* @param bool $bWriteToLog = true * @param bool $bWriteToLog = true

View file

@ -973,12 +973,12 @@ class Actions
'Plugins' => array() 'Plugins' => array()
); );
if ($aResult['UseRsaEncryption'] && if ($aResult['UseRsaEncryption'] &&
\file_exists(APP_PRIVATE_DATA.'rsa/public') && \file_exists(APP_PRIVATE_DATA.'rsa/private')) \file_exists(APP_PRIVATE_DATA.'rsa/public') && \file_exists(APP_PRIVATE_DATA.'rsa/private'))
{ {
$aResult['RsaPublicKey'] = \file_get_contents(APP_PRIVATE_DATA.'rsa/public'); $aResult['RsaPublicKey'] = \file_get_contents(APP_PRIVATE_DATA.'rsa/public');
$aResult['RsaPublicKey'] = $aResult['RsaPublicKey'] ? $aResult['RsaPublicKey'] : ''; $aResult['RsaPublicKey'] = $aResult['RsaPublicKey'] ? $aResult['RsaPublicKey'] : '';
if (false === \strpos($aResult['RsaPublicKey'], 'PUBLIC KEY')) if (false === \strpos($aResult['RsaPublicKey'], 'PUBLIC KEY'))
{ {
$aResult['RsaPublicKey'] = ''; $aResult['RsaPublicKey'] = '';
@ -1563,7 +1563,7 @@ class Actions
$oLogger = $this->Logger(); $oLogger = $this->Logger();
$oLogger->Write('Trying to decode encrypted data', \MailSo\Log\Enumerations\Type::INFO, 'RSA'); $oLogger->Write('Trying to decode encrypted data', \MailSo\Log\Enumerations\Type::INFO, 'RSA');
$sPrivateKey = file_exists(APP_PRIVATE_DATA.'rsa/private') ? $sPrivateKey = file_exists(APP_PRIVATE_DATA.'rsa/private') ?
\file_get_contents(APP_PRIVATE_DATA.'rsa/private') : ''; \file_get_contents(APP_PRIVATE_DATA.'rsa/private') : '';
if (!empty($sPrivateKey)) if (!empty($sPrivateKey))
@ -2737,13 +2737,27 @@ class Actions
$oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this, 'domain-test-connection.de'); $oDomain = $this->DomainProvider()->LoadOrCreateNewFromAction($this, 'domain-test-connection.de');
if ($oDomain) if ($oDomain)
{ {
// $oOpenSSL = \MailSo\Base\Utils::FunctionExistsAndEnabled('openssl_x509_parse');
$oOpenSSL = false; // TODO in dev
try try
{ {
$oImapClient = \MailSo\Imap\ImapClient::NewInstance()->SetLogger($this->Logger()); $oImapClient = \MailSo\Imap\ImapClient::NewInstance()->SetLogger($this->Logger());
$oImapClient->SetTimeOuts(5); $oImapClient->SetTimeOuts(5);
$iTime = \microtime(true); $iTime = \microtime(true);
$oImapClient->Connect($oDomain->IncHost($oDomain->Name()), $oDomain->IncPort(), $oDomain->IncSecure()); $oImapClient->Connect($oDomain->IncHost($oDomain->Name()), $oDomain->IncPort(), $oDomain->IncSecure(), $oOpenSSL);
if ($oOpenSSL)
{
$aStreamContextParams = $oImapClient->StreamContextParams();
if (isset($aStreamContextParams['options']['ssl']['peer_certificate']))
{
$aParseData = @\openssl_x509_parse($aStreamContextParams['options']['ssl']['peer_certificate']);
$this->Logger()->WriteDump($aParseData);
}
}
$iImapTime = \microtime(true) - $iTime; $iImapTime = \microtime(true) - $iTime;
$oImapClient->Disconnect(); $oImapClient->Disconnect();
$bImapResult = true; $bImapResult = true;
@ -3756,7 +3770,7 @@ class Actions
'Send Mails' => \MailSo\Imap\Enumerations\FolderType::SENT, 'Send Mails' => \MailSo\Imap\Enumerations\FolderType::SENT,
'Drafts' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, 'Drafts' => \MailSo\Imap\Enumerations\FolderType::DRAFTS,
'Draft' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, 'Draft' => \MailSo\Imap\Enumerations\FolderType::DRAFTS,
'Draft Mail' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, 'Draft Mail' => \MailSo\Imap\Enumerations\FolderType::DRAFTS,
'Draft Mails' => \MailSo\Imap\Enumerations\FolderType::DRAFTS, 'Draft Mails' => \MailSo\Imap\Enumerations\FolderType::DRAFTS,
@ -3817,7 +3831,7 @@ class Actions
$aResult[$iFolderListType] = $oFolder->FullNameRaw(); $aResult[$iFolderListType] = $oFolder->FullNameRaw();
} }
} }
foreach ($aFolders as $oFolder) foreach ($aFolders as $oFolder)
{ {
$oSub = $oFolder->SubFolders(); $oSub = $oFolder->SubFolders();
@ -3833,7 +3847,7 @@ class Actions
{ {
$sName = $oFolder->Name(); $sName = $oFolder->Name();
$sFullName = $oFolder->FullName(); $sFullName = $oFolder->FullName();
if (isset($aMap[$sName], $aMap[$sFullName])) if (isset($aMap[$sName], $aMap[$sFullName]))
{ {
$iFolderType = isset($aMap[$sName]) ? $aMap[$sName] : $aMap[$sFullName]; $iFolderType = isset($aMap[$sName]) ? $aMap[$sName] : $aMap[$sFullName];
@ -3849,7 +3863,7 @@ class Actions
} }
} }
} }
foreach ($aFolders as $oFolder) foreach ($aFolders as $oFolder)
{ {
$oSub = $oFolder->SubFolders(); $oSub = $oFolder->SubFolders();
@ -4151,8 +4165,9 @@ class Actions
try try
{ {
$aInboxInformation = $this->MailClient()->FolderInformation( $aInboxInformation = $this->MailClient()->FolderInformation(
$sFolder, $sPrevUidNext, $aFlagsFilteredUids, $this->cacherForUids() $sFolder, $sPrevUidNext, $aFlagsFilteredUids
); );
if (\is_array($aInboxInformation) && isset($aInboxInformation['Flags']) && \is_array($aInboxInformation['Flags'])) if (\is_array($aInboxInformation) && isset($aInboxInformation['Flags']) && \is_array($aInboxInformation['Flags']))
{ {
foreach ($aInboxInformation['Flags'] as $iUid => $aFlags) foreach ($aInboxInformation['Flags'] as $iUid => $aFlags)
@ -4205,10 +4220,7 @@ class Actions
{ {
try try
{ {
$aInboxInformation = $this->MailClient()->FolderInformation( $aInboxInformation = $this->MailClient()->FolderInformation($sFolder, '', array());
$sFolder, '', array(), $this->cacherForUids()
);
if (\is_array($aInboxInformation) && isset($aInboxInformation['Folder'])) if (\is_array($aInboxInformation) && isset($aInboxInformation['Folder']))
{ {
$aResult['List'][] = $aInboxInformation; $aResult['List'][] = $aInboxInformation;
@ -4245,7 +4257,7 @@ class Actions
$sRawKey = $this->GetActionParam('RawKey', ''); $sRawKey = $this->GetActionParam('RawKey', '');
$aValues = $this->getDecodedClientRawKeyValue($sRawKey, 9); $aValues = $this->getDecodedClientRawKeyValue($sRawKey, 9);
if (is_array($aValues) && 9 === count($aValues)) if (is_array($aValues) && 9 === count($aValues))
{ {
$sFolder =(string) $aValues[0]; $sFolder =(string) $aValues[0];
@ -5650,9 +5662,10 @@ class Actions
try try
{ {
$this->MailClient()->MessageDelete($sFolder, $aFilteredUids, true); $this->MailClient()->MessageDelete($sFolder, $aFilteredUids, true,
!!$this->Config()->Get('labs', 'use_imap_expunge_all_on_delete', false));
$sHash = $this->MailClient()->FolderHash($sFolder, $this->cacherForUids());
$sHash = $this->MailClient()->FolderHash($sFolder);
} }
catch (\Exception $oException) catch (\Exception $oException)
{ {
@ -5682,10 +5695,12 @@ class Actions
try try
{ {
$this->MailClient()->MessageMove($sFromFolder, $sToFolder, $this->MailClient()->MessageMove($sFromFolder, $sToFolder, $aFilteredUids, true,
$aFilteredUids, true, $this->Config()->Get('labs', 'use_imap_move', true)); !!$this->Config()->Get('labs', 'use_imap_move', true),
!!$this->Config()->Get('labs', 'use_imap_expunge_all_on_delete', false)
);
$sHash = $this->MailClient()->FolderHash($sFromFolder, $this->cacherForUids()); $sHash = $this->MailClient()->FolderHash($sFromFolder);
} }
catch (\Exception $oException) catch (\Exception $oException)
{ {
@ -5719,7 +5734,7 @@ class Actions
$this->MailClient()->MessageCopy($sFromFolder, $sToFolder, $this->MailClient()->MessageCopy($sFromFolder, $sToFolder,
$aFilteredUids, true); $aFilteredUids, true);
$sHash = $this->MailClient()->FolderHash($sFromFolder, $this->cacherForUids()); $sHash = $this->MailClient()->FolderHash($sFromFolder);
} }
catch (\Exception $oException) catch (\Exception $oException)
{ {
@ -7225,7 +7240,7 @@ class Actions
return isset($aLang[$sKey]) ? $aLang[$sKey] : $sKey; return isset($aLang[$sKey]) ? $aLang[$sKey] : $sKey;
} }
/** /**
* @return MailSo\Cache\CacheClient|null * @return MailSo\Cache\CacheClient|null
*/ */

View file

@ -78,16 +78,13 @@ class Api
\MailSo\Config::$MessageListFastSimpleSearch = \MailSo\Config::$MessageListFastSimpleSearch =
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_fast_simple_search', true); !!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_fast_simple_search', true);
\MailSo\Config::$MessageListCountLimitTrigger = \MailSo\Config::$MessageListCountLimitTrigger =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_count_limit_trigger', 0); (int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_count_limit_trigger', 0);
\MailSo\Config::$MessageListDateFilter = \MailSo\Config::$MessageListDateFilter =
(int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_date_filter', 0); (int) \RainLoop\Api::Config()->Get('labs', 'imap_message_list_date_filter', 0);
\MailSo\Config::$MessageListUndeletedFilter =
!!\RainLoop\Api::Config()->Get('labs', 'imap_message_list_hide_deleted_messages', false);
\MailSo\Config::$SystemLogger = \RainLoop\Api::Logger(); \MailSo\Config::$SystemLogger = \RainLoop\Api::Logger();
} }
} }

View file

@ -238,11 +238,11 @@ Enables caching in the system'),
'use_imap_thread' => array(true), 'use_imap_thread' => array(true),
'use_imap_move' => array(true), 'use_imap_move' => array(true),
'use_imap_auth_plain' => array(false), 'use_imap_auth_plain' => array(false),
'use_imap_expunge_all_on_delete' => array(false),
'imap_forwarded_flag' => array('$Forwarded'), 'imap_forwarded_flag' => array('$Forwarded'),
'imap_read_receipt_flag' => array('$ReadReceipt'), 'imap_read_receipt_flag' => array('$ReadReceipt'),
'imap_body_text_limit' => array(555000), 'imap_body_text_limit' => array(555000),
'imap_message_list_fast_simple_search' => array(true), 'imap_message_list_fast_simple_search' => array(true),
'imap_message_list_hide_deleted_messages' => array(false),
'imap_message_list_count_limit_trigger' => array(0), 'imap_message_list_count_limit_trigger' => array(0),
'imap_message_list_date_filter' => array(0), 'imap_message_list_date_filter' => array(0),
'smtp_show_server_errors' => array(false), 'smtp_show_server_errors' => array(false),