dump_mac_addressbook.m
author Ryan C. Gordon <icculus@icculus.org>
Wed, 17 Aug 2016 17:17:19 -0400
changeset 46 981bac1188ab
parent 28 201eface7ff4
permissions -rw-r--r--
Optionally allow output in mbox format instead of Maildir.
icculus@28
     1
#include <stdio.h>
icculus@28
     2
#include <AddressBook/AddressBook.h>
icculus@28
     3
icculus@28
     4
static void print_propstr(const char *str)
icculus@28
     5
{
icculus@28
     6
    printf("%s\n", str ? str : "");
icculus@28
     7
}
icculus@28
     8
icculus@28
     9
int main(int argc, char **argv)
icculus@28
    10
{
icculus@28
    11
    @autoreleasepool {
icculus@28
    12
        int idx = 0;
icculus@28
    13
icculus@28
    14
        NSArray *list = [[ABAddressBook sharedAddressBook] people];
icculus@28
    15
icculus@28
    16
        for (ABPerson *person in list) {
icculus@28
    17
            print_propstr([[person valueForProperty:kABNicknameProperty] cStringUsingEncoding:NSUTF8StringEncoding]);
icculus@28
    18
            print_propstr([[person valueForProperty:kABFirstNameProperty] cStringUsingEncoding:NSUTF8StringEncoding]);
icculus@28
    19
            print_propstr([[person valueForProperty:kABMiddleNameProperty] cStringUsingEncoding:NSUTF8StringEncoding]);
icculus@28
    20
            print_propstr([[person valueForProperty:kABLastNameProperty] cStringUsingEncoding:NSUTF8StringEncoding]);
icculus@28
    21
            static NSString *props[] = { @"Phone", @"Email", nil };
icculus@28
    22
            for (int propidx = 0; props[propidx] != nil; propidx++) {
icculus@28
    23
                ABMultiValue *mval = [person valueForProperty:props[propidx]];
icculus@28
    24
                const int total = [mval count];
icculus@28
    25
                for (int i = 0; i < total; i++) {
icculus@28
    26
                    NSString *nsstr = [mval valueAtIndex:i];
icculus@28
    27
                    printf("%s\n", [nsstr cStringUsingEncoding:NSUTF8StringEncoding]);
icculus@28
    28
                }
icculus@28
    29
                printf("\n");
icculus@28
    30
            }
icculus@28
    31
        }
icculus@28
    32
    }
icculus@28
    33
icculus@28
    34
    return 0;
icculus@28
    35
}
icculus@28
    36
icculus@28
    37
// end of dump_mac_addressbook.m ...