function getDelegatorStore($messageprops)
 {
     // Find the organiser of appointment in addressbook
     $delegatorName = array(array(PR_DISPLAY_NAME => $messageprops[PR_RCVD_REPRESENTING_NAME]));
     $ab = mapi_openaddressbook($this->session);
     $user = mapi_ab_resolvename($ab, $delegatorName, EMS_AB_ADDRESS_LOOKUP);
     // Get StoreEntryID by username
     $delegatorEntryid = mapi_msgstore_createentryid($this->store, $user[0][PR_EMAIL_ADDRESS]);
     // Open store of the delegator
     $delegatorStore = mapi_openmsgstore($this->session, $delegatorEntryid);
     // Open root folder
     $delegatorRoot = mapi_msgstore_openentry($delegatorStore, null);
     // Get calendar entryID
     $delegatorRootProps = mapi_getprops($delegatorRoot, array(PR_IPM_APPOINTMENT_ENTRYID));
     // Open the calendar Folder
     $calFolder = mapi_msgstore_openentry($delegatorStore, $delegatorRootProps[PR_IPM_APPOINTMENT_ENTRYID]);
     return array('store' => $delegatorStore, 'calFolder' => $calFolder);
 }
$msgstores = mapi_table_queryallrows($msgstorestable, array(PR_DEFAULT_STORE, PR_ENTRYID));
foreach ($msgstores as $row) {
    if ($row[PR_DEFAULT_STORE]) {
        $storeentryid = $row[PR_ENTRYID];
    }
}
if (!$storeentryid) {
    print "Can't find default store\n";
    exit(1);
}
$store = mapi_openmsgstore($session, $storeentryid);
if (!$store) {
    print "Unable to open system store\n";
    exit(1);
}
$userstoreentryid = mapi_msgstore_createentryid($store, $argv[1]);
if (!$userstoreentryid) {
    print "Unknown user\n";
    exit(1);
}
$userstore = mapi_openmsgstore($session, $userstoreentryid);
if (!$userstore) {
    print "Unable to open user store\n";
    exit(1);
}
isUnicodeStore($userstore);
$inbox = mapi_msgstore_getreceivefolder($userstore);
$root = mapi_msgstore_openentry($userstore);
$storeprops = mapi_getprops($userstore, array(PR_IPM_SENTMAIL_ENTRYID, PR_IPM_OUTBOX_ENTRYID, PR_IPM_WASTEBASKET_ENTRYID));
$inboxprops = mapi_getprops($inbox, array(PR_ENTRYID, PR_IPM_APPOINTMENT_ENTRYID, PR_IPM_CONTACT_ENTRYID, PR_IPM_DRAFTS_ENTRYID, PR_IPM_JOURNAL_ENTRYID, PR_IPM_NOTE_ENTRYID, PR_IPM_TASK_ENTRYID));
$rootprops = mapi_getprops($root, array(PR_ADDITIONAL_REN_ENTRYIDS));
 /**
  * Function will resolve the user and open its store
  * @param String $userName display name of the user
  * @return MAPIStore store of the user
  */
 function openCustomUserStore($userName)
 {
     // resolve user
     $ab = mapi_openaddressbook($this->session);
     $userName = array(array(PR_DISPLAY_NAME => $userName));
     $user = mapi_ab_resolvename($ab, $userName, EMS_AB_ADDRESS_LOOKUP);
     // Get StoreEntryID by username
     $userEntryid = mapi_msgstore_createentryid($this->store, $user[0][PR_EMAIL_ADDRESS]);
     // Open store of the user
     $userStore = mapi_openmsgstore($this->session, $userEntryid);
     return $userStore;
 }
