Example #1
0
/**
 * Delete the messages that are queued for deletion.
 * @return HRESULT
 */
HRESULT Deleter::PurgeQueuedMessages()
{
	HRESULT hr = hrSuccess;
	EntryListPtr ptrEntryList;
	list<entryid_t>::const_iterator iEntryId;
	ULONG ulIdx = 0;
	
	if (m_lstEntryIds.empty())
		goto exit;
	
	hr = MAPIAllocateBuffer(sizeof(ENTRYLIST), &ptrEntryList);
	if (hr != hrSuccess)
		goto exit;
	
	hr = MAPIAllocateMore(m_lstEntryIds.size() * sizeof(SBinary), ptrEntryList, (LPVOID*)&ptrEntryList->lpbin);
	if (hr != hrSuccess)
		goto exit;
		
	ptrEntryList->cValues = m_lstEntryIds.size();
	for (iEntryId = m_lstEntryIds.begin(); iEntryId != m_lstEntryIds.end(); ++iEntryId, ++ulIdx) {
		ptrEntryList->lpbin[ulIdx].cb = iEntryId->size();
		ptrEntryList->lpbin[ulIdx].lpb = *iEntryId;
	}
	
	hr = CurrentFolder()->DeleteMessages(ptrEntryList, 0, NULL, 0);
	if (hr != hrSuccess) {
		Logger()->Log(EC_LOGLEVEL_FATAL, "Failed to delete %u messages. (hr=%s)", ptrEntryList->cValues, stringify(hr, true).c_str());
		goto exit;
	}
	
	m_lstEntryIds.clear();
	
exit:
	return hr;
}
Example #2
0
void CAclDlg::OnAddItem()
{
    HRESULT			hRes = S_OK;

    CEditor MyData(
        this,
        IDS_ACLADDITEM,
        IDS_ACLADDITEMPROMPT,
        2,
        CEDITOR_BUTTON_OK|CEDITOR_BUTTON_CANCEL);
    MyData.SetPromptPostFix(AllFlagsToString(PROP_ID(PR_MEMBER_RIGHTS),true));
    MyData.InitPane(0, CreateSingleLinePane(IDS_USEREID, NULL, false));
    MyData.InitPane(1, CreateSingleLinePane(IDS_MASKINHEX, NULL, false));
    MyData.SetHex(1,0);

    WC_H(MyData.DisplayDialog());
    if (S_OK != hRes)
    {
        DebugPrint(DBGGeneric,_T("OnAddItem cancelled.\n"));
        return;
    }

    LPROWLIST lpNewItem = NULL;

    EC_H(MAPIAllocateBuffer(CbNewROWLIST(1),(LPVOID*) &lpNewItem));

    if (lpNewItem)
    {
        lpNewItem->cEntries = 1;
        lpNewItem->aEntries[0].ulRowFlags = ROW_ADD;
        lpNewItem->aEntries[0].cValues = 2;
        lpNewItem->aEntries[0].rgPropVals = 0;

        EC_H(MAPIAllocateMore(2 * sizeof(SPropValue), lpNewItem, (LPVOID*)&lpNewItem->aEntries[0].rgPropVals));

        if (lpNewItem->aEntries[0].rgPropVals)
        {
            LPENTRYID lpEntryID = NULL;
            size_t cbBin = 0;
            EC_H(MyData.GetEntryID(0, false, &cbBin, &lpEntryID));

            lpNewItem->aEntries[0].rgPropVals[0].ulPropTag = PR_MEMBER_ENTRYID;
            lpNewItem->aEntries[0].rgPropVals[0].Value.bin.cb = (ULONG)cbBin;
            lpNewItem->aEntries[0].rgPropVals[0].Value.bin.lpb = (LPBYTE)lpEntryID;
            lpNewItem->aEntries[0].rgPropVals[1].ulPropTag = PR_MEMBER_RIGHTS;
            lpNewItem->aEntries[0].rgPropVals[1].Value.ul = MyData.GetHex(1);

            EC_MAPI(m_lpExchTbl->ModifyTable(
                        m_ulTableFlags,
                        lpNewItem));
            MAPIFreeBuffer(lpNewItem);
            if (S_OK == hRes)
                OnRefreshView();

            delete[] lpEntryID;
        }
    }
} // CAclDlg::OnAddItem
Example #3
0
BOOL AllocMVBuffer(PyObject *seq, size_t itemSize, void *pAllocMoreLinkBlock, void **pbuf, ULONG *pLen)
{
    if (!PySequence_Check(seq))
        return FALSE;
    *pLen = PySequence_Length(seq);
    int bufSize = *pLen * itemSize;
    HRESULT hr = MAPIAllocateMore(bufSize, pAllocMoreLinkBlock, (void **)pbuf);
    if (S_OK!=hr) {
        OleSetOleError(hr);
        return FALSE;
    }
    return TRUE;
}
Example #4
0
/**
 * Generates new UID and sets it in SpropValue structure
 *
 * @param[in]	ulNamedTag		Property tag to set in returned property
 * @param[in]	base			base for allocating memory, can be NULL and returned *lppPropVal must be freed using MAPIFreeBuffer
 * @param[out]	lppPropVal		returned SpropValue structure
 * @return		MAPI error code
 */
