mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
Improved Kolab detection
This commit is contained in:
parent
ea5224c7e3
commit
d93a31dda0
2 changed files with 32 additions and 36 deletions
|
|
@ -12,6 +12,17 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
||||||
$oImapClient,
|
$oImapClient,
|
||||||
$sFolderName;
|
$sFolderName;
|
||||||
|
|
||||||
|
function __construct(string $sFolderName)
|
||||||
|
{
|
||||||
|
$metadata = $this->ImapClient()->FolderGetMetadata($sFolderName, [\MailSo\Imap\Enumerations\MetadataKeys::KOLAB_CTYPE]);
|
||||||
|
if (!$metadata || 'contact' !== \array_shift($metadata)) {
|
||||||
|
$sFolderName = '';
|
||||||
|
// throw new \Exception("Invalid kolab contact folder: {$sFolderName}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sFolderName = $sFolderName;
|
||||||
|
}
|
||||||
|
|
||||||
protected function MailClient() : \MailSo\Mail\MailClient
|
protected function MailClient() : \MailSo\Mail\MailClient
|
||||||
{
|
{
|
||||||
$oActions = \RainLoop\Api::Actions();
|
$oActions = \RainLoop\Api::Actions();
|
||||||
|
|
@ -30,39 +41,21 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
||||||
return $this->oImapClient;
|
return $this->oImapClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function FolderName() : string
|
|
||||||
{
|
|
||||||
if (!\is_string($this->sFolderName)) {
|
|
||||||
$oActions = \RainLoop\Api::Actions();
|
|
||||||
$oAccount = $oActions->getAccountFromToken();
|
|
||||||
$sFolderName = (string) $oActions->SettingsProvider(true)->Load($oAccount)->GetConf('KolabContactFolder', '');
|
|
||||||
|
|
||||||
$metadata = $this->ImapClient()->FolderGetMetadata($sFolderName, [\MailSo\Imap\Enumerations\MetadataKeys::KOLAB_CTYPE]);
|
|
||||||
if (!$metadata || 'contact' !== \array_shift($metadata)) {
|
|
||||||
$sFolderName = '';
|
|
||||||
// throw new \Exception("Invalid kolab contact folder: {$sFolderName}");
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->sFolderName = $sFolderName;
|
|
||||||
}
|
|
||||||
return $this->sFolderName;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function SelectFolder() : bool
|
protected function SelectFolder() : bool
|
||||||
{
|
{
|
||||||
try {
|
$sFolderName = $this->sFolderName;
|
||||||
$sFolderName = $this->FolderName();
|
|
||||||
if ($sFolderName) {
|
if ($sFolderName) {
|
||||||
|
try {
|
||||||
$this->ImapClient()->FolderSelect($sFolderName);
|
$this->ImapClient()->FolderSelect($sFolderName);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
\trigger_error("KolabAddressBook {$sFolderName} error: {$e->getMessage()}");
|
\trigger_error("KolabAddressBook {$sFolderName} error: {$e->getMessage()}");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fetchXCardFromMessage(\MailSo\Mail\Message $oMessage) : ?\Sabre\VObject\Component\VCard
|
protected function fetchXCardFromMessage(\MailSo\Mail\Message $oMessage) : ?\Sabre\VObject\Component\VCard
|
||||||
{
|
{
|
||||||
$xCard = null;
|
$xCard = null;
|
||||||
foreach ($oMessage->Attachments() ?: [] as $oAttachment) {
|
foreach ($oMessage->Attachments() ?: [] as $oAttachment) {
|
||||||
|
|
@ -71,7 +64,7 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
||||||
if (\is_resource($rResource)) {
|
if (\is_resource($rResource)) {
|
||||||
$xCard = \Sabre\VObject\Reader::readXML($rResource);
|
$xCard = \Sabre\VObject\Reader::readXML($rResource);
|
||||||
}
|
}
|
||||||
}, $this->FolderName(), $oMessage->Uid(), $oAttachment->MimeIndex());
|
}, $this->sFolderName, $oMessage->Uid(), $oAttachment->MimeIndex());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +135,7 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
||||||
|
|
||||||
$iUID = $oContact->IdContact;
|
$iUID = $oContact->IdContact;
|
||||||
|
|
||||||
$oPrevMessage = $this->MailClient()->Message($this->FolderName(), $iUID);
|
$oPrevMessage = $this->MailClient()->Message($this->sFolderName, $iUID);
|
||||||
if ($oPrevMessage) {
|
if ($oPrevMessage) {
|
||||||
$oVCard = $this->fetchXCardFromMessage($oPrevMessage);
|
$oVCard = $this->fetchXCardFromMessage($oPrevMessage);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -205,7 +198,7 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->MailClient()->MessageDelete(
|
$this->MailClient()->MessageDelete(
|
||||||
$this->FolderName(),
|
$this->sFolderName,
|
||||||
new \MailSo\Imap\SequenceSet($aContactIds)
|
new \MailSo\Imap\SequenceSet($aContactIds)
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -218,14 +211,14 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
||||||
{
|
{
|
||||||
// Called by \RainLoop\Api::ClearUserData()
|
// Called by \RainLoop\Api::ClearUserData()
|
||||||
// Not needed as the contacts are inside IMAP mailbox
|
// Not needed as the contacts are inside IMAP mailbox
|
||||||
// $this->MailClient()->FolderClear($this->FolderName());
|
// $this->MailClient()->FolderClear($this->sFolderName);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetContacts(string $sEmail, int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array
|
public function GetContacts(string $sEmail, int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array
|
||||||
{
|
{
|
||||||
$oParams = new \MailSo\Mail\MessageListParams;
|
$oParams = new \MailSo\Mail\MessageListParams;
|
||||||
$oParams->sFolderName = $this->FolderName();
|
$oParams->sFolderName = $this->sFolderName;
|
||||||
$oParams->iOffset = $iOffset;
|
$oParams->iOffset = $iOffset;
|
||||||
$oParams->iLimit = $iLimit;
|
$oParams->iLimit = $iLimit;
|
||||||
if ($sSearch) {
|
if ($sSearch) {
|
||||||
|
|
@ -265,7 +258,7 @@ class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInt
|
||||||
if ($bIsStrID) {
|
if ($bIsStrID) {
|
||||||
$oMessage = null;
|
$oMessage = null;
|
||||||
} else {
|
} else {
|
||||||
$oMessage = $this->MailClient()->Message($this->FolderName(), $mID);
|
$oMessage = $this->MailClient()->Message($this->sFolderName, $mID);
|
||||||
}
|
}
|
||||||
return $oMessage ? $this->MessageAsContact($oMessage) : null;
|
return $oMessage ? $this->MessageAsContact($oMessage) : null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,10 @@ class KolabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
{
|
{
|
||||||
const
|
const
|
||||||
NAME = 'Kolab',
|
NAME = 'Kolab',
|
||||||
VERSION = '0.1',
|
VERSION = '0.2',
|
||||||
RELEASE = '2022-05-13',
|
RELEASE = '2022-05-18',
|
||||||
CATEGORY = 'Security',
|
CATEGORY = 'Contacts',
|
||||||
DESCRIPTION = 'Get contacts suggestions from Kolab.',
|
DESCRIPTION = 'Use an Address Book of Kolab.',
|
||||||
REQUIRED = '2.15.4';
|
REQUIRED = '2.15.4';
|
||||||
|
|
||||||
public function Init() : void
|
public function Init() : void
|
||||||
|
|
@ -82,8 +82,11 @@ class KolabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
if ('address-book' === $sName) {
|
if ('address-book' === $sName) {
|
||||||
|
$sFolderName = $this->Settings()->GetConf('KolabContactFolder', '');
|
||||||
|
if ($sFolderName) {
|
||||||
require_once __DIR__ . '/KolabAddressBook.php';
|
require_once __DIR__ . '/KolabAddressBook.php';
|
||||||
$mResult = new KolabAddressBook();
|
$mResult = new KolabAddressBook($sFolderName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue