<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://www.zarafa.com/wiki/skins/common/feed.css?270"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://www.zarafa.com/wiki/index.php?title=Clear_Suggestion_List_for_WebAccess&amp;feed=atom&amp;action=history</id>
		<title>Clear Suggestion List for WebAccess - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://www.zarafa.com/wiki/index.php?title=Clear_Suggestion_List_for_WebAccess&amp;feed=atom&amp;action=history"/>
		<link rel="alternate" type="text/html" href="http://www.zarafa.com/wiki/index.php?title=Clear_Suggestion_List_for_WebAccess&amp;action=history"/>
		<updated>2013-05-24T04:26:55Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.16.0</generator>

	<entry>
		<id>http://www.zarafa.com/wiki/index.php?title=Clear_Suggestion_List_for_WebAccess&amp;diff=1630&amp;oldid=prev</id>
		<title>Msartor: Created page with &quot;The Webaccess shows a suggestion list when typing an email address in the &quot;TO:&quot; field. Over time it could be that users may complain about a too large suggestion list.   With the...&quot;</title>
		<link rel="alternate" type="text/html" href="http://www.zarafa.com/wiki/index.php?title=Clear_Suggestion_List_for_WebAccess&amp;diff=1630&amp;oldid=prev"/>
				<updated>2011-07-21T10:25:33Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;The Webaccess shows a suggestion list when typing an email address in the &amp;quot;TO:&amp;quot; field. Over time it could be that users may complain about a too large suggestion list.   With the...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The Webaccess shows a suggestion list when typing an email address in the &amp;quot;TO:&amp;quot; field. Over time it could be that users may complain about a too large suggestion list.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
