From a9c60137da0e04e6f5d3fdf52fdebeaa25cb00cd Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Tue, 3 Jan 2023 17:00:58 +0100 Subject: [PATCH] Added untested KolabAddressBook autocreate contacts #812 --- plugins/kolab/KolabAddressBook.php | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/plugins/kolab/KolabAddressBook.php b/plugins/kolab/KolabAddressBook.php index 475325ac9..1876ee1d0 100644 --- a/plugins/kolab/KolabAddressBook.php +++ b/plugins/kolab/KolabAddressBook.php @@ -1,6 +1,7 @@ $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; }