ECMessage.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 ECMESSAGE_H
  18. #define ECMESSAGE_H
  19. #include <kopano/zcdefs.h>
  20. #include <kopano/ECMemTable.h>
  21. #include <kopano/Util.h>
  22. #include <mapidefs.h>
  23. #include "WSTransport.h"
  24. #include "ECMsgStore.h"
  25. #include "ECMAPIProp.h"
  26. class ECAttach;
  27. class IAttachFactory {
  28. public:
  29. virtual HRESULT Create(ECMsgStore *lpMsgStore, ULONG ulObjType, BOOL fModify, ULONG ulAttachNum, ECMAPIProp *lpRoot, ECAttach **lppAttach) const = 0;
  30. };
  31. /**
  32. * \brief Represents a MAPI message.
  33. *
  34. * This class represents any kind of MAPI message and exposes it through
  35. * the IMessage interface.
  36. */
  37. class ECMessage : public ECMAPIProp {
  38. protected:
  39. /**
  40. * \param lpMsgStore The store owning this message.
  41. * \param fNew Specifies whether the message is a new message.
  42. * \param fModify Specifies whether the message is writable.
  43. * \param ulFlags Flags.
  44. * \param bEmbedded Specifies whether the message is embedded.
  45. * \param lpRoot The parent object when the message is embedded.
  46. */
  47. ECMessage(ECMsgStore *lpMsgStore, BOOL fNew, BOOL fModify, ULONG ulFlags, BOOL bEmbedded, ECMAPIProp *lpRoot);
  48. virtual ~ECMessage();
  49. public:
  50. /**
  51. * \brief Creates a new ECMessage object.
  52. *
  53. * Use this static method to create a new ECMessage object.
  54. *
  55. * \param lpMsgStore The store owning this message.
  56. * \param fNew Specifies whether the message is a new message.
  57. * \param fModify Specifies whether the message is writable.
  58. * \param ulFlags Flags.
  59. * \param bEmbedded Specifies whether the message is embedded.
  60. * \param lpRoot The parent object when the message is embedded.
  61. * \param lpMessage Pointer to a pointer in which the create object will be returned.
  62. *
  63. * \return hrSuccess on success.
  64. */
  65. static HRESULT Create(ECMsgStore *lpMsgStore, BOOL fNew, BOOL fModify, ULONG ulFlags, BOOL bEmbedded, ECMAPIProp *lpRoot, ECMessage **lpMessage);
  66. /**
  67. * \brief Handles GetProp requests for previously registered properties.
  68. *
  69. * Properties can be registered through ECGenericProp::HrAddPropHandlers to be obtained through
  70. * this function when special processing is needed.
  71. *
  72. * \param[in] ulPropTag The proptag of the requested property.
  73. * \param[in] lpProvider The provider for the requested property (Probably an ECMsgStore pointer).
  74. * \param[out] lpsPropValue Pointer to an SPropValue structure in which the result will be stored.
  75. * \param[in] lpParam Pointer passed to ECGenericProp::HrAddPropHandlers (usually an ECMessage pointer).
  76. * \param[in] lpBase Base pointer used for allocating more memory
  77. *
  78. * \return hrSuccess on success.
  79. */
  80. static HRESULT GetPropHandler(ULONG ulPropTag, void* lpProvider, ULONG ulFlags, LPSPropValue lpsPropValue, void *lpParam, void *lpBase);
  81. /**
  82. * \brief Handles SetProp requests for previously registered properties.
  83. *
  84. * Properties can be registered through ECGenericProp::HrAddPropHandlers to be set through
  85. * this function when special processing is needed.
  86. *
  87. * \param ulPropTag The proptag of the requested property.
  88. * \param lpProvider The provider for the requested property (Probably an ECMsgStore pointer).
  89. * \param lpsPropValue Pointer to an SPropValue structure which holds the data to be set.
  90. * \param lpParam Pointer passed to ECGenericProp::HrAddPropHandlers (usually an ECMessage pointer).
  91. *
  92. * \return hrSuccess on success.
  93. */
  94. static HRESULT SetPropHandler(ULONG ulPropTag, void *lpProvider, const SPropValue *lpsPropValue, void *lpParam);
  95. virtual HRESULT QueryInterface(REFIID refiid, void **lppInterface) _kc_override;
  96. virtual HRESULT OpenProperty(ULONG ulPropTag, LPCIID lpiid, ULONG ulInterfaceOptions, ULONG ulFlags, LPUNKNOWN *lppUnk);
  97. virtual HRESULT GetAttachmentTable(ULONG ulFlags, LPMAPITABLE *lppTable);
  98. virtual HRESULT OpenAttach(ULONG ulAttachmentNum, LPCIID lpInterface, ULONG ulFlags, LPATTACH *lppAttach);
  99. virtual HRESULT CreateAttach(LPCIID lpInterface, ULONG ulFlags, ULONG *lpulAttachmentNum, LPATTACH *lppAttach);
  100. virtual HRESULT DeleteAttach(ULONG ulAttachmentNum, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, ULONG ulFlags);
  101. virtual HRESULT GetRecipientTable(ULONG ulFlags, LPMAPITABLE *lppTable);
  102. virtual HRESULT ModifyRecipients(ULONG ulFlags, const ADRLIST *lpMods);
  103. virtual HRESULT SubmitMessage(ULONG ulFlags);
  104. virtual HRESULT SetReadFlag(ULONG ulFlags);
  105. // override for IMAPIProp::SaveChanges
  106. virtual HRESULT SaveChanges(ULONG ulFlags);
  107. virtual HRESULT HrSaveChild(ULONG ulFlags, MAPIOBJECT *lpsMapiObject);
  108. // override for IMAPIProp::CopyTo
  109. virtual HRESULT CopyTo(ULONG ciidExclude, LPCIID rgiidExclude, const SPropTagArray *lpExcludeProps, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, LPCIID lpInterface, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems);
  110. virtual HRESULT CopyProps(const SPropTagArray *lpIncludeProps, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, LPCIID lpInterface, LPVOID lpDestObj, ULONG ulFlags, LPSPropProblemArray *lppProblems);
  111. // RTF/Subject overrides
  112. virtual HRESULT SetProps(ULONG cValues, const SPropValue *lpPropArray, LPSPropProblemArray *lppProblems);
  113. virtual HRESULT DeleteProps(const SPropTagArray *lpPropTagArray, LPSPropProblemArray *lppProblems);
  114. virtual HRESULT HrLoadProps();
  115. // Our table-row getprop handler (handles client-side generation of table columns)
  116. static HRESULT TableRowGetProp(void* lpProvider, struct propVal *lpsPropValSrc, LPSPropValue lpsPropValDst, void **lpBase, ULONG ulType);
  117. // RTF overrides
  118. virtual HRESULT HrSetRealProp(const SPropValue *lpsPropValue);
  119. class xMessage _kc_final : public IMessage {
  120. #include <kopano/xclsfrag/IUnknown.hpp>
  121. #include <kopano/xclsfrag/IMAPIProp.hpp>
  122. // <kopano/xclsfrag/IMessage.hpp>
  123. virtual HRESULT __stdcall GetAttachmentTable(ULONG flags, LPMAPITABLE *lppTable) _kc_override;
  124. virtual HRESULT __stdcall OpenAttach(ULONG ulAttachmentNum, LPCIID lpInterface, ULONG flags, LPATTACH *lppAttach) _kc_override;
  125. virtual HRESULT __stdcall CreateAttach(LPCIID lpInterface, ULONG flags, ULONG *lpulAttachmentNum, LPATTACH *lppAttach) _kc_override;
  126. virtual HRESULT __stdcall DeleteAttach(ULONG ulAttachmentNum, ULONG ui_param, LPMAPIPROGRESS lpProgress, ULONG flags) _kc_override;
  127. virtual HRESULT __stdcall GetRecipientTable(ULONG flags, LPMAPITABLE *lppTable) _kc_override;
  128. virtual HRESULT __stdcall ModifyRecipients(ULONG flags, const ADRLIST *lpMods) _kc_override;
  129. virtual HRESULT __stdcall SubmitMessage(ULONG flags) _kc_override;
  130. virtual HRESULT __stdcall SetReadFlag(ULONG flags) _kc_override;
  131. } m_xMessage;
  132. protected:
  133. void RecursiveMarkDelete(MAPIOBJECT *lpObj);
  134. HRESULT CreateAttach(LPCIID lpInterface, ULONG ulFlags, const IAttachFactory &refFactory, ULONG *lpulAttachmentNum, LPATTACH *lppAttach);
  135. HRESULT GetRtfData(std::string *lpstrRtfData);
  136. HRESULT GetCodePage(unsigned int *lpulCodePage);
  137. private:
  138. enum eSyncChange {syncChangeNone, syncChangeBody, syncChangeRTF, syncChangeHTML};
  139. enum eBodyType { bodyTypeUnknown, bodyTypePlain, bodyTypeRTF, bodyTypeHTML };
  140. HRESULT UpdateTable(ECMemTable *lpTable, ULONG ulObjType, ULONG ulObjKeyProp);
  141. HRESULT SaveRecips();
  142. HRESULT SyncAttachments();
  143. BOOL HasAttachment();
  144. HRESULT SyncRecips();
  145. HRESULT SyncSubject();
  146. HRESULT GetBodyType(eBodyType *lpulBodyType);
  147. // Override GetProps/GetPropList so we can sync RTF before calling GetProps
  148. virtual HRESULT GetProps(const SPropTagArray *lpPropTagArray, ULONG ulFlags, ULONG *lpcValues, LPSPropValue *lppPropArray);
  149. virtual HRESULT GetPropList(ULONG ulFlags, LPSPropTagArray *lppPropTagArray);
  150. HRESULT GetSyncedBodyProp(ULONG ulPropTag, ULONG ulFlags, void *lpBase, LPSPropValue lpsPropValue);
  151. HRESULT SyncBody(ULONG ulPropTag);
  152. HRESULT SyncPlainToRtf();
  153. HRESULT SyncPlainToHtml();
  154. HRESULT SyncRtf();
  155. HRESULT SyncHtmlToPlain();
  156. HRESULT SyncHtmlToRtf();
  157. BOOL fNew;
  158. BOOL m_bEmbedded;
  159. BOOL m_bExplicitSubjectPrefix = false;
  160. BOOL m_bRecipsDirty = false, m_bInhibitSync = false;
  161. eBodyType m_ulBodyType = bodyTypeUnknown;
  162. public:
  163. ULONG m_cbParentID = 0;
  164. ENTRYID *m_lpParentID = nullptr; // For new messages
  165. ECMemTable *lpRecips = nullptr, *lpAttachments = nullptr;
  166. ULONG ulNextRecipUniqueId = 0, ulNextAttUniqueId = 0;
  167. ALLOC_WRAP_FRIEND;
  168. };
  169. class ECMessageFactory _kc_final : public IMessageFactory {
  170. public:
  171. HRESULT Create(ECMsgStore *lpMsgStore, BOOL fNew, BOOL fModify, ULONG ulFlags, BOOL bEmbedded, ECMAPIProp *lpRoot, ECMessage **lpMessage) const;
  172. };
  173. #endif // ECMESSAGE_H