mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
create addressbook if not already exists
This commit is contained in:
parent
147ba65a35
commit
dc6e93afaa
1 changed files with 10 additions and 7 deletions
|
|
@ -12,14 +12,17 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
|||
function __construct()
|
||||
{
|
||||
$this->contactsManager = \OC::$server->getContactsManager();
|
||||
foreach ($this->contactsManager->getUserAddressBooks() as $addressbook) {
|
||||
if ($addressbook->getUri() !== self::URI) {
|
||||
$this->contactsManager->unregisterAddressBook($addressbook);
|
||||
}
|
||||
else {
|
||||
$this->key = $addressbook->getKey();
|
||||
}
|
||||
$uid = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
$cardDavBackend = \OC::$server->get(\OCA\DAV\CardDAV\CardDavBackend::class);
|
||||
$principalUri = 'principals/users/'. $uid;
|
||||
$addressBookId = $cardDavBackend->getAddressBooksByUri($principalUri, self::URI)->id;
|
||||
if (empty($addressBookId)) {
|
||||
$addressBookId = $cardDavBackend->createAddressBook($principalUri, self::URI, array_filter([
|
||||
'{DAV:}displayname' => 'Webmail',
|
||||
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'Recipients from snappymail',
|
||||
]));
|
||||
}
|
||||
$this->key = $addressBookId;
|
||||
}
|
||||
|
||||
public function IsSupported() : bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue