mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-08 22:18:28 +03:00
Imap ESEARCH/ESORT helper
This commit is contained in:
parent
26cd65d763
commit
29f579dc4e
8 changed files with 159 additions and 38 deletions
|
|
@ -331,7 +331,7 @@ MailBoxMessageViewViewModel.prototype.onBuild = function (oDom)
|
|||
});
|
||||
|
||||
oDom
|
||||
.on('click', '.messageView .messageItem', function () {
|
||||
.on('click', '.messageView .messageItem .messageItemHeader', function () {
|
||||
if (oData.useKeyboardShortcuts() && self.message())
|
||||
{
|
||||
self.message.focused(true);
|
||||
|
|
|
|||
|
|
@ -1180,7 +1180,7 @@ class Utils
|
|||
}
|
||||
|
||||
/**
|
||||
* @param string $sString
|
||||
* @param string $sUtfString
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
|
@ -1259,7 +1259,7 @@ class Utils
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function ExpandFetchSequence($sSequence)
|
||||
public static function ParseFetchSequence($sSequence)
|
||||
{
|
||||
$aResult = array();
|
||||
$sSequence = \trim($sSequence);
|
||||
|
|
@ -1287,6 +1287,56 @@ class Utils
|
|||
|
||||
return $aResult;
|
||||
}
|
||||
/**
|
||||
* @param array $aSequence
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function PrepearFetchSequence($aSequence)
|
||||
{
|
||||
$aResult = array();
|
||||
if (\is_array($aSequence) && 0 < \count($aSequence))
|
||||
{
|
||||
$iStart = null;
|
||||
$iPrev = null;
|
||||
|
||||
foreach ($aSequence as $sItem)
|
||||
{
|
||||
// simple protection
|
||||
if (false !== \strpos($sItem, ':'))
|
||||
{
|
||||
$aResult[] = $sItem;
|
||||
continue;
|
||||
}
|
||||
|
||||
$iItem = (int) $sItem;
|
||||
if (null === $iStart || null === $iPrev)
|
||||
{
|
||||
$iStart = $iItem;
|
||||
$iPrev = $iItem;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($iPrev === $iItem - 1)
|
||||
{
|
||||
$iPrev = $iItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
$aResult[] = $iStart === $iPrev ? $iStart : $iStart.':'.$iPrev;
|
||||
$iStart = $iItem;
|
||||
$iPrev = $iItem;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== $iStart && null !== $iPrev)
|
||||
{
|
||||
$aResult[] = $iStart === $iPrev ? $iStart : $iStart.':'.$iPrev;
|
||||
}
|
||||
}
|
||||
|
||||
return \implode(',', $aResult);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1035,16 +1035,17 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
}
|
||||
}
|
||||
|
||||
$aReturn = array_reverse($aReturn);
|
||||
return $aReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bSort = false
|
||||
* @param string $sSearchCriterias = 'ALL'
|
||||
* @param array $aSearchReturn = null
|
||||
* @param array $aSearchOrSortReturn = null
|
||||
* @param bool $bReturnUid = true
|
||||
* @param string $sLimit = ''
|
||||
* @param string $sCharset = ''
|
||||
* @param array $aSortTypes = null
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
|
|
@ -1052,47 +1053,66 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Imap\Exceptions\Exception
|
||||
*/
|
||||
public function MessageSimpleESearch($sSearchCriterias = 'ALL', $aSearchReturn = null, $bReturnUid = true, $sLimit = '', $sCharset = '')
|
||||
private function simpleESearchOrESortHelper($bSort = false, $sSearchCriterias = 'ALL', $aSearchOrSortReturn = null, $bReturnUid = true, $sLimit = '', $sCharset = '', $aSortTypes = null)
|
||||
{
|
||||
$sCommandPrefix = ($bReturnUid) ? 'UID ' : '';
|
||||
$sSearchCriterias = 0 === \strlen($sSearchCriterias) || '*' === $sSearchCriterias
|
||||
? 'ALL' : $sSearchCriterias;
|
||||
|
||||
if (!$this->IsSupported('ESEARCH'))
|
||||
$sCmd = $bSort ? 'SORT': 'SEARCH';
|
||||
if ($bSort && (!\is_array($aSortTypes) || 0 === \count($aSortTypes) || !$this->IsSupported('SORT')))
|
||||
{
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException(),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
if (!\is_array($aSearchReturn) || 0 === \count($aSearchReturn))
|
||||
if (!$this->IsSupported($bSort ? 'ESORT' : 'ESEARCH'))
|
||||
{
|
||||
$aSearchReturn = array('ALL');
|
||||
$this->writeLogException(
|
||||
new \MailSo\Base\Exceptions\InvalidArgumentException(),
|
||||
\MailSo\Log\Enumerations\Type::ERROR, true);
|
||||
}
|
||||
|
||||
if (!\is_array($aSearchOrSortReturn) || 0 === \count($aSearchOrSortReturn))
|
||||
{
|
||||
$aSearchOrSortReturn = array('ALL');
|
||||
}
|
||||
|
||||
$aRequest = array();
|
||||
if (0 < \strlen($sCharset))
|
||||
if ($bSort)
|
||||
{
|
||||
$aRequest[] = 'CHARSET';
|
||||
$aRequest[] = \strtoupper($sCharset);
|
||||
$aRequest[] = 'RETURN';
|
||||
$aRequest[] = $aSearchOrSortReturn;
|
||||
|
||||
$aRequest[] = $aSortTypes;
|
||||
$aRequest[] = \MailSo\Base\Utils::IsAscii($sSearchCriterias) ? 'US-ASCII' : 'UTF-8';
|
||||
}
|
||||
else
|
||||
{
|
||||
if (0 < \strlen($sCharset))
|
||||
{
|
||||
$aRequest[] = 'CHARSET';
|
||||
$aRequest[] = \strtoupper($sCharset);
|
||||
}
|
||||
|
||||
$aRequest[] = 'RETURN';
|
||||
$aRequest[] = $aSearchOrSortReturn;
|
||||
}
|
||||
|
||||
$aRequest[] = 'RETURN';
|
||||
$aRequest[] = $aSearchReturn;
|
||||
|
||||
$aRequest[] = $sSearchCriterias;
|
||||
|
||||
|
||||
if (0 < \strlen($sLimit))
|
||||
{
|
||||
$aRequest[] = $sLimit;
|
||||
}
|
||||
|
||||
$this->SendRequest($sCommandPrefix.('SEARCH'), $aRequest);
|
||||
$this->SendRequest($sCommandPrefix.$sCmd, $aRequest);
|
||||
$sRequestTag = $this->getCurrentTag();
|
||||
|
||||
$aResult = array();
|
||||
$aResponse = $this->parseResponseWithValidation();
|
||||
|
||||
|
||||
if (\is_array($aResponse))
|
||||
{
|
||||
$oImapResponse = null;
|
||||
|
|
@ -1132,6 +1152,42 @@ class ImapClient extends \MailSo\Net\NetClient
|
|||
return $aResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSearchCriterias = 'ALL'
|
||||
* @param array $aSearchReturn = null
|
||||
* @param bool $bReturnUid = true
|
||||
* @param string $sLimit = ''
|
||||
* @param string $sCharset = ''
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Imap\Exceptions\Exception
|
||||
*/
|
||||
public function MessageSimpleESearch($sSearchCriterias = 'ALL', $aSearchReturn = null, $bReturnUid = true, $sLimit = '', $sCharset = '')
|
||||
{
|
||||
return $this->simpleESearchOrESortHelper(false, $sSearchCriterias, $aSearchReturn, $bReturnUid, $sLimit, $sCharset);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $aSortTypes
|
||||
* @param string $sSearchCriterias = 'ALL'
|
||||
* @param array $aSearchReturn = null
|
||||
* @param bool $bReturnUid = true
|
||||
* @param string $sLimit = ''
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @throws \MailSo\Base\Exceptions\InvalidArgumentException
|
||||
* @throws \MailSo\Net\Exceptions\Exception
|
||||
* @throws \MailSo\Imap\Exceptions\Exception
|
||||
*/
|
||||
public function MessageSimpleESort($aSortTypes, $sSearchCriterias = 'ALL', $aSearchReturn = null, $bReturnUid = true, $sLimit = '')
|
||||
{
|
||||
return $this->simpleESearchOrESortHelper(true, $sSearchCriterias, $aSearchReturn, $bReturnUid, $sLimit, '', $aSortTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sSearchCriterias
|
||||
* @param bool $bReturnUid = true
|
||||
|
|
|
|||
|
|
@ -239,8 +239,8 @@ class MailClient
|
|||
: \MailSo\Imap\Enumerations\StoreAction::REMOVE_FLAGS_SILENT
|
||||
;
|
||||
|
||||
$sIndexRange = \implode(',', $aIndexRange);
|
||||
$this->oImapClient->MessageStoreFlag($sIndexRange, $bIndexIsUid, array($sMessageFlag), $sStoreAction);
|
||||
$this->oImapClient->MessageStoreFlag(\MailSo\Base\Utils::PrepearFetchSequence($aIndexRange),
|
||||
$bIndexIsUid, array($sMessageFlag), $sStoreAction);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -536,7 +536,7 @@ class MailClient
|
|||
|
||||
$this->oImapClient->FolderSelect($sFolder);
|
||||
|
||||
$sIndexRange = \implode(',', $aIndexRange);
|
||||
$sIndexRange = \MailSo\Base\Utils::PrepearFetchSequence($aIndexRange);
|
||||
|
||||
$this->oImapClient->MessageStoreFlag($sIndexRange, $bIndexIsUid,
|
||||
array(\MailSo\Imap\Enumerations\MessageFlag::DELETED),
|
||||
|
|
@ -576,11 +576,14 @@ class MailClient
|
|||
|
||||
if ($bUseMoveSupported && $this->oImapClient->IsSupported('MOVE'))
|
||||
{
|
||||
$this->oImapClient->MessageMove($sToFolder, \implode(',', $aIndexRange), $bIndexIsUid);
|
||||
$this->oImapClient->MessageMove($sToFolder,
|
||||
\MailSo\Base\Utils::PrepearFetchSequence($aIndexRange), $bIndexIsUid);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->oImapClient->MessageCopy($sToFolder, \implode(',', $aIndexRange), $bIndexIsUid);
|
||||
$this->oImapClient->MessageCopy($sToFolder,
|
||||
\MailSo\Base\Utils::PrepearFetchSequence($aIndexRange), $bIndexIsUid);
|
||||
|
||||
$this->MessageDelete($sFromFolder, $aIndexRange, $bIndexIsUid, true);
|
||||
}
|
||||
|
||||
|
|
@ -608,7 +611,8 @@ class MailClient
|
|||
}
|
||||
|
||||
$this->oImapClient->FolderSelect($sFromFolder);
|
||||
$this->oImapClient->MessageCopy($sToFolder, \implode(',', $aIndexRange), $bIndexIsUid);
|
||||
$this->oImapClient->MessageCopy($sToFolder,
|
||||
\MailSo\Base\Utils::PrepearFetchSequence($aIndexRange), $bIndexIsUid);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -806,7 +810,7 @@ class MailClient
|
|||
\MailSo\Imap\Enumerations\FetchType::INDEX,
|
||||
\MailSo\Imap\Enumerations\FetchType::UID,
|
||||
\MailSo\Imap\Enumerations\FetchType::FLAGS
|
||||
), \implode(',', $aUids), true);
|
||||
), \MailSo\Base\Utils::PrepearFetchSequence($aUids), true);
|
||||
|
||||
if (\is_array($aFetchResponse) && 0 < \count($aFetchResponse))
|
||||
{
|
||||
|
|
@ -1469,7 +1473,7 @@ class MailClient
|
|||
\MailSo\Imap\Enumerations\FetchType::FLAGS,
|
||||
\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE,
|
||||
$this->getEnvelopeOrHeadersRequestString()
|
||||
), \implode(',', $aRequestIndexOrUids), $bIndexAsUid);
|
||||
), \MailSo\Base\Utils::PrepearFetchSequence($aRequestIndexOrUids), $bIndexAsUid);
|
||||
|
||||
if (\is_array($aFetchResponse) && 0 < \count($aFetchResponse))
|
||||
{
|
||||
|
|
@ -1520,7 +1524,7 @@ class MailClient
|
|||
* @param bool $bUseSortIfSupported = false
|
||||
* @param bool $bUseThreadSortIfSupported = false
|
||||
* @param array $aExpandedThreadsUids = array()
|
||||
* @param bool $bUseESearchOrESortRequest = true
|
||||
* @param bool $bUseESearchOrESortRequest = false
|
||||
*
|
||||
* @return \MailSo\Mail\MessageCollection
|
||||
*
|
||||
|
|
@ -1530,7 +1534,7 @@ class MailClient
|
|||
*/
|
||||
public function MessageList($sFolderName, $iOffset = 0, $iLimit = 10, $sSearch = '', $sPrevUidNext = '',
|
||||
$oCacher = null, $bUseSortIfSupported = false, $bUseThreadSortIfSupported = false, $aExpandedThreadsUids = array(),
|
||||
$bUseESearchOrESortRequest = true)
|
||||
$bUseESearchOrESortRequest = false)
|
||||
{
|
||||
$sSearch = \trim($sSearch);
|
||||
if (!\MailSo\Base\Validator::RangeInt($iOffset, 0) ||
|
||||
|
|
@ -1623,12 +1627,17 @@ class MailClient
|
|||
{
|
||||
if ($bESortSupported)
|
||||
{
|
||||
// TODO
|
||||
$aIndexOrUids = $this->oImapClient->MessageSimpleSort(array('ARRIVAL'), $sSearchCriterias, $bIndexAsUid);
|
||||
$aESorthData = $this->oImapClient->MessageSimpleESort(array('ARRIVAL'), $sSearchCriterias, array('ALL'), $bIndexAsUid, '');
|
||||
if (isset($aESorthData['ALL']))
|
||||
{
|
||||
$aIndexOrUids = \MailSo\Base\Utils::ParseFetchSequence($aESorthData['ALL']);
|
||||
$aIndexOrUids = \array_reverse($aIndexOrUids);
|
||||
}
|
||||
unset($aESorthData);
|
||||
}
|
||||
else
|
||||
{
|
||||
$aIndexOrUids = $this->oImapClient->MessageSimpleSort(array('ARRIVAL'), $sSearchCriterias, $bIndexAsUid);
|
||||
$aIndexOrUids = $this->oImapClient->MessageSimpleSort(array('REVERSE ARRIVAL'), $sSearchCriterias, $bIndexAsUid);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -1642,8 +1651,10 @@ class MailClient
|
|||
$aESearchData = $this->oImapClient->MessageSimpleESearch($sSearchCriterias, array('ALL'), $bIndexAsUid, '', 'UTF-8');
|
||||
if (isset($aESearchData['ALL']))
|
||||
{
|
||||
$aIndexOrUids = \MailSo\Base\Utils::ExpandFetchSequence($aESearchData['ALL']);
|
||||
$aIndexOrUids = \MailSo\Base\Utils::ParseFetchSequence($aESearchData['ALL']);
|
||||
$aIndexOrUids = \array_reverse($aIndexOrUids);
|
||||
}
|
||||
unset($aESearchData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1664,8 +1675,10 @@ class MailClient
|
|||
$aESearchData = $this->oImapClient->MessageSimpleESearch($sSearchCriterias, array('ALL'), $bIndexAsUid);
|
||||
if (isset($aESearchData['ALL']))
|
||||
{
|
||||
$aIndexOrUids = \MailSo\Base\Utils::ExpandFetchSequence($aESearchData['ALL']);
|
||||
$aIndexOrUids = \MailSo\Base\Utils::ParseFetchSequence($aESearchData['ALL']);
|
||||
$aIndexOrUids = \array_reverse($aIndexOrUids);
|
||||
}
|
||||
unset($aESearchData);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1686,7 +1699,7 @@ class MailClient
|
|||
$oCacher);
|
||||
|
||||
$aIndexOrUids = $this->compileLineThreadUids($aThreads, $aLastCollapsedThreadUids, $aExpandedThreadsUids, 0);
|
||||
$iMessageCount = count($aIndexOrUids);
|
||||
$iMessageCount = \count($aIndexOrUids);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3959,7 +3959,8 @@ class Actions
|
|||
($this->Config()->Get('cache', 'enable', true) && $this->Config()->Get('cache', 'server_uids', false)) ? $this->Cacher() : null,
|
||||
!!$this->Config()->Get('labs', 'use_imap_sort', false),
|
||||
$bUseThreads,
|
||||
$aExpandedThreadUid
|
||||
$aExpandedThreadUid,
|
||||
!!$this->Config()->Get('labs', 'use_imap_esearch_esort', false)
|
||||
);
|
||||
}
|
||||
catch (\Exception $oException)
|
||||
|
|
|
|||
|
|
@ -225,7 +225,8 @@ Enables caching in the system'),
|
|||
'allow_html_editor_source_button' => array(false),
|
||||
'use_app_debug_js' => array(false),
|
||||
'use_app_debug_css' => array(false),
|
||||
'use_imap_sort' => array(false),
|
||||
'use_imap_sort' => array(true),
|
||||
'use_imap_esearch_esort' => array(false),
|
||||
'use_imap_force_selection' => array(false),
|
||||
'use_imap_list_subscribe' => array(true),
|
||||
'use_imap_thread' => array(true),
|
||||
|
|
|
|||
|
|
@ -13362,7 +13362,7 @@ MailBoxMessageViewViewModel.prototype.onBuild = function (oDom)
|
|||
});
|
||||
|
||||
oDom
|
||||
.on('click', '.messageView .messageItem', function () {
|
||||
.on('click', '.messageView .messageItem .messageItemHeader', function () {
|
||||
if (oData.useKeyboardShortcuts() && self.message())
|
||||
{
|
||||
self.message.focused(true);
|
||||
|
|
|
|||
2
rainloop/v/0.0.0/static/js/app.min.js
vendored
2
rainloop/v/0.0.0/static/js/app.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue