1 #include <libebook/e-book.h>
2 #include <libedataserver/e-source-group.h>
3 #include <gconf/gconf.h>
6 void dump_as_vcard(EContact *contact, int dump_all)
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);
48 static gchar **search_filter = NULL;
50 static GOptionEntry entries[] =
52 { G_OPTION_REMAINING, 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_STRING_ARRAY, &search_filter, NULL, NULL},
56 int main(int argc, char **argv)
59 ESourceList *source_list;
69 GOptionContext *optioncontext;
71 optioncontext = g_option_context_new ("- whack address book");
72 g_option_context_add_main_entries (optioncontext, entries, NULL);
73 g_option_context_parse (optioncontext, &argc, &argv, &error);
76 fprintf(stderr, "%s\n", error->message);
79 e_book_get_addressbooks(&source_list, &error);
82 fprintf(stderr, "%s\n", error->message);
85 if (search_filter != NULL) {
86 char *qu = g_strdup_printf ("(or (contains \"email\" \"%s\") "
87 "(contains \"full_name\" \"%s\"))",
88 *search_filter, *search_filter);
89 query = e_book_query_from_string(qu);
92 query = e_book_query_field_exists(E_CONTACT_FULL_NAME);
95 groups = e_source_list_peek_groups(source_list);
96 for (g = groups; g; g = g->next) {
98 group = E_SOURCE_GROUP (g->data);
99 sources = e_source_group_peek_sources(group);
101 for (s = sources ; s; s = s->next) {
102 source = E_SOURCE(s->data);
103 book = e_book_new(source, &error);
104 e_book_open(book, TRUE, &error);
105 e_book_get_contacts(book, query, &contacts, &error);
107 for (c = contacts; c; c = c->next) {
108 dump_as_vcard(E_CONTACT(c->data), 1);
112 e_book_query_unref (query);