~ubuntu-branches/ubuntu/oneiric/openchange/oneiric

« back to all changes in this revision

Viewing changes to utils/openchangeclient.c

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-08-23 14:14:19 UTC
  • mfrom: (3.2.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20100823141419-u35vdnmilt8ghudh
Tags: 1:0.9+svn2132-1
* New upstream snapshot.
* Bump standards version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
   OpenChange Project
5
5
 
6
 
   Copyright (C) Julien Kerihuel 2007-2008
 
6
   Copyright (C) Julien Kerihuel 2007-2010
7
7
 
8
8
   This program is free software; you can redistribute it and/or modify
9
9
   it under the terms of the GNU General Public License as published by
19
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
*/
21
21
 
22
 
#include <libmapi/libmapi.h>
23
 
#include <libmapi/defs_private.h>
24
 
#include <libocpf/ocpf.h>
 
22
#include "libmapi/libmapi.h"
 
23
#include "libmapi/libmapi_private.h"
 
24
#include "libocpf/ocpf.h"
25
25
#include <samba/popt.h>
26
26
#include <param.h>
27
27
 
65
65
        oclient->private = false;
66
66
        oclient->freebusy = NULL;
67
67
        oclient->force = false;
 
68
        oclient->summary = false;
68
69
 
69
70
        /* contact related parameters */
70
71
        oclient->email = NULL;
93
94
        oclient->ocpf_dump = NULL;
94
95
}
95
96
 
96
 
static char *utf8tolinux(TALLOC_CTX *mem_ctx, const char *wstring)
97
 
