~ubuntu-branches/debian/experimental/openchange/experimental

« back to all changes in this revision

Viewing changes to libexchange2ical/ical2exchange_property.c

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij, Mathieu Parent, Jelmer Vernooij
  • Date: 2010-06-19 00:14:54 UTC
  • mfrom: (1.2.1 upstream) (4.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100619001454-c9qbwzlbv3rgqrir
Tags: 1:0.9+svn1970-1
[ Mathieu Parent ]
* Add Vcs-Browser
* libmapi-dev depends on libndr-standard-dev.
  Fix "Missing dependency on samba4-dev" (Closes: #549012)

[ Jelmer Vernooij ]
* Use source format version 3.
* Bump standards version to 3.8.4.
* New upstream snapshot.
* Add build dependency on zlib1g-dev. Closes: #577330
* Migrate packaging to Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Common conversion routines for exchange2ical
 
3
 
 
4
   OpenChange Project
 
5
 
 
6
   Copyright (C) Julien Kerihuel 2008
 
7
 
 
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.
 
12
   
 
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.
 
17
   
 
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/>.
 
20
*/
 
21
 
 
22
#include <libexchange2ical/libexchange2ical.h>
 
23
 
 
24
#define MAXCAT  100000
 
25
 
 
26
 
 
27
/*Taken from Samba4 code*/
 
28
/*
 
29
  this base64 decoder was taken from jitterbug (written by tridge).
 
30
  we might need to replace it with a new version
 
31
*/
 
32
static int ldb_base64_decode(char *s)
 
33
{
 
34
        const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
 
35
        int bit_offset=0, byte_offset, idx, i, n;
 
36
        uint8_t *d = (uint8_t *)s;
 
37
        char *p=NULL;
 
38
 
 
39
        n=i=0;
 
40
 
 
41
        while (*s && (p=strchr(b64,*s))) {
 
42
                idx = (int)(p - b64);
 
43
                byte_offset = (i*6)/8;
 
44
                bit_offset = (i*6)%8;
 
45
                d[byte_offset] &= ~((1<<(8-bit_offset))-1);
 
46
                if (bit_offset < 3) {
 
47
                        d[byte_offset] |= (idx << (2-bit_offset));
 
48
                        n = byte_offset+1;
 
49
                } else {
 
50
                        d[byte_offset] |= (idx >> (bit_offset-2));
 
51
                        d[byte_offset+1] = 0;
 
52
                        d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF;
 
53
                        n = byte_offset+2;
 
54
                }
 
55
                s++; i++;
 
56
        }
 
57
        if (bit_offset >= 3) {
 
58
                n--;
 
59
        }
 
60
 
 
61
        if (*s && !p) {
 
62
                /* the only termination allowed */
 
63
                if (*s != '=') {
 
64
                        return -1;
 
65
                }
 
66
        }
 
67
 
 
68
        /* null terminate */
 
69
        d[n] = 0;
 
70
        return n;
 
71
}
 
72
 
 
73
 
 
74
void ical2exchange_property_ATTACH(struct ical2exchange *ical2exchange)
 
75
{
 
76
        int             data;
 
77
        char            *extension = NULL;
 
78
        char            *filename = NULL;
 
79
        const char      *fmttype = NULL;
 
80
        icalattach      *icalattach = NULL;
 
81
        icalparameter   *fmttypePar = NULL;
 
82
        icalparameter   *xfilePar = NULL;
 
83
        const char      *xname = NULL;
 
84
        icalproperty    *attachProp = NULL;
 
85
        
 
86
        /*sanity check*/
 
87
        if(!ical2exchange->attachEvent) return;
 
88
        
 
89
        attachProp=icalcomponent_get_first_property(ical2exchange->attachEvent, ICAL_ATTACH_PROPERTY);
 
90
        while(attachProp){
 
91
        
 
92
                icalattach = icalproperty_get_attach(attachProp);
 
93
                data = ldb_base64_decode((char *) icalattach_get_data (icalattach));
 
94
                
 
95
                /*FMTTYPE*/
 
96
                fmttypePar = icalproperty_get_first_parameter(attachProp, ICAL_FMTTYPE_PARAMETER);
 
97
                if(fmttypePar){
 
98
                        fmttype = icalparameter_get_fmttype(fmttypePar);
 
99
                }
 
100
                
 
101
                /*X-FIlename*/
 
102
                xfilePar = icalproperty_get_first_parameter(attachProp, ICAL_X_PARAMETER);
 
103
                if(xfilePar){
 
104
                        xname = icalparameter_get_xname(xfilePar);
 
105
                        if(!strcmp(xname,"X-FILENAME")){
 
106
                                filename = (char *) icalparameter_get_x(xfilePar);
 
107
                
 
108
                        }
 
109
                }
 
110
                
 
111
                /*Extension*/
 
112
                if(filename){
 
113
                        char buff[256]; 
 
114
                        char *temp;
 
115
                        strncpy(buff,filename, 255);
 
116
                        buff[255] = '\0';
 
117
                        extension = strtok(buff, ".");
 
118
                        while((temp = strtok(NULL, "."))) extension = temp;
 
119
                }
 
120
                
 
121
                printf("Create a new attachment object with\n");
 
122
                printf("        set PidTagAttachDataBinary to %d\n", data);
 
123
                printf("        set PidTagAttachExtension to %s\n", extension);
 
124
                printf("        set PidTagAttachFilename to %s\n", filename);
 
125
                printf("        set PidTagAttachLongFilename to %s\n", filename);
 
126
                printf("        set PidTagAttachMimeTag to %s\n", fmttype);
 
127
                printf("        set PidTagAttachFlags to 0x00000000\n");
 
128
                printf("        set PidTagAttachMethod to 0x00000001\n");
 
129
                printf("        set PidTagAttachmentContactPhoto to FALSE\n");
 
130
                printf("        set PidTagAttachmentFlags to 0x00000000\n");
 
131
                printf("        set PidTagAttachEncoding to empty SBinary");
 
132
                printf("        set PidTagAttachmentHidden to FALSE\n");
 
133
                printf("        set PidTagAttachmentLinkId to 0x00000000\n");
 
134
                printf("        set PidTagDisplayName to  %s\n", filename);
 
135
                printf("        set PidTagExceptionEndTime to 0x0CB34557A3DD4000\n");
 
136
                printf("        set PidTagExceptionStartTime to 0x0CB34557A3DD4000\n");
 
137
                printf("        set PidTagRenderingPosition to 0xFFFFFFFF\n");
 
138
                
 
139
                attachProp=icalcomponent_get_next_property(ical2exchange->attachEvent, ICAL_ATTACH_PROPERTY);
 
140
        }
 
141
}
 
142
 
 
143
 
 
144
//TODO:
 
145
void ical2exchange_property_CATEGORIES(struct ical2exchange *ical2exchange)
 
146
{
 
147
        struct StringArray_r *sArray;
 
148
        char **stringArray = NULL;
 
149
        char string[256];
 
150
        char *value;
 
151
        char *tok;
 
152
        icalproperty *categoriesProp;
 
153
        uint32_t i = 0;
 
154
 
 
155
        /*sanity check*/
 
156
        if(!ical2exchange->categoriesEvent) return;
 
157
        
 
158
        sArray = talloc(ical2exchange->mem_ctx, struct StringArray_r);
 
159
        
 
160
        categoriesProp = icalcomponent_get_first_property(ical2exchange->categoriesEvent, ICAL_CATEGORIES_PROPERTY);
 
161
        sArray->cValues = 0;
 
162
        while(categoriesProp){
 
163
        
 
164
                value = strdup(icalproperty_get_categories(categoriesProp));
 
165
                tok = strtok(value, ",");
 
166
                while(tok){
 
167
                        if(!stringArray){
 
168
                                stringArray = talloc_array(ical2exchange->mem_ctx, char *, 1);
 
169
                        } else {
 
170
                                stringArray = talloc_realloc(ical2exchange->mem_ctx, stringArray, char *, sArray->cValues+2);
 
171
                        }
 
172
                        strcpy(string, "");
 
173
                        while(tok[i]){
 
174
                                if (strlen(string) == 255) break;
 
175
                                //remove beginning and ending white spaces
 
176
                                if((tok[i]!= ' ' || (tok[i+1] && tok[i+1] != ' ')) && (strlen(string) || tok[i]!=' ')){
 
177
                                        strncat(string, &tok[i], 1);
 
178
                                }
 
179
                                i++;
 
180
                        }
 
181
                        stringArray[sArray->cValues] = talloc_strdup(ical2exchange->mem_ctx, string);
 
182
                        sArray->cValues++;
 
183
                        i=0;
 
184
                        tok= strtok(NULL, ",");
 
185
                }
 
186
                categoriesProp = icalcomponent_get_next_property(ical2exchange->categoriesEvent, ICAL_CATEGORIES_PROPERTY);
 
187
 
 
188
        }
 
189
        sArray->lppszA= (const char **) stringArray;
 
190
        
 
191
        /* SetProps */
 
192
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidNameKeywords, 
 
193
                                        (const void *) sArray);
 
194
}
 
195
 
 
196
void ical2exchange_property_CLASS(struct ical2exchange *ical2exchange)
 
197
{
 
198
        enum icalproperty_class class;
 
199
        uint32_t        temp = 0;
 
200
        uint32_t        *tag;
 
201
        
 
202
        /*sanity check*/
 
203
        if(!ical2exchange->classProp) return;
 
204
        
 
205
        class = icalproperty_get_class(ical2exchange->classProp); 
 
206
        
 
207
        switch(class){
 
208
                case ICAL_CLASS_PUBLIC:
 
209
                        temp = 0x00000000;
 
210
                        break;
 
211
                case ICAL_CLASS_X:
 
212
                        temp = 0x00000001;
 
213
                        break;
 
214
                case ICAL_CLASS_PRIVATE:
 
215
                        temp = 0x00000002;
 
216
                        break;
 
217
                case ICAL_CLASS_CONFIDENTIAL:
 
218
                        temp = 0x00000003;
 
219
                        break;
 
220
                case ICAL_CLASS_NONE:
 
221
                        return;
 
222
        }
 
223
        
 
224
        tag = talloc(ical2exchange->mem_ctx, uint32_t);
 
225
        *tag = temp;
 
226
        
 
227
        /* SetProps */
 
228
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PR_SENSITIVITY, 
 
229
                                        (const void *) tag);
 
230
}
 
