Example #1
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]);
            }
        }
    }
}
Example #2
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;
 }
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
/**
 * Get all public contact folders
 */
function getPublicContactFolders($session, $publicstore)
{
    $pub_folder = mapi_msgstore_openentry($publicstore);
    $h_table = mapi_folder_gethierarchytable($pub_folder, CONVENIENT_DEPTH);
    $contact_properties = getContactProperties($publicstore);
    $subfolders = mapi_table_queryallrows($h_table, array(PR_ENTRYID, PR_DISPLAY_NAME, PR_DISPLAY_TYPE, PR_CONTAINER_CLASS, PR_SUBFOLDERS));
    $pub_list2 = array();
    $contacts = array();
    foreach ($subfolders as $folder) {
        // check if folder contains PR_CONTAINER_CLASS and if its a contact
        if (isset($folder[907214878]) && $folder[907214878] == "IPF.Contact" && $folder[805371934] != "Kontakte") {
            $entryid = $folder[268370178];
            $pub_folder2 = mapi_msgstore_openentry($publicstore, $entryid);
            $pub_table2 = mapi_folder_getcontentstable($pub_folder2);
            $pub_list2 = mapi_table_queryallrows($pub_table2, $contact_properties);
            for ($j = 0; $j < sizeof($pub_list2); $j++) {
                $pub_list2[$j][268370178] = md5($pub_list2[$j][268370178]);
            }
            for ($k = 0; $k < sizeof($pub_list2); $k++) {
                foreach ($pub_list2[$k] as $key => $value) {
                    $attribute = mapKey($key);
                    if ($attribute != "") {
                        $contacts[$k][$attribute] = $value;
                    }
                }
            }
            //$contactFolders[$folder[805371934]] = $pub_list2;
            $contactFolders[] = array("foldername" => $folder[805371934], "contacts" => $contacts);
        }
    }
    //print_r($contactFolders);
    return $contactFolders;
}
    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
        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) {
            delete_duplicate_messages($default_store, $row[PR_ENTRYID]);
Example #6
0
 function _getFoldersRecursive($mapifolder, $parent, &$list)
 {
     $hierarchytable = mapi_folder_gethierarchytable($mapifolder);
     $folderprops = mapi_getprops($mapifolder, array(PR_ENTRYID));
     if (!$hierarchytable) {
         return false;
     }
     $rows = mapi_table_queryallrows($hierarchytable, array(PR_DISPLAY_NAME, PR_SUBFOLDERS, PR_ENTRYID));
     foreach ($rows as $row) {
         $folder = array();
         $folder["mod"] = $row[PR_DISPLAY_NAME];
         $folder["id"] = bin2hex($row[PR_ENTRYID]);
         $folder["parent"] = $parent;
         array_push($list, $folder);
         if (isset($row[PR_SUBFOLDERS]) && $row[PR_SUBFOLDERS]) {
             $this->_getFoldersRecursive(mapi_msgstore_openentry($this->_defaultstore, $row[PR_ENTRYID]), $folderprops[PR_ENTRYID], $list);
         }
     }
     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";
        }
    }
}
Example #8
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]);
     }
 }
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";
    }
}
Example #10
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 #11
0
 /**
  * Returns the internal identifier (folder-id) of the hidden folder.
  *
  * @param string $gabId         the id of the gab where the hidden folder should be searched. If not set (null) the default gab is used.
  * @param string $gabName       the name of the gab where the hidden folder should be searched. If not set (null) the default gab is used.
  *
  * @access protected
  * @return string|boolean on error
  */
 protected function getHiddenFolderId($gabId = null, $gabName = 'default')
 {
     $store = $this->getStore($gabId, $gabName);
     if (!$store) {
         return false;
     }
     $parentfolder = $this->getRootFolder($store);
     $table = mapi_folder_gethierarchytable($parentfolder);
     $restriction = array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_DISPLAY_NAME, VALUE => HIDDEN_FOLDERNAME));
     mapi_table_restrict($table, $restriction);
     $querycnt = mapi_table_getrowcount($table);
     if ($querycnt == 1) {
         $entry = mapi_table_queryallrows($table, array(PR_SOURCE_KEY));
         if (isset($entry[0]) && isset($entry[0][PR_SOURCE_KEY])) {
             return bin2hex($entry[0][PR_SOURCE_KEY]);
         }
     }
     return false;
 }