Example #1
0
 /**
  * Imports a change on a folder
  *
  * @param object        $folder     SyncFolder
  *
  * @access public
  * @return string       id of the folder
  * @throws StatusException
  */
 public function ImportFolderChange($folder)
 {
     $id = isset($folder->serverid) ? $folder->serverid : false;
     $parent = $folder->parentid;
     $displayname = u2wi($folder->displayname);
     $type = $folder->type;
     if (Utils::IsSystemFolder($type)) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, system folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER);
     }
     // create a new folder if $id is not set
     if (!$id) {
         // the root folder is "0" - get IPM_SUBTREE
         if ($parent == "0") {
             $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
             if (isset($parentprops[PR_IPM_SUBTREE_ENTRYID])) {
                 $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
             }
         } else {
             $parentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent));
         }
         if (!$parentfentryid) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (no entry id)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         $parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         if (!$parentfolder) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (open entry)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         //  mapi_folder_createfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION
         $newfolder = mapi_folder_createfolder($parentfolder, $displayname, "");
         if (mapi_last_hresult()) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_folder_createfolder() failed: 0x%X", Utils::PrintAsString(false), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS);
         }
         mapi_setprops($newfolder, array(PR_CONTAINER_CLASS => MAPIUtils::GetContainerClassFromFolderType($type)));
         $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY));
         if (isset($props[PR_SOURCE_KEY])) {
             $sourcekey = bin2hex($props[PR_SOURCE_KEY]);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("Created folder '%s' with id: '%s'", $displayname, $sourcekey));
             return $sourcekey;
         } else {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder created but PR_SOURCE_KEY not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
         }
         return false;
     }
     // update folder
     $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($id));
     if (!$entryid) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
     }
     $folder = mapi_msgstore_openentry($this->store, $entryid);
     if (!$folder) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
     }
     $props = mapi_getprops($folder, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS));
     if (!isset($props[PR_SOURCE_KEY]) || !isset($props[PR_PARENT_SOURCE_KEY]) || !isset($props[PR_DISPLAY_NAME]) || !isset($props[PR_CONTAINER_CLASS])) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder data not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
     }
     if ($parent == "0") {
         $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
         $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
         $mapifolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         $rootfolderprops = mapi_getprops($mapifolder, array(PR_SOURCE_KEY));
         $parent = bin2hex($rootfolderprops[PR_SOURCE_KEY]);
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportFolderChange(): resolved AS parent '0' to sourcekey '%s'", $parent));
     }
     // In theory the parent id could change, which means that the folder was moved.
     // It is unknown if any device supports this, so we do currently not implement it (no known device is able to do this)
     if (bin2hex($props[PR_PARENT_SOURCE_KEY]) !== $parent) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Folder was moved to another location, which is currently not supported. Please report this to the Z-Push dev team together with the WBXML log and your device details (model, firmware etc).", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_UNKNOWNERROR);
     }
     $props = array(PR_DISPLAY_NAME => $displayname);
     mapi_setprops($folder, $props);
     mapi_savechanges($folder);
     if (mapi_last_hresult()) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_savechanges() failed: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
     }
     ZLog::Write(LOGLEVEL_DEBUG, "Imported changes for folder: {$id}");
     return $id;
 }
Example #2
0
 function ImportFolderChange($id, $parent, $displayname, $type)
 {
     //create a new folder if $id is not set
     if (!$id) {
         $parentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent));
         $parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         $parentpros = mapi_getprops($parentfolder, array(PR_DISPLAY_NAME));
         $newfolder = mapi_folder_createfolder($parentfolder, $displayname, "");
         $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY));
         $id = bin2hex($props[PR_SOURCE_KEY]);
     }
     // 'type' is ignored because you can only create email (standard) folders
     mapi_importhierarchychanges_importfolderchange($this->importer, array(PR_SOURCE_KEY => hex2bin($id), PR_PARENT_SOURCE_KEY => hex2bin($parent), PR_DISPLAY_NAME => $displayname));
     debugLog("Imported changes for folder:{$id}");
     return $id;
 }