Example #4
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;
}
Example #5
0
 /**
  * Open the store marked with PR_DEFAULT_STORE = TRUE
  * if $return_public is set, the public store is opened
  *
  * @param string    $user               User which store should be opened
  *
  * @access public
  * @return boolean
  */
 private function openMessageStore($user)
 {
     // During PING requests the operations store has to be switched constantly
     // the cache prevents the same store opened several times
     if (isset($this->storeCache[$user])) {
         return $this->storeCache[$user];
     }
     $entryid = false;
     $return_public = false;
     if (strtoupper($user) == 'SYSTEM') {
         $return_public = true;
     }
     // loop through the storestable if authenticated user of public folder
     if ($user == $this->mainUser || $return_public === true) {
         // Find the default store
         $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 (!$return_public && isset($row[PR_DEFAULT_STORE]) && $row[PR_DEFAULT_STORE] == true) {
                     $entryid = $row[PR_ENTRYID];
                     break;
                 }
                 if ($return_public && isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
                     $entryid = $row[PR_ENTRYID];
                     break;
                 }
             }
         }
     } else {
         $entryid = @mapi_msgstore_createentryid($this->defaultstore, $user);
     }
     if ($entryid) {
         $store = @mapi_openmsgstore($this->session, $entryid);
         if (!$store) {
             ZLog::Write(LOGLEVEL_WARN, sprintf("ZarafaBackend->openMessageStore('%s'): Could not open store", $user));
             return false;
         }
         // add this store to the cache
         if (!isset($this->storeCache[$user])) {
             $this->storeCache[$user] = $store;
         }
         ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZarafaBackend->openMessageStore('%s'): Found '%s' store: '%s'", $user, $return_public ? 'PUBLIC' : 'DEFAULT', $store));
         return $store;
     } else {
         ZLog::Write(LOGLEVEL_WARN, sprintf("ZarafaBackend->openMessageStore('%s'): No store found for this user", $user));
         return false;
     }
 }
