Example #1
0
function delete_duplicate_messages($store, $entryid)
{
    global $total_deleted;
    $folder = mapi_msgstore_openentry($store, $entryid);
    if (!$folder) {
        print "Unable to open folder.";
        return false;
    }
    $table = mapi_folder_getcontentstable($folder);
    if (!$table) {
        print "Unable to open table.";
        return false;
    }
    $org_hash = null;
    $dup_messages = array();
    $dup_count = 0;
    $result = mapi_table_sort($table, array(PR_SUBJECT => TABLE_SORT_ASCEND));
    if ($result == false) {
        die("Could not sort table\n");
    }
    while (1) {
        // query messages from folders content table
        $rows = mapi_table_queryrows($table, array(PR_MESSAGE_SIZE, PR_CLIENT_SUBMIT_TIME, PR_BODY, PR_HTML, PR_ENTRYID, PR_SUBJECT), 0, 50);
        if (count($rows) == 0) {
            break;
        }
        // we got the messages
        foreach ($rows as $row) {
            // hash message body (plaintext + html + subject)
            $md5_subject = md5($row[PR_SUBJECT]);
            $md5_body = md5($row[PR_BODY]);
            $md5_html = md5($row[PR_HTML]);
            // concat hashes, just in case there are messages with
            // no HTML or plaintext content.
            $cur_hash = $md5_body . $md5_html . $md5_subject;
            // when we have accumulated enough messages, perform a burst delete
            if ($dup_count == 50) {
                echo " [i] Deleting {$dup_count} duplicates...";
                delete_messages($folder, $dup_messages);
                // reset the delete-queue
                $dup_messages = array();
                $dup_count = 0;
                $total_deleted += 100;
                echo "done.\n";
                echo "Deleted {$total_deleted} messages so far.\n\n";
            }
            // duplicate messages are adjacent, so we push the first message with
            // a distinct hash and mark all following messages with this hash
            // for deletion.
            if ($org_hash != $cur_hash) {
                $org_hash = $cur_hash;
            } else {
                $dup_messages[] = $row[PR_ENTRYID];
                $dup_count++;
                echo " [i] For {$org_hash} adding DUP {$md5_eid} to delete list\n";
            }
        }
    }
    // final cleanup
    $dup_count = count($dup_messages);
    if ($dup_count) {
        $total_deleted += $dup_count;
        echo " [i] Finally deleting {$dup_count} duplicates. \n";
        delete_messages($folder, $dup_messages);
        $dup_messages = array();
        echo "Deleted {$total_deleted} messages so far.\n\n";
    }
}
Example #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;
}
Example #3
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;
 }
Example #4
0
 /**
  * Searches the GAB of Zarafa
  * Can be overwitten globally by configuring a SearchBackend
  *
  * @param string        $searchquery
  * @param string        $searchrange
  *
  * @access public
  * @return array
  * @throws StatusException
  */
 public function GetGALSearchResults($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);
     if ($addrbook) {
         $ab_entryid = mapi_ab_getdefaultdir($addrbook);
     }
     if ($ab_entryid) {
         $ab_dir = mapi_ab_openentry($addrbook, $ab_entryid);
     }
     if ($ab_dir) {
         $table = mapi_folder_getcontentstable($ab_dir);
     }
     if (!$table) {
         throw new StatusException(sprintf("ZarafaBackend->GetGALSearchResults(): could not open addressbook: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_CONNECTIONFAILED);
     }
     $restriction = MAPIUtils::GetSearchRestriction(u2w($searchquery));
     mapi_table_restrict($table, $restriction);
     mapi_table_sort($table, array(PR_DISPLAY_NAME => TABLE_SORT_ASCEND));
     if (mapi_last_hresult()) {
         throw new StatusException(sprintf("ZarafaBackend->GetGALSearchResults(): could not apply restriction: 0x%X", mapi_last_hresult()), SYNC_SEARCHSTATUS_STORE_TOOCOMPLEX);
     }
     //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'] = $querylimit > 0 ? $rangestart . '-' . ($querylimit - 1) : '0-0';
     $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;
 }
Example #5
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;
 }