~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to utils/openchangeclient.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "libmapi/libmapi.h"
23
23
#include "libmapi/libmapi_private.h"
 
24
#include "libmapi/mapi_nameid.h"
24
25
#include "libocpf/ocpf.h"
25
 
#include <samba/popt.h>
 
26
#include <popt.h>
26
27
#include <param.h>
27
28
 
28
29
#include "openchangeclient.h"
281
282
static char *build_uniqueID(TALLOC_CTX *mem_ctx, mapi_object_t *obj_folder,
282
283
                            mapi_object_t *obj_message)
283
284
{
284
 
        enum MAPISTATUS         retval;
285
285
        char                    *id;
286
286
        struct SPropTagArray    *SPropTagArray;
287
287
        struct SPropValue       *lpProps;
291
291
 
292
292
        /* retrieve the folder ID */
293
293
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_FID);
294
 
        retval = GetProps(obj_folder, 0, SPropTagArray, &lpProps, &count);
 
294
        GetProps(obj_folder, 0, SPropTagArray, &lpProps, &count);
295
295
        MAPIFreeBuffer(SPropTagArray);
296
296
        if (GetLastError() != MAPI_E_SUCCESS) return NULL;
297
297
        fid = (const uint64_t *)get_SPropValue_data(lpProps);
298
298
 
299
299
        /* retrieve the message ID */
300
300
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_MID);
301
 
        retval = GetProps(obj_message, 0, SPropTagArray, &lpProps, &count);
 
301
        GetProps(obj_message, 0, SPropTagArray, &lpProps, &count);
302
302
        MAPIFreeBuffer(SPropTagArray);
303
303
        if (GetLastError() != MAPI_E_SUCCESS) return NULL;
304
304
        mid = (const uint64_t *)get_SPropValue_data(lpProps);
320
320
{
321
321
        TALLOC_CTX      *mem_ctx;
322
322
        enum MAPISTATUS retval;
323
 
        ssize_t         len;
324
323
        char            *path;
325
324
        mapi_object_t   obj_stream;
326
325
        uint16_t        read_size;
330
329
 
331
330
        if (!filename || !size) return false;
332
331
 
 
332
        mapi_object_init(&obj_stream);
 
333
 
333
334
        mem_ctx = talloc_named(NULL, 0, "store_attachment");
334
 
        mapi_object_init(&obj_stream);
335
335
 
336
336
        if (!(dir = opendir(oclient->store_folder))) {
337
337
                if (mkdir(oclient->store_folder, 0700) == -1) return false;
352
352
        do {
353
353
                retval = ReadStream(&obj_stream, buf, MAX_READ_SIZE, &read_size);
354
354
                if (retval != MAPI_E_SUCCESS) goto error;
355
 
                len = write(fd, buf, read_size);
 
355
                write(fd, buf, read_size);
356
356
        } while (read_size);
357
357
        
358
358
        close(fd);
429
429
                                          PR_MID,
430
430
                                          PR_INST_ID,
431
431
                                          PR_INSTANCE_NUM,
432
 
                                          PR_SUBJECT);
 
432
                                          PR_SUBJECT_UNICODE);
433
433
        retval = SetColumns(&obj_table, SPropTagArray);
434
434
        MAPIFreeBuffer(SPropTagArray);
435
435
        MAPI_RETVAL_IF(retval, retval, mem_ctx);
450
450
                                        struct SRow             aRow;
451
451
                                        
452
452
                                        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_HASATTACH);
453
 
                                        lpProps = talloc_zero(mem_ctx, struct SPropValue);
 
453
                                        lpProps = NULL;
454
454
                                        retval = GetProps(&obj_message, 0, SPropTagArray, &lpProps, &count);
455
455
                                        MAPIFreeBuffer(SPropTagArray);
456
456
                                        if (retval != MAPI_E_SUCCESS) return retval;
488
488
                                                                                                          PR_ATTACH_LONG_FILENAME,
489
489
                                                                                                          PR_ATTACH_SIZE,
490
490
                                                                                                          PR_ATTACH_CONTENT_ID);
491
 
                                                                        lpProps2 = talloc_zero(mem_ctx, struct SPropValue);
 
491
                                                                        lpProps2 = NULL;
492
492
                                                                        retval = GetProps(&obj_attach, MAPI_UNICODE, SPropTagArray, &lpProps2, &count2);
493
493
                                                                        MAPIFreeBuffer(SPropTagArray);
494
494
                                                                        if (retval != MAPI_E_SUCCESS) return retval;
699
699
 
700
700
        /* Open a stream on the parent for the given property */
701
701
        retval = OpenStream(&obj_parent, mapitag, access_flags, &obj_stream);
 
702
        fprintf (stderr, "openstream: retval = %s (0x%.8x)\n",
 
703
                 mapi_get_errstr (retval), retval);
 
704
 
702
705
        if (retval != MAPI_E_SUCCESS) return false;
703
706
 
704
707
        /* WriteStream operation */
717
720
                fflush(0);
718
721
 
719
722
                /* Exit when there is nothing left to write */
720
 
                if (!read_size) return true;
 
723
                if (!read_size) {
 
724
                        mapi_object_release(&obj_stream);
 
725
                        return true;
 
726
                }
721
727
                
722
728
                offset += read_size;
723
729
 
726
732
                }
727
733
        }
728
734
 
 
735
        mapi_object_release(&obj_stream);
 
736
 
729
737
        return true;
730
738
}
731
739
 
763
771
                if (retval != MAPI_E_SUCCESS) return retval;
764
772
        } else {
765
773
                /* Get Sent Items folder but should be using olFolderOutbox */
766
 
                retval = GetDefaultFolder(obj_store, &id_outbox, olFolderSentMail);
 
774
                retval = GetDefaultFolder(obj_store, &id_outbox, olFolderOutbox);
767
775
                if (retval != MAPI_E_SUCCESS) return retval;
768
776
 
769
777
                /* Open outbox folder */
848
856
                        
849
857
                        bin.lpb = (uint8_t *)oclient->pr_html_inline;
850
858
                        bin.cb = strlen(oclient->pr_html_inline);
 
859
 
851
860
                        openchangeclient_stream(mem_ctx, obj_message, obj_stream, PR_HTML, 2, bin);
852
861
                } else {
853
862
                        struct SBinary_short bin;
873
882
                } else {
874
883
                        mapi_object_init(&obj_stream);
875
884
                        openchangeclient_stream(mem_ctx, obj_message, obj_stream, PR_HTML, 2, oclient->pr_html);
876
 
                        mapi_object_release(&obj_stream);
877
885
                }
878
886
        }
879
887
 
911
919
                        if (retval != MAPI_E_SUCCESS) return retval;
912
920
 
913
921
                        /* Stream operations */
 
922
                        mapi_object_init(&obj_stream);
914
923
                        openchangeclient_stream(mem_ctx, obj_attach, obj_stream, PR_ATTACH_DATA_BIN, 2, oclient->attach[i].bin);
915
924
 
916
925
                        /* Save changes on attachment */
983
992
                                          PR_MID,
984
993
                                          PR_INST_ID,
985
994
                                          PR_INSTANCE_NUM,
986
 
                                          PR_SUBJECT);
 
995
                                          PR_SUBJECT_UNICODE);
987
996
        retval = SetColumns(&obj_table, SPropTagArray);
988
997
        if (retval != MAPI_E_SUCCESS) return false;
989
998
        
1117
1126
        }
1118
1127
 
1119
1128
        if (!oclient->update) {
1120
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_CLASS, (const void *)"IPM.Appointment");
 
1129
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_CLASS_UNICODE, (const void *)"IPM.Appointment");
1121
1130
 
1122
1131
                flag = 1;
1123
1132
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_FLAGS, (const void *)&flag);
1252
1261
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PidLidEmail1EmailAddress, (const void *)oclient->email);
1253
1262
        }
1254
1263
        if (!oclient->update) {
1255
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_CLASS, (const void *)"IPM.Contact");
 
1264
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_CLASS_UNICODE, (const void *)"IPM.Contact");
1256
1265
        }
1257
1266
        retval = SetProps(obj_message, 0, lpProps, cValues);
1258
1267
        MAPIFreeBuffer(SPropTagArray);
1360
1369
        }
1361
1370
 
1362
1371
        if (!oclient->update) {
1363
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_CLASS, (const void *)"IPM.Task");
 
1372
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_CLASS_UNICODE, (const void *)"IPM.Task");
1364
1373
                oclient->importance = (oclient->importance == -1) ? 1 : oclient->importance;
1365
1374
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_IMPORTANCE, (const void *)&oclient->importance);
1366
1375
                oclient->taskstatus = (oclient->taskstatus == -1) ? 0 : oclient->taskstatus;
1450
1459
        }
1451
1460
 
1452
1461
        if (!oclient->update) {
1453
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_CLASS, (const void *)"IPM.StickyNote");
 
1462
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_CLASS_UNICODE, (const void *)"IPM.StickyNote");
1454
1463
 
1455
1464
                value = 1;
1456
1465
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_MESSAGE_FLAGS, (const void *)&value);
1789
1798
                                          PR_MID,
1790
1799
                                          PR_INST_ID,
1791
1800
                                          PR_INSTANCE_NUM,
1792
 
                                          PR_SUBJECT,
1793
 
                                          PR_MESSAGE_CLASS,
 
1801
                                          PR_SUBJECT_UNICODE,
 
1802
                                          PR_MESSAGE_CLASS_UNICODE,
1794
1803
                                          PR_RULE_MSG_PROVIDER,
1795
1804
                                          PR_RULE_MSG_NAME);
1796
1805
        retval = SetColumns(&obj_table, SPropTagArray);
2171
2180
        struct HierarchyTableChange     *htable;
2172
2181
        struct ContentsTableChange      *ctable;
2173
2182
        struct ContentsTableChange      *stable;
2174
 
        enum MAPISTATUS                 retval;
2175
2183
 