{
98
 
        char            *newstr;
99
 
 
100
 
        newstr = windows_to_utf8(mem_ctx, wstring);
101
 
        return newstr;
102
 
}
103
 
 
104
97
static enum MAPISTATUS openchangeclient_getdir(TALLOC_CTX *mem_ctx,
105
98
                                               mapi_object_t *obj_container,
106
99
                                               mapi_object_t *obj_child,
111
104
        struct SRowSet          SRowSet;
112
105
        mapi_object_t           obj_htable;
113
106
        mapi_object_t           obj_folder;
114
 
        char                    *newname;
115
107
        char                    **folder  = NULL;
116
108
        const char              *name;
117
109
        const uint64_t          *fid;
140
132
                while (((retval = QueryRows(&obj_htable, 0x32, TBL_ADVANCE, &SRowSet)) != MAPI_E_NOT_FOUND) && SRowSet.cRows) {
141
133
                        for (index = 0; (index < SRowSet.cRows) && (found == false); index++) {
142
134
                                fid = (const uint64_t *)find_SPropValue_data(&SRowSet.aRow[index], PR_FID);
143
 
                                name = (const char *)find_SPropValue_data(&SRowSet.aRow[index], PR_DISPLAY_NAME);
 
135
                                name = (const char *)find_SPropValue_data(&SRowSet.aRow[index], PR_DISPLAY_NAME_UNICODE);
144
136
 
145
 
                                newname = utf8tolinux(mem_ctx, name);
146
 
                                if (newname && fid && !strcmp(newname, folder[i])) {
 
137
                                if (name && fid && !strcmp(name, folder[i])) {
147
138
                                        retval = OpenFolder(&obj_folder, *fid, obj_child);
148
139
                                        MAPI_RETVAL_IF(retval, retval, folder);
149
140
 
150
141
                                        found = true;
151
142
                                        mapi_object_copy(&obj_folder, obj_child);
152
143
                                }
153
 
                                MAPIFreeBuffer(newname);
154
144
                        }
155
145
                }
156
146
 
201
191
                return false;
202
192
        }
203
193
        /* stat the file */
204
 
        if (fstat(fd, &sb) != 0) return false;
 
194
        if (fstat(fd, &sb) != 0) {
 
195
                close(fd);
 
196
                return false;
 
197
        }
205
198
 
206
199
        switch (mapitag) {
207
200
        case PR_HTML:
213
206
                oclient->attach[oclient->attach_num].filename = talloc_strdup(mem_ctx, filename);
214
207
                oclient->attach[oclient->attach_num].bin.lpb = talloc_size(mem_ctx, sb.st_size);
215
208
                oclient->attach[oclient->attach_num].bin.cb = sb.st_size;
216
 
                if ((oclient->attach[oclient->attach_num].bin.lpb = mmap(NULL, sb.st_size, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0)) == (void *) -1) {
 
209
                if ((oclient->attach[oclient->attach_num].bin.lpb = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0)) == (void *) -1) {
217
210
                        perror("mmap");
218
211
                        close(fd);
219
212
                        return false;
346
339
        }
347
340
 
348
341
        path = talloc_asprintf(mem_ctx, "%s/%s", oclient->store_folder, filename);
349
 
        if ((fd = open(path, O_CREAT|O_WRONLY, S_IWUSR|S_IRUSR)) == -1) return false;
 
342
        if ((fd = open(path, O_CREAT|O_WRONLY, S_IWUSR|S_IRUSR)) == -1) {
 
343
                goto error;
 
344
        }
350
345
        talloc_free(path);
351
346
 
352
347
        retval = OpenStream(&obj_attach, PR_ATTACH_DATA_BIN, 0, &obj_stream);
426
421
        MAPI_RETVAL_IF(retval, retval, mem_ctx);
427
422
 
428
423
        printf("MAILBOX (%u messages)\n", count);
 
424
        if (!count) goto end;
429
425
 
430
426
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x5,
431
427
                                          PR_FID,
446
442
                                             rowset.aRow[i].lpProps[1].value.d,
447
443
                                             &obj_message, 0);
448
444
                        if (GetLastError() == MAPI_E_SUCCESS) {
449
 
                                struct SPropValue       *lpProps;
450
 
                                struct SRow             aRow;
451
 
 
452
 
                                SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_HASATTACH);
453
 
                                lpProps = talloc_zero(mem_ctx, struct SPropValue);
454
 
                                retval = GetProps(&obj_message, SPropTagArray, &lpProps, &count);
455
 
                                MAPIFreeBuffer(SPropTagArray);
456
 
                                if (retval != MAPI_E_SUCCESS) return retval;
457
 
 
458
 
                                aRow.ulAdrEntryPad = 0;
459
 
                                aRow.cValues = count;
460
 
                                aRow.lpProps = lpProps;
461
 
 
462
 
                                retval = octool_message(mem_ctx, &obj_message);
463
 
 
464
 
                                has_attach = (const uint8_t *) get_SPropValue_SRow_data(&aRow, PR_HASATTACH);
465
 
 
466
 
                                /* If we have attachments, retrieve them */
467
 
                                if (has_attach && *has_attach) {
468
 
                                        mapi_object_init(&obj_tb_attach);
469
 
                                        retval = GetAttachmentTable(&obj_message, &obj_tb_attach);
470
 
                                        if (retval == MAPI_E_SUCCESS) {
471
 
                                                SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_ATTACH_NUM);
472
 
                                                retval = SetColumns(&obj_tb_attach, SPropTagArray);
473
 
                                                if (retval != MAPI_E_SUCCESS) return retval;
474
 
                                                MAPIFreeBuffer(SPropTagArray);
475
 
                                                
476
 
                                                retval = QueryRows(&obj_tb_attach, 0xa, TBL_ADVANCE, &rowset_attach);
477
 
                                                if (retval != MAPI_E_SUCCESS) return retval;
478
 
 
479
 
                                                for (j = 0; j < rowset_attach.cRows; j++) {
480
 
                                                        attach_num = (const uint32_t *)find_SPropValue_data(&(rowset_attach.aRow[j]), PR_ATTACH_NUM);
481
 
                                                        retval = OpenAttach(&obj_message, *attach_num, &obj_attach);
482
 
                                                        if (retval == MAPI_E_SUCCESS) {
483
 
                                                                struct SPropValue       *lpProps2;
484
 
                                                                uint32_t                count2;
485
 
 
486
 
                                                                SPropTagArray = set_SPropTagArray(mem_ctx, 0x3, 
487
 
                                                                                                  PR_ATTACH_FILENAME,
488
 
                                                                                                  PR_ATTACH_LONG_FILENAME,
489
 
                                                                                                  PR_ATTACH_SIZE);
490
 
                                                                lpProps2 = talloc_zero(mem_ctx, struct SPropValue);
491
 
                                                                retval = GetProps(&obj_attach, SPropTagArray, &lpProps2, &count2);
492
 
                                                                MAPIFreeBuffer(SPropTagArray);
493
 
                                                                if (retval != MAPI_E_SUCCESS) return retval;
494
 
                                                                
495
 
                                                                aRow.ulAdrEntryPad = 0;
496
 
                                                                aRow.cValues = count2;
497
 
                                                                aRow.lpProps = lpProps2;
498
 
 
499
 
                                                                attach_filename = get_filename(octool_get_propval(&aRow, PR_ATTACH_LONG_FILENAME));
500
 
                                                                if (!attach_filename || (attach_filename && !strcmp(attach_filename, ""))) {
501
 
                                                                        attach_filename = get_filename(octool_get_propval(&aRow, PR_ATTACH_FILENAME));
502
 
                                                                }
503
 
                                                                attach_size = (const uint32_t *) octool_get_propval(&aRow, PR_ATTACH_SIZE);
504
 
                                                                printf("[%u] %s (%u Bytes)\n", j, attach_filename, attach_size ? *attach_size : 0);
505
 
                                                                fflush(0);
506
 
                                                                if (oclient->store_folder) {
507
 
                                                                  status = store_attachment(obj_attach, attach_filename, attach_size ? *attach_size : 0, oclient);
508
 
                                                                        if (status == false) {
509
 
                                                                                printf("A Problem was encountered while storing attachments on the filesystem\n");
510
 
                                                                                MAPI_RETVAL_IF(status == false, MAPI_E_UNABLE_TO_COMPLETE, mem_ctx);
511
 
 
512
 
                                                                        }
513
 
                                                                }
514
 
                                                                MAPIFreeBuffer(lpProps2);
 
445
                                if (oclient->summary) {
 
446
                                        mapidump_message_summary(&obj_message);
 
447
                                } else {
 
448
                                        struct SPropValue       *lpProps;
 
449
                                        struct SRow             aRow;
 
450
                                        
 
451
                                        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_HASATTACH);
 
452
                                        lpProps = talloc_zero(mem_ctx, struct SPropValue);
 
453
                                        retval = GetProps(&obj_message, SPropTagArray, &lpProps, &count);
 
454
                                        MAPIFreeBuffer(SPropTagArray);
 
455
                                        if (retval != MAPI_E_SUCCESS) return retval;
 
456
                                        
 
457
                                        aRow.ulAdrEntryPad = 0;
 
458
                                        aRow.cValues = count;
 
459
                                        aRow.lpProps = lpProps;
 
460
                                        
 
461
                                        retval = octool_message(mem_ctx, &obj_message);
 
462
                                        
 
463
                                        has_attach = (const uint8_t *) get_SPropValue_SRow_data(&aRow, PR_HASATTACH);
 
464
                                        
 
465
                                        /* If we have attachments, retrieve them */
 
466
                                        if (has_attach && *has_attach) {
 
467
                                                mapi_object_init(&obj_tb_attach);
 
468
                                                retval = GetAttachmentTable(&obj_message, &obj_tb_attach);
 
469
                                                if (retval == MAPI_E_SUCCESS) {
 
470
                                                        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_ATTACH_NUM);
 
471
                                                        retval = SetColumns(&obj_tb_attach, SPropTagArray);
 
472
                                                        if (retval != MAPI_E_SUCCESS) return retval;
 
473
                                                        MAPIFreeBuffer(SPropTagArray);
 
474
                                                        
 
475
                                                        retval = QueryRows(&obj_tb_attach, 0xa, TBL_ADVANCE, &rowset_attach);
 
476
                                                        if (retval != MAPI_E_SUCCESS) return retval;
 
477
                                                        
 
478
                                                        for (j = 0; j < rowset_attach.cRows; j++) {
 
479
                                                                attach_num = (const uint32_t *)find_SPropValue_data(&(rowset_attach.aRow[j]), PR_ATTACH_NUM);
 
480
                                                                retval = OpenAttach(&obj_message, *attach_num, &obj_attach);
 
481
                                                                if (retval == MAPI_E_SUCCESS) {
 
482
                                                                        struct SPropValue       *lpProps2;
 
483
                                                                        uint32_t                count2;
 
484
                                                                        
 
485
                                                                        SPropTagArray = set_SPropTagArray(mem_ctx, 0x3, 
 
486
                                                                                                          PR_ATTACH_FILENAME,
 
487
                                                                                                          PR_ATTACH_LONG_FILENAME,
 
488
                                                                                                          PR_ATTACH_SIZE);
 
489
                                                                        lpProps2 = talloc_zero(mem_ctx, struct SPropValue);
 
490
                                                                        retval = GetProps(&obj_attach, SPropTagArray, &lpProps2, &count2);
 
491
                                                                        MAPIFreeBuffer(SPropTagArray);
 
492
                                                                        if (retval != MAPI_E_SUCCESS) return retval;
 
493
                                                                        
 
494
                                                                        aRow.ulAdrEntryPad = 0;
 
495
                                                                        aRow.cValues = count2;
 
496
                                                                        aRow.lpProps = lpProps2;
 
497
                                                                        
 
498
                                                                        attach_filename = get_filename(octool_get_propval(&aRow, PR_ATTACH_LONG_FILENAME));
 
499
                                                                        if (!attach_filename || (attach_filename && !strcmp(attach_filename, ""))) {
 
500
                                                                                attach_filename = get_filename(octool_get_propval(&aRow, PR_ATTACH_FILENAME));
 
501
                                                                        }
 
502
                                                                        attach_size = (const uint32_t *) octool_get_propval(&aRow, PR_ATTACH_SIZE);
 
503
                                                                        printf("[%u] %s (%u Bytes)\n", j, attach_filename, attach_size ? *attach_size : 0);
 
504
                                                                        fflush(0);
 
505
                                                                        if (oclient->store_folder) {
 
506
                                                                                status = store_attachment(obj_attach, attach_filename, attach_size ? *attach_size : 0, oclient);
 
507
                                                                                if (status == false) {
 
508
                                                                                        printf("A Problem was encountered while storing attachments on the filesystem\n");
 
509
                                                                                        MAPI_RETVAL_IF(status == false, MAPI_E_UNABLE_TO_COMPLETE, mem_ctx);
 
510
                                                                                        
 
511
                                                                                }
 
512
                                                                        }
 
513
                                                                        MAPIFreeBuffer(lpProps2);
 
514
                                                                }
515
515
                                                        }
 
516
                                                        errno = 0;
516
517
                                                }
517
 
                                                errno = 0;
 
518
                                                MAPIFreeBuffer(lpProps);
518
519
                                        }
519
 
                                        MAPIFreeBuffer(lpProps);
520
520
                                }
521
521
                        }
522
522
                        mapi_object_release(&obj_message);
523
523
                }
