<commit_before>#include "stdafx.h"
#include "MAPIPropPropertyBag.h"
#include "MAPIFunctions.h"
#include "InterpretProp.h"
#include <Controls/SortList/SortListData.h>

MAPIPropPropertyBag::MAPIPropPropertyBag(LPMAPIPROP lpProp, SortListData* lpListData)
{
	m_lpListData = lpListData;
	m_lpProp = lpProp;
	if (m_lpProp) m_lpProp->AddRef();
	m_bGetPropsSucceeded = false;
}

MAPIPropPropertyBag::~MAPIPropPropertyBag()
{
	if (m_lpProp) m_lpProp->Release();
}

ULONG MAPIPropPropertyBag::GetFlags()
{
	ULONG ulFlags = pbNone;
	if (m_bGetPropsSucceeded) ulFlags |= pbBackedByGetProps;
	return ulFlags;
}

propBagType MAPIPropPropertyBag::GetType()
{
	return pbMAPIProp;
}

bool MAPIPropPropertyBag::IsEqual(LPMAPIPROPERTYBAG lpPropBag)
{
	if (!lpPropBag) return false;
	if (GetType() != lpPropBag->GetType()) return false;

	auto lpOther = static_cast<MAPIPropPropertyBag*>(lpPropBag);
	if (lpOther)
	{
		if (m_lpListData != lpOther->m_lpListData) return false;
		if (m_lpProp != lpOther->m_lpProp) return false;
		return true;
	}

	return false;
}

// Returns the underlying MAPI prop object, if one exists. Does NOT ref count it.
_Check_return_ LPMAPIPROP MAPIPropPropertyBag::GetMAPIProp()
{
	return m_lpProp;
}

_Check_return_ HRESULT MAPIPropPropertyBag::Commit()
{
	if (NULL == m_lpProp) return S_OK;

	auto hRes = S_OK;
	WC_H(m_lpProp->SaveChanges(KEEP_OPEN_READWRITE));
	return hRes;
}

_Check_return_ HRESULT MAPIPropPropertyBag::GetAllProps(
	ULONG FAR* lpcValues,
	LPSPropValue FAR* lppPropArray)
{
	if (NULL == m_lpProp) return S_OK;
	auto hRes = S_OK;
	m_bGetPropsSucceeded = false;

	if (!RegKeys[regkeyUSE_ROW_DATA_FOR_SINGLEPROPLIST].ulCurDWORD)
	{
		hRes = ::GetPropsNULL(m_lpProp,
			fMapiUnicode,
			lpcValues,
			lppPropArray);
		if (SUCCEEDED(hRes))
		{
			m_bGetPropsSucceeded = true;
		}
		if (MAPI_E_CALL_FAILED == hRes)
		{
			// Some stores, like public folders, don't support properties on the root folder
			DebugPrint(DBGGeneric, L"Failed to get call GetProps on this object!\n");
		}
		else if (FAILED(hRes)) // only report errors, not warnings
		{
			CHECKHRESMSG(hRes, IDS_GETPROPSNULLFAILED);
		}

		return hRes;
	}

	if (!m_bGetPropsSucceeded && m_lpListData)
	{
		*lpcValues = m_lpListData->cSourceProps;
		*lppPropArray = m_lpListData->lpSourceProps;
		hRes = S_OK;
	}

	return hRes;
}

_Check_return_ HRESULT MAPIPropPropertyBag::GetProps(
	LPSPropTagArray lpPropTagArray,
	ULONG ulFlags,
	ULONG FAR* lpcValues,
	LPSPropValue FAR* lppPropArray)
{
	if (NULL == m_lpProp) return S_OK;

	auto hRes = S_OK;
	WC_H(m_lpProp->GetProps(lpPropTagArray, ulFlags, lpcValues, lppPropArray));
	return hRes;
}

