if (!$session) {
    print "Unable to open session\n";
    exit(1);
}
$msgstorestable = mapi_getmsgstorestable($session);
if (!$msgstorestable) {
    print "Unable to open message stores table\n";
    exit(1);
}
$msgstores = mapi_table_queryallrows($msgstorestable, array(PR_DEFAULT_STORE, PR_ENTRYID));
foreach ($msgstores as $row) {
    if ($row[PR_DEFAULT_STORE]) {
        $default_store_entry_id = $row[PR_ENTRYID];
    }
}
$default_store = mapi_openmsgstore($session, $default_store_entry_id);
if (!$default_store) {
    print "Unable to open default store\n";
    exit(1);
}
$root = mapi_msgstore_openentry($default_store);
// get folders
$folders = mapi_folder_gethierarchytable($root, CONVENIENT_DEPTH);
// loop over every folder
while (1) {
    $rows = mapi_table_queryrows($folders, array(PR_DISPLAY_NAME, PR_FOLDER_TYPE, PR_ENTRYID), 0, 100);
    if (count($rows) == 0) {
        break;
    }
    foreach ($rows as $row) {
        // skip searchfolders
 function getDefaultStore()
 {
     $table = mapi_getmsgstorestable($this->session);
     $rows = mapi_table_queryallrows($table, array(PR_DEFAULT_STORE, PR_ENTRYID));
     foreach ($rows as $row) {
         if ($row[PR_DEFAULT_STORE]) {
             return mapi_openmsgstore($this->session, $row[PR_ENTRYID]);
         }
     }
     return false;
 }
 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 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);
 }