Example #3
0
 /**
  * Creates a search folder if it not exists or opens an existing one
  * and returns it.
  *
  * @param mapiFolderObject $searchFolderRoot
  *
  * @return mapiFolderObject
  */
 private function createSearchFolder($searchFolderRoot)
 {
     $folderName = "Z-Push Search Folder " . @getmypid();
     $searchFolders = mapi_folder_gethierarchytable($searchFolderRoot);
     $restriction = array(RES_CONTENT, array(FUZZYLEVEL => FL_PREFIX, ULPROPTAG => PR_DISPLAY_NAME, VALUE => array(PR_DISPLAY_NAME => $folderName)));
     //restrict the hierarchy to the z-push search folder only
     mapi_table_restrict($searchFolders, $restriction);
     if (mapi_table_getrowcount($searchFolders)) {
         $searchFolder = mapi_table_queryrows($searchFolders, array(PR_ENTRYID), 0, 1);
         return mapi_msgstore_openentry($this->store, $searchFolder[0][PR_ENTRYID]);
     }
     return mapi_folder_createfolder($searchFolderRoot, $folderName, null, 0, FOLDER_SEARCH);
 }
Example #4
0
 /**
  * Imports a change on a folder
  *
  * @param object        $folder     SyncFolder
  *
  * @access public
  * @return string       id of the folder
  * @throws StatusException
  */
 public function ImportFolderChange($folder)
 {
     $id = isset($folder->serverid) ? $folder->serverid : false;
     $parent = $folder->parentid;
     $displayname = u2wi($folder->displayname);
     $type = $folder->type;
     if (Utils::IsSystemFolder($type)) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, system folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER);
     }
     // create a new folder if $id is not set
     if (!$id) {
         // the root folder is "0" - get IPM_SUBTREE
         if ($parent == "0") {
             $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
             if (isset($parentprops[PR_IPM_SUBTREE_ENTRYID])) {
                 $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
             }
         } else {
             $parentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent));
         }
         if (!$parentfentryid) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (no entry id)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         $parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         if (!$parentfolder) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent folder (open entry)", Utils::PrintAsString(false), $folder->parentid, $displayname), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         //  mapi_folder_createfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION
         $newfolder = mapi_folder_createfolder($parentfolder, $displayname, "");
         if (mapi_last_hresult()) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_folder_createfolder() failed: 0x%X", Utils::PrintAsString(false), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS);
         }
         mapi_setprops($newfolder, array(PR_CONTAINER_CLASS => MAPIUtils::GetContainerClassFromFolderType($type)));
         $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY));
         if (isset($props[PR_SOURCE_KEY])) {
             $sourcekey = bin2hex($props[PR_SOURCE_KEY]);
             ZLog::Write(LOGLEVEL_DEBUG, sprintf("Created folder '%s' with id: '%s'", $displayname, $sourcekey));
             return $sourcekey;
         } else {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder created but PR_SOURCE_KEY not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
         }
         return false;
     }
     // open folder for update
     $entryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($id));
     if (!$entryid) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
     }
     // check if this is a MAPI default folder
     if ($this->mapiprovider->IsMAPIDefaultFolder($entryid)) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, MAPI default folder can not be created/modified", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname), SYNC_FSSTATUS_SYSTEMFOLDER);
     }
     $mfolder = mapi_msgstore_openentry($this->store, $entryid);
     if (!$mfolder) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
     }
     $props = mapi_getprops($mfolder, array(PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS));
     if (!isset($props[PR_SOURCE_KEY]) || !isset($props[PR_PARENT_SOURCE_KEY]) || !isset($props[PR_DISPLAY_NAME]) || !isset($props[PR_CONTAINER_CLASS])) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, folder data not available: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
     }
     // get the real parent source key from mapi
     if ($parent == "0") {
         $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
         $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
         $mapifolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         $rootfolderprops = mapi_getprops($mapifolder, array(PR_SOURCE_KEY));
         $parent = bin2hex($rootfolderprops[PR_SOURCE_KEY]);
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ImportChangesICS->ImportFolderChange(): resolved AS parent '0' to sourcekey '%s'", $parent));
     }
     // a changed parent id means that the folder should be moved
     if (bin2hex($props[PR_PARENT_SOURCE_KEY]) !== $parent) {
         $sourceparentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, $props[PR_PARENT_SOURCE_KEY]);
         if (!$sourceparentfentryid) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent source folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         $sourceparentfolder = mapi_msgstore_openentry($this->store, $sourceparentfentryid);
         if (!$sourceparentfolder) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open parent source folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_PARENTNOTFOUND);
         }
         $destparentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent));
         if (!$sourceparentfentryid) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open destination folder (no entry id): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
         }
         $destfolder = mapi_msgstore_openentry($this->store, $destparentfentryid);
         if (!$destfolder) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to open destination folder (open entry): 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
         }
         // mapi_folder_copyfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION
         if (!mapi_folder_copyfolder($sourceparentfolder, $entryid, $destfolder, $displayname, FOLDER_MOVE)) {
             throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, unable to move folder: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_FOLDEREXISTS);
         }
         $folderProps = mapi_getprops($mfolder, array(PR_SOURCE_KEY));
         return $folderProps[PR_SOURCE_KEY];
     }
     // update the display name
     $props = array(PR_DISPLAY_NAME => $displayname);
     mapi_setprops($mfolder, $props);
     mapi_savechanges($mfolder);
     if (mapi_last_hresult()) {
         throw new StatusException(sprintf("ImportChangesICS->ImportFolderChange('%s','%s','%s'): Error, mapi_savechanges() failed: 0x%X", Utils::PrintAsString($folder->serverid), $folder->parentid, $displayname, mapi_last_hresult()), SYNC_FSSTATUS_SERVERERROR);
     }
     ZLog::Write(LOGLEVEL_DEBUG, "Imported changes for folder: {$id}");
     return $id;
 }
