LPMAPIFOLDER CExMapi::GetNextSubFolder(CString& strFolderName,LPMAPIFOLDER pFolder)
{
	if(!m_pHierarchy) return NULL;
	if(!pFolder) {
		pFolder=m_pFolder;
		if(!pFolder) return FALSE;
	}

	DWORD dwObjType;
	LPSRowSet pRows=NULL;	

	LPMAPIFOLDER pSubFolder=NULL;
	if(m_pHierarchy->QueryRows(1,0,&pRows)==S_OK) 
	{
		if(pRows->cRows) 
		{
			if(pFolder->OpenEntry(pRows->aRow[0].lpProps[PROP_ENTRYID].Value.bin.cb,(LPENTRYID)pRows->aRow[0].lpProps[PROP_ENTRYID].Value.bin.lpb, NULL, MAPI_MODIFY, &dwObjType,(LPUNKNOWN*)&pSubFolder)==S_OK) 
			{				
				strFolderName=CString(GetValidString(pRows->aRow[0].lpProps[0]));												
			}
		}
		FreeProws(pRows);
		MAPIFreeBuffer(pRows);
	}		
	return pSubFolder;
}
Esempio n. 2
0
HRESULT RunFolderValidation(const std::set<std::string> &setFolderIgnore, LPMAPIFOLDER lpRootFolder, LPSRow lpRow, CHECKMAP checkmap)
{
	HRESULT hr = hrSuccess;
	LPSPropValue lpItemProperty = NULL;
	LPMAPIFOLDER lpFolder = NULL;
	ZarafaFsck *lpFsck = NULL;
	ULONG ulObjectType = 0;
	string strName;
	string strClass;
	ULONG ulFolderType = 0;

	lpItemProperty = PpropFindProp(lpRow->lpProps, lpRow->cValues, PR_ENTRYID);
	if (!lpItemProperty) {
		cout << "Row does not contain an EntryID." << endl;
		goto exit;
	}

	hr = lpRootFolder->OpenEntry(lpItemProperty->Value.bin.cb,
				   (LPENTRYID)lpItemProperty->Value.bin.lpb,
				   &IID_IMAPIFolder,
				   0,
				   &ulObjectType,
				   (IUnknown**)&lpFolder);
	if (hr != hrSuccess) {
		cout << "Failed to open EntryID." << endl;
		goto exit;
	}

	/*
	 * Detect folder name and class.
	 */
	hr = DetectFolderDetails(lpFolder, &strName, &strClass, &ulFolderType);
	if (hr != hrSuccess) {
		if (!strName.empty()) {
			cout << "Unknown class, skipping entry";
			cout << " \"" << strName << "\"" << endl;
		} else
			cout << "Failed to detect folder details." << endl;
		goto exit;
	}

	if (setFolderIgnore.find(string((const char*)lpItemProperty->Value.bin.lpb, lpItemProperty->Value.bin.cb)) != setFolderIgnore.end()) {
		cout << "Ignoring folder: ";
		cout << "\"" << strName << "\" (" << strClass << ")" << endl;
		goto exit;
	}

	if (ulFolderType != FOLDER_GENERIC) {
		cout << "Ignoring search folder: ";
		cout << "\"" << strName << "\" (" << strClass << ")" << endl;
		goto exit;
	}

	for (CHECKMAP_I i = checkmap.begin(); i != checkmap.end(); ++i) {
		if (i->first == strClass) {
			lpFsck = i->second;
			break;
		}
	}

	if (lpFsck)
		lpFsck->ValidateFolder(lpFolder, strName);
	else {
		cout << "Ignoring folder: ";
		cout << "\"" << strName << "\" (" << strClass << ")" << endl;
	}

exit:
	if(lpFolder)
		lpFolder->Release();

	return hr;
}
Esempio n. 3
0
// Finds an arbitrarily nested folder in the indicated folder given
// a hierarchical list of subfolders.
HRESULT HrMAPIFindSubfolderExW(
	_In_ LPMAPIFOLDER lpRootFolder,    // open root folder
	ULONG ulFolderCount,               // count of hierarchical list of subfolders to navigate
	LPWSTR* lppszFolderList,           // hierarchical list of subfolders to navigate
	_Out_opt_ ULONG* lpcbeid,          // pointer to count of bytes in entry ID
	_Deref_out_opt_ LPENTRYID* lppeid) // pointer to entry ID pointer
{
	HRESULT hRes = S_OK;
	LPMAPIFOLDER lpParentFolder = lpRootFolder;
	LPMAPIFOLDER lpChildFolder = NULL;
	ULONG cbeid = 0;
	LPENTRYID lpeid = NULL;
	ULONG ulObjType = 0;
	ULONG i = 0;

	if (!lpcbeid || !lppeid) return MAPI_E_INVALID_PARAMETER;
	if (!ulFolderCount || !lppszFolderList) return MAPI_E_INVALID_PARAMETER;

	for (i = 0; i < ulFolderCount; i++)
	{
		// Free entryid before re-use.
		MAPIFreeBuffer(lpeid);

		WC_H(HrMAPIFindFolderW(lpParentFolder, lppszFolderList[i], &cbeid, &lpeid));
		if (FAILED(hRes)) break;

		// Only OpenEntry if needed for next tier of folder path.
		if (lppszFolderList[i+1] != NULL)
		{
			WC_MAPI(lpParentFolder->OpenEntry(
				cbeid,
				lpeid,
				NULL,
				MAPI_DEFERRED_ERRORS,
				&ulObjType,
				(LPUNKNOWN*)&lpChildFolder));
			if (FAILED(hRes) || ulObjType != MAPI_FOLDER)
			{
				MAPIFreeBuffer(lpeid);
				hRes = MAPI_E_CALL_FAILED;
				break;
			}
		}

		// No longer need the parent folder
		// (Don't release the folder that was passed!)
		if (i > 0)
		{
			if (lpParentFolder) lpParentFolder->Release();
		}

		lpParentFolder = lpChildFolder;
		lpChildFolder  = NULL;
	}

	// Success!
	*lpcbeid = cbeid;
	*lppeid  = lpeid;

	return hRes;
} // HrMAPIFindSubfolderExW