HRESULT HrCreateGlobalID(ULONG ulNamedTag, void *base, LPSPropValue *lppPropVal)
{
	HRESULT hr = hrSuccess;
	LPSPropValue lpPropVal = NULL;
	std::string strUid, strBinUid;

	if (base) {
		hr = MAPIAllocateMore(sizeof(SPropValue), base, (void**)&lpPropVal);
	} else {
		hr = MAPIAllocateBuffer(sizeof(SPropValue), (void**)&lpPropVal);
		base = lpPropVal;
	}
	if (hr != hrSuccess)
		goto exit;

	lpPropVal->ulPropTag = ulNamedTag;

	hr = HrGenerateUid(&strUid);
	if (hr != hrSuccess)
		goto exit;

	strBinUid = hex2bin(strUid);

	lpPropVal->Value.bin.cb = strBinUid.length();

	hr = MAPIAllocateMore(lpPropVal->Value.bin.cb, base, (void**)&lpPropVal->Value.bin.lpb);
	if (hr != hrSuccess)
		goto exit;

	memcpy(lpPropVal->Value.bin.lpb, strBinUid.data(), lpPropVal->Value.bin.cb);

	*lppPropVal = lpPropVal;

exit:
	if (hr != hrSuccess && lpPropVal)
		MAPIFreeBuffer(lpPropVal);

	return hr;
}
Example #5
0
// @object PySNotRestriction|
BOOL PyMAPIObject_AsSNotRestriction(PyObject *ob, SNotRestriction *pRest, void *pAllocMoreLinkBlock)
{
    PyObject *subOb;
    pRest->ulReserved = 0;
    // @pyparm <o PySRestriction>|restriction||
    // @pyparm int|reserved|0|
    if (!PyArg_ParseTuple(ob, "O|l:SNotRestriction tuple", &subOb, &pRest->ulReserved))
        return FALSE;

    HRESULT hr;
    if (FAILED((hr=MAPIAllocateMore(sizeof(SRestriction), pAllocMoreLinkBlock, (void **)&pRest->lpRes)))) {
        OleSetOleError(hr);
        return FALSE;
    }
    return PyMAPIObject_AsSingleSRestriction(subOb, pRest->lpRes, pAllocMoreLinkBlock);
}
Example #6
0
// @object PySContentRestriction|
BOOL PyMAPIObject_AsSContentRestriction(PyObject *ob, SContentRestriction *pRest, void *pAllocMoreLinkBlock)
{
    // @pyparm int|fuzzyLevel||
    // @pyparm int|propTag||The property ID.
    // @pyparm <o PySPropValue>|propertyValue||
    PyObject *subOb;
    if (!PyArg_ParseTuple(ob, "llO:SContentRestriction tuple", &pRest->ulFuzzyLevel, &pRest->ulPropTag, &subOb))
        return FALSE;
    HRESULT hr;
    if (FAILED((hr=MAPIAllocateMore(sizeof(SPropValue), pAllocMoreLinkBlock, (void **)&pRest->lpProp)))) {
        OleSetOleError(hr);
        return FALSE;
    }
    return PyMAPIObject_AsSPropValue(subOb, pRest->lpProp, pAllocMoreLinkBlock);

}
Example #7
0
// @object PySAndRestriction|
BOOL PyMAPIObject_AsSAndRestriction(PyObject *ob, SAndRestriction *pRest, void *pAllocMoreLinkBlock)
{
    // @pyparm [<o PySRestriction>, ...]|restriction||A sequence of <o PySRestriction> objects.
    pRest->cRes = PySequence_Length(ob);
    if (pRest->cRes==(ULONG)-1 && PyErr_Occurred())
        return FALSE;

    HRESULT hr;
    BOOL ok = !FAILED((hr=MAPIAllocateMore(sizeof(SRestriction) * pRest->cRes, pAllocMoreLinkBlock, (void **)&pRest->lpRes)));
    if (!ok) {
        OleSetOleError(hr);
        return FALSE;
    }
    for (ULONG i=0; ok && i<pRest->cRes; i++) {
        // Each object is a restriction structure.
        PyObject *subOb = PySequence_GetItem(ob, i);
        ok = (subOb != NULL);
        ok = ok && PyMAPIObject_AsSingleSRestriction(subOb, pRest->lpRes+i, pAllocMoreLinkBlock);
        Py_XDECREF(subOb);
    }
    return ok;
}
Example #8
0
_Check_return_ HRESULT CRulesDlg::GetSelectedItems(ULONG ulFlags, ULONG ulRowFlags, _In_ LPROWLIST* lppRowList)
{
	if (!lppRowList || !m_lpContentsTableListCtrl) return MAPI_E_INVALID_PARAMETER;
	*lppRowList = NULL;
	HRESULT hRes = S_OK;
	int iNumItems = m_lpContentsTableListCtrl->GetSelectedCount();

	if (!iNumItems) return S_OK;
	if (iNumItems > MAXNewROWLIST) return MAPI_E_INVALID_PARAMETER;

	LPROWLIST lpTempList = NULL;

	EC_H(MAPIAllocateBuffer(CbNewROWLIST(iNumItems),(LPVOID*) &lpTempList));

	if (lpTempList)
	{
		lpTempList->cEntries = iNumItems;
		int iArrayPos = 0;
		int iSelectedItem = -1;

		for (iArrayPos = 0 ; iArrayPos < iNumItems ; iArrayPos++)
		{
			lpTempList->aEntries[iArrayPos].ulRowFlags = ulRowFlags;
			lpTempList->aEntries[iArrayPos].cValues = 0;
			lpTempList->aEntries[iArrayPos].rgPropVals = 0;
			iSelectedItem = m_lpContentsTableListCtrl->GetNextItem(
				iSelectedItem,
				LVNI_SELECTED);
			if (-1 != iSelectedItem)
			{
				SortListData* lpData = (SortListData*) m_lpContentsTableListCtrl->GetItemData(iSelectedItem);
				if (lpData)
				{
					if (ulFlags & RULE_INCLUDE_ID && ulFlags & RULE_INCLUDE_OTHER)
					{
						EC_H(MAPIAllocateMore(
							lpData->cSourceProps * sizeof(SPropValue),
							lpTempList,
							(LPVOID*) &lpTempList->aEntries[iArrayPos].rgPropVals));
						if (SUCCEEDED(hRes) && lpTempList->aEntries[iArrayPos].rgPropVals)
						{
							ULONG ulSrc = 0;
							ULONG ulDst = 0;
							for (ulSrc = 0; ulSrc < lpData->cSourceProps; ulSrc++)
							{
								if (lpData->lpSourceProps[ulSrc].ulPropTag == PR_RULE_PROVIDER_DATA)
								{
									if (!lpData->lpSourceProps[ulSrc].Value.bin.cb ||
										!lpData->lpSourceProps[ulSrc].Value.bin.lpb)
									{
										// PR_RULE_PROVIDER_DATA was NULL - we don't want this
										continue;
									}
								}

								EC_H(MyPropCopyMore(
									&lpTempList->aEntries[iArrayPos].rgPropVals[ulDst],
									&lpData->lpSourceProps[ulSrc],
									MAPIAllocateMore,
									lpTempList));
								ulDst++;
							}
							lpTempList->aEntries[iArrayPos].cValues = ulDst;
						}
					}
					else if (ulFlags & RULE_INCLUDE_ID)
					{
						lpTempList->aEntries[iArrayPos].cValues = 1;
						lpTempList->aEntries[iArrayPos].rgPropVals = PpropFindProp(
							lpData->lpSourceProps,
							lpData->cSourceProps,
							PR_RULE_ID);
					}
				}
			}
		}
	}

	*lppRowList = lpTempList;
	return hRes;
} // CRulesDlg::GetSelectedItems
Example #9
0
// @object PyMAPINAMEIDArray|A sequence (<o PyIID>, string/int) objects
BOOL PyMAPIObject_AsMAPINAMEIDArray(PyObject *ob, MAPINAMEID ***pppNameId, ULONG *pNumIds, BOOL bNoneOK /*= FALSE*/ )
{
    if (bNoneOK && ob==Py_None) {
        *pppNameId = NULL;
        *pNumIds = 0;
        return TRUE;
    }
    PyErr_Clear();
    ULONG len = (ULONG)PySequence_Length(ob);
    if (PyErr_Occurred()) {
        PyErr_Clear();
        PyErr_SetString(PyExc_TypeError, "MAPINAMEID array list be a sequence of tuples");
        return FALSE;
    }
    MAPINAMEID **ppNew = NULL;
    MAPINAMEID *prgIds = NULL;
    IID *pIIDs = NULL;
    HRESULT hr = MAPIAllocateBuffer(len * sizeof(MAPINAMEID *), (void **)&ppNew);
    if (SUCCEEDED(hr)) hr = MAPIAllocateMore(len * sizeof(MAPINAMEID), ppNew, (void **)&prgIds);
    if (SUCCEEDED(hr)) hr = MAPIAllocateMore(len * sizeof(IID), ppNew, (void **)&pIIDs);
    if (FAILED(hr)) {
        MAPIFreeBuffer(ppNew);
        OleSetOleError(hr);
        return FALSE;
    }
    for (ULONG i=0; i<len; i++) {
        ppNew[i] = prgIds+i;
        MAPINAMEID *pNew = prgIds+i;
        PyObject *obIID, *obPropId;
        PyObject *pMe = PySequence_GetItem(ob, i);
        if (pMe==NULL) {
            goto loop_error;
        }
        if (!PyArg_ParseTuple(pMe, "OO", &obIID, &obPropId )) {
            PyErr_Clear();
            PyErr_SetString(PyExc_TypeError, "MAPINAMEIDArray must be a sequence of (iid, string/int) tuples");
            goto loop_error;
        }

        pNew->lpguid = pIIDs+i;
        BSTR bstrVal;
        if (!PyWinObject_AsIID(obIID, pIIDs+i))
            goto loop_error;
        if (PyInt_Check(obPropId)) {
            pNew->ulKind = MNID_ID;
            pNew->Kind.lID = PyInt_AsLong(obPropId);
        } else if (PyWinObject_AsBstr(obPropId, &bstrVal)) {
            // Make a copy of the string
            pNew->ulKind = MNID_STRING;
            DWORD strLen = SysStringLen(bstrVal);
            hr = MAPIAllocateMore(sizeof(WCHAR) * (strLen+1), ppNew, (void **)&pNew->Kind.lpwstrName);
            if (FAILED(hr)) {
                PyWinObject_FreeBstr(bstrVal);
                OleSetOleError(hr);
                goto loop_error;
            }
            wcsncpy(pNew->Kind.lpwstrName, bstrVal, strLen+1);
            PyWinObject_FreeBstr(bstrVal);
        } else {
            PyErr_SetString(PyExc_TypeError, "The type of property ID is invalid - must be string/unicode or int");
            goto loop_error;
        }
        Py_DECREF(pMe);
        continue;
loop_error:
        Py_XDECREF(pMe);
        MAPIFreeBuffer(ppNew);
        return NULL;
    }
    *pppNameId = ppNew;
    *pNumIds = len;
    return TRUE;
}
Example #10
0
// @object PySPropValue|A MAPI property value.  Property values can either be passed from
// python into MAPI functions, or returned from MAPI functions to Python.
BOOL PyMAPIObject_AsSPropValue(PyObject *Valob, SPropValue *pv, void *pAllocMoreLinkBlock)
{
    PyObject *ob;
    // @pyparm int|propType||The type of the MAPI property
    // @pyparm object|value||The property value
    if (!PyArg_ParseTuple(Valob, "lO:SPropValue item", &pv->ulPropTag, &ob )) {
        PyErr_Clear();
        PyErr_SetString(PyExc_TypeError, "An SPropValue item must be a tuple of (integer, object)");
        return NULL;
    }
    BOOL ok = TRUE;
    unsigned int i;
    PyErr_Clear();
    // @comm The parameters can be one of the following pairs of values.
    // @flagh propType|value
    switch (PROP_TYPE(pv->ulPropTag)) {
    // @flag PT_I2|An integer
    case PT_I2:	//		case PT_SHORT:
        pv->Value.i = (int)PyInt_AsLong(ob);
        break;
    // @flag PT_MV_I2|A sequence of integers
    case PT_MV_I2:
        MAKE_MV(short int, pAllocMoreLinkBlock, pv->Value.MVi.lpi, pv->Value.MVi.cValues, PyInt_AsLong)
    // @flag PT_I4|An integer
    case PT_I4: //		case PT_LONG:
        pv->Value.l = PyInt_AsLong(ob);
        break;
    // @flag PT_MV_I4|A sequence of integers
    case PT_MV_I4:
        MAKE_MV(long, pAllocMoreLinkBlock, pv->Value.MVl.lpl, pv->Value.MVl.cValues, PyInt_AsLong)
    // @flag PT_R4|A float
    case PT_R4: //		case PT_FLOAT:
        pv->Value.flt = (float)PyFloat_AsDouble(ob);
        break;
    // @flag PT_MV_R4|A sequence of floats
    case PT_MV_R4:
        MAKE_MV(float, pAllocMoreLinkBlock, pv->Value.MVflt.lpflt, pv->Value.MVflt.cValues, PyFloat_AsDouble)
    // @flag PT_R8|A float
    case PT_R8: //		case PT_DOUBLE:
        pv->Value.dbl = PyFloat_AsDouble(ob);
        break;
    // @flag PT_MV_R8|A sequence of floats
    case PT_MV_R8:
        MAKE_MV(double, pAllocMoreLinkBlock, pv->Value.MVdbl.lpdbl, pv->Value.MVdbl.cValues, PyFloat_AsDouble)
    // @flag PT_BOOLEAN|A boolean value (or an int)
    case PT_BOOLEAN:
        pv->Value.b = PyInt_AsLong(ob) ? VARIANT_TRUE : VARIANT_FALSE;
        break;

    /*
    		case PT_CURRENCY:
    			p->Value.cur ??
    			break;

    */
    // @flag PT_APPTIME|A <o PyTime> object
    case PT_APPTIME :
        ok = PyWinObject_AsDATE(ob, &pv->Value.at);
        break;

    // @flag PT_MV_APPTIME|An sequence of <o PyTime> object
    case PT_MV_APPTIME:
        MAKEB_MV(double, pAllocMoreLinkBlock, pv->Value.MVat.lpat, pv->Value.MVat.cValues, PyWinObject_AsDATE)

    // @flag PT_SYSTIME|A <o PyTime> object
    case PT_SYSTIME:
        ok = PyWinObject_AsFILETIME(ob, &pv->Value.ft);
        break;

    // @flag PT_MV_APPTIME|An sequence of <o PyTime> object
    case PT_MV_SYSTIME:
        MAKEB_MV(FILETIME, pAllocMoreLinkBlock, pv->Value.MVft.lpft, pv->Value.MVft.cValues, PyWinObject_AsFILETIME)

    // @flag PT_STRING8|A string or <o PyUnicode>
    case PT_STRING8:
    {   // Copy into new MAPI memory block
        DWORD bufLen;
        char *str;
        ok = PyWinObject_AsString(ob, &str, FALSE, &bufLen);
        if (ok) {
            bufLen++;
            HRESULT hr = MAPIAllocateMore(bufLen, pAllocMoreLinkBlock, (void **)&pv->Value.lpszA);
            if (S_OK!=hr) {
                OleSetOleError(hr);
                ok = FALSE;
            } else {
                memcpy(pv->Value.lpszA, str, bufLen-sizeof(char));
                // Null terminate
                memcpy(((char *)pv->Value.lpszA)+(bufLen-sizeof(char)),"\0", sizeof(char));
            }
        }
        PyWinObject_FreeString(str);
        break;
    }

    // @flag PT_STRING8|A sequence of string or <o PyUnicode> objects.
    case PT_MV_STRING8:
        ok = AllocMVBuffer( ob, sizeof(char *), pAllocMoreLinkBlock, (void **)&pv->Value.MVszA.lppszA, &pv->Value.MVszA.cValues);
        if (!ok) break;
        for (i=0; ok && !PyErr_Occurred() && i<pv->Value.MVszA.cValues; i++) {
            PyObject *obmv=PySequence_GetItem(ob,i);
            if (obmv==NULL) break;

            DWORD bufLen;
            char *str;
            ok = PyWinObject_AsString(obmv, &str, FALSE, &bufLen);
            if (ok) {
                bufLen++;
                HRESULT hr = MAPIAllocateMore(bufLen, pAllocMoreLinkBlock, (void **)&pv->Value.MVszA.lppszA[i]);
                if (S_OK!=hr) {
                    OleSetOleError(hr);
                    ok = FALSE;
                } else {
                    memcpy(pv->Value.MVszA.lppszA[i], str, bufLen-sizeof(char));
                    // Null terminate
                    memcpy(((char *)pv->Value.MVszA.lppszA[i])+(bufLen-sizeof(char)),"\0", sizeof(char));
                }
            }
            PyWinObject_FreeString(str);
            Py_DECREF(obmv);
        }
        break;

    // @flag PT_UNICODE|A string or <o PyUnicode>
    case PT_UNICODE:
    {   // Bit of a hack - need to copy into MAPI block.
        BSTR wstr = NULL;
        ok = PyWinObject_AsBstr(ob, &wstr, FALSE);
        if (ok) {
            DWORD bufSize = sizeof(WCHAR) * (SysStringLen(wstr)+1);
            HRESULT hr = MAPIAllocateMore(bufSize, pAllocMoreLinkBlock, (void **)&pv->Value.lpszW);
            if (S_OK!=hr) {
                OleSetOleError(hr);
                ok = FALSE;
            } else {
                memcpy(pv->Value.lpszW, wstr, bufSize-2);
                // Null terminate
                memcpy(((char *)pv->Value.lpszW)+(bufSize-2),"\0\0", 2);
            }
        }
        SysFreeString(wstr);
        break;
    }

    // @flag PT_MV_UNICODE|A sequence of string or <o PyUnicode>
    case PT_MV_UNICODE:
        ok = AllocMVBuffer( ob, sizeof(char *), pAllocMoreLinkBlock, (void **)&pv->Value.MVszW.lppszW, &pv->Value.MVszW.cValues);
        if (!ok) break;
        for (i=0; ok && !PyErr_Occurred() && i<pv->Value.MVszW.cValues; i++) {
            PyObject *obmv=PySequence_GetItem(ob,i);
            if (obmv==NULL) break;

            BSTR wstr = NULL;
            ok = PyWinObject_AsBstr(obmv, &wstr, FALSE);
            if (ok) {
                DWORD bufSize = sizeof(WCHAR) * (SysStringLen(wstr)+1);
                HRESULT hr = MAPIAllocateMore(bufSize, pAllocMoreLinkBlock, (void **)&pv->Value.MVszW.lppszW[i]);
                if (S_OK!=hr) {
                    OleSetOleError(hr);
                    ok = FALSE;
                } else {
                    memcpy(pv->Value.MVszW.lppszW[i], wstr, bufSize-2);
                    // Null terminate
                    memcpy(((char *)pv->Value.MVszW.lppszW[i])+(bufSize-2),"\0\0", 2);
                }
            }
            SysFreeString(wstr);
            Py_DECREF(obmv);
        }
        break;

    // @flag PT_BINARY|A string containing binary data
    case PT_BINARY:
        pv->Value.bin.lpb = (unsigned char *)PyString_AsString(ob);
        pv->Value.bin.cb = PyString_Size(ob);
        break;

    // @flag PT_MV_BINARY|A sequence of strings containing binary data
    case PT_MV_BINARY:
        ok = AllocMVBuffer( ob, sizeof(SBinary), pAllocMoreLinkBlock, (void **)&pv->Value.MVbin.lpbin, &pv->Value.MVbin.cValues);
        for (i=0; !PyErr_Occurred() && i<pv->Value.MVbin.cValues; i++) {
            PyObject *obmv=PySequence_GetItem(ob,i);
            if (obmv==NULL) break;
            pv->Value.MVbin.lpbin[i].lpb = (unsigned char *)PyString_AsString(ob);
            pv->Value.MVbin.lpbin[i].cb = PyString_Size(ob);
            Py_DECREF(obmv);
        }
        break;

    // @flag PT_CLSID|A <o PyIID>
    case PT_CLSID:
    {
        HRESULT hr = MAPIAllocateMore(sizeof(CLSID), pAllocMoreLinkBlock, (void **)&pv->Value.lpguid);
        if (S_OK != hr) {
            OleSetOleError(hr);
            ok = FALSE;
        } else
            ok = PyWinObject_AsIID(ob, pv->Value.lpguid);
        break;
    }

    // @flag PT_MV_CLSID|A sequence of <o PyIID> objects
    case PT_MV_CLSID:
        MAKEB_MV(CLSID, pAllocMoreLinkBlock, pv->Value.MVguid.lpguid, pv->Value.MVguid.cValues, PyWinObject_AsIID)

    // @flag PT_I8|A <o PyLARGE_INTEGER>
    case PT_I8:
//		case PT_LONGLONG:
        ok = PyWinObject_AsLARGE_INTEGER(ob, &pv->Value.li);
        break;

    // @flag PT_MV_I8|A sequence of <o PyLARGE_INTEGER>
    case PT_MV_I8:
        MAKEB_MV(LARGE_INTEGER, pAllocMoreLinkBlock, pv->Value.MVli.lpli, pv->Value.MVli.cValues, PyWinObject_AsLARGE_INTEGER)

    // @flag PT_ERROR|An integer error code.
    case PT_ERROR:
        pv->Value.err = (SCODE)PyInt_AsLong(ob);
        break;

    // @flag PT_NULL|Anything!
    case PT_NULL:
        pv->Value.x = 0;
        break;

    default: {
        char buf[128];
        sprintf(buf, "Unsupported MAPI property type 0x%X", PROP_TYPE(pv->ulPropTag));
        PyErr_SetString(PyExc_TypeError, buf);
        ok = FALSE;
    }
    }
    ok = (ok && !PyErr_Occurred());
    return ok;
}
Example #11
0
_Check_return_ HRESULT CAclDlg::GetSelectedItems(ULONG ulFlags, ULONG ulRowFlags, _In_ LPROWLIST* lppRowList)
{
    if (!lppRowList || !m_lpContentsTableListCtrl)
        return MAPI_E_INVALID_PARAMETER;

    *lppRowList = NULL;
    HRESULT hRes = S_OK;
    int iNumItems = m_lpContentsTableListCtrl->GetSelectedCount();

    if (!iNumItems) return S_OK;
    if (iNumItems > MAXNewROWLIST) return MAPI_E_INVALID_PARAMETER;

    LPROWLIST lpTempList = NULL;

    EC_H(MAPIAllocateBuffer(CbNewROWLIST(iNumItems),(LPVOID*) &lpTempList));

    if (lpTempList)
    {
        lpTempList->cEntries = iNumItems;
        int iArrayPos = 0;
        int iSelectedItem = -1;

        for (iArrayPos = 0 ; iArrayPos < iNumItems ; iArrayPos++)
        {
            lpTempList->aEntries[iArrayPos].ulRowFlags = ulRowFlags;
            lpTempList->aEntries[iArrayPos].cValues = 0;
            lpTempList->aEntries[iArrayPos].rgPropVals = 0;
            iSelectedItem = m_lpContentsTableListCtrl->GetNextItem(
                                iSelectedItem,
                                LVNI_SELECTED);
            if (-1 != iSelectedItem)
            {
                SortListData* lpData = (SortListData*) m_lpContentsTableListCtrl->GetItemData(iSelectedItem);
                if (lpData)
                {
                    if (ulFlags & ACL_INCLUDE_ID && ulFlags & ACL_INCLUDE_OTHER)
                    {
                        LPSPropValue lpSPropValue = NULL;
                        EC_H(MAPIAllocateMore(2 * sizeof(SPropValue), lpTempList, (LPVOID*)&lpTempList->aEntries[iArrayPos].rgPropVals));

                        lpTempList->aEntries[iArrayPos].cValues = 2;

                        lpSPropValue = PpropFindProp(
                                           lpData->lpSourceProps,
                                           lpData->cSourceProps,
                                           PR_MEMBER_ID);

                        lpTempList->aEntries[iArrayPos].rgPropVals[0].ulPropTag = lpSPropValue->ulPropTag;
                        lpTempList->aEntries[iArrayPos].rgPropVals[0].Value = lpSPropValue->Value;

                        lpSPropValue = PpropFindProp(
                                           lpData->lpSourceProps,
                                           lpData->cSourceProps,
                                           PR_MEMBER_RIGHTS);

                        lpTempList->aEntries[iArrayPos].rgPropVals[1].ulPropTag = lpSPropValue->ulPropTag;
                        lpTempList->aEntries[iArrayPos].rgPropVals[1].Value = lpSPropValue->Value;
                    }
                    else if (ulFlags & ACL_INCLUDE_ID)
                    {
                        lpTempList->aEntries[iArrayPos].cValues = 1;
                        lpTempList->aEntries[iArrayPos].rgPropVals = PpropFindProp(
                                    lpData->lpSourceProps,
                                    lpData->cSourceProps,
                                    PR_MEMBER_ID);
                    }
                }
            }
        }
    }

    *lppRowList = lpTempList;
    return hRes;
} // CAclDlg::GetSelectedItems
Example #12
0
// Same as CreatePropertyStringRestriction, but skips the existence part.
_Check_return_ HRESULT CreateANRRestriction(ULONG ulPropTag,
	_In_z_ LPCTSTR szString,
	_In_opt_ LPVOID lpParent,
	_Deref_out_opt_ LPSRestriction* lppRes)
{
	HRESULT hRes = S_OK;
	LPSRestriction	lpRes = NULL;
	LPSPropValue	lpspvSubject = NULL;
	LPVOID			lpAllocationParent = NULL;

	*lppRes = NULL;

	// Allocate and create our SRestriction
	// Allocate base memory:
	if (lpParent)
	{
		EC_H(MAPIAllocateMore(
			sizeof(SRestriction),
			lpParent,
			(LPVOID*)&lpRes));

		lpAllocationParent = lpParent;
	}
	else
	{
		EC_H(MAPIAllocateBuffer(
			sizeof(SRestriction),
			(LPVOID*)&lpRes));

		lpAllocationParent = lpRes;
	}


	EC_H(MAPIAllocateMore(
		sizeof(SPropValue),
		lpAllocationParent,
		(LPVOID*)&lpspvSubject));

	if (lpRes && lpspvSubject)
	{
		// Zero out allocated memory.
		ZeroMemory(lpRes, sizeof(SRestriction));
		ZeroMemory(lpspvSubject, sizeof(SPropValue));

		// Root Node
		lpRes->rt = RES_PROPERTY;
		lpRes->res.resProperty.relop = RELOP_EQ;
		lpRes->res.resProperty.ulPropTag = ulPropTag;
		lpRes->res.resProperty.lpProp = lpspvSubject;

		// Allocate and fill out properties:
		lpspvSubject->ulPropTag = ulPropTag;
		lpspvSubject->Value.LPSZ = NULL;

		if (szString)
		{
			EC_H(CopyString(
				&lpspvSubject->Value.LPSZ,
				szString,
				lpAllocationParent));
		}

		DebugPrint(DBGGeneric, _T("CreateANRRestriction built restriction:\n"));
		DebugPrintRestriction(DBGGeneric, lpRes, NULL);

		*lppRes = lpRes;
	}

	if (hRes != S_OK)
	{
		DebugPrint(DBGGeneric, _T("Failed to create restriction\n"));
		MAPIFreeBuffer(lpRes);
		*lppRes = NULL;
	}
	return hRes;
} // CreateANRRestriction