function openMsgStore($username, $password)
{
    $session = mapi_logon_zarafa($username, $password, SERVER);
    if (mapi_last_hresult() != 0) {
        trigger_error(sprintf("MAPI Error: 0x%x", mapi_last_hresult()), E_USER_ERROR);
    }
    $storesTable = mapi_getmsgstorestable($session);
    $stores = mapi_table_queryallrows($storesTable, array(PR_ENTRYID, PR_MDB_PROVIDER));
    for ($i = 0; $i < count($stores); $i++) {
        if ($stores[$i][PR_MDB_PROVIDER] == ZARAFA_SERVICE_GUID) {
            $storeEntryid = $stores[$i][PR_ENTRYID];
            break;
        }
    }
    if (!isset($storeEntryid)) {
        trigger_error("Default store not found", E_USER_ERROR);
    }
    $store = mapi_openmsgstore($session, $storeEntryid);
    isUnicodeStore($store);
    return $store;
}
예제 #6
0
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);
    }
}
예제 #7
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;
}
$session = mapi_logon_zarafa($username, $password, SERVER);
if (mapi_last_hresult() != 0) {
    trigger_error(sprintf("MAPI Error: 0x%x", mapi_last_hresult()), E_USER_ERROR);
}
$storesTable = mapi_getmsgstorestable($session);
$stores = mapi_table_queryallrows($storesTable, array(PR_ENTRYID, PR_MDB_PROVIDER));
for ($i = 0; $i < count($stores); $i++) {
    if ($stores[$i][PR_MDB_PROVIDER] == ZARAFA_SERVICE_GUID) {
        $storeEntryid = $stores[$i][PR_ENTRYID];
        break;
    }
}
if (!isset($storeEntryid)) {
    trigger_error("Default store not found", E_USER_ERROR);
}
$store = mapi_openmsgstore($session, $storeEntryid);
$root = mapi_msgstore_openentry($store, null);
$rootProps = mapi_getprops($root, array(PR_IPM_CONTACT_ENTRYID));
$folder = mapi_msgstore_openentry($store, $rootProps[PR_IPM_CONTACT_ENTRYID]);
isUnicodeStore($store);
// open the csv file and start reading
$fh = fopen($csv_file, "r");
if (!$fh) {
    trigger_error("Can't open CSV file \"" . $csv_file . "\"", E_USER_ERROR);
}
// empty folder if needed
if (EMPTY_FOLDER) {
    mapi_folder_emptyfolder($folder, DEL_ASSOCIATED);
}
$properties = array();
loadProperties($properties);
예제 #9
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);
 }
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;
}
예제 #11
0
 /**
  * Connect to Zarafa and do some init
  * @param $user user login
  * @param $password user password
  */
 public function connect($user, $password)
 {
     $this->logger->debug("connect({$user}," . md5($password) . ")");
     $this->session = NULL;
     try {
         $session = mapi_logon_zarafa($user, $password, ZARAFA_SERVER);
     } catch (Exception $e) {
         $this->logger->debug("connection failed: " . get_mapi_error_name());
         return false;
     }
     if ($session === FALSE) {
         // Failed
         return false;
     }
     $this->logger->trace("Connected to zarafa server - init bridge");
     $this->session = $session;
     // Find user store
     $storesTable = mapi_getmsgstorestable($session);
     $stores = mapi_table_queryallrows($storesTable, array(PR_ENTRYID, PR_MDB_PROVIDER));
     for ($i = 0; $i < count($stores); $i++) {
         switch ($stores[$i][PR_MDB_PROVIDER]) {
             case ZARAFA_SERVICE_GUID:
                 $storeEntryid = $stores[$i][PR_ENTRYID];
                 break;
             case ZARAFA_STORE_PUBLIC_GUID:
                 $pubStoreEntryid = $stores[$i][PR_ENTRYID];
                 break;
         }
     }
     if (!isset($storeEntryid)) {
         trigger_error("Default store not found", E_USER_ERROR);
     }
     $this->store = mapi_openmsgstore($this->session, $storeEntryid);
     $root = mapi_msgstore_openentry($this->store, null);
     $rootProps = mapi_getprops($root, array(PR_IPM_CONTACT_ENTRYID));
     // Store rootfolder
     $this->rootFolder = mapi_msgstore_openentry($this->store, $rootProps[PR_IPM_CONTACT_ENTRYID]);
     $this->rootFolderId = $rootProps[PR_IPM_CONTACT_ENTRYID];
     if (isset($pubStoreEntryid)) {
         $this->pubStore = mapi_openmsgstore($this->session, $pubStoreEntryid);
         $pubFolder = mapi_msgstore_openentry($this->pubStore);
         $h_table = mapi_folder_gethierarchytable($pubFolder, CONVENIENT_DEPTH);
         // $subfolders = mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME));
         $subfolders = mapi_table_queryallrows($h_table);
         for ($i = 0; $i < count($subfolders); $i++) {
             $name = $subfolders[$i][PR_DISPLAY_NAME];
             $entryid = $subfolders[$i][PR_ENTRYID];
             $folder = mapi_msgstore_openentry($this->pubStore, $entryid);
             $props = mapi_getprops($folder);
             if (isset($props[PR_CONTAINER_CLASS_A]) && $props[PR_CONTAINER_CLASS_A] == "IPF.Contact") {
                 $this->pubFolderIds[] = $entryid;
                 $this->pubFolders[] = mapi_msgstore_openentry($this->pubStore, $entryid);
             }
         }
     }
     // Check for unicode
     $this->isUnicodeStore($this->store);
     // Load properties
     $this->initProperties();
     // Store username for principals
     $this->connectedUser = $user;
     // Set protected variable to NULL.
     $this->adressBooks = NULL;
     return true;
 }
