#include <gconf/gconf.h>
#include <glib.h>
-void dump_as_rfc822(EContact *contact)
+void dump_as_vcard(EContact *contact, int dump_all)
{
GList *attrs;
int i;
- attrs = e_contact_get_attributes(contact, E_CONTACT_PHONE_MOBILE);
- printf("\t\tCONTACT: %s\n", e_contact_get(contact, E_CONTACT_FULL_NAME));
- if (! attrs) {
- fprintf(stderr, "Could not get phone attributes for contact\n");
- return;
- }
+
+ attrs = e_vcard_get_attributes(&contact->parent);
for (i = 0; i < g_list_length(attrs); i++) {
- EVCardAttribute *attr = (EVCardAttribute *) g_list_nth_data(attrs, i);
+ EVCardAttribute *attr = (EVCardAttribute *)
+ g_list_nth_data(attrs, i);
int j;
-
+ char *attr_name = e_vcard_attribute_get_name(attr);
+
+ if (!dump_all &&
+ strcmp(attr_name, "TEL") != 0 &&
+ strcmp(attr_name, "FN") != 0 &&
+ strcmp(attr_name, "BDAY") != 0 &&
+ strcmp(attr_name, "ORG") != 0 &&
+ strcmp(attr_name, "TEL") != 0 &&
+ strcmp(attr_name, "EMAIL") != 0 &&
+ strcmp(attr_name, "NOTE") != 0 &&
+ strcmp(attr_name, "NICKNAME") != 0
+ ) {
+ continue;
+ }
+
+ if (strcmp(attr_name, "N") == 0 ||
+ strcmp(attr_name, "ADR") == 0) {
+ continue;
+ }
+
if (e_vcard_attribute_is_single_valued(attr)) {
- printf("\t\tphone: %s\n", e_vcard_attribute_get_value(attr));
+ char *av = e_vcard_attribute_get_value(attr);
+ printf("%s: %s\n",
+ attr_name,
+ av);
} else {
GList *vals = e_vcard_attribute_get_values(attr);
-
- if (! vals) {
- continue;
- }
-
+
for (j = 0; j < g_list_length(vals); j++) {
- printf("\t\tphone: %s\n", (char*) g_list_nth(vals, j));
+ char *av = g_list_nth(vals, j);
+
+ printf("%s: %s\n",
+ attr_name,
+ av);
}
}
}
+
+/* char *name = e_contact_get(contact, E_CONTACT_FULL_NAME);
+ char *nickname = e_contact_get(contact, E_CONTACT_NICKNAME);
+
+ printf("Name: %s\n", name);
+
+ if (nickname && strcmp("", nickname) != 0) {
+ printf("Nickname: %s\n", nickname);
+ }
+
+ free(name);
+ free(nickname);
+
+*/
+
}
int main(int argc, char **argv)
e_book_get_contacts(book, query, &contacts, &error);
for (c = contacts; c; c = c->next) {
- dump_as_rfc822(E_CONTACT(c->data));
+ dump_as_vcard(E_CONTACT(c->data), 1);
}
}
}