231
 
 
232
void ical2exchange_property_COMMENT(struct ical2exchange *ical2exchange)
 
233
{
 
234
        const char *comment;
 
235
 
 
236
        /*sanity check*/
 
237
        if(!ical2exchange->commentProp) return;
 
238
        if(ical2exchange->method != ICAL_METHOD_COUNTER && ical2exchange->method != ICAL_METHOD_REPLY) return;
 
239
        
 
240
        comment  = icalproperty_get_comment(ical2exchange->commentProp);
 
241
        comment = talloc_strdup(ical2exchange->mem_ctx, comment);
 
242
        
 
243
        /* SetProps */
 
244
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PR_BODY,
 
245
                        (const void *) comment);
 
246
}
 
247
 
 
248
void ical2exchange_property_CONTACT(struct ical2exchange *ical2exchange)
 
249
{
 
250
        struct StringArray_r *sArray;
 
251
        char *value;
 
252
        char **stringArray = NULL;
 
253
        icalproperty *contactProp;
 
254
        
 
255
        /*sanity check*/
 
256
        if(!ical2exchange->contactEvent) return;
 
257
        
 
258
 
 
259
        contactProp=icalcomponent_get_first_property(ical2exchange->contactEvent, ICAL_CONTACT_PROPERTY);
 
260
        sArray = talloc(ical2exchange->mem_ctx, struct StringArray_r);  
 
261
        sArray->cValues =0;
 
262
        while(contactProp){
 
263
                if(!stringArray){
 
264
                        stringArray = talloc_array(ical2exchange->mem_ctx, char *, 1);
 
265
                } else {
 
266
                        stringArray = talloc_realloc(ical2exchange->mem_ctx, stringArray, char *, sArray->cValues+2);
 
267
                }
 
268
                value = strdup(icalproperty_get_contact(contactProp));
 
269
                if(strlen(value)<500){
 
270
                        stringArray[sArray->cValues] = talloc_strdup(ical2exchange->mem_ctx, value);
 
271
                } else {
 
272
                        value[499] = '\0';
 
273
                        stringArray[sArray->cValues] = talloc_strndup(ical2exchange->mem_ctx, value, 500);
 
274
                }
 
275
                sArray->cValues++;
 
276
                contactProp=icalcomponent_get_next_property(ical2exchange->contactEvent, ICAL_CONTACT_PROPERTY);
 
277
        }
 
278
                
 
279
        /*set up struct*/
 
280
        sArray->lppszA=(const char **) stringArray;
 
281
 
 
282
        /* SetProps */
 
283
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidContacts, 
 
284
                                        (const void *) sArray);
 
285
 
 
286
}
 
287
 
 
288
void ical2exchange_property_DESCRIPTION(struct ical2exchange *ical2exchange)
 
289
{
 
290
        const char *description;
 
291
        
 
292
        /*sanity check*/
 
293
        if(!ical2exchange->descriptionProp) return;
 
294
        
 
295
        if(ical2exchange->method == ICAL_METHOD_COUNTER || ical2exchange->method == ICAL_METHOD_REPLY) return;
 
296
        
 
297
        description  = icalproperty_get_description(ical2exchange->descriptionProp);
 
298
        description = talloc_strdup(ical2exchange->mem_ctx, description);
 
299
        
 
300
        /* SetProps */
 
301
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PR_BODY,
 
302
                        (const void *) description);    
 
