Index: libmapi/mapi_notification.h
===================================================================
--- libmapi/mapi_notification.h	(revision 1322)
+++ libmapi/mapi_notification.h	(working copy)
@@ -32,6 +32,7 @@
 	uint32_t		NotificationFlags;	/* events mask associated */
 	mapi_id_t		parentID;		/* parent EntryID == FID here */
 	mapi_notify_callback_t	callback;		/* callback to run when */
+	void			*private_data;		/* private data for the callback */
 	struct mapi_object     	obj_notif;		/* notification object */
 	struct notifications	*prev;
 	struct notifications	*next;
Index: libmapi/IMAPISupport.c
===================================================================
--- libmapi/IMAPISupport.c	(revision 1322)
+++ libmapi/IMAPISupport.c	(working copy)
@@ -42,6 +42,7 @@
    \param WholeStore whether the scope for this notification is whole
    database
    \param notify_callback notification callback function.
+   \param private_data the data to be passed at the callback function when invoked
    
    The Notification Flags can take the following values:
    - fnevCriticalError
@@ -71,7 +72,8 @@
 _PUBLIC_ enum MAPISTATUS Subscribe(mapi_object_t *obj, uint32_t	*connection, 
 				   uint16_t NotificationFlags,
 				   bool WholeStore,
-				   mapi_notify_callback_t notify_callback)
+				   mapi_notify_callback_t notify_callback,
+				   void			*private_data)
 {
 	TALLOC_CTX			*mem_ctx;
 	struct mapi_request		*mapi_request;
@@ -153,6 +155,7 @@
 
 	notification->NotificationFlags = NotificationFlags;
 	notification->callback = notify_callback;
+	notification->private_data = private_data;
 
 	DLIST_ADD(notify_ctx->notifications, notification);
 
@@ -215,10 +218,8 @@
 	return MAPI_E_SUCCESS;
 }
 
-
-static enum MAPISTATUS ProcessNotification(struct mapi_notify_ctx *notify_ctx, 
-					   struct mapi_response *mapi_response,
-					   void *private_data)
+enum MAPISTATUS ProcessNotification(struct mapi_notify_ctx *notify_ctx, 
+					   struct mapi_response *mapi_response)
 {
 	struct notifications	*notification;
 	void			*NotificationData;
@@ -303,7 +304,7 @@
 					if (notification->callback) {
 						notification->callback(mapi_response->mapi_repl[i].u.mapi_Notify.NotificationType,
 								       (void *)NotificationData,
-								       (void *)private_data);
+								       notification->private_data);
 					}
 				}
 				notification = notification->next;
@@ -313,7 +314,45 @@
 	return MAPI_E_SUCCESS;
 }
 