524
524
        }
525
 
 
 
525
 end:
526
526
        mapi_object_release(&obj_table);
527
527
        mapi_object_release(&obj_inbox);
528
528
        mapi_object_release(&obj_tis);
774
774
        if (retval != MAPI_E_SUCCESS) return retval;
775
775
 
776
776
        /* Recipients operations */
777
 
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x6,
 
777
        SPropTagArray = set_SPropTagArray(mem_ctx, 0xA,
 
778
                                          PR_ENTRYID,
 
779
                                          PR_DISPLAY_NAME_UNICODE,
778
780
                                          PR_OBJECT_TYPE,
779
781
                                          PR_DISPLAY_TYPE,
780
 
                                          PR_7BIT_DISPLAY_NAME,
781
 
                                          PR_DISPLAY_NAME,
782
 
                                          PR_SMTP_ADDRESS,
783
 
                                          PR_GIVEN_NAME);
 
782
                                          PR_TRANSMITTABLE_DISPLAY_NAME_UNICODE,
 
783
                                          PR_EMAIL_ADDRESS_UNICODE,
 
784
                                          PR_ADDRTYPE_UNICODE,
 
785
                                          PR_SEND_RICH_INFO,
 
786
                                          PR_7BIT_DISPLAY_NAME_UNICODE,
 
787
                                          PR_SMTP_ADDRESS_UNICODE);
784
788
 
785
789
        oclient->usernames = collapse_recipients(mem_ctx, oclient);
786
790
 
787
791
        /* ResolveNames */
788
792
        retval = ResolveNames(mapi_object_get_session(&obj_message), (const char **)oclient->usernames, 
789
 
                              SPropTagArray, &SRowSet, &flaglist, 0);
 
793
                              SPropTagArray, &SRowSet, &flaglist, MAPI_UNICODE);
790
794
        MAPIFreeBuffer(SPropTagArray);
791
795
        if (retval != MAPI_E_SUCCESS) return retval;
792
796
 
811
815
        /* set message properties */
812
816
        msgflag = MSGFLAG_UNSENT;
813
817
        oclient->subject = (!oclient->subject) ? "" : oclient->subject;
814
 
        set_SPropValue_proptag(&props[0], PR_SUBJECT, 
 
818
        set_SPropValue_proptag(&props[0], PR_SUBJECT_UNICODE, 
815
819
                               (const void *)oclient->subject);
816
820
        set_SPropValue_proptag(&props[1], PR_MESSAGE_FLAGS, 
817
821
                               (const void *)&msgflag);
829
833
                        bin.cb = strlen(oclient->pr_body);
830
834
                        openchangeclient_stream(mem_ctx, obj_message, obj_stream, PR_BODY, 2, bin);
831
835
                } else {
832
 
                        set_SPropValue_proptag(&props[2], PR_BODY, 
 
836
                        set_SPropValue_proptag(&props[2], PR_BODY_UNICODE, 
833
837
                                                                   (const void *)oclient->pr_body);
834
838
                        prop_count++;
835
839
                }
1057
1061
        lpProps = talloc_array(mem_ctx, struct SPropValue, 2);
1058
1062
 
1059
1063
        if (oclient->subject) {
1060
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_CONVERSATION_TOPIC, 
 
1064
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_CONVERSATION_TOPIC_UNICODE, 
1061
1065
                               (const void *) oclient->subject);
1062
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_NORMALIZED_SUBJECT,
 
1066
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_NORMALIZED_SUBJECT_UNICODE,
1063
1067
                               (const void *) oclient->subject);
1064
1068
        }
1065
1069
        if (oclient->pr_body) {
1066
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_BODY, (const void *)oclient->pr_body);
 
1070
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_BODY_UNICODE, (const void *)oclient->pr_body);
1067
1071
        }
