Пример #1
0
 /**
  * A wrapper for mapi_inetmapi_imtoinet function
  *
  * @param MAPIMessage       $mapimessage
  * @param SyncObject        $message
  *
  * @access private
  * @return boolean
  */
 private function imtoinet($mapimessage, &$message)
 {
     // if it is a signed message get a full attachment generated by ZCP
     $props = mapi_getprops($mapimessage, array(PR_MESSAGE_CLASS));
     if (isset($props[PR_MESSAGE_CLASS]) && $props[PR_MESSAGE_CLASS] && strpos(strtolower($props[PR_MESSAGE_CLASS]), 'multipartsigned')) {
         // find the required attachment
         $attachtable = mapi_message_getattachmenttable($mapimessage);
         mapi_table_restrict($attachtable, MAPIUtils::GetSignedAttachmentRestriction());
         if (mapi_table_getrowcount($attachtable) == 1) {
             $rows = mapi_table_queryrows($attachtable, array(PR_ATTACH_NUM, PR_ATTACH_SIZE), 0, 1);
             if (isset($rows[0][PR_ATTACH_NUM])) {
                 $mapiattach = mapi_message_openattach($mapimessage, $rows[0][PR_ATTACH_NUM]);
                 $stream = mapi_openpropertytostream($mapiattach, PR_ATTACH_DATA_BIN);
                 $streamsize = $rows[0][PR_ATTACH_SIZE];
             }
         }
     } elseif (function_exists("mapi_inetmapi_imtoinet")) {
         $addrbook = $this->getAddressbook();
         $stream = mapi_inetmapi_imtoinet($this->session, $addrbook, $mapimessage, array('use_tnef' => -1));
         $mstreamstat = mapi_stream_stat($stream);
         $streamsize = $mstreamstat["cb"];
     }
     if (isset($stream) && isset($streamsize)) {
         if (Request::GetProtocolVersion() >= 12.0) {
             if (!isset($message->asbody)) {
                 $message->asbody = new SyncBaseBody();
             }
             //TODO data should be wrapped in a MapiStreamWrapper
             $message->asbody->data = mapi_stream_read($stream, $streamsize);
             $message->asbody->estimatedDataSize = $streamsize;
             $message->asbody->truncated = 0;
         } else {
             $message->mimetruncated = 0;
             //TODO mimedata should be a wrapped in a MapiStreamWrapper
             $message->mimedata = mapi_stream_read($stream, $streamsize);
             $message->mimesize = $streamsize;
         }
         unset($message->body, $message->bodytruncated);
         return true;
     } else {
         ZLog::Write(LOGLEVEL_ERROR, sprintf("Error opening attachment for imtoinet"));
     }
     return false;
 }
Пример #2
0
/**
 * Get the private contact folder of all users
 */
