123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- #include "ECFeatures.h"
- #include "ECFeatureList.h"
- #include <kopano/CommonUtil.h>
- #include <kopano/mapi_ptr.h>
- using namespace std;
- namespace KC {
- bool isFeature(const char* feature)
- {
- for (size_t i = 0; i < ARRAY_SIZE(kopano_features); ++i)
- if (strcasecmp(feature, kopano_features[i]) == 0)
- return true;
- return false;
- }
- HRESULT hasFeature(const char *feature, const SPropValue *lpProps)
- {
- if (!feature || !lpProps || PROP_TYPE(lpProps->ulPropTag) != PT_MV_STRING8)
- return MAPI_E_INVALID_PARAMETER;
- for (ULONG i = 0; i < lpProps->Value.MVszA.cValues; ++i)
- if (strcasecmp(lpProps->Value.MVszA.lppszA[i], feature) == 0)
- return hrSuccess;
- return MAPI_E_NOT_FOUND;
- }
- HRESULT hasFeature(const wchar_t *feature, const SPropValue *lpProps)
- {
- if (!feature || !lpProps || PROP_TYPE(lpProps->ulPropTag) != PT_MV_UNICODE)
- return MAPI_E_INVALID_PARAMETER;
- for (ULONG i = 0; i < lpProps->Value.MVszW.cValues; ++i)
- if (wcscasecmp(lpProps->Value.MVszW.lppszW[i], feature) == 0)
- return hrSuccess;
- return MAPI_E_NOT_FOUND;
- }
- static HRESULT HrGetUserProp(IAddrBook *lpAddrBook, IMsgStore *lpStore,
- ULONG ulPropTag, LPSPropValue *lpProps)
- {
- SPropValuePtr ptrProps;
- MailUserPtr ptrUser;
- ULONG ulObjType;
- if (lpStore == NULL || PROP_TYPE(ulPropTag) != PT_MV_STRING8 ||
- lpProps == NULL)
- return MAPI_E_INVALID_PARAMETER;
- HRESULT hr = HrGetOneProp(lpStore, PR_MAILBOX_OWNER_ENTRYID, &~ptrProps);
- if (hr != hrSuccess)
- return hr;
- hr = lpAddrBook->OpenEntry(ptrProps->Value.bin.cb, reinterpret_cast<ENTRYID *>(ptrProps->Value.bin.lpb), &IID_IMailUser, 0, &ulObjType, &~ptrUser);
- if (hr != hrSuccess)
- return hr;
- hr = HrGetOneProp(ptrUser, ulPropTag, &~ptrProps);
- if (hr != hrSuccess)
- return hr;
- *lpProps = ptrProps.release();
- return hrSuccess;
- }
- static bool checkFeature(const char *feature, IAddrBook *lpAddrBook,
- IMsgStore *lpStore, ULONG ulPropTag)
- {
- SPropValuePtr ptrProps;
- if (feature == NULL || lpStore == NULL ||
- PROP_TYPE(ulPropTag) != PT_MV_STRING8)
- return MAPI_E_INVALID_PARAMETER == hrSuccess;
- HRESULT hr = HrGetUserProp(lpAddrBook, lpStore, ulPropTag, &~ptrProps);
- if (hr != hrSuccess)
- return false;
- return hasFeature(feature, ptrProps) == hrSuccess;
- }
- bool isFeatureDisabled(const char* feature, IAddrBook *lpAddrBook, IMsgStore *lpStore)
- {
- return checkFeature(feature, lpAddrBook, lpStore, PR_EC_DISABLED_FEATURES_A);
- }
- }
|