ECMAPIContainer.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <kopano/platform.h>
  17. #include <kopano/ECInterfaceDefs.h>
  18. #include <kopano/memory.hpp>
  19. #include "kcore.hpp"
  20. #include "ECMAPIContainer.h"
  21. #include "ECMAPITable.h"
  22. #include "Mem.h"
  23. #include <kopano/ECGuid.h>
  24. #include <kopano/ECDebug.h>
  25. //#include <edkmdb.h>
  26. #include <kopano/mapiext.h>
  27. #include <mapiutil.h>
  28. using namespace KCHL;
  29. ECMAPIContainer::ECMAPIContainer(ECMsgStore *lpMsgStore, ULONG ulObjType,
  30. BOOL fModify, const char *szClassName) :
  31. ECMAPIProp(lpMsgStore, ulObjType, fModify, NULL, szClassName)
  32. {
  33. }
  34. HRESULT ECMAPIContainer::QueryInterface(REFIID refiid, void **lppInterface)
  35. {
  36. REGISTER_INTERFACE2(ECMAPIContainer, this);
  37. REGISTER_INTERFACE2(ECMAPIProp, this);
  38. REGISTER_INTERFACE2(ECUnknown, this);
  39. REGISTER_INTERFACE2(IMAPIContainer, &this->m_xMAPIContainer);
  40. REGISTER_INTERFACE2(IMAPIProp, &this->m_xMAPIContainer);
  41. REGISTER_INTERFACE2(IUnknown, &this->m_xMAPIContainer);
  42. return MAPI_E_INTERFACE_NOT_SUPPORTED;
  43. }
  44. HRESULT ECMAPIContainer::CopyTo(ULONG ciidExclude, LPCIID rgiidExclude,
  45. const SPropTagArray *lpExcludeProps, ULONG ulUIParam,
  46. LPMAPIPROGRESS lpProgress, LPCIID lpInterface, void *lpDestObj,
  47. ULONG ulFlags, SPropProblemArray **lppProblems)
  48. {
  49. return Util::DoCopyTo(&IID_IMAPIContainer, &this->m_xMAPIContainer, ciidExclude, rgiidExclude, lpExcludeProps, ulUIParam, lpProgress, lpInterface, lpDestObj, ulFlags, lppProblems);
  50. }
  51. HRESULT ECMAPIContainer::CopyProps(const SPropTagArray *lpIncludeProps,
  52. ULONG ulUIParam, LPMAPIPROGRESS lpProgress, LPCIID lpInterface,
  53. void *lpDestObj, ULONG ulFlags, SPropProblemArray **lppProblems)
  54. {
  55. return Util::DoCopyProps(&IID_IMAPIContainer, &this->m_xMAPIContainer, lpIncludeProps, ulUIParam, lpProgress, lpInterface, lpDestObj, ulFlags, lppProblems);
  56. }
  57. HRESULT ECMAPIContainer::SetSearchCriteria(LPSRestriction lpRestriction, LPENTRYLIST lpContainerList, ULONG ulSearchFlags)
  58. {
  59. return MAPI_E_NO_SUPPORT;
  60. }
  61. HRESULT ECMAPIContainer::GetSearchCriteria(ULONG ulFlags, LPSRestriction *lppRestriction, LPENTRYLIST *lppContainerList, ULONG *lpulSearchState)
  62. {
  63. return MAPI_E_NO_SUPPORT;
  64. }
  65. HRESULT ECMAPIContainer::GetContentsTable(ULONG ulFlags, LPMAPITABLE *lppTable)
  66. {
  67. HRESULT hr = hrSuccess;
  68. object_ptr<ECMAPITable> lpTable;
  69. object_ptr<WSTableView> lpTableOps;
  70. std::string strName = "Contents table";
  71. #ifdef DEBUG
  72. {
  73. LPSPropValue lpDisplay;
  74. HrGetOneProp(&this->m_xMAPIProp, PR_DISPLAY_NAME_A, &lpDisplay);
  75. if (lpDisplay != nullptr)
  76. strName = lpDisplay->Value.lpszA;
  77. }
  78. #endif
  79. hr = ECMAPITable::Create(strName.c_str(), this->GetMsgStore()->m_lpNotifyClient, 0, &~lpTable);
  80. if(hr != hrSuccess)
  81. return hr;
  82. hr = this->GetMsgStore()->lpTransport->HrOpenTableOps(MAPI_MESSAGE, ulFlags & (MAPI_UNICODE | SHOW_SOFT_DELETES | MAPI_ASSOCIATED | EC_TABLE_NOCAP), m_cbEntryId, m_lpEntryId, this->GetMsgStore(), &~lpTableOps);
  83. if(hr != hrSuccess)
  84. return hr;
  85. hr = lpTable->HrSetTableOps(lpTableOps, !(ulFlags & MAPI_DEFERRED_ERRORS));
  86. if(hr != hrSuccess)
  87. return hr;
  88. hr = lpTable->QueryInterface(IID_IMAPITable, (void **)lppTable);
  89. AddChild(lpTable);
  90. return hr;
  91. }
  92. HRESULT ECMAPIContainer::GetHierarchyTable(ULONG ulFlags, LPMAPITABLE *lppTable)
  93. {
  94. HRESULT hr = hrSuccess;
  95. object_ptr<ECMAPITable> lpTable;
  96. object_ptr<WSTableView> lpTableOps;
  97. SizedSPropTagArray(1, sPropTagArray);
  98. ULONG cValues = 0;
  99. ecmem_ptr<SPropValue> lpPropArray;
  100. std::string strName = "Hierarchy table";
  101. #ifdef DEBUG
  102. {
  103. LPSPropValue lpDisplay;
  104. HrGetOneProp(&this->m_xMAPIProp, PR_DISPLAY_NAME_A, &lpDisplay);
  105. if (lpDisplay != nullptr)
  106. strName = lpDisplay->Value.lpszA;
  107. }
  108. #endif
  109. sPropTagArray.aulPropTag[0] = PR_FOLDER_TYPE;
  110. sPropTagArray.cValues = 1;
  111. hr = GetProps(sPropTagArray, 0, &cValues, &~lpPropArray);
  112. if(FAILED(hr))
  113. return hr;
  114. // block for searchfolders
  115. if (lpPropArray != nullptr && lpPropArray[0].ulPropTag == PR_FOLDER_TYPE &&
  116. lpPropArray[0].Value.l == FOLDER_SEARCH)
  117. return MAPI_E_NO_SUPPORT;
  118. hr = ECMAPITable::Create(strName.c_str(), this->GetMsgStore()->m_lpNotifyClient, 0, &~lpTable);
  119. if(hr != hrSuccess)
  120. return hr;
  121. hr = this->GetMsgStore()->lpTransport->HrOpenTableOps(MAPI_FOLDER, ulFlags & (MAPI_UNICODE | SHOW_SOFT_DELETES | CONVENIENT_DEPTH), m_cbEntryId, m_lpEntryId, this->GetMsgStore(), &~lpTableOps);
  122. if(hr != hrSuccess)
  123. return hr;
  124. hr = lpTable->HrSetTableOps(lpTableOps, !(ulFlags & MAPI_DEFERRED_ERRORS));
  125. if(hr != hrSuccess)
  126. return hr;
  127. hr = lpTable->QueryInterface(IID_IMAPITable, (void **)lppTable);
  128. AddChild(lpTable);
  129. return hr;
  130. }
  131. HRESULT ECMAPIContainer::OpenEntry(ULONG cbEntryID, LPENTRYID lpEntryID, LPCIID lpInterface, ULONG ulFlags, ULONG *lpulObjType, LPUNKNOWN *lppUnk)
  132. {
  133. return this->GetMsgStore()->OpenEntry(cbEntryID, lpEntryID, lpInterface, ulFlags, lpulObjType, lppUnk);
  134. }
  135. // From IMAPIContainer
  136. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, GetContentsTable, (ULONG, ulFlags), (LPMAPITABLE *, lppTable))
  137. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, GetHierarchyTable, (ULONG, ulFlags), (LPMAPITABLE *, lppTable))
  138. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, OpenEntry, (ULONG, cbEntryID), (LPENTRYID, lpEntryID), (LPCIID, lpInterface), (ULONG, ulFlags), (ULONG *, lpulObjType), (LPUNKNOWN *, lppUnk))
  139. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, SetSearchCriteria, (LPSRestriction, lpRestriction), (LPENTRYLIST, lpContainerList), (ULONG, ulSearchFlags))
  140. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, GetSearchCriteria, (ULONG, ulFlags), (LPSRestriction *, lppRestriction), (LPENTRYLIST *, lppContainerList), (ULONG *, lpulSearchState))
  141. // From IUnknown
  142. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, QueryInterface, (REFIID, refiid), (void **, lppInterface))
  143. DEF_ULONGMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, AddRef, (void))
  144. DEF_ULONGMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, Release, (void))
  145. // From IMAPIProp
  146. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, GetLastError, (HRESULT, hError), (ULONG, ulFlags), (LPMAPIERROR *, lppMapiError))
  147. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, SaveChanges, (ULONG, ulFlags))
  148. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, GetProps, (const SPropTagArray *, lpPropTagArray), (ULONG, ulFlags), (ULONG *, lpcValues), (SPropValue **, lppPropArray))
  149. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, GetPropList, (ULONG, ulFlags), (LPSPropTagArray *, lppPropTagArray))
  150. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, OpenProperty, (ULONG, ulPropTag), (LPCIID, lpiid), (ULONG, ulInterfaceOptions), (ULONG, ulFlags), (LPUNKNOWN *, lppUnk))
  151. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, SetProps, (ULONG, cValues), (const SPropValue *, lpPropArray), (SPropProblemArray **, lppProblems))
  152. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, DeleteProps, (const SPropTagArray *, lpPropTagArray), (SPropProblemArray **, lppProblems))
  153. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, CopyTo, (ULONG, ciidExclude), (LPCIID, rgiidExclude), (const SPropTagArray *, lpExcludeProps), (ULONG, ulUIParam), (LPMAPIPROGRESS, lpProgress), (LPCIID, lpInterface), (void *, lpDestObj), (ULONG, ulFlags), (SPropProblemArray **, lppProblems))
  154. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, CopyProps, (const SPropTagArray *, lpIncludeProps), (ULONG, ulUIParam), (LPMAPIPROGRESS, lpProgress), (LPCIID, lpInterface), (void *, lpDestObj), (ULONG, ulFlags), (SPropProblemArray **, lppProblems))
  155. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, GetNamesFromIDs, (LPSPropTagArray *, pptaga), (LPGUID, lpguid), (ULONG, ulFlags), (ULONG *, pcNames), (LPMAPINAMEID **, pppNames))
  156. DEF_HRMETHOD1(TRACE_MAPI, ECMAPIContainer, MAPIContainer, GetIDsFromNames, (ULONG, cNames), (LPMAPINAMEID *, ppNames), (ULONG, ulFlags), (LPSPropTagArray *, pptaga))