Update of /cvsroot/pywin32/pywin32/com/win32comext/mapi/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7290/com/win32comext/mapi/src
Modified Files:
PyIMAPISession.i PyIMAPITable.i PyMAPIUtil.h mapi.i mapilib.i
mapiutil.cpp
Added Files:
PyIMAPIAdviseSink.cpp PyIMAPIAdviseSink.h
Log Message:
Add support for IMAPIAdviseSink
Index: mapiutil.cpp
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/mapi/src/mapiutil.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** mapiutil.cpp 18 Apr 2006 11:53:47 -0000 1.5
--- mapiutil.cpp 9 Aug 2008 01:51:39 -0000 1.6
***************
*** 54,57 ****
--- 54,90 ----
}
+ PyObject *PyObject_FromMAPIERROR(MAPIERROR *e, BOOL bIsUnicode, BOOL free_buffer)
+ {
+ PyObject *obError;
+ if (e->lpszError)
+ obError = bIsUnicode ? PyWinObject_FromWCHAR((const WCHAR *)e->lpszError) :
+ PyString_FromString((const char *)e->lpszError);
+
+ else {
+ obError = Py_None;
+ Py_INCREF(Py_None);
+ }
+ PyObject *obComp;
+ if (e->lpszComponent)
+ obComp = bIsUnicode ? PyWinObject_FromWCHAR((const WCHAR *)e->lpszComponent) :
+ PyString_FromString((const char *)e->lpszComponent);
+ else {
+ obComp = Py_None;
+ Py_INCREF(Py_None);
+ }
+
+ PyObject *ret = Py_BuildValue("lOOll",
+ e->ulVersion,
+ obError,
+ obComp,
+ e->ulLowLevelError,
+ e->ulContext);
+ Py_XDECREF(obError);
+ Py_XDECREF(obComp);
+ if (free_buffer)
+ MAPIFreeBuffer(e);
+ return ret;
+ }
+
BOOL AllocMVBuffer(PyObject *seq, size_t itemSize, void *pAllocMoreLinkBlock, void **pbuf, ULONG *pLen)
{
***************
*** 489,492 ****
--- 522,542 ----
}
+ PyObject *PyMAPIObject_FromSPropValueArray(SPropValue *pv, ULONG nvalues)
+ {
+ PyObject *ret = PyList_New(nvalues);
+ if (!ret)
+ return NULL;
+ ULONG i;
+ for (i=0;i<nvalues;i++) {
+ PyObject *sub = PyMAPIObject_FromSPropValue(pv+i);
+ if (!sub) {
+ Py_DECREF(ret);
+ return NULL;
+ }
+ PyList_SET_ITEM(ret, i, sub);
+ }
+ return ret;
+ }
+
// @object PySPropValueArray|A sequence of <o PySPropValue>, as passed to many MAPI functions.
BOOL PyMAPIObject_AsSPropValueArray(PyObject *obs, SPropValue **ppv, ULONG *pcValues)
--- NEW FILE: PyIMAPIAdviseSink.cpp ---
// This file implements the IMAPIAdviseSink Interface and Gateway for Python.
// Generated by makegw.py
#include "PythonCOM.h"
#include "PythonCOMServer.h"
#include "mapidefs.h"
#include "mapiguid.h"
#include "PyMAPIUtil.h"
#include "PyIMAPIAdviseSink.h"
// @doc - This file contains autoduck documentation
// ---------------------------------------------------
//
PyObject *PyObject_FromNOTIFICATION(NOTIFICATION *n)
{
PyObject *ret = NULL;
switch (n->ulEventType) {
case fnevCriticalError: {
ERROR_NOTIFICATION &err(n->info.err);
ret = Py_BuildValue("k(s#iiN)",
n->ulEventType,
err.lpEntryID, err.cbEntryID,
err.scode,
err.ulFlags,
PyObject_FromMAPIERROR(err.lpMAPIError, err.ulFlags&MAPI_UNICODE, FALSE));
break;
}
case fnevExtended: {
EXTENDED_NOTIFICATION &ext(n->info.ext);
ret = Py_BuildValue("k(ks#)", n->ulEventType, ext.ulEvent,
ext.pbEventParameters, ext.cb);
break;
}
case fnevNewMail: {
NEWMAIL_NOTIFICATION &newmail(n->info.newmail);
PyObject *msg_class = newmail.ulFlags&MAPI_UNICODE?
PyWinObject_FromWCHAR((const WCHAR *)newmail.lpszMessageClass) :
PyString_FromString((const char *)newmail.lpszMessageClass);
if (!msg_class)
return NULL;
ret = Py_BuildValue("k(s#s#kNk)",
n->ulEventType,
newmail.lpEntryID, newmail.cbEntryID,
newmail.lpParentID, newmail.cbParentID,
newmail.ulFlags,
msg_class,
newmail.ulMessageFlags);
break;
}
case fnevObjectCopied:
case fnevObjectCreated:
case fnevObjectDeleted:
case fnevObjectModified:
case fnevObjectMoved:
case fnevSearchComplete: {
OBJECT_NOTIFICATION &obj(n->info.obj);
PyObject *obArray = PyMAPIObject_FromSPropTagArray(obj.lpPropTagArray);
if (!obArray)
return NULL;
ret = Py_BuildValue("k(s#is#s#s#N)",
n->ulEventType,
obj.lpEntryID, obj.cbEntryID,
obj.ulObjType,
obj.lpParentID, obj.cbParentID,
obj.lpOldID, obj.cbOldID,
obj.lpOldParentID, obj.cbOldParentID,
obArray);
break;
}
case fnevTableModified: {
TABLE_NOTIFICATION &tab(n->info.tab);
ret = Py_BuildValue("k(kiNNN)",
n->ulEventType,
tab.ulTableEvent,
tab.hResult,
PyMAPIObject_FromSPropValue(&tab.propIndex),
PyMAPIObject_FromSPropValue(&tab.propPrior),
PyMAPIObject_FromSRow(&tab.row));
break;
}
case fnevStatusObjectModified: {
STATUS_OBJECT_NOTIFICATION &statobj(n->info.statobj);
ret = Py_BuildValue("k(s#N)",
n->ulEventType,
statobj.lpEntryID, statobj.cbEntryID,
PyMAPIObject_FromSPropValueArray(statobj.lpPropVals, statobj.cValues));
break;
}
default: {
PyCom_LoggerWarning(NULL, "unknown MAPI notification type %x", n->ulEventType);
ret = Py_BuildValue("k(O)", n->ulEventType, Py_None);
break;
}
}
return ret;
}
ULONG PyGMAPIAdviseSink::OnNotify(ULONG cNotif, LPNOTIFICATION lpNotifications )
{
PY_GATEWAY_METHOD;
PyObject *arg = PyList_New(cNotif);
if (!arg)
return MAKE_PYCOM_GATEWAY_FAILURE_CODE("OnNotify");
ULONG i;
for (i=0;i<cNotif;i++) {
PyObject *sub = PyObject_FromNOTIFICATION(lpNotifications+i);
if (!sub) {
Py_DECREF(arg);
return MAKE_PYCOM_GATEWAY_FAILURE_CODE("OnNotify");
}
PyList_SET_ITEM(arg, i, sub);
}
return InvokeViaPolicy("OnNotify", NULL, "(N)", arg);
}
Index: mapi.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/mapi/src/mapi.i,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** mapi.i 16 Mar 2006 11:20:55 -0000 1.7
--- mapi.i 9 Aug 2008 01:51:39 -0000 1.8
***************
*** 44,47 ****
--- 44,48 ----
#include "PyIProfSect.h"
#include "PyIMsgServiceAdmin.h"
+ #include "PyIMAPIAdviseSink.h"
#include "MAPISPI.H"
***************
*** 172,176 ****
if ( PyCom_RegisterClientType(&PyIMsgServiceAdmin::type, &IID_IMsgServiceAdmin) != 0 ) return;
ADD_IID(IID_IMsgServiceAdmin);
!
ADD_IID(PS_PUBLIC_STRINGS);
--- 173,179 ----
if ( PyCom_RegisterClientType(&PyIMsgServiceAdmin::type, &IID_IMsgServiceAdmin) != 0 ) return;
ADD_IID(IID_IMsgServiceAdmin);
!
! if ( PyCom_RegisterGatewayObject(IID_IMAPIAdviseSink, GET_PYGATEWAY_CTOR(PyGMAPIAdviseSink), "IMAPIAdviseSink") != 0) return;
! ADD_IID(IID_IMAPIAdviseSink);
ADD_IID(PS_PUBLIC_STRINGS);
Index: mapilib.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/mapi/src/mapilib.i,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** mapilib.i 11 Feb 2006 03:47:02 -0000 1.3
--- mapilib.i 9 Aug 2008 01:51:39 -0000 1.4
***************
*** 469,497 ****
%typemap(python,argout) MAPIERROR **OUTPUT {
! PyObject *obError;
! if ((*$source)->lpszError)
! obError = PyWinObject_FromTCHAR((*$source)->lpszError);
! else {
! obError = Py_None;
! Py_INCREF(Py_None);
! }
! PyObject *obComp;
! if ((*$source)->lpszComponent)
! obComp = PyWinObject_FromTCHAR((*$source)->lpszComponent);
! else {
! obComp = Py_None;
! Py_INCREF(Py_None);
! }
!
! Py_DECREF($target);
! $target = Py_BuildValue("lOOll",
! (*$source)->ulVersion,
! obError,
! obComp,
! (*$source)->ulLowLevelError,
! (*$source)->ulContext);
! Py_XDECREF(obError);
! Py_XDECREF(obComp);
! MAPIFreeBuffer(*$source);
}
--- 469,473 ----
%typemap(python,argout) MAPIERROR **OUTPUT {
! PyObject_FromMAPIERROR(*$source, TRUE, TRUE);
}
Index: PyMAPIUtil.h
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/mapi/src/PyMAPIUtil.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** PyMAPIUtil.h 21 Oct 2005 06:14:03 -0000 1.3
--- PyMAPIUtil.h 9 Aug 2008 01:51:39 -0000 1.4
***************
*** 8,11 ****
--- 8,13 ----
PyObject *PyMAPIObject_FromTypedUnknown( ULONG typ, IUnknown *pUnk, BOOL bAddRef);
+ PyObject *PyObject_FromMAPIERROR(MAPIERROR *e, BOOL bIsUnicode, BOOL free_buffer);
+
/* Create (and free) a SBinaryArray from a PyObject */
BOOL PyMAPIObject_AsSBinaryArray(PyObject *ob, SBinaryArray *pv);
***************
*** 17,22 ****
PyObject *PyMAPIObject_FromSPropValue(SPropValue *pv);
! /* Create a PyObject from a SPropValue Array*/
BOOL PyMAPIObject_AsSPropValueArray(PyObject *ob, SPropValue **ppv, ULONG *pcValues);
/* Create a PyObject from a SRow/SRowSet */
--- 19,26 ----
PyObject *PyMAPIObject_FromSPropValue(SPropValue *pv);
! /* Create a PyObject to/from a SPropValue Array*/
BOOL PyMAPIObject_AsSPropValueArray(PyObject *ob, SPropValue **ppv, ULONG *pcValues);
+ PyObject *PyMAPIObject_FromSPropValueArray(SPropValue *pv, ULONG nvalues);
+
/* Create a PyObject from a SRow/SRowSet */
--- NEW FILE: PyIMAPIAdviseSink.h ---
// This file declares the IMAPIAdviseSink Gateway for Python.
// ----------------------------------------------------------
//
// Gateway Declaration
class PyGMAPIAdviseSink : public PyGatewayBase, public IMAPIAdviseSink
{
protected:
PyGMAPIAdviseSink(PyObject *instance) : PyGatewayBase(instance) { ; }
PYGATEWAY_MAKE_SUPPORT2(PyGMAPIAdviseSink, IMAPIAdviseSink, IID_IMAPIAdviseSink, PyGatewayBase)
// IMAPIAdviseSink
MAPIMETHOD_(ULONG, OnNotify)(ULONG cNotif, LPNOTIFICATION lpNotifications);
};
Index: PyIMAPISession.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/mapi/src/PyIMAPISession.i,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PyIMAPISession.i 16 Jun 2003 05:01:11 -0000 1.2
--- PyIMAPISession.i 9 Aug 2008 01:51:39 -0000 1.3
***************
*** 149,152 ****
--- 149,209 ----
%}
+ // @pyswig int|Advise|
+ // @rdesc The result is an integer which should be passed to
+ // <om PyIMAPISession.Unadvise>
+ %native(Advise) Advise;
+ %{
+ PyObject *PyIMAPISession::Advise(PyObject *self, PyObject *args)
+ {
+ IMAPISession *_swig_self;
+ if ((_swig_self=GetI(self))==NULL) return NULL;
+
+ // @pyparm string|entryId||The entryID of the object
+ // @pyparm int|mask||
+ // @pyparm <o PyIMAPIAdviseSink>|sink||
+ PyObject *obEntry, *obSink;
+ int mask;
+ if(!PyArg_ParseTuple(args,"OkO:Advise",&obEntry, &mask, &obSink))
+ return NULL;
+ char *entryString;
+ Py_ssize_t entryStrLen;
+ if (obEntry==Py_None) {
+ entryString = NULL;
+ entryStrLen = 0;
+ } else if PyString_Check(obEntry) {
+ entryString = PyString_AsString(obEntry);
+ entryStrLen = PyString_Size(obEntry);
+ } else {
+ PyErr_SetString(PyExc_TypeError, "EntryID must be a string or None");
+ return NULL;
+ }
+ IMAPIAdviseSink *psink = NULL;
+ if (!PyCom_InterfaceFromPyObject(obSink, IID_IMAPIAdviseSink, (void **)&psink, FALSE))
+ return NULL;
+ unsigned long connection;
+ HRESULT _result;
+ PyObject *rc;
+ Py_BEGIN_ALLOW_THREADS
+ _result = _swig_self->Advise(entryStrLen, (LPENTRYID)entryString,
+ mask, psink, &connection);
+ Py_END_ALLOW_THREADS
+ if (FAILED(_result))
+ rc = OleSetOleError(_result);
+ else
+ rc = PyLong_FromUnsignedLong(connection);
+ {
+ Py_BEGIN_ALLOW_THREADS
+ psink->Release();
+ Py_END_ALLOW_THREADS
+ }
+ return rc;
+ }
+ %}
+
+ // @pyswig |Unadvise|
+ // @pyparm int|connection||Value returned from <om PyIMAPISession.Advise>
+ HRESULT Unadvise(unsigned long connection);
+
+
// @pyswig int|CompareEntryIDs|Compares two entry identifiers belonging to a particular address book provider to determine if they refer to the same address book object
// @rdesc The result is set to TRUE if the two entry identifiers refer to the same object, and FALSE otherwise.
Index: PyIMAPITable.i
===================================================================
RCS file: /cvsroot/pywin32/pywin32/com/win32comext/mapi/src/PyIMAPITable.i,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** PyIMAPITable.i 12 Jun 2004 13:29:31 -0000 1.2
--- PyIMAPITable.i 9 Aug 2008 01:51:39 -0000 1.3
***************
*** 126,134 ****
);
! /*
! Unadvise|Cancels the sending of notifications previously set up with a call to the IMAPITable::Advise method.
!
QuerySortOrder|Retrieves the current sort order for a table.
--- 126,135 ----
);
! // @pyswig |Unadvise|Cancels the sending of notifications previously set up with a call to the IMAPITable::Advise method.
! HRESULT Unadvise(
! unsigned long handle); // @pyparm int|handle||Handle returned from <om PyIMAPITable.Advise>
+ /*
QuerySortOrder|Retrieves the current sort order for a table.
|