예제 #12
0
define("ZARAFA_PASS", "");
require MAPI_PATH . "mapi.util.php";
require MAPI_PATH . "mapicode.php";
require MAPI_PATH . "mapidefs.php";
require MAPI_PATH . "mapitags.php";
require MAPI_PATH . "mapiguid.php";
$supported_classes = array("IPF.Note" => "SYNC_FOLDER_TYPE_USER_MAIL", "IPF.Task" => "SYNC_FOLDER_TYPE_USER_TASK", "IPF.Appointment" => "SYNC_FOLDER_TYPE_USER_APPOINTMENT", "IPF.Contact" => "SYNC_FOLDER_TYPE_USER_CONTACT", "IPF.StickyNote" => "SYNC_FOLDER_TYPE_USER_NOTE");
$session = @mapi_logon_zarafa(ZARAFA_USER, ZARAFA_PASS, ZARAFA_SERVER);
if (!$session) {
    die("Login to Zarafa failed\n");
}
$storetable = @mapi_getmsgstorestable($session);
$storeslist = @mapi_table_queryallrows($storetable, array(PR_ENTRYID, PR_MDB_PROVIDER));
for ($i = 0; $i < count($storeslist); $i++) {
    if ($storeslist[$i][PR_MDB_PROVIDER] == ZARAFA_STORE_PUBLIC_GUID) {
        $publicstore = @mapi_openmsgstore($session, $storeslist[$i][PR_ENTRYID]);
        break;
    }
}
if (!isset($publicstore)) {
    die("Public folder not available");
}
$pub_folder = @mapi_msgstore_openentry($publicstore);
$h_table = @mapi_folder_gethierarchytable($pub_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 public folder:\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 "Name:\t\t" . $folder[PR_DISPLAY_NAME] . "\n";
        echo "Sync-class:\t" . $supported_classes[$folder[PR_CONTAINER_CLASS]] . "\n";
        echo "PUID:\t\t" . bin2hex($folder[PR_SOURCE_KEY]) . "\n\n";
예제 #13
0
 /**
  * open_zarafa
  *
  * @param	descriptor	An open Zarafa session id.
  * @return	array		Array with session and store information.
  */
 function open_zarafa($session)
 {
     $ret = array("root" => "/");
     $storesTable = mapi_getmsgstorestable($session);
     $stores = mapi_table_queryallrows($storesTable, array(PR_ENTRYID, PR_MDB_PROVIDER));
     for ($i = 0; $i < count($stores); $i++) {
         if ($stores[$i][PR_MDB_PROVIDER] == ZARAFA_SERVICE_GUID) {
             $storeEntryid = $stores[$i][PR_ENTRYID];
             break;
         }
     }
     if (!isset($storeEntryid)) {
         trigger_error("Default store not found", PR_USER_ERROR);
     }
     $store = mapi_openmsgstore($session, $storeEntryid);
     $root = mapi_msgstore_openentry($store, null);
     $rootProps = mapi_getprops($root, array(PR_IPM_CONTACT_ENTRYID));
     $folder = mapi_msgstore_openentry($store, $rootProps[PR_IPM_CONTACT_ENTRYID]);
     $table = mapi_folder_getcontentstable($folder);
     $contacts = mapi_table_queryallrows($table);
     $ret["session"] = $session;
     $ret["store"] = $store;
     $ret["contacts"] = $contacts;
     // ZCP 7 and up know unicode...
     $supportmask = mapi_getprops($store, array(PR_STORE_SUPPORT_MASK));
     if (isset($supportmask[PR_STORE_SUPPORT_MASK]) && $supportmask[PR_STORE_SUPPORT_MASK] & STORE_UNICODE_OK) {
         $ret["unicode_store"] = true;
         setlocale(LC_CTYPE, 'en_US.utf-8');
     }
     // END ZCP7 and up know unicode
     return $ret;
 }
예제 #14
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";
        }
    }
}
예제 #15
0
파일: ics.php 프로젝트: nnaannoo/paskot
 function _openDefaultMessageStore($session)
 {
     // Find the default store
     $storestables = mapi_getmsgstorestable($session);
     $result = mapi_last_hresult();
     $entryid = false;
     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_DEFAULT_STORE]) && $row[PR_DEFAULT_STORE] == true) {
                 $entryid = $row[PR_ENTRYID];
                 break;
             }
         }
     }
     if ($entryid) {
         return mapi_openmsgstore($session, $entryid);
     } else {
         return false;
     }
 }
$l_aTableRows = mapi_table_queryallrows($l_rTableStores, array(PR_ENTRYID, PR_DEFAULT_STORE));
echo (mapi_last_hresult() == 0 ? "Retrieving default store..." : "Some error in retrieving default store...") . "\n";
$l_bbnEntryID = false;
// Either boolean or binary
// Loop through returned rows
for ($i = 0; $i < count($l_aTableRows); $i++) {
    // Check to see if this entry is the default store
    if (isset($l_aTableRows[$i][PR_DEFAULT_STORE]) && $l_aTableRows[$i][PR_DEFAULT_STORE] == true) {
        $l_bbnEntryID = $l_aTableRows[$i][PR_ENTRYID];
        break;
    }
}
// check if default root store's entry id found
if ($l_bbnEntryID) {
    // Open msg store by using the entryID
    $l_rDefaultStore = mapi_openmsgstore($l_rSession, $l_bbnEntryID);
    echo 'Opening default store result (0=success): ' . mapi_last_hresult() . "\n";
    // Get inbox
    $l_rInbox = mapi_msgstore_getreceivefolder($l_rDefaultStore);
    echo 'Getting entryID of inbox folder result (0=success): ' . mapi_last_hresult() . "\n";
    // Check if folder has been opened
    if ($l_rInbox) {
        // Open contents table
        $l_rInboxTable = mapi_folder_getcontentstable($l_rInbox);
        echo 'Opening contents table result (0=success): ' . mapi_last_hresult() . "\n";
        // Find the item by restricting all items to the correct ID
        $restrict = array(RES_AND, array(array(RES_PROPERTY, array(RELOP => RELOP_NE, ULPROPTAG => PR_PROCESSED, VALUE => array(PR_PROCESSED => true))), array(RES_CONTENT, array(FUZZYLEVEL => FL_PREFIX, ULPROPTAG => PR_MESSAGE_CLASS, VALUE => array(PR_SUBJECT => 'IPM.Schedule.Meeting'))), array(RES_BITMASK, array(ULTYPE => BMR_EQZ, ULMASK => MSGFLAG_READ, ULPROPTAG => PR_MESSAGE_FLAGS))));
        // Just get all items from table
        $l_aRows = mapi_table_queryallrows($l_rInboxTable, array(PR_ENTRYID, PR_MESSAGE_CLASS, PR_SUBJECT, PR_PROCESSED), $restrict);
        echo 'Querying contents table result (0=success): ' . mapi_last_hresult() . "\n";
        //print_r(count($l_aRows));
예제 #17
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;
     }
 }
