ECIterators.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. */
  17. #include <kopano/platform.h>
  18. #include "ECIterators.h"
  19. #include <kopano/ECRestriction.h>
  20. #include "HrException.h"
  21. namespace KC {
  22. ECHierarchyIteratorBase::ECHierarchyIteratorBase(LPMAPICONTAINER lpContainer, ULONG ulFlags, ULONG ulDepth)
  23. : m_ptrContainer(lpContainer, true)
  24. , m_ulFlags(ulFlags)
  25. , m_ulDepth(ulDepth)
  26. , m_ulRowIndex(0)
  27. {
  28. increment();
  29. }
  30. void ECHierarchyIteratorBase::increment()
  31. {
  32. HRESULT hr = hrSuccess;
  33. ULONG ulType;
  34. enum {IDX_ENTRYID};
  35. if (!m_ptrTable) {
  36. SPropValuePtr ptrFolderType;
  37. static constexpr const SizedSPropTagArray(1, sptaColumnProps) = {1, {PR_ENTRYID}};
  38. hr = HrGetOneProp(m_ptrContainer, PR_FOLDER_TYPE, &~ptrFolderType);
  39. if (hr == hrSuccess && ptrFolderType->Value.ul == FOLDER_SEARCH) {
  40. // No point in processing search folders
  41. m_ptrCurrent.reset();
  42. goto exit;
  43. }
  44. hr = m_ptrContainer->GetHierarchyTable(m_ulDepth == 1 ? 0 : CONVENIENT_DEPTH, &~m_ptrTable);
  45. if (hr != hrSuccess)
  46. goto exit;
  47. if (m_ulDepth > 1) {
  48. SPropValue sPropDepth;
  49. sPropDepth.ulPropTag = PR_DEPTH;
  50. sPropDepth.Value.ul = m_ulDepth;
  51. hr = ECPropertyRestriction(RELOP_LE, PR_DEPTH, &sPropDepth, ECRestriction::Cheap)
  52. .RestrictTable(m_ptrTable, TBL_BATCH);
  53. if (hr != hrSuccess)
  54. goto exit;
  55. }
  56. hr = m_ptrTable->SetColumns(sptaColumnProps, TBL_BATCH);
  57. if (hr != hrSuccess)
  58. goto exit;
  59. }
  60. if (!m_ptrRows.get()) {
  61. hr = m_ptrTable->QueryRows(32, 0, &m_ptrRows);
  62. if (hr != hrSuccess)
  63. goto exit;
  64. if (m_ptrRows.empty()) {
  65. m_ptrCurrent.reset();
  66. goto exit;
  67. }
  68. m_ulRowIndex = 0;
  69. }
  70. assert(m_ulRowIndex < m_ptrRows.size());
  71. hr = m_ptrContainer->OpenEntry(m_ptrRows[m_ulRowIndex].lpProps[IDX_ENTRYID].Value.bin.cb, reinterpret_cast<ENTRYID *>(m_ptrRows[m_ulRowIndex].lpProps[IDX_ENTRYID].Value.bin.lpb), &m_ptrCurrent.iid(), m_ulFlags, &ulType, &~m_ptrCurrent);
  72. if (hr != hrSuccess)
  73. goto exit;
  74. if (++m_ulRowIndex == m_ptrRows.size())
  75. m_ptrRows.reset();
  76. exit:
  77. if (hr != hrSuccess)
  78. throw HrException(hr); // @todo: Fix this
  79. }
  80. } /* namespace */