Example #5
0
 function getSearchResultsMailbox($searchquery)
 {
     if (!is_array($searchquery)) {
         return array();
     }
     foreach ($searchquery['query'] as $value) {
         $query = $this->_getSearchResultsMailboxTranslation($value);
     }
     // get search folder
     $storeProps = mapi_getprops($this->_defaultstore, array(PR_STORE_SUPPORT_MASK, PR_FINDER_ENTRYID));
     if (($storeProps[PR_STORE_SUPPORT_MASK] & STORE_SEARCH_OK) != STORE_SEARCH_OK) {
         return array('global_search_status' => '3');
     } else {
         // open search folders root
         $searchFolderEntryID = mapi_msgstore_openentry($this->_defaultstore, $storeProps[PR_FINDER_ENTRYID]);
         if (($hresult = mapi_last_hresult()) != 0 || $searchFolderEntryID == false) {
             debugLog("getSearchResultsMailbox: searchFolderEntryID is " . ($searchFolderEntryID === 'true' ? 'true' : 'false') . " mapi_last_hresult = " . sprintf("0x%08x", $hresult));
             return array('global_search_status' => '3');
         }
     }
     $result = mapi_table_queryallrows(mapi_folder_gethierarchytable($searchFolderEntryID), array(PR_DISPLAY_NAME, PR_ENTRYID, PR_SOURCE_KEY));
     $folderName = "Z-Push Search " . $this->_devid;
     $found = false;
     foreach ($result as $array) {
         if (array_keys($array, $folderName)) {
             $found = $array[PR_ENTRYID];
             $searchfoldersourcekey = $array[PR_SOURCE_KEY];
             break;
         }
     }
     if ($found == false) {
         // create search folder
         $folder = mapi_folder_createfolder($searchFolderEntryID, $folderName, null, 0, FOLDER_SEARCH);
         if ($folder === false || ($hresult = mapi_last_hresult()) != 0) {
             debugLog("getSearchResultsMailbox: searchFolderEntryID is " . ($searchFolderEntryID === 'true' ? 'true' : 'false') . " folderName is " . $folderName . " mapi_last_hresult = " . sprintf("0x%08x", $hresult));
             return array('global_search_status' => '3');
         }
     } else {
         $folder = mapi_openentry($this->_session, $found);
         if ($folder === false || ($hresult = mapi_last_hresult()) != 0) {
             debugLog("getSearchResultsMailbox: _session is " . $this->_session . " found " . ($found == 'true' ? 'true' : 'false') . " mapi_last_hresult = " . sprintf("0x%08x", $hresult));
             return array('global_search_status' => '3');
         }
     }
     $props = mapi_getprops($folder, array(PR_SOURCE_KEY));
     $searchfoldersourcekey = $props[PR_SOURCE_KEY];
     if (!isset($query[PR_SOURCE_KEY]) || !($startsearchinfolderid = mapi_msgstore_entryidfromsourcekey($this->_defaultstore, $query[PR_SOURCE_KEY]))) {
         $tmp = mapi_getprops($this->_defaultstore, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_IPM_SUBTREE_ENTRYID));
         $startsearchinfolderid = $tmp[PR_IPM_SUBTREE_ENTRYID];
     }
     $search = mapi_folder_getsearchcriteria($folder);
     $range = explode("-", $searchquery['range']);
     //		if ($range[0] == 0 &&
     //		    (!isset($search['restriction']) ||
     //		     md5(serialize(ksort_recursive($search['restriction']))) != md5(serialize(ksort_recursive($query['query']))))) {
     if ($range[0] == 0 || isset($searchquery['rebuildresults']) && $searchquery['rebuildresults'] == true) {
         //			debugLog("\n".serialize(ksort_recursive($search['restriction']))."\n".serialize(ksort_recursive($query['query'])));
         //		    debugLog("Set Search Criteria ".md5(serialize(ksort_recursive($search['restriction']))) . " ".  md5(serialize(ksort_recursive($query['query']))));
         if (($search['searchstate'] & SEARCH_REBUILD) == true && ($search['searchstate'] & SEARCH_RUNNING) == true) {
             mapi_folder_setsearchcriteria($folder, $query["query"], array($startsearchinfolderid), STOP_SEARCH);
         }
         mapi_folder_setsearchcriteria($folder, $query["query"], array($startsearchinfolderid), (isset($searchquery['deeptraversal']) && $searchquery['deeptraversal'] == true ? RECURSIVE_SEARCH : SHALLOW_SEARCH) | (isset($searchquery['rebuildresults']) && $searchquery['rebuildresults'] == true ? RESTART_SEARCH : 0));
     }
     $i = 0;
     $table = mapi_folder_getcontentstable($folder);
     do {
         $search = mapi_folder_getsearchcriteria($folder);
         usleep(100000);
         $i++;
     } while (($search['searchstate'] & SEARCH_REBUILD) == true && ($search['searchstate'] & SEARCH_RUNNING) == true && $i < 4000 && mapi_table_getrowcount($table) <= $range[1] * 2 + 1);
     if ($rows = mapi_table_queryallrows($table, array(PR_ENTRYID, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY))) {
         foreach ($rows as $value) {
             $res["searchfolderid"] = bin2hex($searchfoldersourcekey);
             $res["uniqueid"] = bin2hex($value[PR_ENTRYID]);
             $res["item"] = bin2hex($value[PR_SOURCE_KEY]);
             $res["parent"] = bin2hex($value[PR_PARENT_SOURCE_KEY]);
             $result['rows'][] = $res;
         }
         $result['status'] = 1;
     } else {
         $result = array();
         $result['status'] = 1;
     }
     if (($search['searchstate'] & SEARCH_REBUILD) == true && ($search['searchstate'] & SEARCH_RUNNING) == true && $i == 4000) {
         $result['status'] = 10;
     }
     $result['global_search_status'] = 1;
     return $result;
 }