303
}
 
304
 
 
305
void ical2exchange_property_DTSTAMP(struct ical2exchange *ical2exchange)
 
306
{
 
307
        struct FILETIME *ft;
 
308
        icaltimetype dtstamp;
 
309
        
 
310
        /*sanity check*/
 
311
        if(!ical2exchange->dtstampProp) return;
 
312
                
 
313
        dtstamp  = icalproperty_get_dtstamp(ical2exchange->dtstampProp);
 
314
        ft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
315
        *ft = get_FILETIME_from_icaltimetype(&dtstamp);
 
316
        
 
317
        if(ical2exchange->method == ICAL_METHOD_COUNTER || ical2exchange->method == ICAL_METHOD_REPLY){
 
318
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAttendeeCriticalChange,
 
319
                               (const void *) ft);
 
320
        } else {
 
321
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidOwnerCriticalChange,
 
322
                               (const void *) ft);
 
323
        }
 
324
}
 
325
 
 
326
void ical2exchange_property_DTSTART_DTEND(struct ical2exchange *ical2exchange)
 
327
{
 
328
        icaltimetype dtstart;
 
329
        icaltimetype dtend;
 
330
        struct FILETIME *startft; 
 
331
        struct FILETIME *endft; 
 
332
        double difference;
 
333
        uint32_t *duration; 
 
334
        
 
335
        /*sanity check*/
 
336
        if(!ical2exchange->dtstartProp) return;
 
337
        if(!ical2exchange->dtendProp) return;
 
338
 
 
339
        /*dtstart property*/
 
340
        dtstart  = icalproperty_get_dtstart(ical2exchange->dtstartProp);
 
341
        startft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
342
        *startft = get_FILETIME_from_icaltimetype(&dtstart);
 
343
        
 
344
        /*dtend property*/
 
345
        dtend  = icalproperty_get_dtend(ical2exchange->dtendProp);
 
346
        endft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
347
        *endft = get_FILETIME_from_icaltimetype(&dtend);
 
348
        
 
349
        if(ical2exchange->method == ICAL_METHOD_COUNTER){
 
350
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentProposedStartWhole,
 
351
                               (const void *) startft);
 
352
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentProposedEndWhole,
 
353
                               (const void *) endft);
 
354
        } else {
 
355
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentStartWhole,
 
356
                               (const void *) startft);
 
357
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentEndWhole,
 
358
                               (const void *) endft);
 
359
                               
 
360
                /*duration property*/
 
361
                duration = talloc(ical2exchange->mem_ctx, uint32_t);
 
362
                difference =  difftime(nt_time_to_unix(FILETIME_to_NTTIME(*endft)), 
 
363
                                       nt_time_to_unix(FILETIME_to_NTTIME(*startft)));  
 
364
                *duration = difference/60;
 
365
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentDuration,
 
366
                                (const void *) duration);
 
367
                /*check if all day appointment*/
 
368
                if(*duration==1440 && dtstart.hour==0 && dtstart.minute==0){
 
369
                        uint32_t *allday = talloc(ical2exchange->mem_ctx, uint32_t);
 
370
                        *allday = 0x00000001;
 
371
                        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentSubType,
 
372
                                        (const void *) allday);
 
373
                }
 
374
        }
 
375
}
 
376
 
 
377
void ical2exchange_property_LOCATION(struct ical2exchange *ical2exchange)
 
378
{
 
379
        uint32_t *langtag;
 
380
        char location[256] = "";
 
381
        icalparameter *param = NULL;
 
382
        const char *value;
 
383
        char *string;
 
384
        
 
385
        /*sanity check*/
 
386
        if(!ical2exchange->locationProp) return;
 
387
                
 
388
        value  = icalproperty_get_location(ical2exchange->locationProp);
 
389
        int i;
 
390
        
 
391
        for(i=0; i<255; i++){
 
392
                if(!value[i]) break;
 
393
                char c = value[i];
 
394
                if(c !='\xD' && c!='\xA' )
 
395
                        strncat(location, &c, 1);
 
396
        }
 
397
        string = talloc_strdup(ical2exchange->mem_ctx, location);
 
398
 
 
399
        /* SetProps */
 
400
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidLocation, 
 
401
                        (const void *) string);
 
402
                        
 
403
        if((param=icalproperty_get_first_parameter(ical2exchange->locationProp, ICAL_LANGUAGE_PARAMETER))){
 
404
                const char* langName;
 
405
                langtag = talloc(ical2exchange->mem_ctx, uint32_t);
 
406
                langName = icalparameter_get_language(param);
 
407
                *langtag = mapi_get_lcid_from_language(langName);
 
408
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PR_MESSAGE_LOCALE_ID, 
 
409
                                        (const void *) langtag);
 
410
        } 
 
411
 
 
412
}
 
413
 
 
414
void ical2exchange_property_PRIORITY(struct ical2exchange *ical2exchange)
 
415
{
 
416
        uint32_t temp = 0;
 
417
        uint32_t *tag;
 
418
        
 
419
        if(ical2exchange->x_importanceProp){
 
420
                const char *value = icalproperty_get_x(ical2exchange->x_importanceProp);
 
421
                switch(atoi(value)){
 
422
                        case 0:
 
423
                                temp = 0x00000000;
 
424
                                break;
 
425
                        case 1:
 
426
                                temp = 0x00000001;
 
427
                                break;
 
428
                        case 2:
 
429
                                temp = 0x00000002;
 
430
                                break;
 
431
                }
 
432
        } else if(ical2exchange->priorityProp){
 
433
                switch(icalproperty_get_priority(ical2exchange->priorityProp)){
 
434
                        case 0:
 
435
                                return;
 
436
                        case 1:
 
437
                        case 2:
 
438
                        case 3:
 
439
                        case 4:
 
440
                                temp = 0x00000002;
 
441
                                break;
 
442
                        case 5:
 
443
                                temp = 0x00000001;
 
444
                                break;
 
445
                        case 6:
 
446
                        case 7:
 
447
                        case 8:
 
448
                        case 9:
 
449
                                temp = 0x00000000;
 
450
                                break;
 
451
                        default:
 
452
                                return;
 
453
                }
 
454
        } else return;
 
455
        
 
456
        tag = talloc(ical2exchange->mem_ctx, uint32_t);
 
457
        *tag = temp;
 
458
        
 
459
        /* SetProps */
 
460
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentSequence, 
 
461
                                        (const void *) tag);    
 
462
}
 
463
 
 
464
//TODO: Finish this
 
465
void ical2exchange_property_RRULE_EXDATE_RDATE(struct ical2exchange *ical2exchange)
 
466
{
 
467
        struct RecurrencePattern        rp;
 
468
        struct icalrecurrencetype       irt;
 
469
        struct icaltimetype             next;
 
470
        struct icaltimetype             last;
 
471
        icalrecur_iterator              *ritr;
 
472
        icaltimetype                    dtstart;
 
473
        icaltimetype                    rdate;
 
474
        icaltimetype                    exdate;
 
475
        icalproperty                    *exdateProp;
 
476
        icalproperty                    *rdateProp;
 
477
        enum CalendarType               calendarType;
 
478
        enum EndType                    endType;
 
479
        enum icalrecurrencetype_weekday weekday; 
 
480
        uint32_t                        startTime;
 
481
        uint32_t                        endTime;
 
482
        uint32_t                        occurrenceCount;
 
483
        uint32_t                        i;
 
484
        uint32_t                        modifiedInstanceDates[ical2exchange->rdateCount];
 
485
        uint32_t                        deletedInstanceDates[ical2exchange->exdateCount+ical2exchange->rdateCount];
 
486
        
 
487
        if(!ical2exchange->rruleProp) return;
 
488
        if(!ical2exchange->dtstartProp) return;
 
489
        
 
490
        irt =  icalproperty_get_rrule(ical2exchange->rruleProp);
 
491
 
 
492
        /*StartTime*/
 
493
        enum icalrecurrencetype_weekday icalrecurrencetype_day_day_of_week(short day);
 
494
        dtstart  = icalproperty_get_dtstart(ical2exchange->dtstartProp);
 
495
        dtstart.hour = 0;
 
496
        dtstart.minute = 0;
 
497
        dtstart.second = 0;
 
498
        startTime = get_minutes_from_icaltimetype(dtstart);
 
499
        
 
500
        /*WeekDay*/
 
501
        if(irt.week_start == ICAL_NO_WEEKDAY){
 
502
                weekday = icalrecurrencetype_day_day_of_week(icaltime_day_of_week(dtstart));
 
503
        } else {
 
504
                weekday = irt.week_start;
 
505
        }
 
506
        
 
507
        /*calendarType*/
 
508
        //if(ical2exchange->calscaleProp){
 
509
                //calendarType = get_exchange_calendartype(icalproperty_get_x(ical2exchange->calscaleProp));
 
510
                
 
511
        //} else {
 
512
                calendarType = CAL_DEFAULT;
 
513
        //}
 
514
        
 
515
        /*endType occurrenceCount endTime*/
 
516
        if(irt.count || !icaltime_is_null_time(irt.until)){
 
517
                endType = END_AFTER_N_OCCURRENCES;
 
518
                occurrenceCount = irt.count;
 
519
                
 
520
                ritr = icalrecur_iterator_new(irt,dtstart);
 
521
                next=icalrecur_iterator_next(ritr);
 
522
                
 
523
                while (!icaltime_is_null_time(next)){
 
524
                        last = next;
 
525
                        next=icalrecur_iterator_next(ritr);
 
526
                        
 
527
                        if(!irt.count) occurrenceCount++;
 
528
                }
 
529
                
 
530
                endTime = get_minutes_from_icaltimetype(last); 
 
531
                icalrecur_iterator_free(ritr);
 
532
                
 
533
        } else {
 
534
                endType = END_NEVER_END;
 
535
                occurrenceCount = 0x0000000A;
 
536
                endTime         = 0x5AE980DF;
 
537
        }
 
538
        
 
539
        /*Common values for all rrule*/
 
540
        rp.ReaderVersion        = 0x3004;
 
541
        rp.WriterVersion        = 0x3004;
 
542
        rp.CalendarType         = calendarType;
 
543
        rp.FirstDateTime        = startTime;
 
544
        rp.SlidingFlag          = 0x00000000;
 
545
        rp.EndType              = endType;
 
546
        rp.OccurrenceCount      = occurrenceCount;
 
547
        rp.FirstDOW             = get_exchange_day_from_ical(weekday);  
 
548
        rp.StartDate            = startTime;
 
549
        rp.EndDate              = endTime;
 
550
        
 
551
        /*Specific values*/
 
552
        switch(irt.freq){
 
553
                case ICAL_DAILY_RECURRENCE:
 
554
                        rp.RecurFrequency       = RecurFrequency_Daily;
 
555
                        rp.PatternType          = PatternType_Day;
 
556
                        rp.Period               = 1440 * irt.interval;
 
557
                        break;
 
558
                case ICAL_WEEKLY_RECURRENCE:
 
559
                        rp.RecurFrequency       = RecurFrequency_Weekly;
 
560
                        rp.PatternType          = PatternType_Day;
 
561
                        rp.Period               = irt.interval;
 
562
                        break;
 
563
                case ICAL_MONTHLY_RECURRENCE:
 
564
                        rp.RecurFrequency       = RecurFrequency_Monthly;
 
565
                        rp.Period               = irt.interval;
 
566
                        
 
567
                        if(irt.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX){
 
568
                                rp.PatternType  = PatternType_Month;
 
569
                                
 
570
                                if(irt.by_month_day[0] == -1){
 
571
                                        rp.PatternTypeSpecific.Day = 0x0000001F;
 
572
                                } else {
 
573
                                        rp.PatternTypeSpecific.Day = irt.by_month_day[0];
 
574
                                }
 
575
                                
 
576
                        } else {
 
577
                                rp.PatternType  = PatternType_MonthNth;
 
578
                                i = 0;
 
579
                                rp.PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern = 0;
 
580
                                while( irt.by_day[i] != ICAL_RECURRENCE_ARRAY_MAX){
 
581
                                        rp.PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern  |= get_exchange_rdfDays_from_ical(irt.by_day[i]);
 
582
                                        i++;
 
583
                                }
 
584
                                if(irt.by_set_pos[0] == -1) rp.PatternTypeSpecific.MonthRecurrencePattern.N = RecurrenceN_Last;
 
585
                                else rp.PatternTypeSpecific.MonthRecurrencePattern.N = irt.by_set_pos[0];
 
586
                        }
 
587
                        break;
 
588
                case ICAL_YEARLY_RECURRENCE:
 
589
                        rp.RecurFrequency       = RecurFrequency_Yearly;
 
590
                        rp.Period               = 12 * irt.interval;
 
591
                        
 
592
                        /*Nth*/
 
593
                        if(irt.by_day[0] == ICAL_RECURRENCE_ARRAY_MAX){
 
594
                                rp.PatternType  = PatternType_Month;
 
595
                                if(irt.by_month_day[0] == -1){
 
596
                                        rp.PatternTypeSpecific.Day = 0x0000001F;
 
597
                                } else {
 
598
                                        rp.PatternTypeSpecific.Day = irt.by_month_day[0];
 
599
                                }
 
600
                        } else {
 
601
                                rp.PatternType  = PatternType_MonthNth;
 
602
                                i = 0;
 
603
                                rp.PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern = 0;
 
604
                                while( irt.by_day[i] != ICAL_RECURRENCE_ARRAY_MAX){
 
605
                                        rp.PatternTypeSpecific.MonthRecurrencePattern.WeekRecurrencePattern  |= get_exchange_rdfDays_from_ical(irt.by_day[i]);
 
606
                                        i++;
 
607
                                }
 
608
                                if(irt.by_set_pos[0] == -1) rp.PatternTypeSpecific.MonthRecurrencePattern.N = RecurrenceN_Last;
 
609
                                else rp.PatternTypeSpecific.MonthRecurrencePattern.N = irt.by_set_pos[0];
 
610
                        }
 
611
                        break;
 
612
                default:
 
613
                        printf("not handled yet\n");
 
614
                        
 
615
        }
 
616
        
 
617
 
 
618
        /*deletedInstanceDates & modifiedInstanceDates*/
 
619
        if(ical2exchange->exdateEvent){
 
620
                exdateProp=icalcomponent_get_first_property(ical2exchange->exdateEvent, ICAL_EXDATE_PROPERTY);
 
621
 
 
622
                for(i=0; i<ical2exchange->exdateCount; i++){
 
623
                        exdate = icalproperty_get_exdate(exdateProp);
 
624
                        deletedInstanceDates[i] = get_minutes_from_icaltimetype(exdate);
 
625
                        exdateProp=icalcomponent_get_first_property(ical2exchange->exdateEvent, ICAL_EXDATE_PROPERTY);
 
626
                }
 
627
        }
 
628
        
 
629
        if(ical2exchange->rdateEvent){
 
630
                rdateProp = icalcomponent_get_first_property(ical2exchange->rdateEvent, ICAL_EXDATE_PROPERTY);
 
631
 
 
632
                for(i=0; i<ical2exchange->rdateCount; i++){
 
633
                        rdate = icalproperty_get_exdate(rdateProp);
 
634
                        deletedInstanceDates[i + ical2exchange->exdateCount] = get_minutes_from_icaltimetype(rdate);
 
635
                        modifiedInstanceDates[i] = get_minutes_from_icaltimetype(rdate);
 
636
                        rdateProp = icalcomponent_get_first_property(ical2exchange->rdateEvent, ICAL_EXDATE_PROPERTY);
 
637
                }
 
638
        }
 
639
        /*Sort array*/
 
640
        qsort(deletedInstanceDates, ical2exchange->rdateCount + ical2exchange->exdateCount, sizeof(uint32_t), compare_minutes);
 
641
        qsort(modifiedInstanceDates, ical2exchange->rdateCount, sizeof(uint32_t), compare_minutes);
 
642
        
 
643
        rp.DeletedInstanceCount = ical2exchange->rdateCount + ical2exchange->exdateCount;
 
644
        rp.ModifiedInstanceCount = ical2exchange->rdateCount;
 
645
        
 
646
        rp.DeletedInstanceDates = deletedInstanceDates;
 
647
        rp.ModifiedInstanceDates = modifiedInstanceDates;
 
648
        
 
649
        
 
650
}
 
651
 
 
652
void ical2exchange_property_SEQUENCE(struct ical2exchange *ical2exchange)
 
653
{
 
654
        uint32_t temp;
 
655
        uint32_t *tag;
 
656
        
 
657
        if(ical2exchange->x_sequenceProp){
 
658
                temp = atoi(icalproperty_get_x(ical2exchange->x_sequenceProp));
 
659
        } else if(ical2exchange->sequenceProp){
 
660
                temp = icalproperty_get_sequence(ical2exchange->sequenceProp);
 
661
        } else return;
 
662
        
 
663
        tag = talloc(ical2exchange->mem_ctx, uint32_t);
 
664
        *tag = temp;
 
665
        
 
666
        /* SetProps */
 
667
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentSequence, 
 
668
                                        (const void *) tag);    
 
669
}
 
670
 
 
671
void ical2exchange_property_STATUS(struct ical2exchange *ical2exchange)
 
672
{
 
673
        
 
674
        enum icalproperty_status status;
 
675
        enum icalproperty_transp transp;
 
676
        uint32_t *tag;
 
677
        uint32_t temp = 0;
 
678
        const char *prop;
 
679
        
 
680
        if(ical2exchange->x_busystatusProp){
 
681
                prop=icalproperty_get_x(ical2exchange->x_busystatusProp);
 
682
 
 
683
                if(!strcmp(prop, "FREE")){
 
684
                        temp = 0x00000000;
 
685
                } else if(!strcmp(prop, "TENTATIVE")){
 
686
                        temp = 0x00000001;
 
687
                } else if(!strcmp(prop, "BUSY")){
 
688
                        temp = 0x00000002;
 
689
                } else if(!strcmp(prop, "OOF")){
 
690
                        temp = 0x00000003;
 
691
                }
 
692
                
 
693
        } else if(ical2exchange->transpProp){
 
694
                transp = icalproperty_get_transp(ical2exchange->transpProp); 
 
695
                switch(transp){
 
696
                        case ICAL_TRANSP_TRANSPARENT:
 
697
                                temp = 0x00000000;
 
698
                                break;
 
699
                        case ICAL_TRANSP_OPAQUE:
 
700
                                temp = 0x00000002;
 
701
                                break;
 
702
                        default:
 
703
                                return;
 
704
                }
 
705
                
 
706
        } else if(ical2exchange->statusProp){
 
707
                status = icalproperty_get_status(ical2exchange->classProp); 
 
708
                switch(status){
 
709
                        case ICAL_STATUS_CANCELLED:
 
710
                                temp = 0x00000000;
 
711
                                break;
 
712
                        case ICAL_STATUS_TENTATIVE:
 
713
                                temp = 0x00000001;
 
714
                                break;
 
715
                        case ICAL_STATUS_CONFIRMED:
 
716
                                temp = 0x00000002;
 
717
                                break;
 
718
                        default:
 
719
                                return;
 
720
                }
 
721
        } else return;
 
722
        
 
723
        tag = talloc(ical2exchange->mem_ctx, uint32_t);
 
724
        *tag = temp;
 
725
        
 
726
        /* SetProps */
 
727
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidBusyStatus, 
 
728
                                        (const void *) tag);    
 
729
}
 
730
 
 
731
void ical2exchange_property_SUMMARY(struct ical2exchange *ical2exchange)
 
732
{
 
733
        const char *value;
 
734
        uint32_t langtag;
 
735
        char summary[256] = "";
 
736
        icalparameter *param = NULL;
 
737
        char *string;
 
738
        
 
739
        /*sanity check*/
 
740
        if(!ical2exchange->summaryProp) return;
 
741
        
 
742
        value  = icalproperty_get_summary(ical2exchange->summaryProp);
 
743
        
 
744
        int i;
 
745
        
 
746
        for(i=0; i<255; i++){
 
747
                if(!value[i]) break;
 
748
                char c = value[i];
 
749
                if(c !='\xD' && c!='\xA' )
 
750
                        strncat(summary, &c, 1);
 
751
        }
 
752
        string = talloc_strdup(ical2exchange->mem_ctx, summary);
 
753
        
 
754
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PR_SUBJECT, 
 
755
                        (const void *) string);
 
756
        if((param=icalproperty_get_first_parameter(ical2exchange->summaryProp, ICAL_LANGUAGE_PARAMETER))){
 
757
                const char *langName;
 
758
                langName = icalparameter_get_language(param);
 
759
                langtag = mapi_get_lcid_from_language(langName);
 
760
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PR_MESSAGE_LOCALE_ID, 
 
761
                                                (const void *) &langtag);
 
762
        }
 
763
}
 
764
 
 
765
void ical2exchange_property_VALARM(struct ical2exchange *ical2exchange)
 
766
{
 
767
        icalproperty *triggerProp = NULL;
 
768
        uint32_t *duration;
 
769
        icaltimetype dtstart;
 
770
        icaltimetype current;
 
771
        icaltimetype triggerSet;
 
772
        icaltimetype next;
 
773
        
 
774
        const icaltimezone *timezone; 
 
775
        struct FILETIME *rtimeft;
 
776
        struct FILETIME *rsignalft;
 
777
        struct icalrecurrencetype       irt;
 
778
        icalrecur_iterator              *ritr;
 
779
        struct icaltriggertype trigger;
 
780
        bool *set;
 
781
        
 
782
 
 
783
        /*sanity check*/
 
784
        if(!ical2exchange->valarmEvent) return;
 
785
        if(!ical2exchange->dtstartProp) return;
 
786
 
 
787
        triggerProp = icalcomponent_get_first_property(ical2exchange->valarmEvent, ICAL_TRIGGER_PROPERTY);
 
788
        if(!triggerProp) return;
 
789
        
 
790
        trigger = icalproperty_get_trigger(triggerProp);
 
791
        dtstart  = icalproperty_get_dtstart(ical2exchange->dtstartProp);
 
792
        duration = talloc(ical2exchange->mem_ctx, uint32_t);
 
793
        
 
794
        if(trigger.duration.is_neg){
 
795
                *duration = -trigger.duration.minutes;
 
796
        } else {
 
797
                *duration = trigger.duration.minutes;
 
798
        }
 
799
 
 
800
        timezone = icaltime_get_timezone(dtstart);
 
801
        current = icaltime_current_time_with_zone(timezone);
 
802
        
 
803
        if(icaltime_compare(dtstart, current)) {
 
804
                rtimeft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
805
                rsignalft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
806
 
 
807
                *rtimeft = get_FILETIME_from_icaltimetype(&dtstart);
 
808
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidReminderTime, 
 
809
                                                (const void *) rtimeft);
 
810
                        
 
811
                triggerSet = icaltime_add(dtstart, trigger.duration);
 
812
                *rsignalft = get_FILETIME_from_icaltimetype(&triggerSet);
 
813
                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidReminderSignalTime, 
 
814
                                                (const void *) rsignalft);
 
815
        } else if(ical2exchange->rruleProp) {
 
816
                irt =  icalproperty_get_rrule(ical2exchange->rruleProp);
 
817
                ritr = icalrecur_iterator_new(irt,dtstart);
 
818
                next = icalrecur_iterator_next(ritr);
 
819
                
 
820
                while (!icaltime_is_null_time(next)){
 
821
                        if(icaltime_compare(next, current)) {
 
822
                                rtimeft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
823
                                rsignalft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
824
                                
 
825
                                *rtimeft = get_FILETIME_from_icaltimetype(&next);
 
826
                                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidReminderTime, 
 
827
                                        (const void *) rtimeft);
 
828
                                        
 
829
                                triggerSet = icaltime_add(next, trigger.duration);
 
830
                                *rsignalft = get_FILETIME_from_icaltimetype(&triggerSet);
 
831
                                ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidReminderSignalTime, 
 
832
                                        (const void *) &rsignalft);
 
833
                                break;
 
834
                        }
 
835
                        next=icalrecur_iterator_next(ritr);
 
836
                }
 
837
        } else return;
 
838
        
 
839
        set = talloc(ical2exchange->mem_ctx, bool);
 
840
        *set = true;
 
841
        
 
842
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidReminderSet, 
 
843
                                        (const void *) set);
 
844
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidReminderDelta, 
 
845
                                        (const void *) duration);
 
846
}
 
847
 
 
848
void ical2exchange_property_X_ALLOWEXTERNCHECK(struct ical2exchange *ical2exchange)
 
849
{
 
850
        const char *prop;
 
851
        bool *allow;
 
852
        
 
853
        if(!ical2exchange->x_allowexterncheckProp) return;
 
854
        
 
855
        prop=icalproperty_get_x(ical2exchange->x_allowexterncheckProp);
 
856
        allow = talloc(ical2exchange->mem_ctx, bool);
 
857
        
 
858
        if(strcmp(prop, "TRUE")){
 
859
                *allow = true;
 
860
        } else {
 
861
                *allow = false;
 
862
        }
 
863
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAllowExternalCheck, 
 
864
                                        (const void *) allow);
 
865
}
 
866
 
 
867
void ical2exchange_property_X_APPTSEQTIME(struct ical2exchange *ical2exchange)
 
868
{
 
869
        const char *prop;
 
870
        struct FILETIME *ft;
 
871
        
 
872
        if(!ical2exchange->x_apptseqtimeProp) return;
 
873
        
 
874
        ft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
875
        
 
876
        prop=icalproperty_get_x(ical2exchange->x_apptseqtimeProp);
 
877
        *ft = get_FILETIME_from_string(prop);
 
878
 
 
879
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentSequenceTime, 
 
880
                                        (const void *) ft);
 
881
}
 
882
 
 
883
void ical2exchange_property_X_APPTLASTSEQUENCE(struct ical2exchange *ical2exchange)
 
884
{
 
885
        uint32_t *tag;
 
886
        const char *prop;
 
887
        
 
888
        if(!ical2exchange->x_apptlastsequenceProp) return;
 
889
 
 
890
        prop=icalproperty_get_x(ical2exchange->x_apptlastsequenceProp);
 
891
        tag = talloc(ical2exchange->mem_ctx, uint32_t);
 
892
        *tag=atoi(prop);
 
893
        
 
894
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentLastSequence, 
 
895
                                        (const void *) tag);
 
896
}
 
897
 
 
898
void ical2exchange_property_X_ATTENDEE_CRITICAL_CHANGE(struct ical2exchange *ical2exchange)
 
