Beispiel #1
0
 /**
  * Resolves recipient from the contact list and gets his certificates.
  *
  * @param string $to
  *
  * @return SyncResolveRecipient|boolean
  */
 private function resolveRecipientContact($to)
 {
     // go through all contact folders of the user and
     // check if there's a contact with the given email address
     $root = mapi_msgstore_openentry($this->defaultstore);
     if (!$root) {
         ZLog::Write(LOGLEVEL_ERROR, sprintf("Unable to open default store: 0x%X", mapi_last_hresult));
     }
     $rootprops = mapi_getprops($root, array(PR_IPM_CONTACT_ENTRYID));
     $contacts = $this->getContactsFromFolder($this->defaultstore, $rootprops[PR_IPM_CONTACT_ENTRYID], $to);
     $recipients = array();
     if ($contacts !== false) {
         // create resolve recipient object
         foreach ($contacts as $contact) {
             $certificates = isset($contact[PR_USER_X509_CERTIFICATE]) && is_array($contact[PR_USER_X509_CERTIFICATE]) && count($contact[PR_USER_X509_CERTIFICATE]) ? $this->getCertificates($contact[PR_USER_X509_CERTIFICATE], 1) : false;
             if ($certificates !== false) {
                 return $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_CONTACT, u2w($contact[PR_DISPLAY_NAME]), $to, $certificates);
             }
         }
     }
     $contactfolder = mapi_msgstore_openentry($this->defaultstore, $rootprops[PR_IPM_CONTACT_ENTRYID]);
     $subfolders = MAPIUtils::GetSubfoldersForType($contactfolder, "IPF.Contact");
     foreach ($subfolders as $folder) {
         $contacts = $this->getContactsFromFolder($this->defaultstore, $folder[PR_ENTRYID], $to);
         if ($contacts !== false) {
             foreach ($contacts as $contact) {
                 $certificates = isset($contact[PR_USER_X509_CERTIFICATE]) && is_array($contact[PR_USER_X509_CERTIFICATE]) && count($contact[PR_USER_X509_CERTIFICATE]) ? $this->getCertificates($contact[PR_USER_X509_CERTIFICATE], 1) : false;
                 if ($certificates !== false) {
                     return $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_CONTACT, u2w($contact[PR_DISPLAY_NAME]), $to, $certificates);
                 }
             }
         }
     }
     // search contacts in public folders
     $storestables = mapi_getmsgstorestable($this->session);
     $result = mapi_last_hresult();
     if ($result == NOERROR) {
         $rows = mapi_table_queryallrows($storestables, array(PR_ENTRYID, PR_DEFAULT_STORE, PR_MDB_PROVIDER));
         foreach ($rows as $row) {
             if (isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
                 // TODO refactor public store
                 $publicstore = mapi_openmsgstore($this->session, $row[PR_ENTRYID]);
                 $publicfolder = mapi_msgstore_openentry($publicstore);
                 $subfolders = MAPIUtils::GetSubfoldersForType($publicfolder, "IPF.Contact");
                 if ($subfolders !== false) {
                     foreach ($subfolders as $folder) {
                         $contacts = $this->getContactsFromFolder($publicstore, $folder[PR_ENTRYID], $to);
                         if ($contacts !== false) {
                             foreach ($contacts as $contact) {
                                 $certificates = isset($contact[PR_USER_X509_CERTIFICATE]) && is_array($contact[PR_USER_X509_CERTIFICATE]) && count($contact[PR_USER_X509_CERTIFICATE]) ? $this->getCertificates($contact[PR_USER_X509_CERTIFICATE], 1) : false;
                                 if ($certificates !== false) {
                                     return $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_CONTACT, u2w($contact[PR_DISPLAY_NAME]), $to, $certificates);
                                 }
                             }
                         }
                     }
                 }
                 break;
             }
         }
     } else {
         ZLog::Write(LOGLEVEL_WARN, sprintf("Unable to open public store: 0x%X", $result));
     }
     $certificates = $this->getCertificates(false);
     return $this->createResolveRecipient(SYNC_RESOLVERECIPIENTS_TYPE_CONTACT, $to, $to, $certificates);
 }