function getPrivateContactFolders($session, $defaultstore)
{
    $addrbook = mapi_openaddressbook($session);
    $addr_entryid = mapi_ab_getdefaultdir($addrbook);
    $abcontainer = mapi_ab_openentry($addrbook, $addr_entryid);
    $contentstable = mapi_folder_getcontentstable($abcontainer);
    // restrict table on only MAPI_MAILUSER accounts
    mapi_table_restrict($contentstable, array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_OBJECT_TYPE, VALUE => array(PR_OBJECT_TYPE => MAPI_MAILUSER))));
    // sort table on display name
    mapi_table_sort($contentstable, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND));
    $users = mapi_table_queryrows($contentstable, array(PR_ACCOUNT, PR_ENTRYID, PR_DISPLAY_NAME), 0, mapi_table_getrowcount($contentstable));
    $contactArray = array();
    for ($i = 0; $i < sizeof($users); $i++) {
        $store_entryid = mapi_msgstore_createentryid($defaultstore, $users[$i][PR_ACCOUNT]);
        $store = mapi_openmsgstore($session, $store_entryid);
        $rootcontainer = mapi_msgstore_openentry($store);
        if ($rootcontainer) {
            $props = mapi_getprops($rootcontainer, array(PR_IPM_CONTACT_ENTRYID));
            if (isset($props[PR_IPM_CONTACT_ENTRYID])) {
                $entryid = $props[PR_IPM_CONTACT_ENTRYID];
                $folder = mapi_msgstore_openentry($store, $entryid);
                if ($folder) {
                    $table = mapi_folder_getcontentstable($folder);
                    $totalrow = mapi_table_getrowcount($table);
                    $rows = array();
                    $contacts = array();
                    $properties = getContactProperties($defaultstore);
                    if ($totalrow > 0) {
                        $rows = mapi_table_queryrows($table, $properties, 0, $totalrow);
                        for ($j = 0; $j < sizeof($rows); $j++) {
                            $rows[$j][268370178] = md5($rows[$j][268370178]);
                        }
                        for ($k = 0; $k < sizeof($rows); $k++) {
                            // do not add private contacts
                            if (!array_key_exists(-2119827445, $rows[$k]) || array_key_exists(-2119827445, $rows[$k]) && $rows[$k][-2119827445] != 1) {
                                foreach ($rows[$k] as $key => $value) {
                                    $attribute = mapKey($key);
                                    if ($attribute != "") {
                                        $contacts[$k][$attribute] = $value;
                                    }
                                }
                            }
                        }
                        $contactArray[] = array("username" => $users[$i][PR_ACCOUNT], "contacts" => $contacts);
                    }
                }
            }
        }
    }
    //	print_r($contactArray);
    return $contactArray;
}
Пример #3
0
 /**
  * Returns subfolders of given type for a folder or false if there are none.
  *
  * @access public
  *
  * @param MAPIFolder $folder
  * @param string $type
  *
  * @return MAPITable|boolean
  */
 public static function GetSubfoldersForType($folder, $type)
 {
     $subfolders = mapi_folder_gethierarchytable($folder, CONVENIENT_DEPTH);
     mapi_table_restrict($subfolders, MAPIUtils::GetFolderTypeRestriction($type));
     if (mapi_table_getrowcount($subfolders) > 0) {
         return mapi_table_queryallrows($subfolders, array(PR_ENTRYID));
     }
     return false;
 }
