2
Common conversion routines for exchange2ical
6
Copyright (C) Julien Kerihuel 2008
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 3 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "libexchange2ical/libexchange2ical.h"
24
static void ical2exchange_get_properties(struct ical2exchange *ical2exchange, icalcomponent *vevent){
25
icalproperty *icalProp = NULL;
26
icalproperty *prop = NULL;
28
enum icalproperty_kind propType;
30
icalProp=icalcomponent_get_first_property(vevent, ICAL_ANY_PROPERTY);
33
propType=icalproperty_isa(icalProp);
35
case ICAL_ATTACH_PROPERTY:
36
if(!ical2exchange->attachEvent){
37
ical2exchange->attachEvent=icalcomponent_new_vevent();
39
prop = icalproperty_new_clone(icalProp);
40
icalcomponent_add_property(ical2exchange->attachEvent, prop);
42
case ICAL_ATTENDEE_PROPERTY:
43
if(!ical2exchange->attendeeEvent){
44
ical2exchange->attendeeEvent=icalcomponent_new_vevent();
46
prop = icalproperty_new_clone(icalProp);
47
icalcomponent_add_property(ical2exchange->attendeeEvent, prop);
49
case ICAL_CATEGORIES_PROPERTY:
50
if(!ical2exchange->categoriesEvent){
51
ical2exchange->categoriesEvent=icalcomponent_new_vevent();
53
prop = icalproperty_new_clone(icalProp);
54
icalcomponent_add_property(ical2exchange->categoriesEvent, prop);
56
case ICAL_CLASS_PROPERTY:
57
ical2exchange->classProp=icalProp;
59
case ICAL_COMMENT_PROPERTY:
60
ical2exchange->commentProp=icalProp;
62
case ICAL_CONTACT_PROPERTY:
63
if(!ical2exchange->contactEvent){
64
ical2exchange->contactEvent=icalcomponent_new_vevent();
66
prop = icalproperty_new_clone(icalProp);
67
icalcomponent_add_property(ical2exchange->contactEvent, prop);
69
case ICAL_CREATED_PROPERTY:
71
case ICAL_DESCRIPTION_PROPERTY:
72
ical2exchange->descriptionProp=icalProp;
74
case ICAL_DTEND_PROPERTY:
75
ical2exchange->dtendProp=icalProp;
77
case ICAL_DTSTAMP_PROPERTY:
78
ical2exchange->dtstampProp=icalProp;
80
case ICAL_DTSTART_PROPERTY:
81
ical2exchange->dtstartProp=icalProp;
83
case ICAL_DURATION_PROPERTY:
84
ical2exchange->durationProp=icalProp;
86
case ICAL_EXDATE_PROPERTY:
87
if(!ical2exchange->exdateEvent){
88
ical2exchange->exdateEvent=icalcomponent_new_vevent();
90
prop = icalproperty_new_clone(icalProp);
91
ical2exchange->exdateCount ++;
92
icalcomponent_add_property(ical2exchange->exdateEvent, prop);
94
case ICAL_LASTMODIFIED_PROPERTY:
96
case ICAL_LOCATION_PROPERTY:
97
ical2exchange->locationProp=icalProp;
99
case ICAL_ORGANIZER_PROPERTY:
100
//TODO: figure out how to MS-OXOABK
101
ical2exchange->organizerProp=icalProp;
103
case ICAL_PRIORITY_PROPERTY:
104
ical2exchange->priorityProp=icalProp;
106
case ICAL_RDATE_PROPERTY:
107
if(!ical2exchange->rdateEvent){
108
ical2exchange->rdateEvent=icalcomponent_new_vevent();
110
prop = icalproperty_new_clone(icalProp);
111
ical2exchange->rdateCount ++;
112
icalcomponent_add_property(ical2exchange->rdateEvent, prop);
114
case ICAL_RECURRENCEID_PROPERTY:
115
ical2exchange->recurrenceidProp=icalProp;
117
case ICAL_RESOURCES_PROPERTY:
118
if(!ical2exchange->resourcesEvent){
119
ical2exchange->resourcesEvent=icalcomponent_new_vevent();
121
prop = icalproperty_new_clone(icalProp);
122
icalcomponent_add_property(ical2exchange->resourcesEvent, prop);
124
case ICAL_RRULE_PROPERTY:
125
ical2exchange->rruleProp=icalProp;
127
case ICAL_SEQUENCE_PROPERTY:
128
ical2exchange->sequenceProp=icalProp;
130
case ICAL_STATUS_PROPERTY:
131
ical2exchange->statusProp=icalProp;
133
case ICAL_SUMMARY_PROPERTY:
134
ical2exchange->summaryProp=icalProp;
136
case ICAL_TRANSP_PROPERTY:
137
ical2exchange->transpProp=icalProp;
139
case ICAL_UID_PROPERTY:
141
ical2exchange->uidProp=icalProp;
143
case ICAL_X_PROPERTY:
144
xname=icalproperty_get_x_name(icalProp);
145
if(!strcmp(xname,"X-MICROSOFT-CDO-BUSYSTATUS")){
146
ical2exchange->x_busystatusProp=icalProp;
147
} else if(!strcmp(xname,"X-MICROSOFT-MSNCALENDAR-BUSYSTATUS")){
148
ical2exchange->x_busystatusProp=icalProp;
149
} else if(!strcmp(xname,"X-MICROSOFT-CDO-APPT-SEQUENCE")){
150
ical2exchange->x_sequenceProp=icalProp;
151
} else if(!strcmp(xname,"X-MICROSOFT-CDO-IMPORTANCE")){
152
ical2exchange->x_importanceProp=icalProp;
153
} else if(!strcmp(xname,"X-MICROSOFT-MSNCALENDAR-IMPORTANCE")){
154
ical2exchange->x_importanceProp=icalProp;
155
} else if(!strcmp(xname,"X-MICROSOFT-CDO-INTENDEDSTATUS")){
156
ical2exchange->x_intendedProp=icalProp;
157
} else if(!strcmp(xname,"X-MICROSOFT-MSNCALENDAR-INTENDEDSTATUS")){
158
ical2exchange->x_intendedProp=icalProp;
159
} else if(!strcmp(xname,"X-MICROSOFT-CDO-OWNERAPPTID")){
160
ical2exchange->x_ownerapptidProp=icalProp;
161
} else if(!strcmp(xname,"X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE")){
162
ical2exchange->x_attendeecriticalchangeProp=icalProp;
163
} else if(!strcmp(xname,"X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE")){
164
ical2exchange->x_ownercriticalchangeProp=icalProp;
165
} else if(!strcmp(xname,"X-MICROSOFT-CDO-REPLYTIME")){
166
ical2exchange->x_replytimeProp=icalProp;
167
} else if(!strcmp(xname,"X-MICROSOFT-DISALLOW-COUNTER")){
168
ical2exchange->x_disallowcounterProp=icalProp;
169
} else if(!strcmp(xname,"X-MICROSOFT-ISDRAFT")){
170
ical2exchange->x_isdraftProp=icalProp;
171
} else if(!strcmp(xname,"X-MS-OLK-ALLOWEXTERNCHECK")){
172
ical2exchange->x_allowexterncheckProp=icalProp;
173
} else if(!strcmp(xname,"X-MS-OLK-APPTLASTSEQUENCE")){
174
ical2exchange->x_apptlastsequenceProp=icalProp;
175
} else if(!strcmp(xname,"X-MS-OLK-APPTSEQTIME")){
176
ical2exchange->x_apptseqtimeProp=icalProp;
177
} else if(!strcmp(xname,"X-MS-OLK-AUTOFILLLOCATION")){
178
ical2exchange->x_autofilllocationProp=icalProp;
179
} else if(!strcmp(xname,"X-MS-OLK-AUTOSTARTCHECK")){
180
ical2exchange->x_autostartcheckProp=icalProp;
181
} else if(!strcmp(xname,"X-MS-OLK-CONFCHECK")){
182
ical2exchange->x_confcheckProp=icalProp;
183
} else if(!strcmp(xname,"X-MS-OLK-COLLABORATEDDOC")){
184
ical2exchange->x_collaborateddocProp=icalProp;
185
} else if(!strcmp(xname,"X-MS-OLK-CONFTYPE")){
186
ical2exchange->x_conftypeProp=icalProp;
187
} else if(!strcmp(xname,"X-MS-OLK-MWSURL")){
188
ical2exchange->x_mwsurlProp=icalProp;
189
} else if(!strcmp(xname,"X-MS-OLK-NETSHOWURL")){
190
ical2exchange->x_netshowurlProp=icalProp;
191
} else if(!strcmp(xname,"X-MS-OLK-ONLINEPASSWORD")){
192
ical2exchange->x_onlinepasswordProp=icalProp;
193
} else if(!strcmp(xname,"X-MS-OLK-ORGALIAS")){
194
ical2exchange->x_orgaliasProp=icalProp;
195
} else if(!strcmp(xname,"X-MS-OLK-ORIGINALEND")){
196
ical2exchange->x_originalendProp=icalProp;
197
} else if(!strcmp(xname,"X-MS-OLK-ORIGINALSTART")){
198
ical2exchange->x_originalstartProp=icalProp;
205
icalProp=icalcomponent_get_next_property(vevent, ICAL_ANY_PROPERTY);
208
ical2exchange->valarmEvent = icalcomponent_get_first_component(vevent,ICAL_VALARM_COMPONENT);
212
static void ical2exchange_convert_event(struct ical2exchange *ical2exchange)
214
ical2exchange_property_ATTACH(ical2exchange);
215
// //TODO ATTENDEE, ORGANIZER, x_ms_ok_sender
216
ical2exchange_property_CATEGORIES(ical2exchange);
217
ical2exchange_property_CLASS(ical2exchange);
218
ical2exchange_property_COMMENT(ical2exchange);
219
ical2exchange_property_CONTACT(ical2exchange);
220
ical2exchange_property_DESCRIPTION(ical2exchange);
221
ical2exchange_property_DTSTAMP(ical2exchange);
222
ical2exchange_property_DTSTART_DTEND(ical2exchange);
223
ical2exchange_property_LOCATION(ical2exchange);
224
ical2exchange_property_PRIORITY(ical2exchange);
225
ical2exchange_property_RRULE_EXDATE_RDATE(ical2exchange);
226
ical2exchange_property_SEQUENCE(ical2exchange);
227
ical2exchange_property_STATUS(ical2exchange);
228
ical2exchange_property_SUMMARY(ical2exchange);
229
ical2exchange_property_VALARM(ical2exchange);
230
ical2exchange_property_X_ALLOWEXTERNCHECK(ical2exchange);
231
ical2exchange_property_X_APPTSEQTIME(ical2exchange);
232
ical2exchange_property_X_APPTLASTSEQUENCE(ical2exchange);
233
ical2exchange_property_X_ATTENDEE_CRITICAL_CHANGE(ical2exchange);
234
ical2exchange_property_X_AUTOFILLLOCATION(ical2exchange);
235
ical2exchange_property_X_AUTOSTARTCHECK(ical2exchange);
236
ical2exchange_property_X_COLLABORATEDDOC(ical2exchange);
237
ical2exchange_property_X_CONFCHECK(ical2exchange);
238
ical2exchange_property_X_CONFTYPE(ical2exchange);
239
ical2exchange_property_X_DISALLOW_COUNTER(ical2exchange);
240
ical2exchange_property_X_INTENDEDSTATUS(ical2exchange);
241
ical2exchange_property_X_ISDRAFT(ical2exchange);
242
ical2exchange_property_X_MWSURL(ical2exchange);
243
ical2exchange_property_X_NETSHOWURL(ical2exchange);
244
ical2exchange_property_X_ONLINEPASSWORD(ical2exchange);
245
ical2exchange_property_X_ORGALIAS(ical2exchange);
246
ical2exchange_property_X_ORIGINALEND_ORIGINALSTART(ical2exchange);
247
ical2exchange_property_X_OWNER_CRITICAL_CHANGE(ical2exchange);
248
ical2exchange_property_X_OWNERAPPTID(ical2exchange);
249
ical2exchange_property_X_REPLYTIME(ical2exchange);
252
static void ical2exchange_init(struct ical2exchange *ical2exchange, TALLOC_CTX *mem_ctx)
254
ical2exchange->mem_ctx = mem_ctx;
255
ical2exchange->classProp = NULL;
256
ical2exchange->commentProp = NULL;
257
ical2exchange->descriptionProp = NULL;
258
ical2exchange->dtendProp = NULL;
259
ical2exchange->dtstampProp = NULL;
260
ical2exchange->dtstartProp = NULL;
261
ical2exchange->durationProp = NULL;
262
ical2exchange->locationProp = NULL;
263
ical2exchange->organizerProp = NULL;
264
ical2exchange->priorityProp = NULL;
265
ical2exchange->recurrenceidProp = NULL;
266
ical2exchange->rruleProp = NULL;
267
ical2exchange->sequenceProp = NULL;
268
ical2exchange->statusProp = NULL;
269
ical2exchange->summaryProp = NULL;
270
ical2exchange->transpProp = NULL;
271
ical2exchange->uidProp = NULL;
272
ical2exchange->attachEvent = NULL;
273
ical2exchange->attendeeEvent = NULL;
274
ical2exchange->categoriesEvent = NULL;
275
ical2exchange->contactEvent = NULL;
276
ical2exchange->exdateEvent = NULL;
277
ical2exchange->rdateEvent = NULL;
278
ical2exchange->resourcesEvent = NULL;
279
ical2exchange->valarmEvent = NULL;
280
ical2exchange->x_busystatusProp = NULL;
281
ical2exchange->x_sequenceProp = NULL;
282
ical2exchange->x_importanceProp = NULL;
283
ical2exchange->x_intendedProp= NULL;
284
ical2exchange->x_ownerapptidProp = NULL;
285
ical2exchange->x_attendeecriticalchangeProp = NULL;
286
ical2exchange->x_ownercriticalchangeProp = NULL;
287
ical2exchange->x_replytimeProp = NULL;
288
ical2exchange->x_disallowcounterProp = NULL;
289
ical2exchange->x_isdraftProp = NULL;
290
ical2exchange->x_allowexterncheckProp = NULL;
291
ical2exchange->x_apptlastsequenceProp = NULL;
292
ical2exchange->x_apptseqtimeProp = NULL;
293
ical2exchange->x_autofilllocationProp = NULL;
294
ical2exchange->x_autostartcheckProp = NULL;
295
ical2exchange->x_confcheckProp = NULL;
296
ical2exchange->x_collaborateddocProp = NULL;
297
ical2exchange->x_conftypeProp = NULL;
298
ical2exchange->x_mwsurlProp = NULL;
299
ical2exchange->x_netshowurlProp = NULL;
300
ical2exchange->x_onlinepasswordProp = NULL;
301
ical2exchange->x_originalstartProp = NULL;
302
ical2exchange->x_originalendProp = NULL;
303
ical2exchange->x_orgaliasProp = NULL;
305
ical2exchange->lpProps = NULL;
306
ical2exchange->rdateCount = 0 ;
307
ical2exchange->exdateCount = 0;
308
ical2exchange->cValues = 0;
312
static void ical2exchange_reset(struct ical2exchange *ical2exchange)
314
if(ical2exchange->attachEvent){
315
icalcomponent_free(ical2exchange->attachEvent);
317
if(ical2exchange->attendeeEvent){
318
icalcomponent_free(ical2exchange->attendeeEvent);
321
if(ical2exchange->contactEvent){
322
icalcomponent_free(ical2exchange->contactEvent);
324
if(ical2exchange->exdateEvent){
325
icalcomponent_free(ical2exchange->exdateEvent);
327
if(ical2exchange->rdateEvent){
328
icalcomponent_free(ical2exchange->rdateEvent);
330
if(ical2exchange->resourcesEvent){
331
icalcomponent_free(ical2exchange->resourcesEvent);
333
if(ical2exchange->categoriesEvent){
334
icalcomponent_free(ical2exchange->categoriesEvent);
336
ical2exchange_init(ical2exchange, NULL);
339
void _IcalEvent2Exchange(mapi_object_t *obj_folder, icalcomponent *vevent)
341
struct ical2exchange ical2exchange;
343
enum MAPISTATUS retval;
344
mapi_object_t obj_message;
345
ical2exchange.obj_message = &obj_message;
347
ical2exchange.method=ICAL_METHOD_PUBLISH;
348
mapi_object_init(&obj_message);
351
if(icalcomponent_isa(vevent) != ICAL_VEVENT_COMPONENT) return;
353
mem_ctx = talloc_named(NULL, 0, "ical2exchange");
354
ical2exchange.lpProps = talloc_array(mem_ctx, struct SPropValue, 2);
356
ical2exchange_init(&ical2exchange, mem_ctx);
357
ical2exchange_get_properties(&ical2exchange, vevent);
358
ical2exchange_convert_event(&ical2exchange);
360
retval = CreateMessage(obj_folder, &obj_message);
362
if (retval != MAPI_E_SUCCESS){
363
mapi_errstr("CreateMessage", GetLastError());
365
retval = SetProps(&obj_message, ical2exchange.lpProps, ical2exchange.cValues);
366
if (retval != MAPI_E_SUCCESS){
367
mapi_errstr("SetProps", GetLastError());
369
retval = SaveChangesMessage(obj_folder, &obj_message, KeepOpenReadOnly);
370
if (retval != MAPI_E_SUCCESS){
371
mapi_errstr("SaveChangesMessage", GetLastError());
377
MAPIFreeBuffer(ical2exchange.lpProps);
378
ical2exchange_reset(&ical2exchange);
379
talloc_free(mem_ctx);