mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-06 07:57:02 +03:00
Fix IncFrec logic to actually create or update
This commit is contained in:
parent
8a4eabe699
commit
b84487f4d6
1 changed files with 32 additions and 6 deletions
|
|
@ -78,18 +78,44 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function GetEmailObjects(array $aEmails) : array {
|
||||||
|
$aEmailsObjects = \array_map(function ($mItem) {
|
||||||
|
$oResult = null;
|
||||||
|
try {
|
||||||
|
$oResult = \MailSo\Mime\Email::Parse(\trim($mItem));
|
||||||
|
}
|
||||||
|
catch (\Throwable $oException) {
|
||||||
|
unset($oException);
|
||||||
|
}
|
||||||
|
return $oResult;
|
||||||
|
}, $aEmails);
|
||||||
|
|
||||||
|
$aEmailsObjects = \array_filter($aEmailsObjects, function ($oItem) {
|
||||||
|
return !!$oItem;
|
||||||
|
});
|
||||||
|
return $aEmailsObjects;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add/increment email address usage
|
* Add/increment email address usage
|
||||||
* Handy for "most used" sorting suggestions in PdoAddressBook
|
* Handy for "most used" sorting suggestions in PdoAddressBook
|
||||||
*/
|
*/
|
||||||
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool {
|
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool {
|
||||||
if ($bCreateAuto) {
|
if ($bCreateAuto) {
|
||||||
$properties = [];
|
$aEmailsObjects = $this->GetEmailObjects($aEmails);
|
||||||
foreach ($aEmails as $sEmail => $sAddress) {
|
foreach ($aEmailsObjects as $oEmail) {
|
||||||
$properties['EMAIL'] = $sAddress;
|
$properties = [];
|
||||||
$sFullName = ucfirst(strstr($sAddress, '@', true));
|
if ('' === \trim($oEmail->GetEmail())) {
|
||||||
if ('' !== $sFullName) {
|
continue;
|
||||||
$properties['FN'] = $sFullName;
|
}
|
||||||
|
$sEmail = \trim($oEmail->GetEmail(true));
|
||||||
|
$existingResults = $this->contactsManager->search($sEmail, ['EMAIL'], ['strict_search' => true]);
|
||||||
|
if (!empty($existingResults)) {
|
||||||
|
$properties['URI'] = $existingResults[0]['UID'] . '.vcf';
|
||||||
|
}
|
||||||
|
$properties['EMAIL'] = \trim($oEmail->GetEmail(true));
|
||||||
|
if ('' !== \trim($oEmail->GetDisplayName())) {
|
||||||
|
$properties['FN'] = $oEmail->GetDisplayName();
|
||||||
}
|
}
|
||||||
$this->contactsManager->createOrUpdate($properties, $this->key);
|
$this->contactsManager->createOrUpdate($properties, $this->key);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue