1 #include <libebook/libebook.h>
5 void dump_as_vcard(EContact *contact, int dump_all)
10 printf("BEGIN:VCARD\n");
11 attrs = e_vcard_get_attributes(&contact->parent);
12 for (i = 0; i < g_list_length(attrs); i++) {
13 EVCardAttribute *attr = (EVCardAttribute *)
14 g_list_nth_data(attrs, i);
16 const char *attr_name = e_vcard_attribute_get_name(attr);
19 strcmp(attr_name, "TEL") != 0 &&
20 strcmp(attr_name, "FN") != 0 &&
21 strcmp(attr_name, "BDAY") != 0 &&
22 strcmp(attr_name, "ORG") != 0 &&
23 strcmp(attr_name, "TEL") != 0 &&
24 strcmp(attr_name, "EMAIL") != 0 &&
25 strcmp(attr_name, "NOTE") != 0 &&
26 strcmp(attr_name, "NICKNAME") != 0
31 if (e_vcard_attribute_is_single_valued(attr)) {
32 char *av = e_vcard_attribute_get_value(attr);
37 GList *vals = e_vcard_attribute_get_values(attr);
39 for (j = 0; j < g_list_length(vals); j++) {
40 const char *av = *(char**) g_list_nth(vals, j);
42 printf("%s: %s\n", attr_name, av);
46 printf("END:VCARD\n");
49 static gchar **search_filter = NULL;
51 static GOptionEntry entries[] =
53 { G_OPTION_REMAINING, 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY, &search_filter, NULL, NULL},
57 int main(int argc, char **argv)
60 ESourceRegistry *eds_source_registry = NULL;
69 GOptionContext *optioncontext;
71 setlocale (LC_ALL, "");
74 optioncontext = g_option_context_new ("- whack address book");
75 g_option_context_add_main_entries (optioncontext, entries, NULL);
76 g_option_context_parse (optioncontext, &argc, &argv, &error);
79 fprintf(stderr, "%s\n", error->message);
83 eds_source_registry = e_source_registry_new_sync (NULL, &error);
85 fprintf(stderr, "%s\n", error->message);
89 sources = e_source_registry_list_sources (eds_source_registry, NULL);
91 if (search_filter != NULL) {
92 query = e_book_query_any_field_contains(*search_filter);
94 query = e_book_query_field_exists(E_CONTACT_FULL_NAME);
97 for (s = sources ; s; s = s->next) {
98 source = E_SOURCE(s->data);
99 book = e_book_new(source, &error);
102 fprintf(stderr, "%s\n", error->message);
106 e_book_open(book, TRUE, &error);
110 fprintf(stderr, "%s\n", error->message);
114 e_book_get_contacts(book, query, &contacts, &error);
116 fprintf(stderr, "%s\n", error->message);
120 for (c = contacts; c; c = c->next) {
121 dump_as_vcard(E_CONTACT(c->data), 1);
124 e_book_query_unref(query);
125 g_list_free_full(sources, g_object_unref);