operations.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #ifndef operations_INCLUDED
  18. #define operations_INCLUDED
  19. #include <kopano/zcdefs.h>
  20. #include "operations_fwd.h"
  21. #include <mapix.h>
  22. #include <kopano/mapi_ptr.h>
  23. namespace KC {
  24. class ECArchiverLogger;
  25. namespace operations {
  26. /**
  27. * IArchiveOperation specifies the interface to all archiver operations.
  28. */
  29. class IArchiveOperation {
  30. public:
  31. /**
  32. * virtual destructor.
  33. */
  34. virtual ~IArchiveOperation(void) _kc_impdtor;
  35. /**
  36. * Entrypoint for all archive operations.
  37. *
  38. * @param[in] lpFolder
  39. * A MAPIFolder pointer that points to the folder that's to be processed. This folder will usually be
  40. * a searchfolder containing the messages that are ready to be processed.
  41. * @param[in] cProps
  42. * The number op properties pointed to by lpProps.
  43. * @param[in] lpProps
  44. * Pointer to an array of properties that are used by the Operation object.
  45. */
  46. virtual HRESULT ProcessEntry(LPMAPIFOLDER lpFolder, ULONG cProps, const LPSPropValue lpProps) = 0;
  47. /**
  48. * Obtain the restriction the messages need to match in order to be processed by this operation.
  49. *
  50. * @param[in] LPMAPIPROP A MAPIProp object that's used to resolve named properties on.
  51. * @param[out] lppRestriction The restriction to be matched.
  52. */
  53. virtual HRESULT GetRestriction(LPMAPIPROP LPMAPIPROP, LPSRestriction *lppRestriction) = 0;
  54. /**
  55. * Verify the message to make sure a message isn't processed while it shouldn't caused
  56. * by searchfolder lags.
  57. *
  58. * @param[in] lpMessage The message to verify
  59. *
  60. * @return hrSuccess The message is verified to be valid for the operation.
  61. * @return MAPI_E_NOT_FOUND The message should not be processed.
  62. */
  63. virtual HRESULT VerifyRestriction(LPMESSAGE lpMessage) = 0;
  64. };
  65. /**
  66. * This class contains some basic functionality for all operations.
  67. *
  68. * It generates the restriction.
  69. * It contains the logger.
  70. */
  71. class ArchiveOperationBase : public IArchiveOperation {
  72. public:
  73. ArchiveOperationBase(ECArchiverLogger *lpLogger, int ulAge, bool bProcessUnread, ULONG ulInhibitMask);
  74. HRESULT GetRestriction(LPMAPIPROP LPMAPIPROP, LPSRestriction *lppRestriction) _kc_override;
  75. HRESULT VerifyRestriction(LPMESSAGE lpMessage) _kc_override;
  76. protected:
  77. /**
  78. * Returns a pointer to the logger.
  79. * @return An ECArchiverLogger pointer.
  80. */
  81. ECArchiverLogger* Logger() { return m_lpLogger; }
  82. private:
  83. ECArchiverLogger *m_lpLogger;
  84. const int m_ulAge;
  85. const bool m_bProcessUnread;
  86. const ULONG m_ulInhibitMask;
  87. FILETIME m_ftCurrent;
  88. };
  89. /**
  90. * ArchiveOperationBaseEx is the base implementation of the IArchiveOperation interface. It's main functionality
  91. * is iterating through all the items in the folder passed to ProcessEntry.
  92. */
  93. class ArchiveOperationBaseEx : public ArchiveOperationBase {
  94. public:
  95. ArchiveOperationBaseEx(ECArchiverLogger *lpLogger, int ulAge, bool bProcessUnread, ULONG ulInhibitMask);
  96. HRESULT ProcessEntry(LPMAPIFOLDER lpFolder, ULONG cProps, const LPSPropValue lpProps) _kc_override;
  97. protected:
  98. /**
  99. * Returns a pointer to a MAPIFolderPtr, which references the current working folder.
  100. * @return A reference to a MAPIFolderPtr.
  101. */
  102. MAPIFolderPtr& CurrentFolder() { return m_ptrCurFolder; }
  103. private:
  104. /**
  105. * Called by ProcessEntry after switching source folders. Derived classes will need to
  106. * implement this method. It can be used to perform operations that only need to be done when
  107. * the source folder is switched.
  108. *
  109. * @param[in] lpFolder The just opened folder.
  110. */
  111. virtual HRESULT EnterFolder(LPMAPIFOLDER lpFolder) = 0;
  112. /**
  113. * Called by ProcessEntry before switching source folders. Derived classes will need to
  114. * implement this method. It can be used to perform operations that only need to be done when
  115. * the source folder is switched.
  116. */
  117. virtual HRESULT LeaveFolder() = 0;
  118. /**
  119. * Called by ProcessEntry for each message found in the search folder that also matches the age restriction.
  120. *
  121. * @param[in] cProps
  122. * The number op properties pointed to by lpProps.
  123. * @param[in] lpProps
  124. * Pointer to an array of properties that are used by the Operation object.
  125. */
  126. virtual HRESULT DoProcessEntry(ULONG cProps, const LPSPropValue &lpProps) = 0;
  127. SPropValuePtr m_ptrCurFolderEntryId;
  128. MAPIFolderPtr m_ptrCurFolder;
  129. };
  130. }} /* namespace */
  131. #endif // ndef operations_INCLUDED