mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-04 15:07:02 +03:00
Move the Kolab Contacts Suggestions test to be IMAP Contacts Suggestions
This commit is contained in:
parent
ddb95b925d
commit
86ac71ea2e
3 changed files with 9 additions and 15 deletions
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
class ImapContactsSuggestions implements \RainLoop\Providers\Suggestions\ISuggestions
|
||||
{
|
||||
// TODO: make setting
|
||||
public $sFolderName = 'INBOX';
|
||||
|
||||
public function Process(\RainLoop\Model\Account $oAccount, string $sQuery, int $iLimit = 20): array
|
||||
{
|
||||
$sQuery = \trim($sQuery);
|
||||
if (2 > \strlen($sQuery)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$oActions = \RainLoop\Api::Actions();
|
||||
$oMailClient = $oActions->MailClient();
|
||||
if (!$oMailClient->IsLoggined()) {
|
||||
$oAccount = $oActions->getAccountFromToken();
|
||||
$oAccount->IncConnectAndLoginHelper($oActions->Plugins(), $oMailClient, $oActions->Config());
|
||||
}
|
||||
$oImapClient = $oMailClient->ImapClient();
|
||||
|
||||
$oImapClient->FolderSelect($this->sFolderName);
|
||||
|
||||
$sQuery = \MailSo\Imap\SearchCriterias::escapeSearchString($oImapClient, $sQuery);
|
||||
$aUids = \array_slice(
|
||||
$oImapClient->MessageSimpleSearch("FROM {$sQuery}"),
|
||||
0, $iLimit
|
||||
);
|
||||
|
||||
$aResult = [];
|
||||
foreach ($oImapClient->Fetch(['BODY.PEEK[HEADER.FIELDS (FROM)]'], \implode(',', $aUids), true) as $oFetchResponse) {
|
||||
$oHeaders = new \MailSo\Mime\HeaderCollection($oFetchResponse->GetHeaderFieldsValue());
|
||||
$oFrom = $oHeaders->GetAsEmailCollection(\MailSo\Mime\Enumerations\Header::FROM_, true);
|
||||
foreach ($oFrom as $oMail) {
|
||||
$aResult[] = [$oMail->GetEmail(), $oMail->GetDisplayName()];
|
||||
}
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue