mapi.i 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. %module(directors="1") MAPICore
  2. %{
  3. #undef LOCK_WRITE
  4. #include <kopano/platform.h>
  5. #include <mapi.h>
  6. #include <mapidefs.h>
  7. #include <mapicode.h>
  8. #include <mapiutil.h>
  9. #include <kopano/CommonUtil.h>
  10. #include <kopano/IECServiceAdmin.h>
  11. #include <kopano/memory.hpp>
  12. #include "IECSpooler.h"
  13. #include "IECTestProtocol.h"
  14. #include "IECMultiStoreTable.h"
  15. #include "IECExportChanges.h"
  16. #include <kopano/IECLicense.h>
  17. #include <kopano/mapi_ptr.h>
  18. // DIRTIEST HACK IN THE WORLD WARNING: we need to fix the broken swig output for mapi_wrap.h .....
  19. #pragma include_alias( "mapi_wrap.h", "mapi_wrap_fixed.h" )
  20. #include "MAPINotifSink.h"
  21. #include <kopano/director_util.h>
  22. /*
  23. * This dummy class ensure that we initialize properly on module load
  24. * and deinitialize as well whenever the intepreter exits.
  25. */
  26. class MAPIInitializer {
  27. public:
  28. MAPIInitializer(void)
  29. {
  30. MAPIINIT_0 init = {0, MAPI_MULTITHREAD_NOTIFICATIONS};
  31. MAPIInitialize(&init);
  32. }
  33. ~MAPIInitializer(void)
  34. {
  35. MAPIUninitialize();
  36. }
  37. };
  38. MAPIInitializer mapiInitializer;
  39. %}
  40. %include <kopano/typemap.i>
  41. #if SWIGPYTHON
  42. %exception {
  43. try {
  44. mark_call_from_python();
  45. $action
  46. unmark_call_from_python();
  47. } catch (const Swig::DirectorException &) {
  48. unmark_call_from_python();
  49. SWIG_fail;
  50. }
  51. }
  52. #endif
  53. class IUnknown {
  54. public:
  55. virtual HRESULT QueryInterface(const IID& USE_IID_FOR_OUTPUT, void **OUTPUT_USE_IID) = 0;
  56. };
  57. %extend IUnknown {
  58. ~IUnknown() { self->Release(); }
  59. };
  60. #define STGM_DIRECT 0x00000000L
  61. #define STGM_TRANSACTED 0x00010000L
  62. #define STGM_SIMPLE 0x08000000L
  63. #define STGM_READ 0x00000000L
  64. #define STGM_WRITE 0x00000001L
  65. #define STGM_READWRITE 0x00000002L
  66. #define STGM_SHARE_DENY_NONE 0x00000040L
  67. #define STGM_SHARE_DENY_READ 0x00000030L
  68. #define STGM_SHARE_DENY_WRITE 0x00000020L
  69. #define STGM_SHARE_EXCLUSIVE 0x00000010L
  70. #define STGM_PRIORITY 0x00040000L
  71. #define STGM_DELETEONRELEASE 0x04000000L
  72. #define STGM_NOSCRATCH 0x00100000L
  73. #define STGM_CREATE 0x00001000L
  74. #define STGM_CONVERT 0x00020000L
  75. #define STGM_FAILIFTHERE 0x00000000L
  76. #define STGM_NOSNAPSHOT 0x00200000L
  77. #define STGM_DIRECT_SWMR 0x00400000L
  78. enum STGTY {
  79. STGTY_STORAGE = 1,
  80. STGTY_STREAM = 2,
  81. STGTY_LOCKBYTES = 3,
  82. STGTY_PROPERTY = 4
  83. };
  84. enum STREAM_SEEK {
  85. STREAM_SEEK_SET = 0,
  86. STREAM_SEEK_CUR = 1,
  87. STREAM_SEEK_END = 2
  88. };
  89. enum LOCKTYPE {
  90. LOCK_WRITE = 1,
  91. LOCK_EXCLUSIVE = 2,
  92. LOCK_ONLYONCE = 4
  93. };
  94. enum STATFLAG {
  95. STATFLAG_DEFAULT = 0,
  96. STATFLAG_NONAME = 1,
  97. STATFLAG_NOOPEN = 2
  98. };
  99. %typemap(argout) (char **lpOutput, ULONG *ulRead) {
  100. if (*$1) {
  101. %append_output(PyBytes_FromStringAndSize(*$1, *$2));
  102. MAPIFreeBuffer(*$1);
  103. }
  104. }
  105. /* IStream Interface */
  106. class ISequentialStream : public IUnknown {
  107. public:
  108. // Hard to typemap so using other method below
  109. // virtual HRESULT Read(void *OUTPUT, ULONG cb, ULONG *OUTPUT) = 0;
  110. virtual HRESULT Write(const void *pv, ULONG cb, ULONG *OUTPUT) = 0;
  111. %extend {
  112. HRESULT Read(ULONG cb, char **lpOutput, ULONG *ulRead) {
  113. HRESULT hr = hrSuccess;
  114. char *buffer;
  115. StreamPtr ptrStream;
  116. if (self->QueryInterface(ptrStream.iid(), &~ptrStream) == hrSuccess) {
  117. const LARGE_INTEGER liMove = {0, 0};
  118. ULARGE_INTEGER liPosition;
  119. STATSTG statbuf;
  120. hr = ptrStream->Seek(liMove, SEEK_CUR, &liPosition);
  121. if (hr != hrSuccess)
  122. return hr;
  123. hr = ptrStream->Stat(&statbuf, 0);
  124. if (hr != hrSuccess)
  125. return hr;
  126. if ((statbuf.cbSize.QuadPart - liPosition.QuadPart) < cb)
  127. cb = (ULONG)(statbuf.cbSize.QuadPart - liPosition.QuadPart);
  128. }
  129. hr = MAPIAllocateBuffer(cb, (void **)&buffer);
  130. if (hr != hrSuccess)
  131. return hr;
  132. hr = self->Read(buffer, cb, ulRead);
  133. if (hr != hrSuccess)
  134. return hr;
  135. *lpOutput = buffer;
  136. return hrSuccess;
  137. }
  138. ~ISequentialStream(void)
  139. {
  140. self->Release();
  141. }
  142. }
  143. };
  144. %feature("notabstract") IStream;
  145. class IStream : public ISequentialStream {
  146. public:
  147. virtual HRESULT Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition) = 0;
  148. virtual HRESULT SetSize(ULARGE_INTEGER libNewSize) = 0;
  149. virtual HRESULT CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten) = 0;
  150. virtual HRESULT Commit(DWORD grfCommitFlags) = 0;
  151. virtual HRESULT Revert() = 0;
  152. virtual HRESULT LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) = 0;
  153. virtual HRESULT UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType) = 0;
  154. virtual HRESULT Stat(STATSTG *OUTPUT, DWORD grfStatFlag) = 0;
  155. virtual HRESULT Clone(IStream **ppstm) = 0;
  156. %extend {
  157. IStream() {
  158. IStream *lpStream = NULL;
  159. HRESULT hr = CreateStreamOnHGlobal(NULL, TRUE, &lpStream);
  160. if(hr == hrSuccess)
  161. return lpStream;
  162. return NULL;
  163. }
  164. ~IStream() {
  165. self->Release();
  166. }
  167. }
  168. };
  169. %include "mapidefs.i"
  170. %include "mapix.i"
  171. %include "mapicode.i"
  172. %include "mapinotifsink.i"
  173. %include "mapiutil.i"
  174. %include "edkmdb.i"
  175. %include "IECServiceAdmin.i"
  176. %include "IECSpooler.i"
  177. %include "IECTestProtocol.i"
  178. %include "IECMultiStoreTable.i"
  179. %include "IECLicense.i"
  180. %include "IECExportChanges.i"
  181. %include "helpers.i"
  182. %include "ecdefs.i"
  183. #define MAPI_ORIG 0x00000000
  184. #define MAPI_TO 0x00000001
  185. #define MAPI_CC 0x00000002
  186. #define MAPI_BCC 0x00000003
  187. #define MAPI_P1 0x10000000
  188. #define MAPI_SUBMITTED 0x80000000
  189. #define MAPI_UNREAD 0x00000001
  190. #define MAPI_RECEIPT_REQUESTED 0x00000002
  191. #define MAPI_SENT 0x00000004
  192. #define MAPI_LOGON_UI 0x00000001
  193. #define MAPI_PASSWORD_UI 0x00020000
  194. #define MAPI_NEW_SESSION 0x00000002
  195. #define MAPI_FORCE_DOWNLOAD 0x00001000
  196. #define MAPI_EXTENDED 0x00000020
  197. #define MAPI_DIALOG 0x00000008
  198. #define MAPI_USE_DEFAULT 0x00000040
  199. #define MAPI_UNREAD_ONLY 0x00000020
  200. #define MAPI_GUARANTEE_FIFO 0x00000100
  201. #define MAPI_LONG_MSGID 0x00004000
  202. #define MAPI_PEEK 0x00000080
  203. #define MAPI_SUPPRESS_ATTACH 0x00000800
  204. #define MAPI_ENVELOPE_ONLY 0x00000040
  205. #define MAPI_BODY_AS_FILE 0x00000200
  206. #define MAPI_AB_NOMODIFY 0x00000400
  207. %{
  208. #include <kopano/ECGuid.h>
  209. #include <edkguid.h>
  210. swig_type_info *TypeFromIID(REFIID iid)
  211. {
  212. #define TYPECASE(x) if(iid == IID_##x) return SWIGTYPE_p_##x;
  213. TYPECASE(IUnknown)
  214. TYPECASE(IStream)
  215. TYPECASE(IMAPIProp)
  216. TYPECASE(IMessage)
  217. TYPECASE(IMAPIContainer)
  218. TYPECASE(IMAPIFolder)
  219. TYPECASE(IMAPITable)
  220. TYPECASE(IABContainer)
  221. TYPECASE(IMailUser)
  222. TYPECASE(IDistList)
  223. TYPECASE(IMsgStore)
  224. if (iid == IID_ECMsgStoreOnline || iid == IID_ECMsgStoreOffline) return SWIGTYPE_p_IMsgStore;
  225. TYPECASE(IExchangeExportChanges)
  226. TYPECASE(IECExportChanges)
  227. TYPECASE(IExchangeImportContentsChanges)
  228. TYPECASE(IExchangeImportHierarchyChanges)
  229. TYPECASE(IExchangeManageStore)
  230. TYPECASE(IExchangeModifyTable)
  231. TYPECASE(IECServiceAdmin)
  232. TYPECASE(IECTestProtocol)
  233. TYPECASE(IECMultiStoreTable)
  234. TYPECASE(IECSpooler)
  235. TYPECASE(IECChangeAdvisor)
  236. TYPECASE(IECChangeAdviseSink)
  237. TYPECASE(IECSingleInstance)
  238. TYPECASE(IECLicense)
  239. TYPECASE(IProxyStoreObject)
  240. TYPECASE(IECImportContentsChanges)
  241. TYPECASE(IECImportHierarchyChanges)
  242. return NULL;
  243. }
  244. LPCIID IIDFromType(const char *type)
  245. {
  246. #define IIDCASE(x) if(strstr(type, #x) != NULL) return &IID_##x;
  247. IIDCASE(IUnknown)
  248. IIDCASE(IStream)
  249. IIDCASE(IMAPIProp)
  250. IIDCASE(IMessage)
  251. IIDCASE(IMAPIContainer)
  252. IIDCASE(IMAPIFolder)
  253. IIDCASE(IMAPITable)
  254. IIDCASE(IABContainer)
  255. IIDCASE(IMailUser)
  256. IIDCASE(IDistList)
  257. IIDCASE(IMsgStore)
  258. IIDCASE(IExchangeExportChanges)
  259. IIDCASE(IECExportChanges)
  260. IIDCASE(IExchangeImportContentsChanges)
  261. IIDCASE(IExchangeImportHierarchyChanges)
  262. IIDCASE(IExchangeManageStore)
  263. IIDCASE(IExchangeModifyTable)
  264. IIDCASE(IECServiceAdmin)
  265. IIDCASE(IECTestProtocol)
  266. IIDCASE(IECMultiStoreTable)
  267. IIDCASE(IECChangeAdvisor)
  268. IIDCASE(IECChangeAdviseSink)
  269. IIDCASE(IECSingleInstance)
  270. IIDCASE(IECLicense)
  271. IIDCASE(IProxyStoreObject)
  272. IIDCASE(IECImportContentsChanges)
  273. IIDCASE(IECImportHierarchyChanges)
  274. return &IID_IUnknown;
  275. }
  276. %}
  277. #if SWIGPYTHON
  278. %include "ECLogger.i"
  279. // Directors for IStream
  280. %{
  281. #include <kopano/swig_iunknown.h>
  282. typedef IUnknownImplementor<IStream> Stream;
  283. %}
  284. %feature("director") Stream;
  285. %feature("nodirector") Stream::QueryInterface;
  286. class Stream : public IStream {
  287. public:
  288. Stream(ULONG cInterfaces, LPCIID lpInterfaces);
  289. virtual HRESULT Read(void *OUTPUT, ULONG cb, ULONG *cbOUTPUT) = 0;
  290. virtual HRESULT Write(const void *pv, ULONG cb, ULONG *OUTPUT) = 0;
  291. %extend {
  292. virtual ~Stream() { self->Release(); };
  293. }
  294. };
  295. %include "kopanosync.i"
  296. #endif