Exemplo n.º 1
0
//$--HrMAPISetAddressList--------------------------------------------------------
//  Set an address list.
// -----------------------------------------------------------------------------
HRESULT HrMAPISetAddressList(                // RETURNS: return code
    IN ULONG iEntry,                        // index of address list entry
    IN ULONG cProps,                        // count of values in address list
                                            // entry
    IN LPSPropValue lpPropValues,           // pointer to address list entry
    IN OUT LPADRLIST lpAdrList)             // pointer to address list pointer
{
    HRESULT         hr              = NOERROR;
    SCODE           sc              = 0;
    LPSPropValue    lpNewPropValues = NULL;
    ULONG           cBytes          = 0;

    DEBUGPUBLIC("HrMAPISetAddressList()\n");

    hr = CHK_HrMAPISetAddressList(
        iEntry,
        cProps,
        lpPropValues,
        lpAdrList);

    if(FAILED(hr))
        RETURN(hr);

    if(iEntry >= lpAdrList->cEntries)
    {
        hr = HR_LOG(E_FAIL);
        goto cleanup;
    }

    sc = ScDupPropset(
        cProps,
        lpPropValues,
		MAPIAllocateBuffer,
		&lpNewPropValues);

    if(FAILED(sc))
    {
        hr = HR_LOG(E_FAIL);
        goto cleanup;
    }

    if(lpAdrList->aEntries[iEntry].rgPropVals != NULL)
    {
        MAPIFREEBUFFER(lpAdrList->aEntries[iEntry].rgPropVals);
    }

    lpAdrList->aEntries[iEntry].cValues = cProps;
    lpAdrList->aEntries[iEntry].rgPropVals = lpNewPropValues;

cleanup:

    RETURN(hr);
}
Exemplo n.º 2
0
//$--HrMAPIAppendSPropValues-----------------------------------------------------
//  Append one set of SPropValue's to another.
// -----------------------------------------------------------------------------
HRESULT HrMAPIAppendSPropValues(         // RETURNS: return code
    IN ULONG cHeadProps,                // count of property values in head
    IN LPSPropValue lpHeadProps,        // pointer to property values in
                                        // head
    IN ULONG cTailProps,                // count of property values in tail
    IN LPSPropValue lpTailProps,        // pointer to property values in
                                        // tail
    OUT ULONG *lpcNewProps,             // pointer to count of property
                                        // values
    OUT LPSPropValue *lppNewProps)      // pointer to property values 
{
    HRESULT         hr                  = NOERROR;
    SCODE           sc                  = 0;
    ULONG           cNewProps           = 0;
    LPSPropValue    lpTmpProps          = NULL;
    LPSPropValue    lpNewProps          = NULL;
    ULONG           cBytes              = 0;
    ULONG           i                   = 0;
    ULONG           j                   = 0;

    DEBUGPUBLIC("HrMAPIAppendSPropValues()\n");

    hr = CHK_HrMAPIAppendSPropValues(
        cHeadProps,
        lpHeadProps,
        cTailProps,
        lpTailProps,
        lpcNewProps,
        lppNewProps);

    if(FAILED(hr))
        RETURN(hr);

    *lpcNewProps = 0;
    *lppNewProps = NULL;

    cNewProps = cHeadProps + cTailProps;

    cBytes = CbSPropValue(cNewProps);

    sc = MAPIAllocateBuffer(cBytes, (void **)&lpTmpProps);

    if(FAILED(sc))                           
    {                                                   
        hr = HR_LOG(E_OUTOFMEMORY);                                 
        goto cleanup;
    }                                                   

    // Copy existing property values
    for(i = 0; i < cHeadProps; i++)
    {
        lpTmpProps[i] = lpHeadProps[i];
    }

    for(i = cHeadProps, j = 0; i < cNewProps; i++, j++)
    {
        lpTmpProps[i] = lpTailProps[j];
    }

    sc = ScDupPropset(
        cNewProps,
        lpTmpProps,
		MAPIAllocateBuffer,
		&lpNewProps);

    if(FAILED(sc))
    {
        hr = HR_LOG(E_FAIL);
        goto cleanup;
    }

    *lpcNewProps = cNewProps;
    *lppNewProps = lpNewProps;

cleanup:

    MAPIFREEBUFFER(lpTmpProps);

    RETURN(hr);
}
Exemplo n.º 3
0
_Check_return_ HRESULT SearchContentsTableForName(
	_In_ LPMAPITABLE pTable,
	_In_z_ LPCTSTR szName,
	ULONG PropTagToCompare,
	_Deref_out_opt_ LPSPropValue *lppPropsFound)
{
	HRESULT			hRes = S_OK;

	LPSRowSet		pRows = NULL;

	enum
	{
		abPR_ENTRYID,
		abPR_DISPLAY_NAME,
		abPR_RECIPIENT_TYPE,
		abPR_ADDRTYPE,
		abPR_DISPLAY_TYPE,
		abPropTagToCompare,
		abNUM_COLS
	};

	const SizedSPropTagArray(abNUM_COLS, abCols) =
	{
		abNUM_COLS,
		PR_ENTRYID,
		PR_DISPLAY_NAME,
		PR_RECIPIENT_TYPE,
		PR_ADDRTYPE,
		PR_DISPLAY_TYPE,
		PropTagToCompare
	};

	*lppPropsFound = NULL;
	if (!pTable || !szName) return MAPI_E_INVALID_PARAMETER;

	DebugPrint(DBGGeneric, _T("SearchContentsTableForName: Looking for \"%s\"\n"), szName);

	// Set a restriction so we only find close matches
	LPSRestriction	lpSRes = NULL;

	EC_H(CreateANRRestriction(
		PR_ANR,
		szName,
		NULL,
		&lpSRes));

	EC_MAPI(pTable->SetColumns((LPSPropTagArray)&abCols, TBL_BATCH));

	// Jump to the top of the table...
	EC_MAPI(pTable->SeekRow(
		BOOKMARK_BEGINNING,
		0,
		NULL));

	// ..and jump to the first matching entry in the table
	EC_MAPI(pTable->Restrict(
		lpSRes,
		NULL
		));

	// Now we iterate through each of the matching entries
	if (!FAILED(hRes)) for (;;)
	{
		hRes = S_OK;
		if (pRows) FreeProws(pRows);
		pRows = NULL;
		EC_MAPI(pTable->QueryRows(
			1,
			NULL,
			&pRows));
		if (FAILED(hRes) || !pRows || (pRows && !pRows->cRows)) break;

		// An error at this point is an error with the current entry, so we can continue this for statement
		// Unless it's an allocation error. Those are bad.
		if (PropTagToCompare == pRows->aRow->lpProps[abPropTagToCompare].ulPropTag &&
			CheckStringProp(&pRows->aRow->lpProps[abPropTagToCompare], PT_TSTRING))
		{
			DebugPrint(DBGGeneric, _T("SearchContentsTableForName: found \"%s\"\n"), pRows->aRow->lpProps[abPropTagToCompare].Value.LPSZ);
			if (lstrcmpi(szName, pRows->aRow->lpProps[abPropTagToCompare].Value.LPSZ) == 0)
			{
				DebugPrint(DBGGeneric, _T("SearchContentsTableForName: This is an exact match!\n"));
				// We found a match! Return it!
				EC_MAPI(ScDupPropset(
					abNUM_COLS,
					pRows->aRow->lpProps,
					MAPIAllocateBuffer,
					lppPropsFound));
				break;
			}
		}
	}

	if (!*lppPropsFound)
	{
		DebugPrint(DBGGeneric, _T("SearchContentsTableForName: No exact match found.\n"));
	}
	MAPIFreeBuffer(lpSRes);
	if (pRows) FreeProws(pRows);
	return hRes;
} // SearchContentsTableForName
Exemplo n.º 4
0
//$--HrMAPIAppendAddressList-----------------------------------------------------
//  Append to an address list.
// -----------------------------------------------------------------------------
HRESULT HrMAPIAppendAddressList(             // RETURNS: return code
    IN ULONG cProps,                        // count of values in address list
                                            // entry
    IN LPSPropValue lpPropValues,           // pointer to address list entry
    IN OUT LPADRLIST *lppAdrList)           // pointer to address list pointer
{
    HRESULT         hr              = NOERROR;
    SCODE           sc              = 0;
    LPADRLIST       lpAdrList       = NULL;
    LPADRENTRY      lpAdrEntry      = NULL;
    LPSPropValue    lpNewPropValues = NULL;
    ULONG           i               = 0;
    ULONG           cBytes          = 0;
    ULONG           cEntries        = 0;

    DEBUGPUBLIC("HrMAPIAppendAddressList()\n");

    hr = CHK_HrMAPIAppendAddressList(
        cProps,
        lpPropValues,
        lppAdrList);

    if(FAILED(hr))
        RETURN(hr);

    sc = ScDupPropset(
        cProps,
        lpPropValues,
		MAPIAllocateBuffer,
		&lpNewPropValues);

    if(FAILED(sc))
    {
        hr = HR_LOG(E_FAIL);
        goto cleanup;
    }

    cEntries = ((*lppAdrList)->cEntries + 1);

    cBytes = CbNewADRLIST(cEntries);

    sc = MAPIAllocateBuffer(cBytes, (void **)&lpAdrList);

    if(FAILED(sc))                           
    {                                                   
        hr = HR_LOG(E_OUTOFMEMORY);                                 
        goto cleanup;
    }                                                   

    // Initialize ADRLIST
    ZeroMemory(lpAdrList, cBytes);

    lpAdrEntry = lpAdrList->aEntries;

    // Copy old ADRENTRY values to array
    for(i = 0; i < (*lppAdrList)->cEntries; i++)
    {
        lpAdrEntry[i].cValues =
            (*lppAdrList)->aEntries[i].cValues;
        lpAdrEntry[i].rgPropVals =
            (*lppAdrList)->aEntries[i].rgPropVals;
    }

    // Copy new ADRENTRY values to array
    lpAdrEntry[i].cValues = cProps;
    lpAdrEntry[i].rgPropVals = lpNewPropValues;

    lpAdrList->cEntries = (*lppAdrList)->cEntries + 1;

    MAPIFREEBUFFER(*lppAdrList);

    *lppAdrList = lpAdrList;

cleanup:

    if(FAILED(hr))
    {
        MAPIFREEBUFFER(lpNewPropValues);
    }

    RETURN(hr);
}
Exemplo n.º 5
0
//$--HrMAPICreateAddressList-----------------------------------------------------
//  Create an address list.
// -----------------------------------------------------------------------------
HRESULT HrMAPICreateAddressList(             // RETURNS: return code
    IN ULONG cProps,                        // count of values in address list
                                            // entry
    IN LPSPropValue lpPropValues,           // pointer to address list entry
    OUT LPADRLIST *lppAdrList)              // pointer to address list pointer
{
    HRESULT         hr              = NOERROR;
    SCODE           sc              = 0;
    LPSPropValue    lpNewPropValues = NULL;
    ULONG           cBytes          = 0;

    DEBUGPUBLIC("HrMAPICreateAddressList()\n");

    hr = CHK_HrMAPICreateAddressList(
        cProps,
        lpPropValues,
        lppAdrList);

    if(FAILED(hr))
        RETURN(hr);

    *lppAdrList = NULL;

    sc = ScDupPropset(
        cProps,
        lpPropValues,
		MAPIAllocateBuffer,
		&lpNewPropValues);

    if(FAILED(sc))
    {
        hr = HR_LOG(E_FAIL);
        goto cleanup;
    }

    cBytes = CbNewADRLIST(1);

    sc = MAPIAllocateBuffer(cBytes, (LPVOID*)lppAdrList);

    if(FAILED(sc))                           
    {                                                   
        hr = HR_LOG(E_OUTOFMEMORY);                                 
        goto cleanup;
    }                                                   

    // Initialize ADRLIST structure
    ZeroMemory(*lppAdrList, cBytes);

    (*lppAdrList)->cEntries = 1;
    (*lppAdrList)->aEntries[0].cValues = cProps;
    (*lppAdrList)->aEntries[0].rgPropVals = lpNewPropValues;

cleanup:

    if(FAILED(hr))
    {
        if(lppAdrList != NULL)
        {
            MAPIFREEBUFFER(*lppAdrList);
            *lppAdrList = NULL;
        }
        MAPIFREEBUFFER(lpNewPropValues);
    }

    RETURN(hr);
}