_Check_return_ HRESULT MAPIPropPropertyBag::GetProp(
	ULONG ulPropTag,
	LPSPropValue FAR* lppProp)
{
	if (NULL == m_lpProp) return S_OK;

	auto hRes = S_OK;
	WC_MAPI(HrGetOneProp(m_lpProp, ulPropTag, lppProp));
<commit_msg>Default stream type defaulted to ANSI because HrGetOneProp does. Switched to GetProps where we can fMapiUnicode<commit_after>#include "stdafx.h"
#include "MAPIPropPropertyBag.h"
#include "MAPIFunctions.h"
#include "InterpretProp.h"
#include <Controls/SortList/SortListData.h>

MAPIPropPropertyBag::MAPIPropPropertyBag(LPMAPIPROP lpProp, SortListData* lpListData)
{
	m_lpListData = lpListData;
	m_lpProp = lpProp;
	if (m_lpProp) m_lpProp->AddRef();
	m_bGetPropsSucceeded = false;
}

MAPIPropPropertyBag::~MAPIPropPropertyBag()
{
	if (m_lpProp) m_lpProp->Release();
}

ULONG MAPIPropPropertyBag::GetFlags()
{
	ULONG ulFlags = pbNone;
	if (m_bGetPropsSucceeded) ulFlags |= pbBackedByGetProps;
	return ulFlags;
}

propBagType MAPIPropPropertyBag::GetType()
{
	return pbMAPIProp;
}

bool MAPIPropPropertyBag::IsEqual(LPMAPIPROPERTYBAG lpPropBag)
{
	if (!lpPropBag) return false;
	if (GetType() != lpPropBag->GetType()) return false;

	auto lpOther = static_cast<MAPIPropPropertyBag*>(lpPropBag);
	if (lpOther)
	{
		if (m_lpListData != lpOther->m_lpListData) return false;
		if (m_lpProp != lpOther->m_lpProp) return false;
		return true;
	}

	return false;
}

// Returns the underlying MAPI prop object, if one exists. Does NOT ref count it.
_Check_return_ LPMAPIPROP MAPIPropPropertyBag::GetMAPIProp()
{
	return m_lpProp;
}

_Check_return_ HRESULT MAPIPropPropertyBag::Commit()
{
	if (NULL == m_lpProp) return S_OK;

	auto hRes = S_OK;
	WC_H(m_lpProp->SaveChanges(KEEP_OPEN_READWRITE));
	return hRes;
}

_Check_return_ HRESULT MAPIPropPropertyBag::GetAllProps(
	ULONG FAR* lpcValues,
	LPSPropValue FAR* lppPropArray)
{
	if (NULL == m_lpProp) return S_OK;
	auto hRes = S_OK;
	m_bGetPropsSucceeded = false;

	if (!RegKeys[regkeyUSE_ROW_DATA_FOR_SINGLEPROPLIST].ulCurDWORD)
	{
		hRes = ::GetPropsNULL(m_lpProp,
			fMapiUnicode,
			lpcValues,
			lppPropArray);
		if (SUCCEEDED(hRes))
		{
			m_bGetPropsSucceeded = true;
		}
		if (MAPI_E_CALL_FAILED == hRes)
		{
			// Some stores, like public folders, don't support properties on the root folder
			DebugPrint(DBGGeneric, L"Failed to get call GetProps on this object!\n");
		}
		else if (FAILED(hRes)) // only report errors, not warnings
		{
			CHECKHRESMSG(hRes, IDS_GETPROPSNULLFAILED);
		}

		return hRes;
	}

	if (!m_bGetPropsSucceeded && m_lpListData)
	{
		*lpcValues = m_lpListData->cSourceProps;
		*lppPropArray = m_lpListData->lpSourceProps;
		hRes = S_OK;
	}

	return hRes;
}

_Check_return_ HRESULT MAPIPropPropertyBag::GetProps(
	LPSPropTagArray lpPropTagArray,
	ULONG ulFlags,
	ULONG FAR* lpcValues,
	LPSPropValue FAR* lppPropArray)
{
	if (NULL == m_lpProp) return S_OK;

	auto hRes = S_OK;
	WC_H(m_lpProp->GetProps(lpPropTagArray, ulFlags, lpcValues, lppPropArray));
	return hRes;
}

_Check_return_ HRESULT MAPIPropPropertyBag::GetProp(
	ULONG ulPropTag,
	LPSPropValue FAR* lppProp)
{
	if (NULL == m_lpProp) return S_OK;

	auto hRes = S_OK;
	SPropTagArray tag = { 1, ulPropTag };
	ULONG cVals = 0;
	WC_H_GETPROPS(m_lpProp->GetProps(&tag, fMapiUnicode, &cVals, lppProp));

{'fraction_non_alphanumeric': 0.1070091867982307, 'fraction_numerical': 0.0003402517863218782, 'mean_word_length': 5.532222222222222, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5812674', 'n_tokens_mistral': 2417, 'n_tokens_neox': 2358, 'n_words': 481}