ECMailBoxTable.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 <new>
  18. #include <kopano/platform.h>
  19. #include "ECDatabase.h"
  20. #include <mapidefs.h>
  21. #include <edkmdb.h>
  22. #include "ECSecurity.h"
  23. #include "ECSessionManager.h"
  24. #include "ECGenProps.h"
  25. #include "ECSession.h"
  26. #include <kopano/stringutil.h>
  27. #include "ECMailBoxTable.h"
  28. namespace KC {
  29. ECMailBoxTable::ECMailBoxTable(ECSession *lpSession, unsigned int ulFlags, const ECLocale &locale) :
  30. ECStoreObjectTable(lpSession, 0, NULL, 0, MAPI_STORE, ulFlags, TABLE_FLAG_OVERRIDE_HOME_MDB, locale)
  31. {
  32. m_ulStoreTypes = 3; // 1. Show all users store 2. Public stores
  33. }
  34. ECRESULT ECMailBoxTable::Create(ECSession *lpSession, unsigned int ulFlags, const ECLocale &locale, ECMailBoxTable **lppTable)
  35. {
  36. *lppTable = new(std::nothrow) ECMailBoxTable(lpSession, ulFlags, locale);
  37. if (*lppTable == nullptr)
  38. return KCERR_NOT_ENOUGH_MEMORY;
  39. (*lppTable)->AddRef();
  40. return erSuccess;
  41. }
  42. ECRESULT ECMailBoxTable::Load()
  43. {
  44. ECRESULT er = erSuccess;
  45. ECDatabase *lpDatabase = NULL;
  46. DB_RESULT lpDBResult;
  47. DB_ROW lpDBRow = NULL;
  48. std::string strQuery;
  49. std::list<unsigned int> lstObjIds;
  50. er = lpSession->GetDatabase(&lpDatabase);
  51. if (er != erSuccess)
  52. return er;
  53. Clear();
  54. //@todo Load all stores depends on m_ulStoreTypes, 1. privates, 2. publics or both
  55. strQuery = "SELECT hierarchy_id FROM stores";
  56. er = lpDatabase->DoSelect(strQuery, &lpDBResult);
  57. if(er != erSuccess)
  58. return er;
  59. while(1) {
  60. lpDBRow = lpDatabase->FetchRow(lpDBResult);
  61. if(lpDBRow == NULL)
  62. break;
  63. if (!lpDBRow[0])
  64. continue; // Broken store table?
  65. lstObjIds.push_back(atoui(lpDBRow[0]));
  66. }
  67. LoadRows(&lstObjIds, 0);
  68. return erSuccess;
  69. }
  70. } /* namespace */