예제 #18
0
// Retrieve the default store by querying the table
$l_aTableRows = mapi_table_queryallrows($l_rTableStores, array(PR_ENTRYID, PR_DEFAULT_STORE));
echo (mapi_last_hresult() == 0 ? "Fetching Deleted Folder..." : "Some error in fetching...") . "\n";
$l_bbnEntryID = false;
// Either boolean or binary
// Loop through returned rows
for ($i = 0; $i < count($l_aTableRows); $i++) {
    // Check to see if this entry is the default store
    if (isset($l_aTableRows[$i][PR_DEFAULT_STORE]) && $l_aTableRows[$i][PR_DEFAULT_STORE] == true) {
        $storeEntryId = $l_aTableRows[$i][PR_ENTRYID];
        break;
    }
}
// check if default root store's entry id found
if ($storeEntryId) {
    $store = mapi_openmsgstore($l_rSession, $storeEntryId);
    $delStoreProps = mapi_getprops($store, array(PR_IPM_WASTEBASKET_ENTRYID));
    $deletedFolder = mapi_msgstore_openentry($store, $delStoreProps[PR_IPM_WASTEBASKET_ENTRYID]);
    $table = mapi_folder_getcontentstable($deletedFolder);
    $delRows = mapi_table_queryallrows($table, array(PR_ENTRYID, PR_CREATION_TIME));
    echo (mapi_last_hresult() == 0 ? "Fetching messages from Deleted Folder..." : "Some error in fetching...") . "\n";
    if (count($delRows) > 0) {
        $delEntryIds = array();
        echo 'Total messages in deleted folder found are : ' . count($delRows) . "\n";
        for ($i = 0; $i < count($delRows); $i++) {
            if (greaterDate(date("Y-m-d G:i:s", $delRows[$i][PR_CREATION_TIME]), $daysBeforeDeleted)) {
                array_push($delEntryIds, $delRows[$i][PR_ENTRYID]);
            }
        }
        if (count($delEntryIds) > 0) {
            echo "\nDeleting all " . count($delEntryIds) . " messages...\n";
 function openDefaultStore()
 {
     $storestable = mapi_getmsgstorestable($this->session);
     $rows = mapi_table_queryallrows($storestable, array(PR_ENTRYID, PR_DEFAULT_STORE));
     $entry = false;
     foreach ($rows as $row) {
         if (isset($row[PR_DEFAULT_STORE]) && $row[PR_DEFAULT_STORE]) {
             $entryid = $row[PR_ENTRYID];
             break;
         }
     }
     if (!$entryid) {
         return false;
     }
     return mapi_openmsgstore($this->session, $entryid);
 }
예제 #20
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);
    }
    $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";
        }
    }
}
예제 #21
0
function ScanMailBox($uid)
{
    $ct = new user($uid);
    $sock = new sockets();
    $username = $uid;
    $password = $ct->password;
    $zarafa_sock = "file:///var/run/zarafa";
    $ZarafaServerListenIP = $sock->GET_INFO("ZarafaServerListenIP");
    if ($ZarafaServerListenIP == null) {
        $ZarafaServerListenIP = "127.0.0.1";
    }
    if ($ZarafaServerListenIP == "0.0.0.0") {
        $ZarafaServerListenIP = "127.0.0.1";
    }
    $ZarafaServerListenPort = intval($sock->GET_INFO("ZarafaServerListenPort"));
    if ($ZarafaServerListenPort == 0) {
        $ZarafaServerListenPort = 236;
    }
    $zarafaServer = "http://{$ZarafaServerListenIP}:{$ZarafaServerListenPort}/zarafa";
    $session = mapi_logon_zarafa($username, $password, $zarafaServer);
    $hard_delete_messages = true;
    $folder_to_process = 'Sent Items';
    $total_deleted = 0;
    if (!$session) {
        print "Unable to open session {$username}@{$zarafaServer} `{$password}`\n";
        return;
    }
    $msgstorestable = mapi_getmsgstorestable($session);
    if (!$msgstorestable) {
        print "Unable to open message stores table\n";
        return;
    }
    $msgstores = mapi_table_queryallrows($msgstorestable, array(PR_DEFAULT_STORE, PR_ENTRYID));
    foreach ($msgstores as $row) {
        if ($row[PR_DEFAULT_STORE]) {
            $default_store_entry_id = $row[PR_ENTRYID];
        }
    }
    $default_store = mapi_openmsgstore($session, $default_store_entry_id);
    if (!$default_store) {
        print "Unable to open default store\n";
        exit(1);
    }
    $root = mapi_msgstore_openentry($default_store);
    // get folders
    $folders = mapi_folder_gethierarchytable($root, CONVENIENT_DEPTH);
    // loop over every folder
    while (1) {
        $rows = mapi_table_queryrows($folders, array(PR_DISPLAY_NAME, PR_FOLDER_TYPE, PR_ENTRYID), 0, 100);
        if (count($rows) == 0) {
            break;
        }
        foreach ($rows as $row) {
            // skip searchfolders
            if (isset($row[PR_FOLDER_TYPE]) && $row[PR_FOLDER_TYPE] == FOLDER_SEARCH) {
                continue;
            }
            // operate only on folders, whose name is specified in the config section.
            // Like 'Sent Objects'.
            if ($row[PR_DISPLAY_NAME] == $folder_to_process) {
                parse_messages($default_store, $row[PR_ENTRYID]);
            }
        }
    }
}
    //////////////////////////////////
    $username = $_POST['user'];
    $password = $_POST['pwd'];
    $server = 'http://localhost:236/zarafa';
    ////////////////////////////////
    //connect to the zarafa server
    ///////////////////////////////
    $GLOBALS["mapisession"] = new MAPISession();
    $sess = $GLOBALS["mapisession"]->logon($username, $password, $server);
    $session = mapi_logon_zarafa($username, $password, $server);
    $bus = new Bus();
    // Create global bus object
    $GLOBALS["bus"] = $bus;
    // Make bus global
    $GLOBALS["settings"] = new Settings();
    $storelist = $GLOBALS["mapisession"]->getAllMessageStores();
    $id = "webclient_7";
    //define an id
    $GLOBALS["operations"] = new Operations();
    $datas = $GLOBALS["operations"]->getHierarchyList(array(PR_IPM_APPOINTMENT_ENTRYID));
    $store_idhex = $datas[store][0][attributes][id];
    $entryidhex = $datas[store][0][defaultfolders][calendar];
    $entryid = hex2bin($entryidhex);
    $appointment_id = $_POST['zid'];
    $GLOBALS["properties"] = new Properties();
    $cont = new AppointmentListModule($id, $data);
    $stores = mapi_getmsgstorestable($session);
    $storeslist = mapi_table_queryallrows($stores);
    $store = mapi_openmsgstore($session, $storeslist[0][PR_ENTRYID]);
    $result = $GLOBALS["operations"]->deleteMessages($store, $entryid, hex2bin($appointment_id));
}
}
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));
$trans_array = translate($argv[2]);
renamefolder($userstore, $storeprops[PR_IPM_SENTMAIL_ENTRYID], utf8_decode($trans_array["Sent Items"]));
renamefolder($userstore, $storeprops[PR_IPM_OUTBOX_ENTRYID], utf8_decode($trans_array["Outbox"]));
renamefolder($userstore, $storeprops[PR_IPM_WASTEBASKET_ENTRYID], utf8_decode($trans_array["Deleted Items"]));
renamefolder($userstore, $inboxprops[PR_ENTRYID], utf8_decode($trans_array["Inbox"]));
예제 #24
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];
 }