Hi Dmitry,
I hope you can take a few minutes and tell me what I am doing wrong - it
would be greatly appreciated.
I have tried a variety of ways to change the message class on my store
folder from Outlook but I run into a road block with every approach. Again my
goal is that all messages from our provider will go to a specified folder in
our msg store. So Essenitally I have the following folder tree of
[-]MyMsgPST
----- Inbox
I am using the below code and every time I try to set the receive (inbox)
folder in my msg store with the new message class I get ACCESS DENIED. Am I
even close to the correct way to change the message class?
Thanks,
Tom
void SetupMessageClassForInbox(CComQIPtr<IMAPISession, &IID_IMAPISession>
spSession)
{
SizedSPropTagArray(2, sptStoreProps) =
{
2,
{
PR_DISPLAY_NAME,
PR_ENTRYID
}
};
try
{
ULONG uFlags = 0;
CComPtr<IMAPITable> spTable;
spSession->GetMsgStoresTable(0, &spTable);
if(spTable != NULL)
{
if(SUCCEEDED(spTable->SetColumns((LPSPropTagArray)&sptStoreProps, 0)))
{
LPSRowSet pProviderRows;
HRESULT hResult = HrQueryAllRows(spTable,
(SPropTagArray*)&sptStoreProps,
NULL,
NULL,
0,
&pProviderRows);
if(SUCCEEDED(hResult))
{
BOOL bFound = FALSE;
for(int nRecp = 0; nRecp < pProviderRows->cRows; nRecp++)
{
TString s = pProviderRows->aRow[nRecp].lpProps[0].Value.lpszW;
if(s.find(_T("MyMsgPST")) != TString::npos)
{
CComPtr<IMsgStore> spStore;
HRESULT hr = spSession->OpenMsgStore(0,
pProviderRows->aRow[nRecp].lpProps[1].Value.bin.cb,
(LPENTRYID)pProviderRows->aRow[nRecp].lpProps[1].Value.bin.lpb,
NULL,
0,
&spStore);
if(SUCCEEDED(hr) && spStore)
{
SPropValue* pPropEID = NULL;
hr = HrGetOneProp(spStore, PR_IPM_SUBTREE_ENTRYID, &pPropEID);
if(SUCCEEDED(hr))
{
ULONG ulObjType = 0;
CComPtr<IMAPIFolder> spFolder;
CComPtr<IMAPIFolder> spParentFolder;
hr = spStore->OpenEntry(
pPropEID->Value.bin.cb,
(LPENTRYID)pPropEID->Value.bin.lpb,
NULL, uFlags, &ulObjType,
(LPUNKNOWN*)&spParentFolder);
if(SUCCEEDED(hr))
{
CComPtr<IMAPITable> spTblHier;
hr = spParentFolder->GetHierarchyTable(uFlags, &spTblHier);
if(SUCCEEDED(hr))
{
LPSRowSet pRowSet = NULL;
SizedSPropTagArray(4, sptFolderProps) =
{
4,
{
PR_ENTRYID,
PR_DISPLAY_NAME,
PR_SUBFOLDERS,
PR_CONTAINER_CLASS
}
};
hr = HrQueryAllRows(spTblHier,
(LPSPropTagArray)&sptFolderProps,
NULL, NULL, 0, &pRowSet);
for(int ind = 0; ind < pRowSet->cRows; ind++)
{
TString strCurrentFolder =
pRowSet->aRow[ind].lpProps[1].Value.lpszW;
if(strCurrentFolder.find("Inbox") != TString::npos)
{
hr = spStore->SetReceiveFolder(
MESSAGE_CLASS, 0,
pRowSet->aRow[ind].lpProps[0].Value.bin.cb,
(LPENTRYID)pRowSet->aRow[ind].lpProps[0].Value.bin.lpb);
return;
}
}
}
}
}
}
break;
}
pProviderRows->aRow[nRecp].lpProps[1].Value;
ATLTRACE(_T("We are here\n"));
}
FreeProws(pProviderRows);
}
}
}
}
catch(...)
{
}
}