Exemplo n.º 1
0
 /**
  * @param IManager $cm
  * @param $addressBooks
  * @param IURLGenerator $urlGenerator
  */
 private function register(IManager $cm, $addressBooks, $urlGenerator)
 {
     foreach ($addressBooks as $addressBookInfo) {
         $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo);
         $cm->registerAddressBook(new AddressBookImpl($addressBook, $addressBookInfo, $this->backend, $urlGenerator));
     }
 }
Exemplo n.º 2
0
 /**
  * @param IManager $cm
  * @param string $userId
  */
 public function setupContactsProvider(IManager $cm, $userId)
 {
     $addressBooks = $this->backend->getAddressBooksForUser("principals/{$userId}");
     foreach ($addressBooks as $addressBookInfo) {
         $addressBook = new \OCA\DAV\CardDAV\AddressBook($this->backend, $addressBookInfo);
         $cm->registerAddressBook(new AddressBookImpl($addressBook, $addressBookInfo, $this->backend));
     }
 }
Exemplo n.º 3
0
 /**
  * @param string $email
  * @return null|string
  */
 public function getPhoto($email)
 {
     $result = $this->contactsManager->search($email, ['EMAIL']);
     if (count($result) > 0) {
         if (isset($result[0]['PHOTO'])) {
             $s = $result[0]['PHOTO'];
             return substr($s, strpos($s, 'http'));
         }
     }
     return null;
 }
 /**
  * @param string $search
  * @return JSONResponse
  *
  * @NoAdminRequired
  * @NoCSRFRequired
  */
 public function searchAttendee($search)
 {
     $result = $this->contacts->search($search, ['FN', 'EMAIL']);
     $contacts = [];
     foreach ($result as $r) {
         if (!isset($r['EMAIL'])) {
             continue;
         }
         $name = $this->getName($r);
         foreach ($r['EMAIL'] as $email) {
             $contacts[] = ['email' => $email, 'name' => $name];
         }
     }
     return new JSONResponse($contacts);
 }
Exemplo n.º 5
0
 /**
  * @param string $search
  * @return array possible sharees
  */
 protected function getRemote($search)
 {
     $this->result['remotes'] = [];
     // Search in contacts
     //@todo Pagination missing
     $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']);
     $foundRemoteById = false;
     foreach ($addressBookContacts as $contact) {
         if (isset($contact['CLOUD'])) {
             foreach ($contact['CLOUD'] as $cloudId) {
                 if (strtolower($contact['FN']) === $search || strtolower($cloudId) === $search) {
                     if (strtolower($cloudId) === $search) {
                         $foundRemoteById = true;
                     }
                     $this->result['exact']['remotes'][] = ['label' => $contact['FN'], 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $cloudId]];
                 } else {
                     $this->result['remotes'][] = ['label' => $contact['FN'], 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $cloudId]];
                 }
             }
         }
     }
     if (!$foundRemoteById && substr_count($search, '@') >= 1 && substr_count($search, ' ') === 0 && $this->offset === 0) {
         $this->result['exact']['remotes'][] = ['label' => $search, 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $search]];
     }
     $this->reachedEndFor[] = 'remotes';
 }
Exemplo n.º 6
0
 /**
  * @NoAdminRequired
  * @return JSONResponse
  */
 public function removeContact($contacts)
 {
     // Create contacts
     $ids = array();
     foreach ($contacts as $contact) {
         $this->cm->delete($contact, 'local:1');
     }
 }
Exemplo n.º 7
0
 /**
  * @dataProvider dataGetRemote
  *
  * @param string $searchTerm
  * @param array $contacts
  * @param array $exactExpected
  * @param array $expected
  * @param bool $reachedEnd
  */
 public function testGetRemote($searchTerm, $contacts, $exactExpected, $expected, $reachedEnd)
 {
     $this->contactsManager->expects($this->any())->method('search')->with($searchTerm, ['CLOUD', 'FN'])->willReturn($contacts);
     $this->invokePrivate($this->sharees, 'getRemote', [$searchTerm]);
     $result = $this->invokePrivate($this->sharees, 'result');
     $this->assertEquals($exactExpected, $result['exact']['remotes']);
     $this->assertEquals($expected, $result['remotes']);
     $this->assertCount((int) $reachedEnd, $this->invokePrivate($this->sharees, 'reachedEndFor'));
 }