Пример #4
0
 function getSearchResults($searchquery, $searchrange)
 {
     // only return users from who the displayName or the username starts with $name
     //TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT
     $addrbook = mapi_openaddressbook($this->_session);
     $ab_entryid = mapi_ab_getdefaultdir($addrbook);
     $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
     $table = mapi_folder_getcontentstable($ab_dir);
     $restriction = $this->_getSearchRestriction(u2w($searchquery));
     mapi_table_restrict($table, $restriction);
     mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND));
     //range for the search results, default symbian range end is 50, wm 99,
     //so we'll use that of nokia
     $rangestart = 0;
     $rangeend = 50;
     if ($searchrange != '0') {
         $pos = strpos($searchrange, '-');
         $rangestart = substr($searchrange, 0, $pos);
         $rangeend = substr($searchrange, $pos + 1);
     }
     $items = array();
     $querycnt = mapi_table_getrowcount($table);
     //do not return more results as requested in range
     $querylimit = $rangeend + 1 < $querycnt ? $rangeend + 1 : $querycnt;
     $items['range'] = $rangestart . '-' . ($querylimit - 1);
     $items['searchtotal'] = $querycnt;
     if ($querycnt > 0) {
         $abentries = mapi_table_queryrows($table, array(PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER, PR_GIVEN_NAME, PR_SURNAME, PR_MOBILE_TELEPHONE_NUMBER, PR_HOME_TELEPHONE_NUMBER, PR_TITLE, PR_COMPANY_NAME, PR_OFFICE_LOCATION), $rangestart, $querylimit);
     }
     for ($i = 0; $i < $querylimit; $i++) {
         $items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_DISPLAY_NAME]);
         if (strlen(trim($items[$i][SYNC_GAL_DISPLAYNAME])) == 0) {
             $items[$i][SYNC_GAL_DISPLAYNAME] = w2u($abentries[$i][PR_ACCOUNT]);
         }
         $items[$i][SYNC_GAL_ALIAS] = w2u($abentries[$i][PR_ACCOUNT]);
         //it's not possible not get first and last name of an user
         //from the gab and user functions, so we just set lastname
         //to displayname and leave firstname unset
         //this was changed in Zarafa 6.40, so we try to get first and
         //last name and fall back to the old behaviour if these values are not set
         if (isset($abentries[$i][PR_GIVEN_NAME])) {
             $items[$i][SYNC_GAL_FIRSTNAME] = w2u($abentries[$i][PR_GIVEN_NAME]);
         }
         if (isset($abentries[$i][PR_SURNAME])) {
             $items[$i][SYNC_GAL_LASTNAME] = w2u($abentries[$i][PR_SURNAME]);
         }
         if (!isset($items[$i][SYNC_GAL_LASTNAME])) {
             $items[$i][SYNC_GAL_LASTNAME] = $items[$i][SYNC_GAL_DISPLAYNAME];
         }
         $items[$i][SYNC_GAL_EMAILADDRESS] = w2u($abentries[$i][PR_SMTP_ADDRESS]);
         //check if an user has an office number or it might produce warnings in the log
         if (isset($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER])) {
             $items[$i][SYNC_GAL_PHONE] = w2u($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]);
         }
         //check if an user has a mobile number or it might produce warnings in the log
         if (isset($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER])) {
             $items[$i][SYNC_GAL_MOBILEPHONE] = w2u($abentries[$i][PR_MOBILE_TELEPHONE_NUMBER]);
         }
         //check if an user has a home number or it might produce warnings in the log
         if (isset($abentries[$i][PR_HOME_TELEPHONE_NUMBER])) {
             $items[$i][SYNC_GAL_HOMEPHONE] = w2u($abentries[$i][PR_HOME_TELEPHONE_NUMBER]);
         }
         if (isset($abentries[$i][PR_COMPANY_NAME])) {
             $items[$i][SYNC_GAL_COMPANY] = w2u($abentries[$i][PR_COMPANY_NAME]);
         }
         if (isset($abentries[$i][PR_TITLE])) {
             $items[$i][SYNC_GAL_TITLE] = w2u($abentries[$i][PR_TITLE]);
         }
         if (isset($abentries[$i][PR_OFFICE_LOCATION])) {
             $items[$i][SYNC_GAL_OFFICE] = w2u($abentries[$i][PR_OFFICE_LOCATION]);
         }
     }
     return $items;
 }
Пример #5
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);
 }
Пример #6
0
 function getSearchResults($searchquery, $searchrange)
 {
     // only return users from who the displayName or the username starts with $name
     //TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT
     $addrbook = mapi_openaddressbook($this->_session);
     $ab_entryid = mapi_ab_getdefaultdir($addrbook);
     $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
     $table = mapi_folder_getcontentstable($ab_dir);
     $restriction = $this->_getSearchRestriction(u2w($searchquery));
     mapi_table_restrict($table, $restriction);
     mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND));
     //range for the search results, default symbian range end is 50, wm 99,
     //so we'll use that of nokia
     $rangestart = 0;
     $rangeend = 50;
     if ($searchrange != '0') {
         $pos = strpos($searchrange, '-');
         $rangestart = substr($searchrange, 0, $pos);
         $rangeend = substr($searchrange, $pos + 1);
     }
     $items = array();
     $querycnt = mapi_table_getrowcount($table);
     //do not return more results as requested in range
     $querylimit = $rangeend + 1 < $querycnt ? $rangeend + 1 : $querycnt;
     $items['range'] = $rangestart . '-' . ($querylimit - 1);
     $abentries = mapi_table_queryrows($table, array(PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER), $rangestart, $querylimit);
     for ($i = 0; $i < $querylimit; $i++) {
         $items[$i]["username"] = w2u($abentries[$i][PR_ACCOUNT]);
         $items[$i]["fullname"] = w2u($abentries[$i][PR_DISPLAY_NAME]);
         if (strlen(trim($items[$i]["fullname"])) == 0) {
             $items[$i]["fullname"] = $items[$i]["username"];
         }
         $items[$i]["emailaddress"] = w2u($abentries[$i][PR_SMTP_ADDRESS]);
         $items[$i]["nameid"] = $searchquery;
         //check if an user has a business phone or it might produce warnings in the log
         $items[$i]["businessphone"] = isset($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]) ? w2u($abentries[$i][PR_BUSINESS_TELEPHONE_NUMBER]) : "";
     }
     return $items;
 }