2176
2184
        switch(NotificationType) {
2177
2185
        case fnevNewMail:
2179
2187
                DEBUG(0, ("[+] New mail Received\n"));
2180
2188
                newmail = (struct NewMailNotification *) NotificationData;
2181
2189
                mapidump_newmail(newmail, "\t");
2182
 
                retval = openchangeclient_findmail((mapi_object_t *)private_data, newmail->MID);
 
2190
                openchangeclient_findmail((mapi_object_t *)private_data, newmail->MID);
2183
2191
                mapi_errstr("openchangeclient_findmail", GetLastError());
2184
2192
                break;
2185
2193
        case fnevObjectCreated:
2310
2318
        mapi_id_t               fid;
2311
2319
        uint32_t                ulConnection;
2312
2320
        uint16_t                ulEventMask;
 
2321
        uint32_t                notification = 0;
2313
2322
        struct mapi_session     *session;
2314
2323
 
2315
2324
        /* Register notification */
2316
2325
        session = mapi_object_get_session(obj_store);
2317
 
        retval = RegisterNotification(session, 0);
 
2326
        retval = RegisterNotification(session);
2318
2327
        if (retval != MAPI_E_SUCCESS) return false;
2319
2328
 
2320
2329
        if (oclient->pf == true) {
2342
2351
        if (retval != MAPI_E_SUCCESS) return false;
2343
2352
 
2344
2353
        /* wait for notifications: infinite loop */
2345
 
        retval = MonitorNotification(mapi_object_get_session(obj_store), (void *)obj_store, NULL);
 
2354
        retval = RegisterAsyncNotification(mapi_object_get_session(obj_store), &notification);
 
2355
        if( retval == MAPI_E_NOT_INITIALIZED ) {
 
2356
                retval = MonitorNotification(mapi_object_get_session(obj_store), (void *)obj_store, NULL);
 
2357
        }
2346
2358
        if (retval != MAPI_E_SUCCESS) return false;
2347
2359
 
2348
2360
        retval = Unsubscribe(mapi_object_get_session(obj_store), ulConnection);
2449
2461
{
2450
2462
        struct SPropTagArray    *SPropTagArray;
2451
2463
        struct SRowSet          *SRowSet;
2452
 
        enum MAPISTATUS         retval;
2453
2464
        uint32_t                i;
2454
2465
        uint32_t                count;
2455
2466
        uint8_t                 ulFlags;
2456
2467
        uint32_t                rowsFetched = 0;
2457
2468
        uint32_t                totalRecs = 0;
2458
2469
 
2459
 
        retval = GetGALTableCount(session, &totalRecs);
 
2470
        GetGALTableCount(session, &totalRecs);
2460
2471
        printf("Total Number of entries in GAL: %d\n", totalRecs);
2461
2472
 
2462
2473
        SPropTagArray = set_SPropTagArray(mem_ctx, 0xc,
2477
2488
        ulFlags = TABLE_START;
2478
2489
        do {
2479
2490
                count += 0x2;
2480
 
                retval = GetGALTable(session, SPropTagArray, &SRowSet, count, ulFlags);
 
2491
                GetGALTable(session, SPropTagArray, &SRowSet, count, ulFlags);
2481
2492
                if ((!SRowSet) || (!(SRowSet->aRow))) {
2482
2493
                        return false;
2483
2494
                }
2716
2727
 
2717
2728
        /* Step 2. Dump properties */
2718
2729
        message_name = (const char *) find_SPropValue_data(&aRow, PR_NORMALIZED_SUBJECT);
2719
 
        publish_start = (const uint32_t *) find_SPropValue_data(&aRow, PR_FREEBUSY_START_RANGE);
2720
 
        publish_end = (const uint32_t *) find_SPropValue_data(&aRow, PR_FREEBUSY_END_RANGE);
2721
 
        busy_months = (const struct LongArray_r *) find_SPropValue_data(&aRow, PR_FREEBUSY_BUSY_MONTHS);
2722
 
        busy_events = (const struct BinaryArray_r *) find_SPropValue_data(&aRow, PR_FREEBUSY_BUSY_EVENTS);
2723
 
        tentative_months = (const struct LongArray_r *) find_SPropValue_data(&aRow, PR_FREEBUSY_TENTATIVE_MONTHS);
2724
 
        tentative_events = (const struct BinaryArray_r *) find_SPropValue_data(&aRow, PR_FREEBUSY_TENTATIVE_EVENTS);
2725
 
        oof_months = (const struct LongArray_r *) find_SPropValue_data(&aRow, PR_FREEBUSY_OOF_MONTHS);
2726
 
        oof_events = (const struct BinaryArray_r *) find_SPropValue_data(&aRow, PR_FREEBUSY_OOF_EVENTS);
 
2730
        publish_start = (const uint32_t *) find_SPropValue_data(&aRow, PR_FREEBUSY_PUBLISH_START);
 
2731
        publish_end = (const uint32_t *) find_SPropValue_data(&aRow, PR_FREEBUSY_PUBLISH_END);
 
2732
        busy_months = (const struct LongArray_r *) find_SPropValue_data(&aRow, PR_SCHDINFO_MONTHS_BUSY);
 
2733
        busy_events = (const struct BinaryArray_r *) find_SPropValue_data(&aRow, PR_SCHDINFO_FREEBUSY_BUSY);
 
2734
        tentative_months = (const struct LongArray_r *) find_SPropValue_data(&aRow, PR_SCHDINFO_MONTHS_TENTATIVE);
 
2735
        tentative_events = (const struct BinaryArray_r *) find_SPropValue_data(&aRow, PR_SCHDINFO_FREEBUSY_TENTATIVE);
 
2736
        oof_months = (const struct LongArray_r *) find_SPropValue_data(&aRow, PR_SCHDINFO_MONTHS_OOF);
 
2737
        oof_events = (const struct BinaryArray_r *) find_SPropValue_data(&aRow, PR_SCHDINFO_FREEBUSY_OOF);
2727
2738
 
2728
2739
        year = GetFreeBusyYear(publish_start);
2729
2740