Exemplo n.º 8
0
 /**
  * Extracts all matching contacts with email address and name
  *
  * @param string $term
  * @return array
  */
 public function getMatchingLocaction($term)
 {
     if (!$this->contactsManager->isEnabled()) {
         return array();
     }
     $result = $this->contactsManager->search($term, array('FN', 'ADR', 'N'));
     //$addressDefArray=array('0'=>'','1'=>'','2'=>'street','3'=>'city','4'=>'','5'=>'postalcode','6'=>'country');
     //$aDefNArray=array('0'=>'lname','1'=>'fname','2'=>'anrede', '3'=>'title');
     $receivers = array();
     foreach ($result as $r) {
         $id = $r['id'];
         $fn = $r['FN'];
         $name = '';
         if (isset($r['N'])) {
             list($lastname, $surename, $gender, $title) = $r['N'];
             $name = !empty($surename) ? $surename : '';
             $name .= !empty($lastname) ? ' ' . $lastname : '';
             $name = '(' . $name . ')';
             //$name .= (!empty($gender)?$gender:'');
             //$name .= (!empty($title)?' '.$title:'');
         }
         $address = $r['ADR'];
         if (!is_array($address)) {
             $address = array($address);
         }
         // loop through all email addresses of this contact
         foreach ($address as $e) {
             $aAddr = '';
             list($zero, $one, $street, $city, $four, $postalcode, $country) = $e;
             $aAddr = !empty($street) ? $street : '';
             $aAddr .= !empty($postalcode) ? ', ' . $postalcode . ' ' : '';
             $aAddr .= !empty($city) ? $city : '';
             $aAddr .= !empty($country) ? ', ' . $country : '';
             $displayName = "\"{$fn}\" {$name} {$aAddr}";
             $valueAddr = $aAddr;
             $receivers[] = array('id' => $id, 'label' => $displayName, 'value' => $valueAddr);
         }
     }
     return $receivers;
 }
Exemplo n.º 9
0
 /**
  * Try to find the user in the contacts
  *
  * @param string $federatedCloudId
  * @return string
  * @throws \OutOfBoundsException when there is no contact for the id
  */
 protected function getDisplayNameFromContact($federatedCloudId)
 {
     $federatedCloudId = strtolower($federatedCloudId);
     if (isset($this->federatedContacts[$federatedCloudId])) {
         if ($this->federatedContacts[$federatedCloudId] !== '') {
             return $this->federatedContacts[$federatedCloudId];
         } else {
             throw new \OutOfBoundsException('No contact found for federated cloud id');
         }
     }
     $addressBookEntries = $this->manager->search($federatedCloudId, ['CLOUD']);
     foreach ($addressBookEntries as $entry) {
         if (isset($entry['CLOUD'])) {
             foreach ($entry['CLOUD'] as $cloudID) {
                 if ($cloudID === $federatedCloudId) {
                     $this->federatedContacts[$federatedCloudId] = $entry['FN'];
                     return $entry['FN'];
                 }
             }
         }
     }
     $this->federatedContacts[$federatedCloudId] = '';
     throw new \OutOfBoundsException('No contact found for federated cloud id');
 }
Exemplo n.º 10
0
 /**
  * @dataProvider dataGetDisplayNameFromContactThrows
  *
  * @param array $addressReturn
  */
 public function testGetDisplayNameFromContactThrows(array $addressReturn)
 {
     $this->contactsManager->expects($this->once())->method('search')->with('test@localhost', ['CLOUD'])->willReturn($addressReturn);
     $formatter = $this->getFormatter();
     try {
         $this->invokePrivate($formatter, 'getDisplayNameFromContact', ['test@localhost']);
         $this->assertTrue(false, 'Asserting that OutOfBoundsException is thrown');
     } catch (\OutOfBoundsException $e) {
         $this->assertTrue(true, 'Asserting that OutOfBoundsException is thrown');
     }
     try {
         $this->invokePrivate($formatter, 'getDisplayNameFromContact', ['test@localhost']);
         $this->assertTrue(false, 'Asserting that OutOfBoundsException is thrown');
     } catch (\OutOfBoundsException $e) {
         $this->assertTrue(true, 'Asserting that OutOfBoundsException is thrown');
     }
 }
Exemplo n.º 11
0
 /**
  * @param string $search
  * @return array possible sharees
  */
 protected function getRemote($search)
 {
     $this->result['remotes'] = [];
     // Search in contacts
     //@todo Pagination missing
     $addressBookContacts = $this->contactsManager->search($search, ['CLOUD', 'FN']);
     $foundRemoteById = false;
     foreach ($addressBookContacts as $contact) {
         if (isset($contact['isLocalSystemBook'])) {
             continue;
         }
         if (isset($contact['CLOUD'])) {
             $cloudIds = $contact['CLOUD'];
             if (!is_array($cloudIds)) {
                 $cloudIds = [$cloudIds];
             }
             foreach ($cloudIds as $cloudId) {
                 list(, $serverUrl) = $this->splitUserRemote($cloudId);
                 if (strtolower($contact['FN']) === $search || strtolower($cloudId) === $search) {
                     if (strtolower($cloudId) === $search) {
                         $foundRemoteById = true;
                     }
                     $this->result['exact']['remotes'][] = ['label' => $contact['FN'], 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $cloudId, 'server' => $serverUrl]];
                 } else {
                     $this->result['remotes'][] = ['label' => $contact['FN'], 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $cloudId, 'server' => $serverUrl]];
                 }
             }
         }
     }
     if (!$this->shareeEnumeration) {
         $this->result['remotes'] = [];
     }
     if (!$foundRemoteById && substr_count($search, '@') >= 1 && substr_count($search, ' ') === 0 && $this->offset === 0) {
         $this->result['exact']['remotes'][] = ['label' => $search, 'value' => ['shareType' => Share::SHARE_TYPE_REMOTE, 'shareWith' => $search]];
     }
     $this->reachedEndFor[] = 'remotes';
 }