1068
1072
        if (oclient->location) {
1069
1073
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PidLidLocation, (const void *)oclient->location);
1224
1228
        lpProps = talloc_array(mem_ctx, struct SPropValue, 2);
1225
1229
 
1226
1230
        if (oclient->card_name) {
1227
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_NORMALIZED_SUBJECT, (const void *)oclient->card_name);
 
1231
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_NORMALIZED_SUBJECT_UNICODE, (const void *)oclient->card_name);
1228
1232
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PidLidFileUnder, (const void *)oclient->card_name);
1229
1233
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, SPropTagArray->aulPropTag[0], (const void *)oclient->card_name);
1230
1234
        }
1231
1235
        if (oclient->full_name) {
1232
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_DISPLAY_NAME, (const void *)oclient->full_name);
 
1236
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_DISPLAY_NAME_UNICODE, (const void *)oclient->full_name);
1233
1237
        }
1234
1238
        if (oclient->email) {
1235
1239
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PidLidEmail1OriginalDisplayName, (const void *)oclient->email);
1268
1272
                if (retval != MAPI_E_SUCCESS) return false;
1269
1273
        }
1270
1274
 
1271
 
        /* Create contact mesage */
 
1275
        /* Create contact message */
1272
1276
        mapi_object_init(&obj_message);
1273
1277
        retval = CreateMessage(&obj_contact, &obj_message);
1274
1278
        if (retval != MAPI_E_SUCCESS) return false;
1311
1315
        lpProps = talloc_array(mem_ctx, struct SPropValue, 2);
1312
1316
 
1313
1317
        if (oclient->card_name) {
1314
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_CONVERSATION_TOPIC, (const void *)oclient->card_name);
1315
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_NORMALIZED_SUBJECT, (const void *)oclient->card_name);
 
1318
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_CONVERSATION_TOPIC_UNICODE, (const void *)oclient->card_name);
 
1319
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_NORMALIZED_SUBJECT_UNICODE, (const void *)oclient->card_name);
1316
1320
        }
1317
1321
 
1318
1322
        if (oclient->dtstart) {
1340
1344
        }
1341
1345
 
1342
1346
        if (oclient->pr_body) {
1343
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_BODY, (const void *)oclient->pr_body);
 
1347
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_BODY_UNICODE, (const void *)oclient->pr_body);
1344
1348
        }
1345
1349
 
1346
1350
        if (!oclient->update) {
1387
1391
                if (retval != MAPI_E_SUCCESS) return false;
1388
1392
        }
1389
1393
 
1390
 
        /* Create contact mesage */
 
1394
        /* Create contact message */
1391
1395
        mapi_object_init(&obj_message);
1392
1396
        retval = CreateMessage(&obj_task, &obj_message);
1393
1397
        if (retval != MAPI_E_SUCCESS) return false;
1427
1431
        lpProps = talloc_array(mem_ctx, struct SPropValue, 2);
1428
1432
 
1429
1433
        if (oclient->card_name) {
1430
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_CONVERSATION_TOPIC, (const void *)oclient->card_name);
1431
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_SUBJECT, (const void *)oclient->card_name);
1432
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_NORMALIZED_SUBJECT, (const void *)oclient->card_name);
1433
 
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_BODY, (const void *)oclient->card_name);
 
1434
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_CONVERSATION_TOPIC_UNICODE, (const void *)oclient->card_name);
 
1435
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_SUBJECT_UNICODE, (const void *)oclient->card_name);
 
1436
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_NORMALIZED_SUBJECT_UNICODE, (const void *)oclient->card_name);
 
1437
                lpProps = add_SPropValue(mem_ctx, lpProps, &cValues, PR_BODY_UNICODE, (const void *)oclient->card_name);
1434
1438
        }
1435
1439
 
1436
1440
        if (!oclient->update) {
1496
1500
                if (retval != MAPI_E_SUCCESS) return false;
1497
1501
        }
1498
1502
 
1499
 
        /* Create contact mesage */
 
1503
        /* Create contact message */
1500
1504
        mapi_object_init(&obj_message);
1501
1505
        retval = CreateMessage(&obj_note, &obj_message);
1502
1506
        if (retval != MAPI_E_SUCCESS) return false;
1536
1540
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_CONTAINER_CLASS);
1537
1541
        retval = GetProps(&obj_folder, SPropTagArray, &lpProps, &count);
1538
1542
        MAPIFreeBuffer(SPropTagArray);
 
1543
        mapi_object_release(&obj_folder);
1539
1544
        if ((lpProps[0].ulPropTag != PR_CONTAINER_CLASS) || (retval != MAPI_E_SUCCESS)) {
1540
1545
                errno = 0;
1541
1546
                return IPF_NOTE;
1552
1557
        struct SPropTagArray    *SPropTagArray;
1553
1558
        struct SRowSet          rowset;
1554
1559
        const char              *name;
1555
 
        char                    *newname;
1556
1560
        const char              *comment;
1557
1561
        const uint32_t          *total;
1558
1562
        const uint32_t          *unread;
1570
1574
        if (retval != MAPI_E_SUCCESS) return false;
1571
1575
 
1572
1576
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x6,
1573
 
                                          PR_DISPLAY_NAME,
 
1577
                                          PR_DISPLAY_NAME_UNICODE,
1574
1578
                                          PR_FID,
1575
 
                                          PR_COMMENT,
 
1579
                                          PR_COMMENT_UNICODE,
1576
1580
                                          PR_CONTENT_UNREAD,
1577
1581
                                          PR_CONTENT_COUNT,
1578
1582
                                          PR_FOLDER_CHILD_COUNT);