With the following script you are able to purge the suggestion list per user (or for all users). Usage:&lt;br /&gt;
* Purge list for selected users:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
php clear_suggestionlist.php -u &amp;lt;username1&amp;gt; &amp;lt;username2&amp;gt; ...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* Purge list for all users:&lt;br /&gt;
&amp;lt;pre&amp;gt; &lt;br /&gt;
php clear_suggestionlist.php -a&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Prerequisites for the script:&lt;br /&gt;
* Run the script on a server which has the php mapi extention installed.&lt;br /&gt;
* You need to have the php-cli package installed.&lt;br /&gt;
* Check the variables on top of the script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The php script:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/php&lt;br /&gt;
&amp;lt;?&lt;br /&gt;
&lt;br /&gt;
// comment this line for debugging&lt;br /&gt;
error_reporting(0);&lt;br /&gt;
&lt;br /&gt;
// mapi include files&lt;br /&gt;
include('/usr/share/php/mapi/mapi.util.php');&lt;br /&gt;
include('/usr/share/php/mapi/mapidefs.php');&lt;br /&gt;
include('/usr/share/php/mapi/mapicode.php');&lt;br /&gt;
include('/usr/share/php/mapi/mapitags.php');&lt;br /&gt;
include('/usr/share/php/mapi/mapiguid.php');&lt;br /&gt;
&lt;br /&gt;
// config options&lt;br /&gt;
$ADMINUSERNAME = &amp;quot;SYSTEM&amp;quot;;&lt;br /&gt;
$ADMINPASSWORD = &amp;quot;&amp;quot;;&lt;br /&gt;
$SERVER = &amp;quot;file:///var/run/zarafa&amp;quot;;&lt;br /&gt;
$USAGEMESSAGE = &amp;quot;Usage:\n\tfor selected users \n\t\tphp clear_suggestionlist.php -u &amp;lt;username1&amp;gt; &amp;lt;username2&amp;gt; ...\n\tfor all users \n\t\tphp clear_suggestionlist.php -a\n&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
if($argc &amp;lt; 2) {&lt;br /&gt;
	exit($USAGEMESSAGE);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// use SYSTEM account for login&lt;br /&gt;
$session = mapi_logon_zarafa($ADMINUSERNAME, $ADMINPASSWORD, $SERVER);&lt;br /&gt;
if(!$session) {&lt;br /&gt;
	exit(&amp;quot;Can't login into zarafa server\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// get all stores of SYSTEM account&lt;br /&gt;
$msgStoresTable = mapi_getmsgstorestable($session);&lt;br /&gt;
$msgStores = mapi_table_queryallrows($msgStoresTable, array(PR_DEFAULT_STORE, PR_ENTRYID));&lt;br /&gt;
&lt;br /&gt;
// get default store&lt;br /&gt;
foreach ($msgStores as $row) {&lt;br /&gt;
	if($row[PR_DEFAULT_STORE]) {&lt;br /&gt;
		$storeEntryid = $row[PR_ENTRYID];&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if(!$storeEntryid) {&lt;br /&gt;
	exit(&amp;quot;Can't find default store\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// open default store&lt;br /&gt;
$store = mapi_openmsgstore($session, $storeEntryid);&lt;br /&gt;
if(!$store) {&lt;br /&gt;
	exit(&amp;quot;Unable to open system store\n&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if(strcasecmp($argv[1], &amp;quot;-a&amp;quot;) == 0) {&lt;br /&gt;
	// get all zarafa users and remove property data&lt;br /&gt;
	$userList = array();&lt;br /&gt;
&lt;br /&gt;
	// for multi company setup&lt;br /&gt;
	$companyList = mapi_zarafa_getcompanylist($store);&lt;br /&gt;
	if(mapi_last_hresult() == NOERROR &amp;amp;&amp;amp; is_array($companyList)) {&lt;br /&gt;
		// multi company setup, get all users from all companies&lt;br /&gt;
		foreach($companyList as $companyName =&amp;gt; $companyData) {&lt;br /&gt;
			$userList = array_merge($userList, mapi_zarafa_getuserlist($store, $companyData[&amp;quot;companyid&amp;quot;]));&lt;br /&gt;
		}&lt;br /&gt;
	} else {&lt;br /&gt;
		// single company setup, get list of all zarafa users&lt;br /&gt;
		$userList = mapi_zarafa_getuserlist($store);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	if(count($userList) &amp;lt;= 0) {&lt;br /&gt;
		exit(&amp;quot;Unable to get user list\n&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	foreach($userList as $userName =&amp;gt; $userData) {&lt;br /&gt;
		// check for valid users&lt;br /&gt;
		if($userName == &amp;quot;SYSTEM&amp;quot;) {&lt;br /&gt;
			continue;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		$result = clearSuggestionList($session, $store, $userName);&lt;br /&gt;
		if($result) {&lt;br /&gt;
			print &amp;quot;Suggestion list cleared for user - &amp;quot; . $userName . &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
		} else {&lt;br /&gt;
			print &amp;quot;Not able to clear suggestion list for user - &amp;quot; . $userName . &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
} else if(strcasecmp($argv[1], &amp;quot;-u&amp;quot;) == 0) {&lt;br /&gt;
	// only clear properties for selected users&lt;br /&gt;
	if($argc == 2) {&lt;br /&gt;
		exit(&amp;quot;No user specified\n\n&amp;quot; . $USAGEMESSAGE);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	for($index = 2; $index &amp;lt; $argc; $index++) {		// start with argv[2]&lt;br /&gt;
		$result = clearSuggestionList($session, $store, $argv[$index]);&lt;br /&gt;
		if($result) {&lt;br /&gt;
			print &amp;quot;Suggestion list cleared for user - &amp;quot; . $argv[$index] . &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
		} else {&lt;br /&gt;
			print &amp;quot;Not able to clear suggestion list for user - &amp;quot; . $argv[$index] . &amp;quot;\n\n&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
} else {&lt;br /&gt;
	exit(&amp;quot;Unknown option specified\n\n&amp;quot; . $USAGEMESSAGE);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
/**************** Internal Functions ******************/&lt;br /&gt;
&lt;br /&gt;
function clearSuggestionList($session, $store, $userName)&lt;br /&gt;
{&lt;br /&gt;
	// create entryid of user's store&lt;br /&gt;
	$userStoreEntryId = mapi_msgstore_createentryid($store, $userName);&lt;br /&gt;
	if(!$userStoreEntryId) {&lt;br /&gt;
		print &amp;quot;Error in creating entryid for user's store - &amp;quot; . $userName . &amp;quot;\n&amp;quot;;&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// open user's store&lt;br /&gt;
	$userStore = mapi_openmsgstore($session, $userStoreEntryId);&lt;br /&gt;
	if(!$userStore) {&lt;br /&gt;
		print &amp;quot;Error in opening user's store - &amp;quot; . $userName . &amp;quot;\n&amp;quot;;&lt;br /&gt;
		return false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	// we are not checking here that proeprty exists or not because it could happen that getprops will return&lt;br /&gt;
	// MAPI_E_NOT_ENOUGH_MEMORY for very large property, if property does not exists then it will be created&lt;br /&gt;
&lt;br /&gt;
	// remove property data, overwirte existing data with a blank string (PT_STRING8)&lt;br /&gt;
	mapi_setprops($userStore, array(PR_EC_RECIPIENT_HISTORY =&amp;gt; &amp;quot;&amp;quot;));&lt;br /&gt;
	$result = mapi_last_hresult();&lt;br /&gt;
&lt;br /&gt;
	if($result == NOERROR) {&lt;br /&gt;
		// Save changes&lt;br /&gt;
		mapi_savechanges($userStore);&lt;br /&gt;
		return (mapi_last_hresult() == NOERROR) ? true : false;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	return false;&lt;br /&gt;
}&lt;br /&gt;
?&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Msartor</name></author>	</entry>

	</feed>