Article ID: 200162 - Last Review: July 2, 2004 - Revision: 2.2
How To Read a Rules Table in Exchange
System Tip This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
This article was previously published under Q200162
Rules are stored in a table. Reading the rules table may be necessary to determine how messages are processed. This table is accessed using OpenProperty with the PR_RULES_TABLE option.
The code below is placed in a Win32 application project and the
Ignore all default libraries option on the
Link tab should be selected. The following libraries are used to compile the code:
Msvcrt.lib, Version.lib, Mapi32.lib, Edkmapi.lib, Edkutils.lib, Addrlkup.lib, Edkdebug.lib
#define EDK_USES_IID
#include <edk.h>
#include <rulecls.h>
void GetRuleList(long,LPSRowSet);
LPMAPISESSION lpSession = NULL;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE,
LPSTR pszCmd, int nCmdShow)
{
LPMDB lpStore = NULL;
CHAR szFolder[MAX_PATH + 1] = {0};
LPMAPIFOLDER lpFolder = NULL;
LPSTR FAR * lppszProviders = NULL;
ULONG cbEIDFolder = 0;
LPENTRYID lpEIDFolder = NULL;
ULONG cProviders = 0;
LPFOLDERRULES lpFRulesLst = NULL;
LPMAPITABLE m_lpMapiTbl = NULL;
LPEXCHANGEMODIFYTABLE m_lpExchTbl = NULL;
ULONG ulFlagsTable = 0;
ULONG lpulCount = NULL;
LPSRowSet lppRows = NULL;
HRESULT hr = MAPIInitialize(NULL);
if (FAILED(hr))
{
MessageBox(0L,"Initialize Failed","Error",MB_OK);
return 1;
}
hr = MAPILogonEx(0, NULL, NULL,
MAPI_LOGON_UI | MAPI_NEW_SESSION | MAPI_EXPLICIT_PROFILE,
&lpSession);
if (FAILED(hr))
{
MessageBox(NULL,"MAPI Logon failed",NULL,MB_OK);
goto cleanup;
}
hr = HrOpenExchangePrivateStore(lpSession, &lpStore);
if (FAILED(hr))
{
MessageBox(NULL,"Message Store Not Opened",NULL,MB_OK);
goto cleanup;
}
strcpy(szFolder, "Top of Information Store\\Inbox");
hr = HrMAPIFindFolderEx(lpStore, '\\', szFolder,
&cbEIDFolder, &lpEIDFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Inbox Not Found",NULL,MB_OK);
goto cleanup;
}
hr = HrMAPIOpenFolderEx(lpStore, '\\', szFolder, &lpFolder);
if (FAILED(hr))
{
MessageBox(NULL,"Inbox not Opened",NULL,MB_OK);
goto cleanup;
}
hr = HrFolderRulesGetProviders(lpStore, cbEIDFolder, lpEIDFolder,
&cProviders, &lppszProviders);
if (FAILED(hr))
{
MessageBox(NULL,"No Providers",NULL,MB_OK);
goto cleanup;
}
hr = HrFolderRulesOpen(lpStore, cbEIDFolder, lpEIDFolder,
*lppszProviders, &lpFRulesLst);
if (FAILED(hr))
{
MessageBox(NULL,"No Rules Found",NULL,MB_OK);
goto cleanup;
}
// Creating MAPITable to get the number of rules
hr = lpFolder->OpenProperty(PR_RULES_TABLE,
(LPGUID)&IID_IExchangeModifyTable, 0,
MAPI_DEFERRED_ERRORS,
(LPUNKNOWN FAR *)&m_lpExchTbl);
if (FAILED(hr))
goto cleanup;
// Open a MAPI table on the RULE table property. This table can be
// read to determine what the rules table looks like.
hr = m_lpExchTbl->GetTable(0, &m_lpMapiTbl);
if (FAILED(hr))
{
hr = HR_LOG(E_FAIL);
goto cleanup;
}
hr = m_lpMapiTbl->GetRowCount(ulFlagsTable,&lpulCount);
if (FAILED(hr))
{
goto cleanup;
}
hr = HrQueryAllRows(m_lpMapiTbl,NULL, NULL, NULL, lpulCount,&lppRows);
if (FAILED(hr))
{
MessageBox(NULL,"Rules not returned",NULL,MB_OK);
goto cleanup;
}
GetRuleList(lpulCount,lppRows);
cleanup:
if (lpSession)
{
lpSession->Logoff(0, 0, 0);
ULRELEASE(lpSession);
}
MAPIUninitialize();
return 0;
}
void GetRuleList(long lulRows, LPSRowSet lppRows)
{
HRESULT hr;
LPSTR p = 0,
pResString,
pActString;
long lState = 0,
lLevel = 0,
lPos = 0;
LPSRestriction pRestriction = 0;
LPACTIONS lpActions = 0;
int lCnt = 0;
while(lPos < lulRows)
{
pRestriction = 0;
lpActions = 0;
pResString = 0;
pActString = 0;
pRestriction =
(LPSRestriction) lppRows->aRow[lPos].lpProps[5].Value.x;
lpActions = (LPACTIONS) lppRows->aRow[lPos].lpProps[6].Value.x;
if (FAILED(hr = HrRestrictionToString(pRestriction, &pResString)))
break;
if (lpActions && lpActions->lpAction)
HrActionToString(lpSession, lpActions->lpAction, &pActString);
if (pActString)
{
char szRule [256];
sprintf(szRule,"\n%s\n",pActString);
OutputDebugString(szRule);
}
lPos ++;
}
MAPIFreeBuffer(pResString);
MAPIFreeBuffer(pActString);
MAPIFreeBuffer(pRestriction);
MAPIFreeBuffer(lpActions);
}
APPLIES TO Microsoft Exchange Development Kit 5.5 Microsoft Exchange Server 2003 Software Development Kit Retired KB Content Disclaimer This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Was this information helpful?
How much effort did you personally put forth to use this article?
Tell us why and what can we do to improve this information
Thank you! Your feedback is used to help us improve our support content. For more assistance options, please visit the
Help and Support Home Page .
Other Resources Other Support Sites
Community
Article Translations