1583
1587
        while (((retval = QueryRows(&obj_htable, 0x32, TBL_ADVANCE, &rowset)) != MAPI_E_NOT_FOUND) && rowset.cRows) {
1584
1588
                for (index = 0; index < rowset.cRows; index++) {
1585
1589
                        fid = (const uint64_t *)find_SPropValue_data(&rowset.aRow[index], PR_FID);
1586
 
                        name = (const char *)find_SPropValue_data(&rowset.aRow[index], PR_DISPLAY_NAME);
1587
 
                        comment = (const char *)find_SPropValue_data(&rowset.aRow[index], PR_COMMENT);
 
1590
                        name = (const char *)find_SPropValue_data(&rowset.aRow[index], PR_DISPLAY_NAME_UNICODE);
 
1591
                        comment = (const char *)find_SPropValue_data(&rowset.aRow[index], PR_COMMENT_UNICODE);
1588
1592
                        total = (const uint32_t *)find_SPropValue_data(&rowset.aRow[index], PR_CONTENT_COUNT);
1589
1593
                        unread = (const uint32_t *)find_SPropValue_data(&rowset.aRow[index], PR_CONTENT_UNREAD);
1590
1594
                        child = (const uint32_t *)find_SPropValue_data(&rowset.aRow[index], PR_FOLDER_CHILD_COUNT);
1592
1596
                        for (i = 0; i < count; i++) {
1593
1597
                                printf("|   ");
1594
1598
                        }
1595
 
                        newname = utf8tolinux(mem_ctx, name);
1596
1599
                        printf("|---+ %-15s : %-20s (Total: %u / Unread: %u - Container class: %s) [FID: 0x%016"PRIx64"]\n", 
1597
 
                               newname, comment?comment:"", total?*total:0, unread?*unread:0,
 
1600
                               name, comment?comment:"", total?*total:0, unread?*unread:0,
1598
1601
                               get_container_class(mem_ctx, parent, *fid), *fid);
1599
 
                        MAPIFreeBuffer(newname);
1600
1602
                        if (child && *child) {
1601
1603
                                ret = get_child_folders(mem_ctx, &obj_folder, *fid, count + 1);
1602
1604
                                if (ret == false) return ret;
1604
1606
                        
1605
1607
                }
1606
1608
        }
 
1609
        mapi_object_release(&obj_htable);
 
1610
        mapi_object_release(&obj_folder);
 
1611
 
1607
1612
        return true;
1608
1613
}
1609
1614
 
1616
1621
        struct SPropTagArray    *SPropTagArray;
1617
1622
        struct SRowSet          rowset;
1618
1623
        const char              *name;
1619
 
        char                    *newname;
1620
1624
        const uint32_t          *child;
1621
1625
        uint32_t                index;
1622
1626
        const uint64_t          *fid;
1631
1635
        if (retval != MAPI_E_SUCCESS) return false;
1632
1636
 
1633
1637
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x3,
1634
 
                                          PR_DISPLAY_NAME,
 
1638
                                          PR_DISPLAY_NAME_UNICODE,
1635
1639
                                          PR_FID,
1636
1640
                                          PR_FOLDER_CHILD_COUNT);
1637
1641
        retval = SetColumns(&obj_htable, SPropTagArray);
1641
1645
        while (((retval = QueryRows(&obj_htable, 0x32, TBL_ADVANCE, &rowset)) != MAPI_E_NOT_FOUND) && rowset.cRows) {
1642
1646
                for (index = 0; index < rowset.cRows; index++) {
1643
1647
                        fid = (const uint64_t *)find_SPropValue_data(&rowset.aRow[index], PR_FID);
1644
 
                        name = (const char *)find_SPropValue_data(&rowset.aRow[index], PR_DISPLAY_NAME);
 
1648
                        name = (const char *)find_SPropValue_data(&rowset.aRow[index], PR_DISPLAY_NAME_UNICODE);
1645
1649
                        child = (const uint32_t *)find_SPropValue_data(&rowset.aRow[index], PR_FOLDER_CHILD_COUNT);
1646
1650
 
1647
1651
                        for (i = 0; i < count; i++) {
1648
1652
                                printf("|   ");
1649
1653
                        }
1650
 
                        newname = utf8tolinux(mem_ctx, name);
1651
 
                        printf("|---+ %-15s [FID: 0x%016"PRIx64"]\n", newname, *fid);
1652
 
                        MAPIFreeBuffer(newname);
 
1654
                        printf("|---+ %-15s [FID: 0x%016"PRIx64"]\n", name, *fid);
1653
1655
                        if (*child) {
1654
1656
                                ret = get_child_folders_pf(mem_ctx, &obj_folder, *fid, count + 1);
1655
1657
                                if (ret == false) return ret;
1682
1684
        struct SPropValue               *lpProps;
1683
1685
        uint32_t                        cValues;
1684
1686
        const char                      *mailbox_name;
1685
 
        char                            *utf8_mailbox_name;
1686
1687
 
1687
1688
        /* Retrieve the mailbox folder name */
1688
 
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_DISPLAY_NAME);
 
1689
        SPropTagArray = set_SPropTagArray(mem_ctx, 0x1, PR_DISPLAY_NAME_UNICODE);
1689
1690
        retval = GetProps(obj_store, SPropTagArray, &lpProps, &cValues);
1690
1691
        MAPIFreeBuffer(SPropTagArray);
1691
1692
        if (retval != MAPI_E_SUCCESS) return false;
1692
1693
 
1693
 
        if (lpProps[0].value.lpszA) {
1694
 
                mailbox_name = lpProps[0].value.lpszA;
 
1694
        if (lpProps[0].value.lpszW) {
 
1695
                mailbox_name = lpProps[0].value.lpszW;
1695
1696
        } else {
1696
1697
                return false;
1697
1698
        }
1700
1701
        retval = GetDefaultFolder(obj_store, &id_mailbox, olFolderTopInformationStore);
1701
1702
        if (retval != MAPI_E_SUCCESS) return false;
1702
1703
 
1703
 
        utf8_mailbox_name = utf8tolinux(mem_ctx, mailbox_name);
1704
 
        printf("+ %s\n", utf8_mailbox_name);
1705
 
        MAPIFreeBuffer(utf8_mailbox_name);
 
1704
        printf("+ %s\n", mailbox_name);
1706
1705
        return get_child_folders(mem_ctx, obj_store, id_mailbox, 0);
1707
1706
}
1708
1707
 
1788
1787
                                             SRowSet.aRow[i].lpProps[1].value.d,
1789
1788
                                             &obj_message, 0);
1790
1789
                        if (retval != MAPI_E_NOT_FOUND) {
1791
 
                                retval = GetPropsAll(&obj_message, &properties_array);
1792
 
                                if (retval == MAPI_E_SUCCESS) {
1793
 
                                        id = talloc_asprintf(mem_ctx, ": %"PRIX64"/%"PRIX64,
1794
 
                                                             SRowSet.aRow[i].lpProps[0].value.d,
1795
 
                                                             SRowSet.aRow[i].lpProps[1].value.d);
1796
 
                                        mapi_SPropValue_array_named(&obj_message, 
1797
 
                                                                    &properties_array);
1798
 
                                        switch (olFolder) {
1799
 
                                        case olFolderInbox:
1800
 
                                          mapidump_message(&properties_array, id);
1801
 
                                                break;
1802
 
                                        case olFolderCalendar:
1803
 
                                                mapidump_appointment(&properties_array, id);
1804
 
                                                break;
1805
 
                                        case olFolderContacts:
1806
 
                                                mapidump_contact(&properties_array, id);
1807
 
                                                break;
1808
 
                                        case olFolderTasks:
1809
 
                                                mapidump_task(&properties_array, id);
1810
 
                                                break;
1811
 
                                        case olFolderNotes:
1812
 
                                                mapidump_note(&properties_array, id);
1813
 
                                                break;
 
1790
                                if (oclient->summary) {
 
1791
                                        mapidump_message_summary(&obj_message);
 
1792
                                } else {
 
1793
                                        retval = GetPropsAll(&obj_message, &properties_array);
 
1794
                                        if (retval == MAPI_E_SUCCESS) {
 
1795
                                                id = talloc_asprintf(mem_ctx, ": %"PRIX64"/%"PRIX64,
 
1796
                                                                     SRowSet.aRow[i].lpProps[0].value.d,
 
1797
                                                                     SRowSet.aRow[i].lpProps[1].value.d);
 
1798
                                                mapi_SPropValue_array_named(&obj_message, 
 
1799
                                                                            &properties_array);
 
1800
                                                switch (olFolder) {
 
1801
                                                case olFolderInbox:
 
1802
                                                  mapidump_message(&properties_array, id, NULL);
 
1803
                                                        break;
 
1804
                                                case olFolderCalendar:
 
1805
                                                        mapidump_appointment(&properties_array, id);
 
1806
                                                        break;
 
1807
                                                case olFolderContacts:
 
1808
                                                        mapidump_contact(&properties_array, id);
 
1809
                                                        break;
 
1810
                                                case olFolderTasks:
 
1811
                                                        mapidump_task(&properties_array, id);
 
1812
                                                        break;
 
1813
                                                case olFolderNotes:
 
1814
                                                        mapidump_note(&properties_array, id);
 
1815
                                                        break;
 
1816
                                                }
 
1817
                                                talloc_free(id);
1814
1818
                                        }
1815
 
                                        talloc_free(id);
1816
 
                                        mapi_object_release(&obj_message);
1817
1819
                                }
 
1820
                                mapi_object_release(&obj_message);
1818
1821
                        }
1819
1822
                }
1820
1823
        }
1870
1873
                                mapi_object_release(&obj_htable);
1871
1874
                                mapi_object_release(&obj_folder);
1872
1875
                                return MAPI_E_SUCCESS;
1873
 
                        } else {
 
1876
                        } else if (fid) {
1874
1877
                                retval = folder_lookup(mem_ctx, sfid, &obj_folder, *fid, obj_ret);
1875
1878
                                if (retval == MAPI_E_SUCCESS) {
1876
1879
                                        mapi_object_release(&obj_htable);
2123
2126
                                                id = talloc_asprintf(mem_ctx, ": %"PRIX64"/%"PRIX64,
2124
2127
                                                                     SRowSet.aRow[i].lpProps[0].value.d,
2125
2128
                                                                     SRowSet.aRow[i].lpProps[1].value.d);
2126
 
                                                mapidump_message(&properties_array, id);
 
2129
                                                mapidump_message(&properties_array, id, NULL);
2127
2130
                                                mapi_object_release(&obj_message);
2128
2131
                                                talloc_free(id);
2129
2132
 
2283
2286
 
2284
2287
static bool openchangeclient_notifications(TALLOC_CTX *mem_ctx, mapi_object_t *obj_store, struct oclient *oclient)
2285
2288
{
2286
 
        enum MAPISTATUS retval;
2287
 
        mapi_object_t   obj_inbox;
2288
 
        mapi_id_t       fid;
2289
 
        uint32_t        ulConnection;
2290
 
        uint16_t        ulEventMask;
 
2289
        enum MAPISTATUS         retval;
 
2290
        mapi_object_t           obj_inbox;
 
2291
        mapi_id_t               fid;
 
2292
        uint32_t                ulConnection;
 
2293
        uint16_t                ulEventMask;
 
2294
        struct mapi_session     *session;
2291
2295
 
2292
2296
        /* Register notification */
2293
 
        retval = RegisterNotification(0);
 
2297
        session = mapi_object_get_session(obj_store);
 
2298
        retval = RegisterNotification(session, 0);
2294
2299
        if (retval != MAPI_E_SUCCESS) return false;
2295
2300
 
2296
2301
        if (oclient->pf == true) {
2313
2318
                fnevSearchComplete|fnevTableModified|fnevStatusObjectModified;
2314
2319
        retval = Subscribe(obj_store, &ulConnection, ulEventMask, true, (mapi_notify_callback_t)callback,
2315
2320
                (void*) obj_store);
2316
 
        retval = Subscribe(&obj_inbox, &ulConnection, ulEventMask, false, (mapi_notify_callback_t)callback,
 
2321
        retval = Subscribe(&obj_inbox, &ulConnection, ulEventMask, true, (mapi_notify_callback_t)callback,
2317
2322
                (void*) obj_store);
2318
2323
        if (retval != MAPI_E_SUCCESS) return false;
2319
2324
 
2320
2325
        /* wait for notifications: infinite loop */
2321
 
        retval = MonitorNotification(mapi_object_get_session(obj_store), (void *)obj_store);
 
2326
        retval = MonitorNotification(mapi_object_get_session(obj_store), (void *)obj_store, NULL);
2322
2327
        if (retval != MAPI_E_SUCCESS) return false;
2323
2328
 
2324
2329
        retval = Unsubscribe(mapi_object_get_session(obj_store), ulConnection);
2429
2434
        uint32_t                i;
2430
2435
        uint32_t                count;
2431
2436
        uint8_t                 ulFlags;
 
2437
        uint32_t                rowsFetched = 0;
 
2438
        uint32_t                totalRecs = 0;
 
2439
 
 
2440
        retval = GetGALTableCount(session, &totalRecs);
 
2441
        printf("Total Number of entries in GAL: %d\n", totalRecs);
2432
2442
 
2433
2443
        SPropTagArray = set_SPropTagArray(mem_ctx, 0xc,
2434
2444
                                          PR_INSTANCE_KEY,
2452
2462
                if ((!SRowSet) || (!(SRowSet->aRow))) {
2453
2463
                        return false;
2454
2464
                }
2455
 
                if (SRowSet->cRows) {
2456
 
                        for (i = 0; i < SRowSet->cRows; i++) {
 
2465
                rowsFetched = SRowSet->cRows;
 
2466
                if (rowsFetched) {
 
2467
                        for (i = 0; i < rowsFetched; i++) {
2457
2468
                                mapidump_PAB_entry(&SRowSet->aRow[i]);
2458
2469
                        }
2459
2470
                }
2460
2471
                ulFlags = TABLE_CUR;
2461
2472
                MAPIFreeBuffer(SRowSet);
2462
 
        } while (SRowSet->cRows == count);
 
2473
        } while (rowsFetched == count);
2463
2474
        mapi_errstr("GetPABTable", GetLastError());
2464
2475
 
2465
2476
        MAPIFreeBuffer(SPropTagArray);
2472
2483
{
2473
2484
        int                     ret;
2474
2485
        struct ocpf_file        *element;
 
2486
        uint32_t                context_id;
2475
2487
 
2476
2488
        /* Sanity checks */
2477
2489
        if (!oclient->ocpf_files || !oclient->ocpf_files->next) {
2488
2500
 
2489
2501
        /* Step2. Parse OCPF files */
2490
2502
        for (element = oclient->ocpf_files; element->next; element = element->next) {
2491
 
                ret = ocpf_parse(element->filename);
2492
 
                if (ret == -1) {
2493
 
                        errno = MAPI_E_INVALID_PARAMETER;
2494
 
                        return false;
2495
 
                }
 
2503
          ret = ocpf_new_context(element->filename, &context_id, OCPF_FLAGS_READ);
 
2504
                if (ret == -1) {
 
2505
                        errno = MAPI_E_INVALID_PARAMETER;
 
2506
                        return false;
 
2507
                }
 
2508
                ret = ocpf_parse(context_id);
 
2509
                if (ret == -1) {
 
2510
                        DEBUG(0, ("ocpf_parse failed ...\n"));
 
2511
                        errno = MAPI_E_INVALID_PARAMETER;
 
2512
                        return false;
 
2513
                }
 
2514
 
 
2515
                /* Dump OCPF contents */
 
2516
                ocpf_dump(context_id);
 
2517
 
 
2518
                ret = ocpf_del_context(context_id);
2496
2519
        }
2497
2520
 
2498
 
        /* Step3. Dump OCPF contents */
2499
 
        ocpf_dump();
2500
2521
 
2501
2522
        /* Step4. Release OCPF context */
2502
2523
        ret = ocpf_release();
2518
2539
        mapi_object_t           obj_message;
2519
2540
        uint32_t                cValues = 0;
2520
2541
        struct SPropValue       *lpProps;
 
2542
        uint32_t                context_id;
2521
2543
 
2522
2544
        /* Sanity Check */
2523
2545
        if (!oclient->ocpf_files || !oclient->ocpf_files->next) {
2534
2556
 
2535
2557
        /* Step2. Parse OCPF files */
2536
2558
        for (element = oclient->ocpf_files; element->next; element = element->next) {
2537
 
                ret = ocpf_parse(element->filename);
 
2559
          ret = ocpf_new_context(element->filename, &context_id, OCPF_FLAGS_READ);
 
2560
                ret = ocpf_parse(context_id);
2538
2561
                if (ret == -1) {
2539
2562
                        errno = MAPI_E_INVALID_PARAMETER;
2540
2563
                        return false;
2543
2566
 
2544
2567
        /* Step3. Open destination folder using ocpf API */
2545
2568
        mapi_object_init(&obj_folder);
2546
 
        retval = ocpf_OpenFolder(obj_store, &obj_folder);
 
2569
        retval = ocpf_OpenFolder(context_id, obj_store, &obj_folder);
2547
2570
        if (retval != MAPI_E_SUCCESS) return false;
2548
2571
 
2549
2572
        /* Step4. Create the message */
2552
2575
        if (retval != MAPI_E_SUCCESS) return false;
2553
2576
 
2554
2577
        /* Step5, Set message recipients */
2555
 
        retval = ocpf_set_Recipients(mem_ctx, &obj_message);
 
2578
        retval = ocpf_set_Recipients(mem_ctx, context_id, &obj_message);
2556
2579
        if (retval != MAPI_E_SUCCESS && GetLastError() != MAPI_E_NOT_FOUND) return false;
2557
2580
        errno = MAPI_E_SUCCESS;
2558
2581
 
2559
2582
        /* Step6. Set message properties */
2560
 
        retval = ocpf_set_SPropValue(mem_ctx, &obj_folder, &obj_message);
 
2583
        retval = ocpf_set_SPropValue(mem_ctx, context_id, &obj_folder, &obj_message);
2561
2584
        if (retval != MAPI_E_SUCCESS) return false;
2562
2585
 
2563
2586
        /* Step7. Set message properties */
2564
 
        lpProps = ocpf_get_SPropValue(&cValues);
 
2587
        lpProps = ocpf_get_SPropValue(context_id, &cValues);
2565
2588
 
2566
2589
        retval = SetProps(&obj_message, lpProps, cValues);
2567
2590
        MAPIFreeBuffer(lpProps);
2574
2597
        mapi_object_release(&obj_message);
2575
2598
        mapi_object_release(&obj_folder);
2576
2599
 
 
2600
        ocpf_del_context(context_id);
 
2601
 
2577
2602
        return true;
2578
2603
}
2579
2604
 
2591
2616
        const char                      *item = NULL;
2592
2617
        char                            *filename = NULL;
2593
2618
        struct mapi_SPropValue_array    lpProps;
 
2619
        uint32_t                        context_id;
2594
2620
 
2595
2621
 
2596
2622
        /* retrieve the FID/MID for ocpf_dump parameter */
2628
2654
        filename = talloc_asprintf(mem_ctx, "%"PRIx64".ocpf", mid);
2629
2655
        DEBUG(0, ("OCPF output file: %s\n", filename));
2630
2656
 
2631
 
        ret = ocpf_write_init(filename, fid);
 
2657
        ret = ocpf_new_context(filename, &context_id, OCPF_FLAGS_CREATE);
2632
2658
        talloc_free(filename);
 
2659
        ret = ocpf_write_init(context_id, fid);
2633
2660
 
2634
 
        ret = ocpf_write_auto(&obj_message, &lpProps);
 
2661
        ret = ocpf_write_auto(context_id, &obj_message, &lpProps);
2635
2662
        if (ret == OCPF_SUCCESS) {
2636
 
                ret = ocpf_write_commit();
 
2663
                ret = ocpf_write_commit(context_id);
2637
2664
        } 
2638
2665
 
 
2666
        ret = ocpf_del_context(context_id);
 
2667
 
2639
2668
        ret = ocpf_release();
2640
2669
 
2641
2670
        mapi_object_release(&obj_message);
2680
2709
        year = GetFreeBusyYear(publish_start);
2681
2710
 
2682
2711
        DEBUG(0, ("FreeBusy (%s):\n", message_name));
2683
 
        mapidump_date_SPropValue(aRow.lpProps[1], "* FreeBusy Last Modification Time");
 
2712
        mapidump_date_SPropValue(aRow.lpProps[1], "* FreeBusy Last Modification Time", "\t");
2684
2713
        mapidump_freebusy_date(*publish_start, "\t* FreeBusy Publishing Start:");
2685
2714
        mapidump_freebusy_date(*publish_end, "\t *FreeBusy Publishing End:  ");
2686
2715
 
2771
2800
        bool                    opt_ocpf_sender = false;
2772
2801
        const char              *opt_profdb = NULL;
2773
2802
        char                    *opt_profname = NULL;
 
2803
        const char              *opt_username = NULL;
2774
2804
        const char              *opt_password = NULL;
2775
2805
        const char              *opt_attachments = NULL;
2776
2806
        const char              *opt_fetchitems = NULL;
2791
2821
              OPT_FOLDER, OPT_MAPI_COLOR, OPT_SENDNOTE, OPT_MKDIR, OPT_RMDIR,
2792
2822
              OPT_FOLDER_NAME, OPT_FOLDER_COMMENT, OPT_USERLIST, OPT_MAPI_PRIVATE,
2793
2823
              OPT_UPDATE, OPT_DELETEITEMS, OPT_OCPF_FILE, OPT_OCPF_SYNTAX,
2794
 
              OPT_OCPF_SENDER, OPT_OCPF_DUMP, OPT_FREEBUSY, OPT_FORCE};
 
2824
              OPT_OCPF_SENDER, OPT_OCPF_DUMP, OPT_FREEBUSY, OPT_FORCE, OPT_FETCHSUMMARY,
 
2825
              OPT_USERNAME };
2795
2826
 
2796
2827
        struct poptOption long_options[] = {
2797
2828
                POPT_AUTOHELP
2799
2830
                {"pf", 0, POPT_ARG_NONE, NULL, OPT_PF, "access public folders instead of mailbox", NULL },
2800
2831
                {"profile", 'p', POPT_ARG_STRING, NULL, OPT_PROFILE, "set the profile name", NULL },
2801
2832
                {"password", 'P', POPT_ARG_STRING, NULL, OPT_PASSWORD, "set the profile password", NULL },
 
2833
                {"username", 0, POPT_ARG_STRING, NULL, OPT_USERNAME, "set the username of the mailbox to use", NULL },
2802
2834
                {"sendmail", 'S', POPT_ARG_NONE, NULL, OPT_SENDMAIL, "send a mail", NULL },
2803
2835
                {"sendappointment", 0, POPT_ARG_NONE, NULL, OPT_SENDAPPOINTMENT, "send an appointment", NULL },
2804
2836
                {"sendcontact", 0, POPT_ARG_NONE, NULL, OPT_SENDCONTACT, "send a contact", NULL },
2805
2837
                {"sendtask", 0, POPT_ARG_NONE, NULL, OPT_SENDTASK, "send a task", NULL },
2806
2838
                {"sendnote", 0, POPT_ARG_NONE, NULL, OPT_SENDNOTE, "send a note", NULL },
2807
2839
                {"fetchmail", 'F', POPT_ARG_NONE, NULL, OPT_FETCHMAIL, "fetch user INBOX mails", NULL },
 
2840
                {"fetchsummary", 0, POPT_ARG_NONE, NULL, OPT_FETCHSUMMARY, "fetch message summaries only", NULL },
2808
2841
                {"storemail", 'G', POPT_ARG_STRING, NULL, OPT_STOREMAIL, "retrieve a mail on the filesystem", NULL },
2809
2842
                {"fetch-items", 'i', POPT_ARG_STRING, NULL, OPT_FETCHITEMS, "fetch specified user INBOX items", NULL },
2810
2843
                {"freebusy", 0, POPT_ARG_STRING, NULL, OPT_FREEBUSY, "display free / busy information for the specified user", NULL },
2897
2930
                case OPT_PASSWORD:
2898
2931
                        opt_password = poptGetOptArg(pc);
2899
2932
                        break;
 
2933
                case OPT_USERNAME:
 
2934
                        opt_username = talloc_strdup(mem_ctx, poptGetOptArg(pc));
 
2935
                        break;
2900
2936
                case OPT_MAILBOX:
2901
2937
                        opt_mailbox = true;
2902
2938
                        break;
2903
2939
                case OPT_FETCHITEMS:
2904
2940
                        opt_fetchitems = poptGetOptArg(pc);
2905
2941
                        break;
 
2942
                case OPT_FETCHSUMMARY:
 
2943
                        oclient.summary = true;
 
2944
                        break;
2906
2945
                case OPT_DELETEITEMS:
2907
2946
                        oclient.delete = poptGetOptArg(pc);
2908
2947
                        break;
3154
3193
                        mapi_errstr("OpenPublicFolder", GetLastError());
3155
3194
                        exit (1);
3156
3195
                }
 
3196
        } else if (opt_username) {
 
3197
                retval = OpenUserMailbox(session, opt_username, &obj_store);
 
3198
                if (retval != MAPI_E_SUCCESS) {
 
3199
                        mapi_errstr("OpenUserMailbox", GetLastError());
 
3200
                        exit (1);
 
3201
                }
3157
3202
        } else {
3158
3203
                retval = OpenMsgStore(session, &obj_store);
3159
3204
                if (retval != MAPI_E_SUCCESS) {