1 #include <libebook/libebook.h>
5 static gchar *id = NULL;
6 static gchar *full_name = NULL;
7 static gchar *nickname = NULL;
8 static gchar *company = NULL;
9 static gchar **phones = NULL;
10 static gchar **emails = NULL;
12 static GOptionEntry entries[] =
14 { "id", 0, 0, G_OPTION_ARG_STRING, &id, "ID of element to modify, new or new-vcard", "ID" },
15 { "full-name", 0, 0, G_OPTION_ARG_STRING, &full_name, "Full name of person", "full_name" },
16 { "nickname", 0, 0, G_OPTION_ARG_STRING, &nickname, "Nickname of person", "nick" },
17 { "company", 0, 0, G_OPTION_ARG_STRING, &company, "Company of person", "company" },
18 { "phones", 0, 0, G_OPTION_ARG_STRING_ARRAY, &phones, "Phone numbers (all)", "phone" },
19 { "emails", 0, 0, G_OPTION_ARG_STRING_ARRAY, &emails, "Email addresses (all)", "email" },
25 Addresses List of `bbdb-record-addresses' List of address vectors
26 Vectors `bbdb-record-set-addresses'
27 Net List of `bbdb-record-net' List of network
28 address Strings `bbdb-record-set-net' addresses
29 Notes String or `bbdb-record-raw-notes' String or Association
30 Alist `bbdb-record-set-raw-notes'list of note fields
34 int main(int argc, char **argv)
37 ESourceRegistry *eds_source_registry = NULL;
45 GOptionContext *optioncontext;
47 setlocale (LC_ALL, "");
49 optioncontext = g_option_context_new ("- whack address book");
50 g_option_context_add_main_entries (optioncontext, entries, NULL);
51 g_option_context_parse (optioncontext, &argc, &argv, &error);
54 fprintf(stderr, "%s\n", error->message);
58 eds_source_registry = e_source_registry_new_sync (NULL, &error);
60 fprintf(stderr, "%s\n", error->message);
65 fprintf(stderr, "You must provide a filter\n");
69 if (strcmp (id, "new-vcard") == 0 || strcmp(id, "new") == 0) {
71 GString *vcard = g_string_new("");
75 if (strcmp (id, "new-vcard") == 0) {
76 while ((r = read(0, buf, 1023)) > 0) {
78 vcard = g_string_append(vcard, buf);
80 c = e_contact_new_from_vcard(vcard->str);
83 fprintf(stderr, "Error parsing vcard\n");
86 } else if (strcmp (id, "new") == 0) {
90 g_object_set(c, "full-name", full_name, NULL);
94 g_object_set(c, "nickname", nickname, NULL);
97 gchar **head = emails;
99 while (*head != NULL) {
100 el = g_list_prepend(el, *head);
103 g_object_set(c, "email", el, NULL);
106 source = e_source_registry_ref_default_address_book(eds_source_registry);
112 ebc = e_book_client_new(source, &error);
114 fprintf(stderr, "%s\n", error->message);
118 e_client_open_sync(E_CLIENT(ebc), TRUE, NULL, &error);
120 fprintf(stderr, "%s\n", error->message);
124 e_book_client_add_contact_sync(ebc, c, NULL, NULL, &error);
126 fprintf(stderr, "%s\n", error->message);
130 char *qu = g_strdup_printf ("(is \"id\" \"%s\")", id);
132 sources = e_source_registry_list_sources (eds_source_registry, E_SOURCE_EXTENSION_ADDRESS_BOOK);
134 for (s = sources ; s; s = s->next) {
135 source = E_SOURCE(s->data);
136 client = E_BOOK_CLIENT(e_book_client_connect_sync(source, NULL, &error));
137 e_book_client_get_contacts_sync(client, qu, &contacts, NULL, &error);
139 for (c = contacts; c; c = c->next) {
141 g_object_set(E_CONTACT(c->data), "full-name", full_name, NULL);
144 g_object_set(E_CONTACT(c->data), "nickname", nickname, NULL);
146 if (emails != NULL) {
147 gchar **head = emails;
150 if (*head[0] == '\0') {
151 printf("removing all emails\n");
154 g_object_get(E_CONTACT(c->data), "email", &el, NULL);
157 while (*head != NULL) {
158 printf("appending %s\n", *head);
159 el = g_list_prepend(el, *head);
162 g_object_set(E_CONTACT(c->data), "email", el, NULL);
164 e_book_client_modify_contact_sync(client, E_CONTACT(c->data), NULL, &error);