+/**
+   \details Force notification of pending events
 
+   This function force the server to send any pending notificaion and
+   process them. These MAPI notifications are next compared to the
+   registered ones and the callback specified in Subscribe() called if
+   it matches.
+
+   \return MAPI_E_SUCCESS on success, otherwise MAPI error.  
+
+   \note Developers may also call GetLastError() to retrieve the last
+   MAPI error code. Possible MAPI error codes are:
+   - MAPI_E_NOT_INITIALIZED: MAPI subsystem has not been initialized
+   - MAPI_E_CALL_FAILED: A network problem was encountered during the
+     transaction
+
+   \sa RegisterNotification, Subscribe, Unsubscribe, GetLastError
+*/
+_PUBLIC_ enum MAPISTATUS DispatchNotifications(struct mapi_session *session)
+{
+	struct mapi_response	*mapi_response;
+	enum MAPISTATUS		retval;
+	NTSTATUS		status;
+
+	/* sanity checks */
+	OPENCHANGE_RETVAL_IF(!global_mapi_ctx, MAPI_E_NOT_INITIALIZED, NULL);
+	OPENCHANGE_RETVAL_IF(!session, MAPI_E_INVALID_PARAMETER, NULL);
+	OPENCHANGE_RETVAL_IF(!session->notify_ctx, MAPI_E_INVALID_PARAMETER, NULL);
+
+	status = emsmdb_transaction_null((struct emsmdb_context *)session->emsmdb->ctx, &mapi_response);
+	if (!NT_STATUS_IS_OK(status))
+		return MAPI_E_CALL_FAILED;
+
+	retval = ProcessNotification(session->notify_ctx, mapi_response);
+	talloc_free(mapi_response);
+	return retval;
+}
+
+
 /**
    \details Wait for notifications and process them
 
@@ -366,7 +405,7 @@
 			if (!NT_STATUS_IS_OK(status)) {
 				err = -1;
 			} else {
-				retval = ProcessNotification(notify_ctx, mapi_response, private_data);
+				retval = ProcessNotification(notify_ctx, mapi_response);
 				OPENCHANGE_RETVAL_IF(retval, retval, NULL);
 			}
 		}
Index: utils/mapitest/modules/module_oxcnotif.c
===================================================================
--- utils/mapitest/modules/module_oxcnotif.c	(revision 1322)
+++ utils/mapitest/modules/module_oxcnotif.c	(working copy)
@@ -78,7 +78,7 @@
 	}
 
 	/* Step 4. Subscribe for notifications */
-	retval = Subscribe(&obj_store, &tcon, fnevObjectCopied, true, cb);
+	retval = Subscribe(&obj_store, &tcon, fnevObjectCopied, true, cb, NULL);
 	mapitest_print_retval(mt, "Subscribe");
 	if (retval != MAPI_E_SUCCESS) {
 		return false;
Index: utils/openchangeclient.c
===================================================================
--- utils/openchangeclient.c	(revision 1322)
+++ utils/openchangeclient.c	(working copy)
@@ -2316,8 +2316,10 @@
 	ulEventMask = fnevNewMail|fnevObjectCreated|fnevObjectDeleted|
 		fnevObjectModified|fnevObjectMoved|fnevObjectCopied|
 		fnevSearchComplete|fnevTableModified|fnevStatusObjectModified;
-	retval = Subscribe(obj_store, &ulConnection, ulEventMask, true, (mapi_notify_callback_t)callback);
-	retval = Subscribe(&obj_inbox, &ulConnection, ulEventMask, false, (mapi_notify_callback_t)callback);
+	retval = Subscribe(obj_store, &ulConnection, ulEventMask, true, (mapi_notify_callback_t)callback,
+		(void*) obj_store);
+	retval = Subscribe(&obj_inbox, &ulConnection, ulEventMask, false, (mapi_notify_callback_t)callback,
+		(void*) obj_store);
 	if (retval != MAPI_E_SUCCESS) return false;
 
 	/* wait for notifications: infinite loop */
Index: torture/mapi_newmail.c
===================================================================
--- torture/mapi_newmail.c	(revision 1322)
+++ torture/mapi_newmail.c	(working copy)
@@ -98,11 +98,11 @@
 
 	/* newmail and created|modified object notifications in inbox */
 	ulEventMask = fnevObjectCreated;
-	retval = Subscribe(&obj_inbox, &ulConnection, ulEventMask, false, (mapi_notify_callback_t)callback);
+	retval = Subscribe(&obj_inbox, &ulConnection, ulEventMask, false, (mapi_notify_callback_t)callback, (void*) &obj_store);
 	mapi_errstr("Subscribe", GetLastError());
 
 	ulEventMask = fnevNewMail;
-	retval = Subscribe(&obj_inbox, &ulConnection, ulEventMask, false, (mapi_notify_callback_t)callback);
+	retval = Subscribe(&obj_inbox, &ulConnection, ulEventMask, false, (mapi_notify_callback_t)callback, (void*) &obj_store);
 	mapi_errstr("Subscribe", GetLastError());
 
 
