Ejemplo n.º 1
0
LPMAPITABLE CMAPIEx::GetHierarchy(LPMAPIFOLDER pFolder) {
    if (!pFolder) {
        pFolder = m_pFolder;
        if (!pFolder) return NULL;
    }
    RELEASE(m_pHierarchy);
    if (pFolder->GetHierarchyTable(0, &m_pHierarchy) != S_OK) return NULL;

    const int nProperties = 2;
    SizedSPropTagArray(nProperties, Columns) = { nProperties, { PR_DISPLAY_NAME, PR_ENTRYID } };
    if (m_pHierarchy->SetColumns((LPSPropTagArray) & Columns, 0) == S_OK) return m_pHierarchy;
    return NULL;
}
Ejemplo n.º 2
0
void CMapiApi::GetStoreInfo( CMapiFolder *pFolder, long *pSzContents)
{
  HRESULT  hr;
  LPMDB  lpMdb;

  if (pSzContents)
    *pSzContents = 0;

  if (!OpenStore( pFolder->GetCBEntryID(), pFolder->GetEntryID(), &lpMdb))
    return;

  LPSPropValue pVal;
  /*
  pVal = GetMapiProperty( lpMdb, PR_DISPLAY_NAME);
  ReportStringProp( "    Message store name:", pVal);
  pVal = GetMapiProperty( lpMdb, PR_MDB_PROVIDER);
  ReportUIDProp( "    Message store provider:", pVal);
  pVal = GetMapiProperty( lpMdb, PR_COMMENT);
  ReportStringProp( "    Message comment:", pVal);
  pVal = GetMapiProperty( lpMdb, PR_ACCESS_LEVEL);
  ReportLongProp( "    Message store Access Level:", pVal);
  pVal = GetMapiProperty( lpMdb, PR_STORE_SUPPORT_MASK);
  ReportLongProp( "    Message store support mask:", pVal);
  pVal = GetMapiProperty( lpMdb, PR_STORE_STATE);
  ReportLongProp( "    Message store state:", pVal);
  pVal = GetMapiProperty( lpMdb, PR_OBJECT_TYPE);
  ReportLongProp( "    Message store object type:", pVal);
  pVal = GetMapiProperty( lpMdb, PR_VALID_FOLDER_MASK);
  ReportLongProp( "    Message store valid folder mask:", pVal);

  pVal = GetMapiProperty( lpMdb, 0x8001001e);
  ReportStringProp( "    Message prop 0x8001001e:", pVal);

  // This key appears to be the OMI Account Manager account that corresponds
  // to this message store.  This is important for IMAP accounts
  // since we may not want to import messages from an IMAP store!
  // Seems silly if you ask me!
  // In order to test this, we'll need the registry key to look under to determine
  // if it contains the "IMAP Server" value, if it does then we are an
  // IMAP store, if not, then we are a non-IMAP store - which may always mean
  // a regular store that should be imported.

  pVal = GetMapiProperty( lpMdb, 0x80000003);
  ReportLongProp( "    Message prop 0x80000003:", pVal);

  // ListProperties( lpMdb);
  */

  pVal = GetMapiProperty( lpMdb, PR_IPM_SUBTREE_ENTRYID);
  if (pVal) {
    ULONG      cbEntry;
    LPENTRYID    pEntry;
    LPMAPIFOLDER  lpSubTree = NULL;

    if (GetEntryIdFromProp( pVal, cbEntry, pEntry)) {
      // Open up the folder!
      ULONG    ulObjType;
      hr = lpMdb->OpenEntry( cbEntry, pEntry, NULL, 0, &ulObjType, (LPUNKNOWN *) &lpSubTree);
      MAPIFreeBuffer( pEntry);
      if (SUCCEEDED( hr) && lpSubTree) {
        // Find out if there are any contents in the
        // tree.
        LPMAPITABLE  lpTable;
        hr = lpSubTree->GetHierarchyTable( 0, &lpTable);
        if (HR_FAILED(hr)) {
          MAPI_TRACE2( "GetStoreInfo: GetHierarchyTable failed: 0x%lx, %d\n", (long)hr, (int)hr);
        }
        else {
          ULONG rowCount;
          hr = lpTable->GetRowCount( 0, &rowCount);
          lpTable->Release();
          if (SUCCEEDED( hr) && pSzContents)
            *pSzContents = (long) rowCount;
        }

        lpSubTree->Release();
      }
    }
  }
}
Ejemplo n.º 3
0
BOOL CMapiApi::IterateHierarchy( CMapiHierarchyIter *pIter, LPMAPIFOLDER pFolder, ULONG flags)
{
  // flags can be CONVENIENT_DEPTH or 0
  // CONVENIENT_DEPTH will return all depths I believe instead
  // of just children
  HRESULT    hr;
  LPMAPITABLE  lpTable;
  hr = pFolder->GetHierarchyTable( flags, &lpTable);
  if (HR_FAILED(hr)) {
    m_lastError = hr;
    MAPI_TRACE2( "IterateHierarchy: GetContentsTable failed: 0x%lx, %d\n", (long)hr, (int)hr);
    return( FALSE);
  }

  ULONG rowCount;
  hr = lpTable->GetRowCount( 0, &rowCount);
  if (!rowCount) {
    lpTable->Release();
    return( TRUE);
  }

  hr = lpTable->SetColumns( (LPSPropTagArray)&ptaEid, 0);
  if (HR_FAILED(hr)) {
    m_lastError = hr;
    lpTable->Release();
    MAPI_TRACE2( "IterateHierarchy: SetColumns failed: 0x%lx, %d\n", (long)hr, (int)hr);
    return( FALSE);
  }

  hr = lpTable->SeekRow( BOOKMARK_BEGINNING, 0, NULL);
  if (HR_FAILED(hr)) {
    m_lastError = hr;
    lpTable->Release();
    MAPI_TRACE2( "IterateHierarchy: SeekRow failed: 0x%lx, %d\n", (long)hr, (int)hr);
    return( FALSE);
  }

  int      cNumRows = 0;
  LPSRowSet  lpRow;
  BOOL    keepGoing = TRUE;
  BOOL    bResult = TRUE;
  do {

    lpRow = NULL;
    hr = lpTable->QueryRows( 1, 0, &lpRow);

        if(HR_FAILED(hr)) {
      MAPI_TRACE2( "QueryRows failed: 0x%lx, %d\n", (long)hr, (int)hr);
      m_lastError = hr;
            bResult = FALSE;
      break;
    }

        if(lpRow) {
            cNumRows = lpRow->cRows;

        if (cNumRows) {
                LPENTRYID  lpEntry = (LPENTRYID) lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.lpb;
                ULONG    cb = lpRow->aRow[0].lpProps[ieidPR_ENTRYID].Value.bin.cb;
        ULONG    oType = lpRow->aRow[0].lpProps[ieidPR_OBJECT_TYPE].Value.ul;

        if (pIter)
          keepGoing = pIter->HandleHierarchyItem( oType, cb, lpEntry);
        else
          keepGoing = HandleHierarchyItem( oType, cb, lpEntry);

        }
      FreeProws( lpRow);
        }

  } while ( SUCCEEDED(hr) && cNumRows && lpRow && keepGoing);

  lpTable->Release();

  if (bResult && !keepGoing)
    bResult = FALSE;

  return( bResult);
}
Ejemplo n.º 4
0
HRESULT RunStoreValidation(char* strHost, char* strUser, char* strPass, char *strAltUser, bool bPublic, CHECKMAP checkmap)
{
	HRESULT hr = hrSuccess;
	LPMAPISESSION lpSession = NULL;
	LPMDB lpStore = NULL;
	LPMDB lpAltStore = NULL;
	LPMDB lpReadStore = NULL;
	LPMAPIFOLDER lpRootFolder = NULL;
	LPMAPITABLE lpHierarchyTable = NULL;
	LPSRowSet lpRows = NULL;
	ULONG ulObjectType;
	ULONG ulCount;
    LPEXCHANGEMANAGESTORE lpIEMS = NULL;
    // user
    ULONG			cbUserStoreEntryID = 0;
    LPENTRYID		lpUserStoreEntryID = NULL;
	wstring strwUsername;
	wstring strwAltUsername;
	wstring strwPassword;
	std::set<std::string> setFolderIgnore;
	LPSPropValue lpAddRenProp = NULL;
	ULONG cbEntryIDSrc = 0;
	LPENTRYID lpEntryIDSrc = NULL;
	ECLogger *const lpLogger = new ECLogger_File(EC_LOGLEVEL_FATAL, 0, "-");

	hr = MAPIInitialize(NULL);
	if (hr != hrSuccess) {
		cout << "Unable to initialize session" << endl;
		goto exit;
	}

	// input from commandline is current locale
	if (strUser)
		strwUsername = convert_to<wstring>(strUser);
	if (strPass)
		strwPassword = convert_to<wstring>(strPass);
	if (strAltUser)
		strwAltUsername = convert_to<wstring>(strAltUser);

	hr = HrOpenECSession(lpLogger, &lpSession, "zarafa-fsck", PROJECT_SVN_REV_STR, strwUsername.c_str(), strwPassword.c_str(), (const char *)strHost, 0, NULL, NULL);
	lpLogger->Release();
	if(hr != hrSuccess) {
		cout << "Wrong username or password." << endl;
		goto exit;
	}
	
	if (bPublic) {
		hr = HrOpenECPublicStore(lpSession, &lpStore);
		if (hr != hrSuccess) {
			cout << "Failed to open public store." << endl;
			goto exit;
		}
	} else {
		hr = HrOpenDefaultStore(lpSession, &lpStore);
		if (hr != hrSuccess) {
			cout << "Failed to open default store." << endl;
			goto exit;
		}
	}

	if (!strwAltUsername.empty()) {
        hr = lpStore->QueryInterface(IID_IExchangeManageStore, (void **)&lpIEMS);
        if (hr != hrSuccess) {
            cout << "Cannot open ExchangeManageStore object" << endl;
            goto exit;
        }

        hr = lpIEMS->CreateStoreEntryID(L"", (LPTSTR)strwAltUsername.c_str(), MAPI_UNICODE | OPENSTORE_HOME_LOGON, &cbUserStoreEntryID, &lpUserStoreEntryID);
        if (hr != hrSuccess) {
            cout << "Cannot get user store id for user" << endl;
            goto exit;
        }

        hr = lpSession->OpenMsgStore(0, cbUserStoreEntryID, lpUserStoreEntryID, NULL, MDB_WRITE | MDB_NO_DIALOG | MDB_NO_MAIL | MDB_TEMPORARY, &lpAltStore);
        if (hr != hrSuccess) {
            cout << "Cannot open user store of user" << endl;
            goto exit;
        }
        
        lpReadStore = lpAltStore;
	} else {
	    lpReadStore = lpStore;
    }

	hr = lpReadStore->OpenEntry(0, NULL, &IID_IMAPIFolder, 0, &ulObjectType, (IUnknown **)&lpRootFolder);
	if(hr != hrSuccess) {
		cout << "Failed to open root folder." << endl;
		goto exit;
	}

	if (HrGetOneProp(lpRootFolder, PR_IPM_OL2007_ENTRYIDS /*PR_ADDITIONAL_REN_ENTRYIDS_EX*/, &lpAddRenProp) == hrSuccess &&
		Util::ExtractSuggestedContactsEntryID(lpAddRenProp, &cbEntryIDSrc, &lpEntryIDSrc) == hrSuccess) {
		setFolderIgnore.insert(string((const char*)lpEntryIDSrc, cbEntryIDSrc));
	}

	hr = lpRootFolder->GetHierarchyTable(CONVENIENT_DEPTH, &lpHierarchyTable);
	if (hr != hrSuccess) {
		cout << "Failed to open hierarchy." << endl;
		goto exit;
	}

	/*
	 * Check if we have found at least *something*.
	 */
	hr = lpHierarchyTable->GetRowCount(0, &ulCount);
	if(hr != hrSuccess) {
		cout << "Failed to count number of rows." << endl;
		goto exit;
	} else if (!ulCount) {
		cout << "No entries inside Calendar." << endl;
		goto exit;
	}

	/*
	 * Loop through each row/entry and validate.
	 */
	while (true) {
		hr = lpHierarchyTable->QueryRows(20, 0, &lpRows);
		if (hr != hrSuccess)
			break;

		if (lpRows->cRows == 0)
			break;

		for (ULONG i = 0; i < lpRows->cRows; i++)
			RunFolderValidation(setFolderIgnore, lpRootFolder, &lpRows->aRow[i], checkmap);

		if (lpRows) {
			FreeProws(lpRows);
			lpRows = NULL;
		}
	}

exit:
    if (lpUserStoreEntryID)
        MAPIFreeBuffer(lpUserStoreEntryID);

    if (lpIEMS)
        lpIEMS->Release();
        
	if (lpRows) {
		FreeProws(lpRows);
		lpRows = NULL;
	}

	if (lpEntryIDSrc)
		MAPIFreeBuffer(lpEntryIDSrc);

	if (lpAddRenProp)
		MAPIFreeBuffer(lpAddRenProp);

	if(lpHierarchyTable)
		lpHierarchyTable->Release();

	if (lpRootFolder)
		lpRootFolder->Release();

    if (lpAltStore)
        lpAltStore->Release();

	if (lpStore)
		lpStore->Release();

	if (lpSession)
		lpSession->Release();

	MAPIUninitialize();

	return hr;
}
Ejemplo n.º 5
0
/**
 * Add new folders to the favorites folder
 *
 * @param lpSession Pointer to the current mapi session
 * @param lpFolder Pointer to a folder in the public store, except a folder from the favorites folder
 * @param lpAliasName Pointer to a string containing another name for the folder
 * @param ulFlags Bitmask of flags that controls how the folder is added. The following flags can be set:
 * FAVO_FOLDER_LEVEL_BASE
 *		Add only the folder itself
 * FAVO_FOLDER_LEVEL_ONE
 *		Add the folder and the immediate subfolders only
 * FAVO_FOLDER_LEVEL_SUB
 *		Add the folder and all subfolders
 * MAPI_UNICODE
 *		lpAliasName parameter is in wide or multibyte format
 */