Пример #7
0
 function getSearchResultsGAL($searchquery)
 {
     // only return users from who the displayName or the username starts with $name
     //TODO: use PR_ANR for this restriction instead of PR_DISPLAY_NAME and PR_ACCOUNT
     $addrbook = mapi_openaddressbook($this->_session);
     $ab_entryid = mapi_ab_getdefaultdir($addrbook);
     $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
     $table = mapi_folder_getcontentstable($ab_dir);
     $restriction = $this->_getSearchRestriction(u2w($searchquery));
     mapi_table_restrict($table, $restriction);
     mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND));
     // CHANGED dw2412 AS V12.0 Support (to menetain single return way...
     $items['rows'] = array();
     for ($i = 0; $i < mapi_table_getrowcount($table); $i++) {
         $user_data = mapi_table_queryrows($table, array(PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER, PR_HOME_TELEPHONE_NUMBER, PR_MOBILE_TELEPHONE_NUMBER, PR_COMPANY_NAME, PR_OFFICE_LOCATION, PR_TITLE), $i, 1);
         $item = array();
         $item["username"] = w2u($user_data[0][PR_ACCOUNT]);
         $item["fullname"] = w2u($user_data[0][PR_DISPLAY_NAME]);
         if (strlen(trim($item["fullname"])) == 0) {
             $item["fullname"] = $item["username"];
         }
         $item["emailaddress"] = w2u($user_data[0][PR_SMTP_ADDRESS]);
         $item["nameid"] = $searchquery;
         $item["phone"] = isset($user_data[0][PR_BUSINESS_TELEPHONE_NUMBER]) ? w2u($user_data[0][PR_BUSINESS_TELEPHONE_NUMBER]) : "";
         $item["homephone"] = isset($user_data[0][PR_HOME_TELEPHONE_NUMBER]) ? w2u($user_data[0][PR_HOME_TELEPHONE_NUMBER]) : "";
         $item["mobilephone"] = isset($user_data[0][PR_MOBILE_TELEPHONE_NUMBER]) ? w2u($user_data[0][PR_MOBILE_TELEPHONE_NUMBER]) : "";
         $item["company"] = isset($user_data[0][PR_COMPANY_NAME]) ? w2u($user_data[0][PR_COMPANY_NAME]) : "";
         $item["office"] = isset($user_data[0][PR_OFFICE_LOCATION]) ? w2u($user_data[0][PR_OFFICE_LOCATION]) : "";
         $item["title"] = isset($user_data[0][PR_TITLE]) ? w2u($user_data[0][PR_TITLE]) : "";
         //do not return users without email
         if (strlen(trim($item["emailaddress"])) == 0) {
             continue;
         }
         // CHANGED dw2412 AS V12.0 Support (to menetain single return way...
         array_push($items['rows'], $item);
     }
     $items['status'] = 1;
     $items['global_search_status'] = 1;
     return $items;
 }
Пример #8
0
 /**
  * Returns contacts matching given email address from a folder.
  *
  * @param MAPIStore $store
  * @param binary $folderEntryid
  * @param string $email
  *
  * @return array|boolean
  */
 private function getContactsFromFolder($store, $folderEntryid, $email)
 {
     $folder = mapi_msgstore_openentry($store, $folderEntryid);
     $folderContent = mapi_folder_getcontentstable($folder);
     mapi_table_restrict($folderContent, MAPIUtils::GetEmailAddressRestriction($store, $email));
     // TODO max limit
     if (mapi_table_getrowcount($folderContent) > 0) {
         return mapi_table_queryallrows($folderContent, array(PR_DISPLAY_NAME, PR_USER_X509_CERTIFICATE));
     }
     return false;
 }
