示例#1
0
void CMapiMessage::GetDownloadState()
{
  // See http://support.microsoft.com/kb/912239
  HRESULT         hRes = S_OK;
  ULONG           ulVal = 0;
  LPSPropValue    lpPropVal = NULL;
  LPSPropTagArray lpNamedPropTag = NULL;
  MAPINAMEID      NamedID = {0};
  LPMAPINAMEID    lpNamedID = NULL;

  NamedID.lpguid = (LPGUID) &PSETID_Common;
  NamedID.ulKind = MNID_ID;
  NamedID.Kind.lID = dispidHeaderItem;
  lpNamedID = &NamedID;

  hRes = m_lpMsg->GetIDsFromNames(1, &lpNamedID, NULL, &lpNamedPropTag);

  if (lpNamedPropTag && 1 == lpNamedPropTag->cValues)
  {
    lpNamedPropTag->aulPropTag[0] = CHANGE_PROP_TYPE(lpNamedPropTag->aulPropTag[0], PT_LONG);

    //Get the value of the property.
    hRes = m_lpMsg->GetProps(lpNamedPropTag, 0, &ulVal, &lpPropVal);
    if (lpPropVal && 1 == ulVal && PT_LONG == PROP_TYPE(lpPropVal->ulPropTag) &&
        lpPropVal->Value.ul)
      m_dldStateHeadersOnly = true;
  }

  CMapiApi::MAPIFreeBuffer(lpPropVal);
  CMapiApi::MAPIFreeBuffer(lpNamedPropTag);
}
示例#2
0
void Workshare::Mail::Mapi::TagMessage(LPMESSAGE pMessage, const LPWSTR lpszTagName)
{
	LPMAPINAMEID pTagNames = 0;
	LPSPropTagArray pPropTags = 0;
	LPSPropProblemArray pPropProblems = 0;

	try
	{
		HRESULT hr = MAPIAllocateBuffer(sizeof(MAPINAMEID), (LPVOID*)&pTagNames);
		if(FAILED(hr))
			throw MapiException(hr, _T("Failed to allocate a MAPI NameId buffer in order to tag the message."));

		pTagNames[0].lpguid = (LPGUID)&PS_PUBLIC_STRINGS;
		pTagNames[0].ulKind = MNID_STRING;
		pTagNames[0].Kind.lpwstrName = lpszTagName;

		IMAPIProp* pmp = pMessage;

		//NOTE: The following returns E_INVALIDARG if cProps is any value other than 1 !!!
		hr = pmp->GetIDsFromNames(1, &pTagNames, MAPI_CREATE, &pPropTags);
		if(FAILED(hr))
		{
			throw MapiException(hr, _T("Failed to get a MAPI Name Id for the named tag in order to tag the message."));
		}

		for (ULONG j = 0; j < pPropTags->cValues; j++)
		{
			if (PT_ERROR == PROP_TYPE(pPropTags->aulPropTag[j]))
			{
				throw MapiException(MAPI_E_NOT_FOUND, _T("Invalid MAPI Name Id retrieved for the named tag in order to tag the message."));
			}
		}

		SPropValue aPropValues[1];

		aPropValues[0].dwAlignPad = 0;
		aPropValues[0].ulPropTag = CHANGE_PROP_TYPE(pPropTags->aulPropTag[0], PT_BOOLEAN);
		aPropValues[0].Value.b = TRUE;

		hr = pmp->SetProps(1, (LPSPropValue)&aPropValues, &pPropProblems);
		if(FAILED(hr))
		{
			throw MapiException(pmp, hr, _T("Failed to set named property in order to tag the message."));
		}

		if (0 != pPropProblems && 0 != pPropProblems->cProblem)
			hr = E_FAIL;
		if(FAILED(hr))
			throw MapiException(hr, _T("Failed to set named property in order to tag the message."));
	}
	catch (...)
	{
		if (pPropProblems != 0)
		{
			MAPIFreeBuffer(pPropProblems);
		}
		if (pPropTags != 0)
		{
			MAPIFreeBuffer(pPropTags);
		}
		if (pTagNames != 0)
		{
			MAPIFreeBuffer(pTagNames);
		}
		throw;
	}
	if (pPropProblems != 0)
	{
		MAPIFreeBuffer(pPropProblems);
	}
	if (pPropTags != 0)
	{
		MAPIFreeBuffer(pPropTags);
	}
	if (pTagNames != 0)
	{
		MAPIFreeBuffer(pTagNames);
	}
}