Skip to content

Commit e6e1122

Browse files
nczeczulinmhammond
authored andcommitted
Add mapi.WrapCompressedRTFStreamEx (mhammond#1419)
1 parent 74f9d8b commit e6e1122

File tree

1 file changed

+66
-0
lines changed
  • com/win32comext/mapi/src

1 file changed

+66
-0
lines changed

com/win32comext/mapi/src/mapi.i

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,72 @@ HRESULT WrapCompressedRTFStream(
671671
IStream **OUTPUT
672672
);
673673

674+
675+
// WrapCompressedRTFStreamEx
676+
#define MAPI_NATIVE_BODY ((ULONG) 0x00010000) // Indicates whether the decompressed stream is also converted to its native body.
677+
#define MAPI_NATIVE_BODY_TYPE_RTF ((ULONG) 1) // Native body is RTF.
678+
#define MAPI_NATIVE_BODY_TYPE_HTML ((ULONG) 2) // Native body is plain text.
679+
#define MAPI_NATIVE_BODY_TYPE_PLAINTEXT ((ULONG) 4) // Native body is HTML.
680+
681+
// @pyswig (<o PyIStream>, ULONG)|WrapCompressedRTFStreamEx|
682+
// @rdesc Result is a tuple of (bodyStream, bodyType);
683+
%native(WrapCompressedRTFStreamEx) PyWrapCompressedRTFStreamEx;
684+
%{
685+
// @object RTF_WCSINFO|A tuple representing a RTF_WCSINFO structure
686+
struct RTF_WCSINFO
687+
{
688+
ULONG size;
689+
ULONG Flags; // @tupleitem 0|ULONG|flags|
690+
ULONG ulInCodePage; // @tupleitem 1|ULONG|incodepage|
691+
ULONG ulOutCodePage; // @tupleitem 2|ULONG|outcodepage|
692+
};
693+
694+
struct RTF_WCSRETINFO
695+
{
696+
ULONG size;
697+
ULONG ulStreamFlags;
698+
};
699+
700+
STDAPI WrapCompressedRTFStreamEx(
701+
LPSTREAM lpCompressedRTFStream,
702+
CONST RTF_WCSINFO *pWCSInfo,
703+
LPSTREAM *lppUncompressedRTFStream,
704+
RTF_WCSRETINFO *pRetInfo);
705+
706+
PyObject *PyWrapCompressedRTFStreamEx(PyObject *self, PyObject *args)
707+
{
708+
HRESULT hRes;
709+
PyObject *obCompressedStream = NULL;
710+
PyObject *obUncompressedStream = NULL;
711+
712+
LPSTREAM lpCompressedStream = NULL; // @pyparm <o PyIStream>|stream||Message stream
713+
RTF_WCSINFO wcsinfo = {0}; // @pyparm <o RTF_WCSINFO>|wcsinfo|(0, 0, 0)|function options
714+
LPSTREAM lpUncompressedStream = NULL;
715+
RTF_WCSRETINFO retinfo = {0};
716+
717+
wcsinfo.size = sizeof(RTF_WCSINFO);
718+
retinfo.size = sizeof(RTF_WCSRETINFO);
719+
720+
if (!PyArg_ParseTuple(args, "O|(kkk):PyWrapCompressedRTFStreamEx", &obCompressedStream,
721+
&wcsinfo.Flags, &wcsinfo.ulInCodePage, &wcsinfo.ulOutCodePage))
722+
return NULL;
723+
724+
if (!PyCom_InterfaceFromPyObject(obCompressedStream, IID_IStream, (void **)&lpCompressedStream, FALSE))
725+
return NULL;
726+
727+
Py_BEGIN_ALLOW_THREADS
728+
hRes = WrapCompressedRTFStreamEx(lpCompressedStream, &wcsinfo, &lpUncompressedStream, &retinfo);
729+
lpCompressedStream->Release();
730+
Py_END_ALLOW_THREADS
731+
732+
if (FAILED(hRes))
733+
return OleSetOleError(hRes);
734+
735+
return Py_BuildValue("Nk", PyCom_PyObjectFromIUnknown(lpUncompressedStream, IID_IStream, FALSE),
736+
retinfo.ulStreamFlags);
737+
}
738+
%}
739+
674740
%native(MAPIUIDFromBinary) MAPIUIDFromBinary;
675741
%{
676742
PyObject *MAPIUIDFromBinary(PyObject *self, PyObject *args)

0 commit comments

Comments
 (0)