Пример #9
0
 /**
  * Build user list of adress books
  * Recursively find folders in Zarafa
  */
 private function buildAdressBooks($store, $prefix, $folder, $parentFolderId)
 {
     $this->logger->trace("buildAdressBooks");
     $folderProperties = mapi_getprops($folder);
     $currentFolderName = $this->to_charset($folderProperties[PR_DISPLAY_NAME]);
     // Compute CTag - issue 8: ctag should be the max of PR_LAST_MODIFICATION_TIME of contacts
     // of the folder.
     $this->logger->trace("Computing CTag for address book " . $folderProperties[PR_DISPLAY_NAME]);
     $ctag = $folderProperties[PR_LAST_MODIFICATION_TIME];
     $contactsTable = mapi_folder_getcontentstable($folder);
     $contacts = mapi_table_queryallrows($contactsTable, array(PR_LAST_MODIFICATION_TIME));
     // Contact count
     $contactCount = mapi_table_getrowcount($contactsTable);
     $storedContactCount = isset($folderProperties[PR_CARDDAV_AB_CONTACT_COUNT]) ? $folderProperties[PR_CARDDAV_AB_CONTACT_COUNT] : 0;
     $this->logger->trace("Contact count: {$contactCount}");
     $this->logger->trace("Stored contact count: {$storedContactCount}");
     if ($contactCount != $storedContactCount) {
         $this->logger->trace("Contact count != stored contact count");
         $ctag = time();
         mapi_setprops($folder, array(PR_CARDDAV_AB_CONTACT_COUNT => $contactCount, PR_LAST_MODIFICATION_TIME => $ctag));
         mapi_savechanges($folder);
     } else {
         foreach ($contacts as $c) {
             if ($c[PR_LAST_MODIFICATION_TIME] > $ctag) {
                 $ctag = $c[PR_LAST_MODIFICATION_TIME];
                 $this->logger->trace("Found new ctag: {$ctag}");
             }
         }
     }
     // Add address book
     $displayPrefix = "";
     if ($store === $this->pubStore) {
         $displayPrefix = "Public ";
     }
     $this->adressBooks[$folderProperties[PR_ENTRYID]] = array('id' => $folderProperties[PR_ENTRYID], 'displayname' => $displayPrefix . $folderProperties[PR_DISPLAY_NAME], 'prefix' => $prefix, 'description' => isset($folderProperties[805568542]) ? $folderProperties[805568542] : '', 'ctag' => $ctag, 'parentId' => $parentFolderId);
     // Get subfolders
     $foldersTable = mapi_folder_gethierarchytable($folder);
     $folders = mapi_table_queryallrows($foldersTable);
     foreach ($folders as $f) {
         $subFold = mapi_msgstore_openentry($store, $f[PR_ENTRYID]);
         $this->buildAdressBooks($store, $prefix . $currentFolderName . "/", $subFold, $folderProperties[PR_ENTRYID]);
     }
 }