899
{
 
900
        const char *prop;
 
901
        struct FILETIME *ft;
 
902
        
 
903
        if(!ical2exchange->x_attendeecriticalchangeProp) return;
 
904
        
 
905
        prop=icalproperty_get_x(ical2exchange->x_attendeecriticalchangeProp);
 
906
        ft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
907
        *ft = get_FILETIME_from_string(prop);
 
908
 
 
909
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAttendeeCriticalChange, 
 
910
                                        (const void *) ft);
 
911
}
 
912
 
 
913
void ical2exchange_property_X_AUTOFILLLOCATION(struct ical2exchange *ical2exchange)
 
914
{
 
915
        const char *prop;
 
916
        bool *autoFill;
 
917
        
 
918
        if(!ical2exchange->x_autofilllocationProp) return;
 
919
        
 
920
        prop=icalproperty_get_x(ical2exchange->x_autofilllocationProp);
 
921
        autoFill = talloc(ical2exchange->mem_ctx, bool);
 
922
        
 
923
        if(strcmp(prop, "TRUE")){
 
924
                *autoFill = true;
 
925
        } else {
 
926
                *autoFill = false;
 
927
        }
 
928
        
 
929
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAutoFillLocation, 
 
930
                                        (const void *) autoFill);
 
931
}
 
932
 
 
933
void ical2exchange_property_X_AUTOSTARTCHECK(struct ical2exchange *ical2exchange)
 
934
{
 
935
        const char *prop;
 
936
        bool *autoStart;
 
937
        
 
938
        if(!ical2exchange->x_autostartcheckProp) return;
 
939
        
 
940
        prop=icalproperty_get_x(ical2exchange->x_autostartcheckProp);
 
941
        autoStart = talloc(ical2exchange->mem_ctx, bool);       
 
942
        
 
943
        if(strcmp(prop, "TRUE")){
 
944
                *autoStart = true;
 
945
        } else {
 
946
                *autoStart = false;
 
947
        }
 
948
        
 
949
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAutoStartCheck, 
 
950
                                        (const void *) autoStart);
 
951
}
 
952
 
 
953
void ical2exchange_property_X_COLLABORATEDDOC(struct ical2exchange *ical2exchange)
 
954
{
 
955
        const char *prop;
 
956
        
 
957
        if(!ical2exchange->x_collaborateddocProp) return;
 
958
        
 
959
        prop=icalproperty_get_x(ical2exchange->x_collaborateddocProp);          
 
960
        
 
961
        prop = talloc_strdup(ical2exchange->mem_ctx, prop);
 
962
        
 
963
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidCollaborateDoc, 
 
964
                                        (const void *) prop);
 
965
}
 
966
 
 
967
void ical2exchange_property_X_CONFCHECK(struct ical2exchange *ical2exchange)
 
968
{
 
969
        const char *prop;
 
970
        bool *confCheck;
 
971
        
 
972
        if(!ical2exchange->x_confcheckProp) return;
 
973
        
 
974
        prop=icalproperty_get_x(ical2exchange->x_confcheckProp);
 
975
        confCheck = talloc(ical2exchange->mem_ctx, bool);
 
976
        
 
977
        if(strcmp(prop, "TRUE")){
 
978
                *confCheck = true;
 
979
        } else {
 
980
                *confCheck = false;
 
981
        }
 
982
        
 
983
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidConferencingCheck, 
 
984
                                        (const void *) confCheck);
 
985
}
 
986
 
 
987
void ical2exchange_property_X_CONFTYPE(struct ical2exchange *ical2exchange)
 
988
{
 
989
        uint32_t *tag;
 
990
        const char *prop;
 
991
        
 
992
        if(!ical2exchange->x_conftypeProp) return;
 
993
        
 
994
        prop=icalproperty_get_x(ical2exchange->x_conftypeProp);
 
995
        tag = talloc(ical2exchange->mem_ctx, uint32_t);
 
996
        *tag=atoi(prop);
 
997
        
 
998
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidConferencingType, 
 
999
                                        (const void *) tag);
 
1000
}
 
1001
 
 
1002
void ical2exchange_property_X_DISALLOW_COUNTER(struct ical2exchange *ical2exchange)
 
1003
{
 
1004
        const char *prop;
 
1005
        bool *disallow;
 
1006
        
 
1007
        if(!ical2exchange->x_disallowcounterProp) return;
 
1008
        
 
1009
        prop=icalproperty_get_x(ical2exchange->x_disallowcounterProp);
 
1010
        disallow = talloc(ical2exchange->mem_ctx, bool);
 
1011
        
 
1012
        if(strcmp(prop, "TRUE")){
 
1013
                *disallow = true;
 
1014
        } else {
 
1015
                *disallow = false;
 
1016
        }
 
1017
        
 
1018
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentNotAllowPropose, 
 
1019
                                        (const void *) disallow);
 
1020
}
 
1021
 
 
1022
void ical2exchange_property_X_INTENDEDSTATUS(struct ical2exchange *ical2exchange)
 
1023
{
 
1024
        uint32_t *tag;
 
1025
        const char *prop;
 
1026
        
 
1027
        if(!ical2exchange->x_intendedProp) return;
 
1028
        
 
1029
        prop=icalproperty_get_x(ical2exchange->x_intendedProp);
 
1030
        tag = talloc(ical2exchange->mem_ctx,uint32_t);
 
1031
        
 
1032
        if(!strcmp(prop, "FREE")){
 
1033
                *tag = 0x00000000;
 
1034
        } else if(!strcmp(prop, "TENTATIVE")){
 
1035
                *tag = 0x00000001;
 
1036
        } else if(!strcmp(prop, "BUSY")){
 
1037
                *tag = 0x00000002;
 
1038
        } else if(!strcmp(prop, "OOF")){
 
1039
                *tag = 0x00000003;
 
1040
        }
 
1041
        
 
1042
        
 
1043
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidIntendedBusyStatus, 
 
1044
                                        (const void *) tag);
 
1045
}
 
1046
 
 
1047
void ical2exchange_property_X_ISDRAFT(struct ical2exchange *ical2exchange)
 
1048
{
 
1049
        const char *prop;
 
1050
        bool *isDraft;
 
1051
        
 
1052
        isDraft = talloc(ical2exchange->mem_ctx, bool);
 
1053
        
 
1054
        if(ical2exchange->method == ICAL_METHOD_COUNTER || ical2exchange->method == ICAL_METHOD_REPLY 
 
1055
                || ical2exchange->method == ICAL_METHOD_REQUEST || ical2exchange->method == ICAL_METHOD_CANCEL){
 
1056
                
 
1057
                *isDraft = true;
 
1058
        } else {
 
1059
                if(ical2exchange->x_isdraftProp){
 
1060
                        prop=icalproperty_get_x(ical2exchange->x_isdraftProp);          
 
1061
                        if(strcmp(prop, "TRUE")){
 
1062
                                *isDraft = true;
 
1063
                        } else {
 
1064
                                *isDraft = false;
 
1065
                        }
 
1066
                } else {
 
1067
                        *isDraft = false;
 
1068
                }
 
1069
        }
 
1070
        
 
1071
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidFInvited, 
 
1072
                                        (const void *) isDraft);
 