function zpa_remove_device($adminStore, $session, $user, $deviceid)
{
    $userEntryId = @mapi_msgstore_createentryid($adminStore, $user);
    $userStore = @mapi_openmsgstore($session, $userEntryId);
    $hresult = mapi_last_hresult();
    if ($hresult != NOERROR) {
        echo "Could not open store for {$user}. The script will exit.\n";
        exit(1);
    }
    $devicesprops = mapi_getprops($userStore, array(0x6880101e, 0x6881101e, 0x6882101e, 0x6883101e, 0x68841003, 0x6885101e, 0x6886101e, 0x6887101e, 0x68881040, 0x68891040));
    if (isset($devicesprops[0x6881101e]) && is_array($devicesprops[0x6881101e])) {
        $ak = array_search($deviceid, $devicesprops[0x6881101e]);
        if ($ak !== false) {
            if (count($devicesprops[0x6880101e]) == 1) {
                mapi_deleteprops($userStore, array(0x6880101e, 0x6881101e, 0x6882101e, 0x6883101e, 0x68841003, 0x6885101e, 0x6886101e, 0x6887101e, 0x68881040, 0x68891040));
            } else {
                unset($devicesprops[0x6880101e][$ak], $devicesprops[0x6881101e][$ak], $devicesprops[0x6882101e][$ak], $devicesprops[0x6883101e][$ak], $devicesprops[0x68841003][$ak], $devicesprops[0x6885101e][$ak], $devicesprops[0x6886101e][$ak], $devicesprops[0x6887101e][$ak], $devicesprops[0x68881040][$ak], $devicesprops[0x68891040][$ak]);
                mapi_setprops($userStore, array(0x6880101e => isset($devicesprops[0x6880101e]) ? $devicesprops[0x6880101e] : array(), 0x6881101e => isset($devicesprops[0x6881101e]) ? $devicesprops[0x6881101e] : array(), 0x6882101e => isset($devicesprops[0x6882101e]) ? $devicesprops[0x6882101e] : array(), 0x6883101e => isset($devicesprops[0x6883101e]) ? $devicesprops[0x6883101e] : array(), 0x68841003 => isset($devicesprops[0x68841003]) ? $devicesprops[0x68841003] : array(), 0x6885101e => isset($devicesprops[0x6885101e]) ? $devicesprops[0x6885101e] : array(), 0x6886101e => isset($devicesprops[0x6886101e]) ? $devicesprops[0x6886101e] : array(), 0x6887101e => isset($devicesprops[0x6887101e]) ? $devicesprops[0x6887101e] : array(), 0x68881040 => isset($devicesprops[0x68881040]) ? $devicesprops[0x68881040] : array(), 0x68891040 => isset($devicesprops[0x68891040]) ? $devicesprops[0x68891040] : array()));
            }
            $hresult = mapi_last_hresult();
            if ($hresult != NOERROR) {
                echo "Could not remove device from list for {$user}. Errorcode 0x" . sprintf("%x", $hresult) . ". The script will exit.\n";
                exit(1);
            } else {
                echo "Removed device from list.\n";
            }
        } else {
            echo "No device found with the given id.\n";
            exit(1);
        }
    } else {
        echo "No devices found for the user {$user}.\n";
        exit(1);
    }
}
 function getTaskFolderStore()
 {
     $ownerentryid = false;
     $rcvdprops = mapi_getprops($this->message, array(PR_RCVD_REPRESENTING_ENTRYID));
     if (isset($rcvdprops[PR_RCVD_REPRESENTING_ENTRYID])) {
         $ownerentryid = $rcvdprops;
     }
     if (!$ownerentryid) {
         $store = $this->store;
     } else {
         $ab = mapi_openaddressbook($this->session);
         // seb changed from $session to $this->session
         if (!$ab) {
             return false;
         }
         // manni $ before ab was missing
         $mailuser = mapi_ab_openentry($ab, $ownerentryid);
         if (!$mailuser) {
             return false;
         }
         $mailuserprops = mapi_getprops($mailuser, array(PR_EMAIL_ADDRESS));
         if (!isset($mailuserprops[PR_EMAIL_ADDRESS])) {
             return false;
         }
         $storeid = mapi_msgstore_createentryid($this->store, $mailuserprops[PR_EMAIL_ADDRESS]);
         $store = mapi_openmsgstore($this->session, $storeid);
     }
     return $store;
 }
 function UpdateFB($addressbook, $session, $rootstore, $entryid)
 {
     $abentry = mapi_ab_openentry($addressbook, $entryid);
     if (!$abentry) {
         print "Unable to open entry in addressbook\n";
         return false;
     }
     $abprops = mapi_getprops($abentry, array(PR_ACCOUNT));
     $storeid = mapi_msgstore_createentryid($rootstore, $abprops[PR_ACCOUNT]);
     if (!$storeid) {
         print "Unable to get store entryid\n";
         return false;
     }
     $store = mapi_openmsgstore($session, $storeid);
     if (!$store) {
         print "Unable to open store\n";
         return false;
     }
     $root = mapi_msgstore_openentry($store);
     if (!$root) {
         print "Unable to open root folder\n";
         return false;
     }
     $rootprops = mapi_getprops($root, array(PR_IPM_APPOINTMENT_ENTRYID));
     $calendar = mapi_msgstore_openentry($store, $rootprops[PR_IPM_APPOINTMENT_ENTRYID]);
     $fbupdate = new FreeBusyPublish($session, $store, $calendar, $entryid);
     $fbupdate->publishFB(0, 0);
     // publish from one week ago, 6 months ahead
     return true;
 }