HRESULT AddFavoriteFolder(LPMAPIFOLDER lpShortcutFolder, LPMAPIFOLDER lpFolder, LPCTSTR lpAliasName, ULONG ulFlags)
{
	HRESULT hr = hrSuccess;
	
	LPMAPITABLE lpTable = NULL;
	LPSPropValue lpsPropArray = NULL;
	LPSPropValue lpPropDepth = NULL; // No free needed

	SRowSet *lpRows = NULL;

	ULONG ulFolderFlags = 0;
	ULONG cValues = 0;

	SizedSPropTagArray(5, sPropsFolderInfo) = {5, { PR_DEPTH, PR_SOURCE_KEY, PR_PARENT_SOURCE_KEY, PR_DISPLAY_NAME, PR_CONTAINER_CLASS}};

// FIXME: check vaiables

	// Add folders to the shorcut folder
	hr = lpFolder->GetProps((LPSPropTagArray)&sPropsFolderInfo, 0, &cValues, &lpsPropArray);
	if (FAILED(hr) != hrSuccess) //Gives always a warning
		goto exit;

	hr = AddToFavorite(lpShortcutFolder, 1, lpAliasName, ulFlags, cValues, lpsPropArray);
	if (hr != hrSuccess)
		goto exit;

	if (lpsPropArray) { MAPIFreeBuffer(lpsPropArray); lpsPropArray = NULL; }


	if (ulFlags == FAVO_FOLDER_LEVEL_SUB) {
		ulFolderFlags = CONVENIENT_DEPTH;
	} else if(ulFlags == FAVO_FOLDER_LEVEL_ONE) {
		ulFolderFlags = 0;
	}else {
		hr = hrSuccess; // Done
		goto exit;
	}

	// Get subfolders
	hr = lpFolder->GetHierarchyTable(ulFolderFlags, &lpTable);
	if (hr != hrSuccess)
		goto exit;

	hr = lpTable->SetColumns((LPSPropTagArray)&sPropsFolderInfo, 0);
	if (hr != hrSuccess)
		goto exit;

	// Add the favorite recusive depended what the flags are
	while(true)
	{
		hr = lpTable->QueryRows (1, 0, &lpRows);
		if (hr != hrSuccess)
			goto exit;

		if (lpRows->cRows == 0)
			break;

		lpPropDepth = PpropFindProp(lpRows->aRow[0].lpProps,lpRows->aRow[0].cValues, PR_DEPTH);
		if (lpPropDepth == NULL) {
			hr = MAPI_E_CORRUPT_DATA;// Break the action
			goto exit;
		}

		hr = AddToFavorite(lpShortcutFolder, lpPropDepth->Value.ul + 1, NULL, 0, lpRows->aRow[0].cValues, lpRows->aRow[0].lpProps);
		if (hr != hrSuccess) {
			// Break the action
			goto exit;
		}

		FreeProws(lpRows);
		lpRows = NULL;

	} //while(true)

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

	if (lpRows)
		FreeProws(lpRows);

	if (lpsPropArray)
		MAPIFreeBuffer(lpsPropArray);


	return hr;
}