Пример #10
0
 /**
  * Returns a list with all GAB entries or a single entry specified by $uniqueId.
  * The search for that single entry is done using the configured UNIQUEID parameter.
  * If no entry is found for a $uniqueId an empty array() must be returned.
  *
  * @param string $uniqueId      A value to be found in the configured UNIQUEID.
  *                              If set, only one item is returned. If false or not set, the entire GAB is returned.
  *                              Default: false
  * @param string $gabId         Id that uniquely identifies the GAB. If not set or null the default GAB is assumed.
  * @param string $gabName       String that uniquely identifies the GAB. If not set the default GAB is assumed.
  *
  * @access protected
  * @return array of GABEntry
  */
 protected function getGAB($uniqueId = false, $gabId = null, $gabName = 'default')
 {
     $data = array();
     $addrbook = mapi_openaddressbook($this->session);
     if (mapi_last_hresult()) {
         $this->Terminate(sprintf("Kopano->getGAB: Error opening addressbook 0x%08X", mapi_last_hresult()));
     }
     if ($gabId == null) {
         $ab_entryid = mapi_ab_getdefaultdir($addrbook);
         if (mapi_last_hresult()) {
             $this->Terminate(sprintf("Kopano->getGAB: Error, could not get '%s' address directory: 0x%08X", $gabName, mapi_last_hresult()));
         }
     } else {
         $ab_entryid = hex2bin($gabId);
     }
     $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
     if (mapi_last_hresult()) {
         $this->Terminate(sprintf("Kopano->getGAB: Error, could not open '%s' address directory: 0x%08X", $gabName, mapi_last_hresult()));
     }
     $table = mapi_folder_getcontentstable($ab_dir);
     if (mapi_last_hresult()) {
         $this->Terminate(sprintf("Kopano->getGAB: error, could not open '%s' addressbook content table: 0x%08X", $gabName, mapi_last_hresult()));
     }
     // get all the groups
     $groups = mapi_zarafa_getgrouplist($this->store, $ab_entryid);
     // restrict the table if we should only return one
     if ($uniqueId) {
         $prop = $this->getPropertyForGABvalue(UNIQUEID);
         $restriction = array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => $prop, VALUE => $uniqueId));
         mapi_table_restrict($table, $restriction);
         $querycnt = mapi_table_getrowcount($table);
         if ($querycnt == 0) {
             $this->Log(sprintf("Kopano->getGAB(): Single GAB entry '%s' requested but could not be found.", $uniqueId));
         } elseif ($querycnt > 1) {
             $this->Terminate(sprintf("Kopano->getGAB(): Single GAB entry '%s' requested but %d entries found. Aborting.", $uniqueId, $querycnt));
         }
     }
     $gabentries = mapi_table_queryallrows($table, array(PR_ENTRYID, PR_ACCOUNT, PR_DISPLAY_NAME, PR_SMTP_ADDRESS, PR_BUSINESS_TELEPHONE_NUMBER, PR_GIVEN_NAME, PR_SURNAME, PR_MOBILE_TELEPHONE_NUMBER, PR_HOME_TELEPHONE_NUMBER, PR_TITLE, PR_COMPANY_NAME, PR_OFFICE_LOCATION, PR_BEEPER_TELEPHONE_NUMBER, PR_PRIMARY_FAX_NUMBER, PR_ORGANIZATIONAL_ID_NUMBER, PR_POSTAL_ADDRESS, PR_BUSINESS_ADDRESS_CITY, PR_BUSINESS_ADDRESS_POSTAL_CODE, PR_BUSINESS_ADDRESS_POST_OFFICE_BOX, PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE, PR_INITIALS, PR_LANGUAGE, PR_EMS_AB_THUMBNAIL_PHOTO, PR_DISPLAY_TYPE_EX));
     foreach ($gabentries as $entry) {
         // do not add SYSTEM user to the GAB
         if (strtoupper($entry[PR_DISPLAY_NAME]) == "SYSTEM") {
             continue;
         }
         $a = new GABEntry();
         $a->type = GABEntry::CONTACT;
         $a->memberOf = array();
         $memberOf = mapi_zarafa_getgrouplistofuser($this->store, $entry[PR_ENTRYID]);
         if (is_array($memberOf)) {
             $a->memberOf = array_keys($memberOf);
         }
         // the company name is 'Everyone'
         if ($gabId != null && $entry[PR_DISPLAY_NAME] == $gabName) {
             $entry[PR_ACCOUNT] = "Everyone";
             $entry[PR_DISPLAY_NAME] = "Everyone";
         }
         // is this a group?
         if (array_key_exists($entry[PR_ACCOUNT], $groups)) {
             $a->type = GABEntry::GROUP;
             $groupentry = mapi_ab_openentry($addrbook, $entry[PR_ENTRYID]);
             $grouptable = mapi_folder_getcontentstable($groupentry, MAPI_DEFERRED_ERRORS);
             $users = mapi_table_queryallrows($grouptable, array(PR_ENTRYID, PR_ACCOUNT, PR_SMTP_ADDRESS));
             $a->members = array();
             if (is_array($users)) {
                 foreach ($users as $user) {
                     if ($user[PR_ENTRYID] == $entry[PR_ENTRYID]) {
                         if (isset($user[PR_SMTP_ADDRESS])) {
                             $a->smtpAddress = $user[PR_SMTP_ADDRESS];
                         }
                         // don't add the group recursively
                         continue;
                     }
                     $a->members[] = $user[PR_ACCOUNT];
                 }
             }
         } else {
             if (isset($entry[PR_DISPLAY_TYPE_EX]) && $entry[PR_DISPLAY_TYPE_EX] == DT_ROOM) {
                 $a->type = GABEntry::ROOM;
             } else {
                 if (isset($entry[PR_DISPLAY_TYPE_EX]) && $entry[PR_DISPLAY_TYPE_EX] == DT_EQUIPMENT) {
                     $a->type = GABEntry::EQUIPMENT;
                 }
             }
         }
         if (isset($entry[PR_ACCOUNT])) {
             $a->account = $entry[PR_ACCOUNT];
         }
         if (isset($entry[PR_DISPLAY_NAME])) {
             $a->displayName = $entry[PR_DISPLAY_NAME];
         }
         if (isset($entry[PR_GIVEN_NAME])) {
             $a->givenName = $entry[PR_GIVEN_NAME];
         }
         if (isset($entry[PR_SURNAME])) {
             $a->surname = $entry[PR_SURNAME];
         }
         if (isset($entry[PR_SMTP_ADDRESS])) {
             $a->smtpAddress = $entry[PR_SMTP_ADDRESS];
         }
         if (isset($entry[PR_TITLE])) {
             $a->title = $entry[PR_TITLE];
         }
         if (isset($entry[PR_COMPANY_NAME])) {
             $a->companyName = $entry[PR_COMPANY_NAME];
         }
         if (isset($entry[PR_OFFICE_LOCATION])) {
             $a->officeLocation = $entry[PR_OFFICE_LOCATION];
         }
         if (isset($entry[PR_BUSINESS_TELEPHONE_NUMBER])) {
             $a->businessTelephoneNumber = $entry[PR_BUSINESS_TELEPHONE_NUMBER];
         }
         if (isset($entry[PR_MOBILE_TELEPHONE_NUMBER])) {
             $a->mobileTelephoneNumber = $entry[PR_MOBILE_TELEPHONE_NUMBER];
         }
         if (isset($entry[PR_HOME_TELEPHONE_NUMBER])) {
             $a->homeTelephoneNumber = $entry[PR_HOME_TELEPHONE_NUMBER];
         }
         if (isset($entry[PR_BEEPER_TELEPHONE_NUMBER])) {
             $a->beeperTelephoneNumber = $entry[PR_BEEPER_TELEPHONE_NUMBER];
         }
         if (isset($entry[PR_PRIMARY_FAX_NUMBER])) {
             $a->primaryFaxNumber = $entry[PR_PRIMARY_FAX_NUMBER];
         }
         if (isset($entry[PR_ORGANIZATIONAL_ID_NUMBER])) {
             $a->organizationalIdNumber = $entry[PR_ORGANIZATIONAL_ID_NUMBER];
         }
         if (isset($entry[PR_POSTAL_ADDRESS])) {
             $a->postalAddress = $entry[PR_POSTAL_ADDRESS];
         }
         if (isset($entry[PR_BUSINESS_ADDRESS_CITY])) {
             $a->businessAddressCity = $entry[PR_BUSINESS_ADDRESS_CITY];
         }
         if (isset($entry[PR_BUSINESS_ADDRESS_POSTAL_CODE])) {
             $a->businessAddressPostalCode = $entry[PR_BUSINESS_ADDRESS_POSTAL_CODE];
         }
         if (isset($entry[PR_BUSINESS_ADDRESS_POST_OFFICE_BOX])) {
             $a->businessAddressPostOfficeBox = $entry[PR_BUSINESS_ADDRESS_POST_OFFICE_BOX];
         }
         if (isset($entry[PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE])) {
             $a->businessAddressStateOrProvince = $entry[PR_BUSINESS_ADDRESS_STATE_OR_PROVINCE];
         }
         if (isset($entry[PR_INITIALS])) {
             $a->initials = $entry[PR_INITIALS];
         }
         if (isset($entry[PR_LANGUAGE])) {
             $a->language = $entry[PR_LANGUAGE];
         }
         if (isset($entry[PR_EMS_AB_THUMBNAIL_PHOTO])) {
             $a->thumbnailPhoto = base64_encode($entry[PR_EMS_AB_THUMBNAIL_PHOTO]);
         }
         $data[] = $a;
     }
     return $data;
 }