function listfolders_getlist($adminStore, $session, $user)
{
    global $supported_classes;
    if (strtoupper($user) == 'SYSTEM') {
        // Find the public store store
        $storestables = @mapi_getmsgstorestable($session);
        $result = @mapi_last_hresult();
        if ($result == NOERROR) {
            $rows = @mapi_table_queryallrows($storestables, array(PR_ENTRYID, PR_MDB_PROVIDER));
            foreach ($rows as $row) {
                if (isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
                    if (!isset($row[PR_ENTRYID])) {
                        echo "Public folder are not available.\nIf this is a multi-tenancy system, use -u and -p and login with an admin user of the company.\nThe script will exit.\n";
                        exit(1);
                    }
                    $entryid = $row[PR_ENTRYID];
                    break;
                }
            }
        }
    } else {
        $entryid = @mapi_msgstore_createentryid($adminStore, $user);
    }
    $userStore = @mapi_openmsgstore($session, $entryid);
    $hresult = mapi_last_hresult();
    // Cache the store for later use
    if ($hresult != NOERROR) {
        echo "Could not open store for '{$user}'. The script will exit.\n";
        exit(1);
    }
    $folder = @mapi_msgstore_openentry($userStore);
    $h_table = @mapi_folder_gethierarchytable($folder, CONVENIENT_DEPTH);
    $subfolders = @mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_CONTAINER_CLASS, PR_SOURCE_KEY));
    echo "Available folders in store '{$user}':\n" . str_repeat("-", 50) . "\n";
    foreach ($subfolders as $folder) {
        if (isset($folder[PR_CONTAINER_CLASS]) && array_key_exists($folder[PR_CONTAINER_CLASS], $supported_classes)) {
            echo "Folder name:\t" . $folder[PR_DISPLAY_NAME] . "\n";
            echo "Folder ID:\t" . bin2hex($folder[PR_SOURCE_KEY]) . "\n";
            echo "Type:\t\t" . $supported_classes[$folder[PR_CONTAINER_CLASS]] . "\n";
            echo "\n";
        }
    }
}
// Set default to false
foreach ($stores as $row) {
    if (isset($row[PR_DEFAULT_STORE]) && $row[PR_DEFAULT_STORE]) {
        $storeentryid = $row[PR_ENTRYID];
        //print "Found store " . $row[PR_DISPLAY_NAME] . "\n";
        break;
    }
}
if (!$storeentryid) {
    print "Unable to find default store\n";
    return;
}
// We now have the store entryid for the admin store, so open the store
$store = mapi_openmsgstore($session, $storeentryid);
// Now, open the store of another user
$userstoreentryid = mapi_msgstore_createentryid($store, $user);
if (!$userstoreentryid) {
    print "Unknown user {$user}\n";
    return;
}
// Open the store here
$userstore = mapi_openmsgstore($session, $userstoreentryid);
if (!$userstore) {
    print "Unable to open store of user {$user}\n";
    return;
}
// This is the list of entryids for the default folders
$folderentryids = array();
$storeprops = mapi_getprops($userstore, array(PR_IPM_WASTEBASKET_ENTRYID, PR_IPM_SENTMAIL_ENTRYID, PR_IPM_OUTBOX_ENTRYID));
if (isset($storeprops[PR_IPM_WASTEBASKET_ENTRYID])) {
    $folderentryids[0] = $storeprops[PR_IPM_WASTEBASKET_ENTRYID];
function clearSuggestionList($session, $store, $userName)
{
    // create entryid of user's store
    $userStoreEntryId = mapi_msgstore_createentryid($store, $userName);
    if (!$userStoreEntryId) {
        print "Error in creating entryid for user's store - " . $userName . "\n";
        return false;
    }
    // open user's store
    $userStore = mapi_openmsgstore($session, $userStoreEntryId);
    if (!$userStore) {
        print "Error in opening user's store - " . $userName . "\n";
        return false;
    }
    // we are not checking here that property exists or not because it could happen that getprops will return
    // MAPI_E_NOT_ENOUGH_MEMORY for very large property, if property does not exists then it will be created
    // remove property data, overwirte existing data with a blank string (PT_STRING8)
    mapi_setprops($userStore, array(PR_EC_RECIPIENT_HISTORY => ""));
    $result = mapi_last_hresult();
    if ($result == NOERROR) {
        // Save changes
        mapi_savechanges($userStore);
        return mapi_last_hresult() == NOERROR ? true : false;
    }
    return false;
}
Example #12
0
function listfolders_getlist($adminStore, $session, $user)
{
    global $supported_classes;
    if (strtoupper($user) == 'SYSTEM') {
        // Find the public store store
        $storestables = @mapi_getmsgstorestable($session);
        $result = @mapi_last_hresult();
        if ($result == NOERROR) {
            $rows = @mapi_table_queryallrows($storestables, array(PR_ENTRYID, PR_MDB_PROVIDER));
            foreach ($rows as $row) {
                if (isset($row[PR_MDB_PROVIDER]) && $row[PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
                    if (!isset($row[PR_ENTRYID])) {
                        echo "Public folder are not available.\nIf this is a multi-tenancy system, use -u and -p and login with an admin user of the company.\nThe script will exit.\n";
                        exit(1);
                    }
                    $entryid = $row[PR_ENTRYID];
                    break;
                }
            }
        }
    } else {
        $entryid = @mapi_msgstore_createentryid($adminStore, $user);
    }
    $userStore = @mapi_openmsgstore($session, $entryid);
    $hresult = mapi_last_hresult();
    // Cache the store for later use
    if ($hresult != NOERROR) {
        echo "Could not open store for '{$user}'. The script will exit.\n";
        exit(1);
    }
    if (strtoupper($user) != 'SYSTEM') {
        $inbox = mapi_msgstore_getreceivefolder($userStore);
        if (mapi_last_hresult() != NOERROR) {
            printf("Could not open inbox for %s (0x%08X). The script will exit.\n", $user, mapi_last_hresult());
            exit(1);
        }
        $inboxProps = mapi_getprops($inbox, array(PR_SOURCE_KEY));
    }
    $storeProps = mapi_getprops($userStore, array(PR_IPM_OUTBOX_ENTRYID, PR_IPM_SENTMAIL_ENTRYID, PR_IPM_WASTEBASKET_ENTRYID));
    $root = @mapi_msgstore_openentry($userStore, null);
    $h_table = @mapi_folder_gethierarchytable($root, CONVENIENT_DEPTH);
    $subfolders = @mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_CONTAINER_CLASS, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_FOLDER_TYPE, PR_ATTR_HIDDEN));
    echo "Available folders in store '{$user}':\n" . str_repeat("-", 50) . "\n";
    foreach ($subfolders as $folder) {
        // do not display hidden and search folders
        if (isset($folder[PR_ATTR_HIDDEN]) && $folder[PR_ATTR_HIDDEN] || isset($folder[PR_FOLDER_TYPE]) && $folder[PR_FOLDER_TYPE] == FOLDER_SEARCH) {
            continue;
        }
        // handle some special folders
        if (strtoupper($user) != 'SYSTEM' && (isset($inboxProps[PR_SOURCE_KEY]) && $folder[PR_SOURCE_KEY] == $inboxProps[PR_SOURCE_KEY] || $folder[PR_ENTRYID] == $storeProps[PR_IPM_SENTMAIL_ENTRYID] || $folder[PR_ENTRYID] == $storeProps[PR_IPM_WASTEBASKET_ENTRYID])) {
            $folder[PR_CONTAINER_CLASS] = "IPF.Note";
        }
        if (isset($folder[PR_CONTAINER_CLASS]) && array_key_exists($folder[PR_CONTAINER_CLASS], $supported_classes)) {
            echo "Folder name:\t" . $folder[PR_DISPLAY_NAME] . "\n";
            echo "Folder ID:\t" . bin2hex($folder[PR_SOURCE_KEY]) . "\n";
            echo "Type:\t\t" . $supported_classes[$folder[PR_CONTAINER_CLASS]] . "\n";
            echo "\n";
        }
    }
}
Example #13
0
 /**
  * Returns the store for a gab id and name
  *
  * @param string $gabId
  * @param string $gabName
  *
  * @access private
  * @return ressource
  */
 private function getStore($gabId, $gabName)
 {
     if (!$gabId) {
         return $this->store;
     }
     if (!isset($this->storeCache[$gabId])) {
         $user = strtoupper($this->targetStore) == 'SYSTEM' ? $gabName : $this->targetStore . "@" . $gabName;
         $store_entryid = mapi_msgstore_createentryid($this->store, $user);
         if ($store_entryid) {
             $store = mapi_openmsgstore($this->session, $store_entryid);
             $this->Log(sprintf("Kopano->getStore(): Found store of user '%s': '%s'", $user, $store));
         } else {
             $this->Log(sprintf("Kopano->getStore(): No store found for '%s'", $user));
             $store = false;
         }
         $this->storeCache[$gabId] = $store;
     }
     return $this->storeCache[$gabId];
 }