Merge pull request #38073 from nextcloud/feat/caldav/map-additional-emails-system-addres-book

feat(carddav): Map user's additional emails into the SAB card
pull/38102/head
Christoph Wurst 2023-05-04 23:50:37 +07:00 committed by GitHub
commit d2606a9b7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 1 deletions

@ -29,10 +29,12 @@ namespace OCA\DAV\CardDAV;
use Exception;
use OCP\Accounts\IAccountManager;
use OCP\Accounts\PropertyDoesNotExistException;
use OCP\IImage;
use OCP\IUser;
use Sabre\VObject\Component\VCard;
use Sabre\VObject\Property\Text;
use function array_merge;
class Converter {
@ -44,7 +46,13 @@ class Converter {
}
public function createCardFromUser(IUser $user): ?VCard {
$userProperties = $this->accountManager->getAccount($user)->getProperties();
$account = $this->accountManager->getAccount($user);
$userProperties = $account->getProperties();
try {
$additionalEmailsCollection = $account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL);
$userProperties = array_merge($userProperties, $additionalEmailsCollection->getProperties());
} catch (PropertyDoesNotExistException $e) {
}
$uid = $user->getUID();
$cloudId = $user->getCloudId();
@ -75,6 +83,7 @@ class Converter {
$vCard->add('PHOTO', $image->data(), ['ENCODING' => 'b', 'TYPE' => $image->mimeType()]);
}
break;
case IAccountManager::COLLECTION_EMAIL:
case IAccountManager::PROPERTY_EMAIL:
$vCard->add(new Text($vCard, 'EMAIL', $property->getValue(), ['TYPE' => 'OTHER']));
break;