Added untested KolabAddressBook autocreate contacts #812

This commit is contained in:
the-djmaze 2023-01-03 17:00:58 +01:00
parent 5ff8b28a12
commit a9c60137da

View file

@ -1,6 +1,7 @@
<?php
use RainLoop\Providers\AddressBook\Classes\Contact;
use Sabre\VObject\Component\VCard;
class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInterface
{
@ -53,7 +54,7 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
return false;
}
protected function fetchXCardFromMessage(\MailSo\Mail\Message $oMessage) : ?\Sabre\VObject\Component\VCard
protected function fetchXCardFromMessage(\MailSo\Mail\Message $oMessage) : ?VCard
{
$xCard = null;
try {
@ -353,6 +354,33 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool
{
if ($bCreateAuto) {
foreach ($aEmails as $sEmail => $sAddress) {
$sSearch = \MailSo\Imap\SearchCriterias::escapeSearchString($this->ImapClient(), $sEmail);
if (!$this->ImapClient()->MessageSimpleSearch("FROM {$sSearch}")) {
$oVCard = new VCard;
$oVCard->add('EMAIL', $sEmail);
$sFullName = \trim(\MailSo\Mime\Email::Parse(\trim($sAddress))->GetDisplayName());
if ('' !== $sFullName) {
$sFirst = $sLast = '';
if (false !== \strpos($sFullName, ' ')) {
$aNames = \explode(' ', $sFullName, 2);
$sFirst = isset($aNames[0]) ? $aNames[0] : '';
$sLast = isset($aNames[1]) ? $aNames[1] : '';
} else {
$sFirst = $sFullName;
}
if (\strlen($sFirst) || \strlen($sLast)) {
$oVCard->N = array($sLast, $sFirst, '', '', '');
}
}
$oContact = new Contact();
$oContact->setVCard($oVCard);
$this->ContactSave($oContact);
}
}
return true;
}
return false;
}