Example #6
0
 function ImportFolderChange($id, $parent, $displayname, $type)
 {
     //create a new folder if $id is not set
     if (!$id) {
         // the root folder is "0" - get IPM_SUBTREE
         if ($parent == "0") {
             $parentprops = mapi_getprops($this->store, array(PR_IPM_SUBTREE_ENTRYID));
             if (isset($parentprops[PR_IPM_SUBTREE_ENTRYID])) {
                 $parentfentryid = $parentprops[PR_IPM_SUBTREE_ENTRYID];
             }
         } else {
             $parentfentryid = mapi_msgstore_entryidfromsourcekey($this->store, hex2bin($parent));
         }
         $parentfolder = mapi_msgstore_openentry($this->store, $parentfentryid);
         $parentpros = mapi_getprops($parentfolder, array(PR_DISPLAY_NAME));
         $newfolder = mapi_folder_createfolder($parentfolder, $displayname, "");
         mapi_setprops($newfolder, array(PR_CONTAINER_CLASS => $this->GetContainerClassFromFolderType($type)));
         $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY));
         $id = bin2hex($props[PR_SOURCE_KEY]);
         debugLog("Folder created with id:{$id}");
         return $id;
     }
     mapi_importhierarchychanges_importfolderchange($this->importer, array(PR_SOURCE_KEY => hex2bin($id), PR_PARENT_SOURCE_KEY => hex2bin($parent), PR_DISPLAY_NAME => $displayname));
     debugLog("Imported changes for folder:{$id}");
     return $id;
 }
 /**
  * Creates a new address book 
  *
  * @param string $principalUri 
  * @param string $url Just the 'basename' of the url. 
  * @param array $properties 
  * @return void
  */
 public function createAddressBook($principalUri, $url, array $properties)
 {
     $this->logger->info("createAddressBook({$principalUri}, {$url})");
     if (READ_ONLY) {
         $this->logger->warn("Cannot create address book: read-only");
         return false;
     }
     $rootFolder = $this->bridge->getRootFolder();
     $displayName = isset($properties['{DAV:}displayname']) ? $properties['{DAV:}displayname'] : '';
     $description = isset($properties['{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description']) ? $properties['{' . Sabre_CardDAV_Plugin::NS_CARDDAV . '}addressbook-description'] : '';
     $subFolder = mapi_folder_createfolder($rootFolder, $displayName, $description, MAPI_UNICODE | OPEN_IF_EXISTS, FOLDER_GENERIC);
     mapi_setprops($subFolder, array(907214878 => 'IPF.Contact'));
     mapi_savechanges($subFolder);
     if (mapi_last_hresult() > 0) {
         $this->logger->fatal("Error saving changes to addressbook: " . get_mapi_error_name());
         return false;
     }
 }
