1 #include <libebook/e-book.h>
2 #include <libedataserver/e-source-group.h>
6 static gchar *id = NULL;
7 static gchar *full_name = NULL;
8 static gchar *nickname = NULL;
9 static gchar *company = NULL;
10 static gchar **phones = NULL;
11 static gchar **emails = NULL;
13 static GOptionEntry entries[] =
15 { "id", 0, 0, G_OPTION_ARG_STRING, &id, "ID of element to modify, new or new-vcard", "ID" },
16 { "full-name", 0, 0, G_OPTION_ARG_STRING, &full_name, "Full name of person", "full_name" },
17 { "nickname", 0, 0, G_OPTION_ARG_STRING, &nickname, "Nickname of person", "nick" },
18 { "company", 0, 0, G_OPTION_ARG_STRING, &company, "Company of person", "company" },
19 { "phones", 0, 0, G_OPTION_ARG_STRING_ARRAY, &phones, "Phone numbers (all)", "phone" },
20 { "emails", 0, 0, G_OPTION_ARG_STRING_ARRAY, &emails, "Email addresses (all)", "email" },
26 Addresses List of `bbdb-record-addresses' List of address vectors
27 Vectors `bbdb-record-set-addresses'
28 Net List of `bbdb-record-net' List of network
29 address Strings `bbdb-record-set-net' addresses
30 Notes String or `bbdb-record-raw-notes' String or Association
31 Alist `bbdb-record-set-raw-notes'list of note fields
35 int main(int argc, char **argv)
38 ESourceList *source_list;
48 GOptionContext *optioncontext;
50 setlocale (LC_ALL, "");
54 optioncontext = g_option_context_new ("- whack address book");
55 g_option_context_add_main_entries (optioncontext, entries, NULL);
56 g_option_context_parse (optioncontext, &argc, &argv, &error);
59 fprintf(stderr, "%s\n", error->message);
63 e_book_get_addressbooks(&source_list, &error);
66 fprintf(stderr, "%s\n", error->message);
71 fprintf(stderr, "You must provide a filter\n");
75 if (strcmp (id, "new-vcard") == 0 || strcmp(id, "new") == 0) {
77 GString *vcard = g_string_new("");
81 if (strcmp (id, "new-vcard") == 0) {
82 while ((r = read(0, buf, 1023)) > 0) {
84 vcard = g_string_append(vcard, buf);
86 c = e_contact_new_from_vcard(vcard->str);
89 fprintf(stderr, "Error parsing vcard\n");
92 } else if (strcmp (id, "new") == 0) {
96 g_object_set(c, "full-name", full_name, NULL);
100 g_object_set(c, "nickname", nickname, NULL);
103 gchar **head = emails;
105 while (*head != NULL) {
106 el = g_list_prepend(el, *head);
109 g_object_set(c, "email", el, NULL);
113 book = e_book_new_system_addressbook (&error);
115 fprintf(stderr, "%s\n", error->message);
119 e_book_open (book, TRUE, &error);
121 fprintf(stderr, "%s\n", error->message);
125 e_book_add_contact (book, c, &error);
127 fprintf(stderr, "%s\n", error->message);
131 char *qu = g_strdup_printf ("(is \"id\" \"%s\")", id);
132 query = e_book_query_from_string(qu);
134 groups = e_source_list_peek_groups(source_list);
135 for (g = groups; g; g = g->next) {
137 group = E_SOURCE_GROUP (g->data);
138 sources = e_source_group_peek_sources(group);
140 for (s = sources ; s; s = s->next) {
141 source = E_SOURCE(s->data);
142 book = e_book_new(source, &error);
143 e_book_open(book, TRUE, &error);
144 e_book_get_contacts(book, query, &contacts, &error);
146 for (c = contacts; c; c = c->next) {
148 g_object_set(E_CONTACT(c->data), "full-name", full_name, NULL);
151 g_object_set(E_CONTACT(c->data), "nickname", nickname, NULL);
153 if (emails != NULL) {
154 gchar **head = emails;
157 if (*head[0] == '\0') {
158 printf("removing all emails\n");
161 g_object_get(E_CONTACT(c->data), "email", &el, NULL);
164 while (*head != NULL) {
165 printf("appending %s\n", *head);
166 el = g_list_prepend(el, *head);
169 g_object_set(E_CONTACT(c->data), "email", el, NULL);
171 e_book_commit_contact(book, E_CONTACT(c->data), &error);
175 e_book_query_unref (query);