1073
}
 
1074
 
 
1075
void ical2exchange_property_X_MWSURL(struct ical2exchange *ical2exchange)
 
1076
{
 
1077
        char *mwsurl;
 
1078
        const char *prop;
 
1079
        
 
1080
        if(!ical2exchange->x_mwsurlProp) return;
 
1081
        
 
1082
        prop = icalproperty_get_x(ical2exchange->x_mwsurlProp);         
 
1083
        mwsurl = talloc_strdup(ical2exchange->mem_ctx, prop);
 
1084
        
 
1085
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidMeetingWorkspaceUrl, 
 
1086
                                        (const void *) mwsurl);
 
1087
}
 
1088
 
 
1089
void ical2exchange_property_X_NETSHOWURL(struct ical2exchange *ical2exchange)
 
1090
{
 
1091
        char *netshow;
 
1092
        const char *prop;
 
1093
        
 
1094
        if(!ical2exchange->x_netshowurlProp) return;
 
1095
        
 
1096
        prop = icalproperty_get_x(ical2exchange->x_netshowurlProp);             
 
1097
        netshow = talloc_strdup(ical2exchange->mem_ctx, prop);
 
1098
 
 
1099
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidNetShowUrl, 
 
1100
                                        (const void *) netshow);
 
1101
}
 
1102
 
 
1103
void ical2exchange_property_X_ONLINEPASSWORD(struct ical2exchange *ical2exchange)
 
1104
{
 
1105
        char *onlinepass;
 
1106
        const char *prop;
 
1107
        
 
1108
        if(!ical2exchange->x_onlinepasswordProp) return;
 
1109
        
 
1110
        prop = icalproperty_get_x(ical2exchange->x_onlinepasswordProp);         
 
1111
        onlinepass = talloc_strdup(ical2exchange->mem_ctx, prop);
 
1112
 
 
1113
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidOnlinePassword, 
 
1114
                                        (const void *) onlinepass);
 
1115
}
 
1116
 
 
1117
void ical2exchange_property_X_ORGALIAS(struct ical2exchange *ical2exchange)
 
1118
{
 
1119
        char *orgalias;
 
1120
        const char *prop;
 
1121
        
 
1122
        if(!ical2exchange->x_orgaliasProp) return;
 
1123
        
 
1124
        prop = icalproperty_get_x(ical2exchange->x_orgaliasProp);               
 
1125
        orgalias = talloc_strdup(ical2exchange->mem_ctx, prop);
 
1126
        
 
1127
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidOrganizerAlias, 
 
1128
                                        (const void *) orgalias);
 
1129
}
 
1130
 
 
1131
void ical2exchange_property_X_ORIGINALEND_ORIGINALSTART(struct ical2exchange *ical2exchange)
 
1132
{
 
1133
        const char *start;
 
1134
        const char *end;
 
1135
        double difference;
 
1136
        uint32_t duration;
 
1137
        struct FILETIME startft;
 
1138
        struct FILETIME endft;
 
1139
        
 
1140
        /*sanity check*/
 
1141
        if(!ical2exchange->x_originalendProp) return;
 
1142
        if(!ical2exchange->x_originalstartProp) return;
 
1143
        if(ical2exchange->method != ICAL_METHOD_COUNTER) return;
 
1144
        
 
1145
        start = icalproperty_get_x(ical2exchange->x_originalstartProp);
 
1146
        end = icalproperty_get_x(ical2exchange->x_originalendProp);
 
1147
 
 
1148
        startft = get_FILETIME_from_string(start);
 
1149
        endft = get_FILETIME_from_string(end);
 
1150
        
 
1151
        /*duration property*/
 
1152
        difference =  difftime(nt_time_to_unix(FILETIME_to_NTTIME(endft)), 
 
1153
                                     nt_time_to_unix(FILETIME_to_NTTIME(startft)));
 
1154
        duration = difference/60;
 
1155
        
 
1156
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentStartWhole, 
 
1157
                        (const void *) &startft);
 
1158
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentEndWhole, 
 
1159
                        (const void *) &endft);
 
1160
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentDuration, 
 
1161
                        (const void *) &duration);
 
1162
                        
 
1163
}
 
1164
 
 
1165
void ical2exchange_property_X_OWNER_CRITICAL_CHANGE(struct ical2exchange *ical2exchange)
 
1166
{
 
1167
        const char *prop;
 
1168
        struct FILETIME ft;
 
1169
        
 
1170
        if(!ical2exchange->x_ownercriticalchangeProp) return;
 
1171
        
 
1172
        prop=icalproperty_get_x(ical2exchange->x_ownercriticalchangeProp);
 
1173
        ft = get_FILETIME_from_string(prop);
 
1174
 
 
1175
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidOwnerCriticalChange, 
 
1176
                                        (const void *) &ft);
 
1177
}
 
1178
 
 
1179
void ical2exchange_property_X_OWNERAPPTID(struct ical2exchange *ical2exchange)
 
1180
{
 
1181
        uint32_t *tag;
 
1182
        const char *prop;
 
1183
        
 
1184
        if(!ical2exchange->x_ownerapptidProp) return;
 
1185
        
 
1186
        prop=icalproperty_get_x(ical2exchange->x_ownerapptidProp);
 
1187
        
 
1188
        tag = talloc(ical2exchange->mem_ctx, uint32_t);
 
1189
        *tag = atoi(prop);
 
1190
        
 
1191
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PR_OWNER_APPT_ID, 
 
1192
                                        (const void *) tag);
 
1193
}
 
1194
 
 
1195
void ical2exchange_property_X_REPLYTIME(struct ical2exchange *ical2exchange)
 
1196
{
 
1197
        const char *prop;
 
1198
        struct FILETIME *ft;
 
1199
        
 
1200
        if(!ical2exchange->x_replytimeProp) return;
 
1201
        
 
1202
        prop=icalproperty_get_x(ical2exchange->x_replytimeProp);
 
1203
        ft = talloc(ical2exchange->mem_ctx, struct FILETIME);
 
1204
        *ft = get_FILETIME_from_string(prop);
 
1205
 
 
1206
        /* SetProps */
 
1207
        ical2exchange->lpProps = add_SPropValue(ical2exchange->mem_ctx, ical2exchange->lpProps, &ical2exchange->cValues, PidLidAppointmentReplyTime, 
 
1208
                                        (const void *) ft);
 
1209
}