Example #8
0
 /**
  * Creates the hidden folder.
  *
  * @param string $gabId         the id of the gab where the hidden folder should be created. If not set (null) the default gab is used.
  * @param string $gabName       the name of the gab where the hidden folder should be created. If not set (null) the default gab is used.
  *
  * @access protected
  * @return string
  */
 protected function createHiddenFolder($gabId = null, $gabName = 'default')
 {
     $store = $this->getStore($gabId, $gabName);
     if (!$store) {
         return false;
     }
     $parentfolder = $this->getRootFolder($store);
     // mapi_folder_createfolder() fails if a folder with this name already exists -> MAPI_E_COLLISION
     $newfolder = mapi_folder_createfolder($parentfolder, HIDDEN_FOLDERNAME, "");
     if (mapi_last_hresult()) {
         $this->Terminate(sprintf("Kopano->createHiddenFolder(): Error, mapi_folder_createfolder() failed: 0x%08X", mapi_last_hresult()));
     }
     mapi_setprops($newfolder, array(PR_CONTAINER_CLASS => "IPF.Appointment", PR_ATTR_HIDDEN => true));
     $props = mapi_getprops($newfolder, array(PR_SOURCE_KEY));
     if (isset($props[PR_SOURCE_KEY])) {
         $sourcekey = bin2hex($props[PR_SOURCE_KEY]);
         $this->Log(sprintf("Created hidden public folder with id: '%s'", $sourcekey));
         return $sourcekey;
     } else {
         $this->Terminate(sprintf("Kopano->createHiddenFolder(): Error, folder created but PR_SOURCE_KEY not available: 0x%08X", mapi_last_hresult()));
     }
 }