1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
#include "MAPINotification.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <Unknwn.h>
#include <mapidefs.h>
#include <mapiutil.h>
#include "../net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactSourceService.h"
#include "../net_java_sip_communicator_plugin_addrbook_msoutlook_MsOutlookAddrBookContactQuery.h"
/**
* Manages notification for the message data base (used to get the list of
* contact).
*
* @author Vincent Lucas
*/
/**
* The List of events we want to retrieve.
*/
static ULONG EVENT_MASK
= fnevObjectCreated
| fnevObjectDeleted
| fnevObjectModified
| fnevObjectMoved;
/**
* Functions called when an event is fired from the message data base.
*
* @param lpvContext A pointer to the message data base.
* @param cNotifications The number of event in this call.
* @param lpNotifications The list of notifications.
*/
LONG STDAPICALLTYPE onNotify(
LPVOID lpvContext,
ULONG cNotifications,
LPNOTIFICATION lpNotifications)
{
for(unsigned int i = 0; i < cNotifications; ++i)
{
LPUNKNOWN iUnknown = NULL;
if(lpvContext != NULL)
{
iUnknown = openEntry(
lpNotifications[i].info.obj.cbEntryID,
lpNotifications[i].info.obj.lpEntryID,
lpvContext);
}
// A contact has been created
if(lpNotifications[i].ulEventType == fnevObjectCreated)
{
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE)
{
callInsertedCallbackMethod(iUnknown);
}
}
// A contact has been Modified
else if(lpNotifications[i].ulEventType == fnevObjectModified)
{
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE)
{
callUpdatedCallbackMethod(iUnknown);
}
}
// A contact has been deleted.
else if(lpNotifications[i].ulEventType == fnevObjectDeleted)
{
if(lpvContext != NULL)
{
char entryIdStr[lpNotifications[i].info.obj.cbEntryID * 2 + 1];
MsOutlookAddrBookContact_hexFromBin(
//HexFromBin(
(LPBYTE) lpNotifications[i].info.obj.lpEntryID,
lpNotifications[i].info.obj.cbEntryID,
entryIdStr);
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE)
{
callDeletedCallbackMethod(entryIdStr);
}
}
}
// A contact has been deleted (moved to trash).
else if(lpNotifications[i].ulEventType == fnevObjectMoved)
{
if(lpvContext != NULL)
{
char entryIdStr[lpNotifications[i].info.obj.cbEntryID * 2 + 1];
MsOutlookAddrBookContact_hexFromBin(
//HexFromBin(
(LPBYTE) lpNotifications[i].info.obj.lpEntryID,
lpNotifications[i].info.obj.cbEntryID,
entryIdStr);
char parentEntryIdStr[
lpNotifications[i].info.obj.cbParentID * 2 + 1];
MsOutlookAddrBookContact_hexFromBin(
//HexFromBin(
(LPBYTE) lpNotifications[i].info.obj.lpParentID,
lpNotifications[i].info.obj.cbParentID,
parentEntryIdStr);
ULONG wasteBasketTags[] = {1, PR_IPM_WASTEBASKET_ENTRYID};
ULONG wasteBasketNbValues = 0;
LPSPropValue wasteBasketProps = NULL;
((LPMDB)lpvContext)->GetProps(
(LPSPropTagArray) wasteBasketTags,
MAPI_UNICODE,
&wasteBasketNbValues,
&wasteBasketProps);
char wasteBasketEntryIdStr[
wasteBasketProps[0].Value.bin.cb * 2 + 1];
MsOutlookAddrBookContact_hexFromBin(
//HexFromBin(
(LPBYTE) wasteBasketProps[0].Value.bin.lpb,
wasteBasketProps[0].Value.bin.cb,
wasteBasketEntryIdStr);
openEntry(
lpNotifications[i].info.obj.cbParentID,
lpNotifications[i].info.obj.lpParentID,
lpvContext);
if(lpNotifications[i].info.obj.ulObjType == MAPI_MESSAGE
&& strcmp(parentEntryIdStr, wasteBasketEntryIdStr) == 0)
{
callDeletedCallbackMethod(entryIdStr);
}
}
}
if(iUnknown != NULL)
{
iUnknown->Release();
}
}
// A client must always return a S_OK.
return S_OK;
}
/**
* Registers to notification for the given message data base.
*
* @param iUnknown The data base to register to in order to receive events.
*
* @return A unsigned long which is a token wich must be used to call the
* unadvise function for the same message data base.
*/
ULONG registerNotifyMessageDataBase(
LPMDB iUnknown)
{
LPMAPIADVISESINK adviseSink;
MsOutlookAddrBookContact_HrAllocAdviseSink(
//HrAllocAdviseSink(
&onNotify,
iUnknown,
&adviseSink);
ULONG nbConnection = 0;
iUnknown->Advise(
0,
NULL,
EVENT_MASK,
adviseSink,
&nbConnection);
return nbConnection;
}
|