hl.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #ifndef _KCHL_HPP
  2. #define _KCHL_HPP 1
  3. #include <kopano/zcdefs.h>
  4. #include <kopano/memory.hpp>
  5. #include <exception>
  6. #include <memory>
  7. #include <stdexcept>
  8. #include <string>
  9. #include <mapidefs.h>
  10. class IAttach;
  11. class IMAPIFolder;
  12. class IMAPISession;
  13. class IMessage;
  14. class IMsgFolder;
  15. class IMsgStore;
  16. class IStream;
  17. class IUnknown;
  18. namespace KCHL {
  19. using namespace KC;
  20. class KAttach;
  21. class KFolder;
  22. class KMessage;
  23. class KStore;
  24. class KStream;
  25. class KTable;
  26. class KUnknown;
  27. class KEntryId;
  28. class _kc_export KProp _kc_final {
  29. public:
  30. KProp(SPropValue *);
  31. KProp(KProp &&);
  32. ~KProp(void);
  33. KProp &operator=(KProp &&);
  34. SPropValue *operator->(void) { return m_s; }
  35. const SPropValue *operator->(void) const { return m_s; }
  36. operator SPropValue *(void) { return m_s; }
  37. operator const SPropValue *(void) const { return m_s; }
  38. unsigned int prop_type() const;
  39. const unsigned int &prop_tag() const;
  40. const bool b() const;
  41. const unsigned int &ul() const;
  42. const int &l() const;
  43. std::string str();
  44. std::wstring wstr();
  45. KEntryId entry_id();
  46. private:
  47. SPropValue *m_s;
  48. };
  49. class _kc_export KAttach _kc_final {
  50. public:
  51. KAttach(IAttach *, unsigned int);
  52. KAttach(KAttach &&);
  53. ~KAttach(void);
  54. KAttach &operator=(KAttach &&);
  55. IAttach *operator->(void) { return m_attach; }
  56. operator IAttach *(void) { return m_attach; }
  57. KStream open_property_stream(unsigned int = 0, unsigned int = 0, unsigned int = 0);
  58. HRESULT save_changes(unsigned int = 0);
  59. protected:
  60. IAttach *m_attach;
  61. unsigned int m_num;
  62. };
  63. class _kc_export KEntryId _kc_final {
  64. public:
  65. KEntryId(void) = default;
  66. KEntryId(KEntryId &&);
  67. KEntryId(ENTRYID *, size_t);
  68. ~KEntryId(void);
  69. KEntryId &operator=(KEntryId &&);
  70. ENTRYID *lpb() { return m_eid; }
  71. const ENTRYID *lpb() const { return m_eid; }
  72. size_t cb() const { return m_size; }
  73. private:
  74. friend class KStore;
  75. ENTRYID *m_eid = nullptr;
  76. size_t m_size = 0;
  77. };
  78. class _kc_export_throw KMAPIError _kc_final : public std::exception {
  79. public:
  80. KMAPIError(HRESULT = hrSuccess);
  81. virtual ~KMAPIError(void) noexcept _kc_impdtor;
  82. HRESULT code(void) const noexcept { return m_code; }
  83. virtual const char *what(void) const noexcept;
  84. private:
  85. HRESULT m_code;
  86. std::string m_message;
  87. };
  88. class _kc_export KFolder _kc_final {
  89. public:
  90. KFolder(void) = default;
  91. KFolder(IMAPIFolder *);
  92. KFolder(KFolder &&);
  93. ~KFolder(void);
  94. KFolder &operator=(KFolder &&);
  95. IMAPIFolder *operator->(void) { return m_folder; }
  96. operator IMAPIFolder *(void) { return m_folder; }
  97. KMessage create_message(LPCIID = NULL, unsigned int = 0);
  98. KTable get_contents_table(unsigned int = 0);
  99. KTable get_hierarchy_table(unsigned int = 0);
  100. KProp get_prop(unsigned int);
  101. protected:
  102. IMAPIFolder *m_folder = nullptr;
  103. };
  104. class _kc_export KMessage _kc_final {
  105. public:
  106. KMessage(void) = default;
  107. KMessage(IMessage *);
  108. KMessage(KMessage &&);
  109. ~KMessage(void);
  110. KMessage &operator=(KMessage &&);
  111. IMessage *operator->(void) { return m_message; }
  112. operator IMessage *(void) { return m_message; }
  113. KAttach create_attach(LPCIID = NULL, unsigned int = 0);
  114. KProp get_prop(unsigned int);
  115. HRESULT save_changes(unsigned int = 0);
  116. HRESULT set_read_flag(unsigned int = 0);
  117. protected:
  118. IMessage *m_message = nullptr;
  119. };
  120. class _kc_export KSession _kc_final {
  121. public:
  122. KSession(void);
  123. KSession(const wchar_t *, const wchar_t *);
  124. KSession(IMAPISession *);
  125. KSession(KSession &&) = delete;
  126. ~KSession(void);
  127. IMAPISession *operator->(void) { return m_session; }
  128. operator IMAPISession *(void) { return m_session; }
  129. KStore open_default_store(void);
  130. protected:
  131. IMAPISession *m_session = nullptr;
  132. };
  133. class _kc_export KStore _kc_final {
  134. public:
  135. KStore(IMsgStore *);
  136. KStore(KStore &&);
  137. ~KStore(void);
  138. KStore &operator=(KStore &&);
  139. IMsgStore *operator->(void) { return m_store; }
  140. operator IMsgStore *(void) { return m_store; }
  141. KEntryId get_receive_folder(const char *cls = nullptr, char **xcls = nullptr);
  142. KProp get_prop(unsigned int);
  143. KUnknown open_entry(const KEntryId &, LPCIID = nullptr, unsigned int = 0);
  144. KUnknown open_entry(const SPropValue * = NULL, LPCIID = NULL, unsigned int = 0);
  145. protected:
  146. IMsgStore *m_store;
  147. ULONG m_type;
  148. };
  149. class _kc_export KStream _kc_final {
  150. public:
  151. KStream(IStream *);
  152. KStream(KStream &&);
  153. ~KStream(void);
  154. KStream &operator=(KStream &&);
  155. IStream *operator->(void) { return m_stream; }
  156. operator IStream *(void) { return m_stream; }
  157. HRESULT write(const std::string &);
  158. HRESULT commit(unsigned int = 0);
  159. protected:
  160. IStream *m_stream;
  161. };
  162. class _kc_export KRow _kc_final {
  163. public:
  164. KRow(SRow);
  165. KProp operator[](size_t index) const;
  166. unsigned int count() const;
  167. private:
  168. SRow m_row;
  169. };
  170. class _kc_export KRowSet _kc_final {
  171. public:
  172. KRowSet(SRowSet*);
  173. KRow operator[](size_t) const;
  174. unsigned int count() const;
  175. SRowSet* operator->(void) { return m_rowset.get(); }
  176. operator SRowSet *(void) { return m_rowset.get(); }
  177. protected:
  178. rowset_ptr m_rowset;
  179. };
  180. class _kc_export KTable _kc_final {
  181. public:
  182. enum SortOrder {
  183. ASCEND = TABLE_SORT_ASCEND,
  184. DESCEND = TABLE_SORT_DESCEND
  185. };
  186. KTable(IMAPITable *);
  187. KTable(KTable &&);
  188. ~KTable(void);
  189. KTable &operator=(KTable &&);
  190. IMAPITable *operator->(void) { return m_table; }
  191. operator IMAPITable *(void) { return m_table; }
  192. HRESULT restrict(const SRestriction &, unsigned int = 0);
  193. void columns(std::initializer_list<unsigned int>, unsigned int = 0);
  194. void sort(std::initializer_list<std::pair<unsigned int, SortOrder> >, unsigned int = 0);
  195. KRowSet rows(unsigned int, unsigned int);
  196. unsigned int count(unsigned int = 0);
  197. protected:
  198. IMAPITable *m_table;
  199. };
  200. class _kc_export KUnknown _kc_final {
  201. public:
  202. KUnknown(IUnknown * = NULL);
  203. KUnknown(KUnknown &&);
  204. ~KUnknown(void);
  205. KUnknown &operator=(KUnknown &&);
  206. operator KFolder(void) const;
  207. operator KMessage(void) const;
  208. protected:
  209. IUnknown *m_ptr;
  210. };
  211. } /* namespace KCHL */
  212. #endif /* _KCHL_HPP */