]> git.datanom.net - vcard-parser.git/blob - src/parser/vcard.c
All features added
[vcard-parser.git] / src / parser / vcard.c
1 /*
2 * vcard.c
3 *
4 * Copyright 2019 Michael Rasmussen <mir@datanom.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include <unistd.h>
23 #include <errno.h>
24 #include <glib/gprintf.h>
25 #include <vcard.h>
26 #include <vcard-parser.h>
27
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
31
32 struct _VCard {
33 VCardParserResponse state;
34 VCardVersion version;
35 GHashTable* vcard;
36 gchar* etag;
37 };
38
39 static char *replaceWord(const char *s, const char *oldW, const char *newW) {
40 char *result;
41 int i, cnt = 0;
42 int newWlen = strlen(newW);
43 int oldWlen = strlen(oldW);
44
45 for (i = 0; s[i] != '\0'; i++) {
46 if (strstr(&s[i], oldW) == &s[i]) {
47 cnt++;
48 i += oldWlen - 1;
49 }
50 }
51
52 result = (char *) malloc(i + cnt * (newWlen - oldWlen) + 1);
53
54 i = 0;
55 while (*s) {
56 if (strstr(s, oldW) == s) {
57 strcpy(&result[i], newW);
58 i += newWlen;
59 s += oldWlen;
60 }
61 else
62 result[i++] = *s++;
63 }
64
65 result[i] = '\0';
66 return result;
67 }
68
69 static gchar* make_line(const gchar* name, const gchar* value) {
70 gchar* line = NULL;
71
72 if (name != NULL) {
73 if (g_ascii_strncasecmp("TEL", name, 3) == 0) {
74 line = g_strdup_printf("%s;%s", name, value);
75 } else if (g_ascii_strncasecmp("ADR", name, 3) == 0) {
76 line = g_strdup_printf("%s;%s", name, value);
77 } else if (g_ascii_strncasecmp("PHOTO", name, 3) == 0) {
78 line = g_strdup_printf("%s;%s", name, value);
79 } else if (g_ascii_strncasecmp("EMAIL", name, 3) == 0) {
80 line = g_strdup_printf("%s;%s", name, value);
81 } else {
82 line = g_strdup_printf("%s:%s", name, value);
83 }
84 }
85
86 return line;
87 }
88
89 static void hash_table_cb(gpointer key, gpointer value, gpointer data) {
90 GSList* list = (GSList*) value;
91 gchar** str = (gchar**) data;
92 gchar* s = NULL;
93
94 if (!list) return;
95
96 while (list) {
97 VCardProperty* vp = (VCardProperty*) list->data;
98
99 gchar* s0 = replaceWord(vp->value, "\n", "\n ");
100 gchar* line = make_line(vp->name, s0);
101 g_free(s0);
102 if (!*str)
103 s = g_strdup(line);
104 else {
105 s = g_strdup_printf("%s\n%s", *str, line);
106 g_free(*str);
107 }
108 *str = g_strdup(s);
109 g_free(s);
110 list = list->next;
111 }
112 }
113
114 static gchar** make_chunks(const gchar* text) {
115 gchar** chunks = NULL;
116 gchar* v_text = g_strdup(text);
117 g_strstrip(v_text);
118
119 gchar** tmp = g_strsplit(v_text, "END:VCARD", 0);
120 g_free(v_text);
121 guint lines = g_strv_length(tmp);
122 if (lines < 2)
123 return tmp;
124
125 if (strlen(tmp[lines-1]) < 1) {
126 chunks = g_new0(gchar*, lines);
127 lines--;
128 } else
129 chunks = g_new0(gchar*, lines + 1);
130
131 for(int i = 0; i < lines; i++) {
132 g_strchug(tmp[i]);
133 chunks[i] = g_strconcat(tmp[i], "END:VCARD", NULL);
134 }
135 g_strfreev(tmp);
136
137 return chunks;
138 }
139
140 static VCardProperty* VCardProperty_new(const gchar* key, const gchar* value) {
141 VCardProperty* vp = g_new0(VCardProperty, 1);
142 vp->name = g_strdup(key);
143 vp->value = g_strdup(value);
144
145 return vp;
146 }
147
148 static void remove_tel_prop(GSList* list, TelefonType type) {
149 VCardProperty* vp = NULL;
150 GSList* search = list;
151
152 if (search) {
153 while (search) {
154 vp = (VCardProperty*) search->data;
155 if (vp) {
156 gchar* tel = (gchar*)vp->value;
157 switch (type) {
158 case TEL_DEFAULT:
159 case TEL_MOBIL:
160 if (g_strstr_len(tel, -1, "TYPE=MOBIL")) {
161 list = g_slist_remove(list, vp);
162 vcard_property_free(vp);
163 }
164 break;
165 case TEL_HOME:
166 if (g_strstr_len(tel, -1, "TYPE=HOME")) {
167 list = g_slist_remove(list, vp);
168 vcard_property_free(vp);
169 }
170 break;
171 case TEL_WORK:
172 if (g_strstr_len(tel, -1, "TYPE=WORK")) {
173 list = g_slist_remove(list, vp);
174 vcard_property_free(vp);
175 }
176 break;
177 }
178
179 }
180 search = search->next;
181 }
182 }
183 }
184
185 static void remove_adr_prop(GSList* list, AddressType type) {
186 VCardProperty* vp = NULL;
187 GSList* search = list;
188
189 if (search) {
190 while (search) {
191 vp = (VCardProperty*) search->data;
192 if (vp) {
193 gchar* adr = (gchar*)vp->value;
194 switch (type) {
195 case ADDR_DEFAULT:
196 case ADDR_HOME:
197 if (g_strstr_len(adr, -1, "TYPE=HOME")) {
198 list = g_slist_remove(list, vp);
199 vcard_property_free(vp);
200 }
201 break;
202 case ADDR_WORK:
203 if (g_strstr_len(adr, -1, "TYPE=WORK")) {
204 list = g_slist_remove(list, vp);
205 vcard_property_free(vp);
206 }
207 break;
208 case ADDR_OTHER:
209 if (g_strstr_len(adr, -1, "TYPE=OTHER")) {
210 list = g_slist_remove(list, vp);
211 vcard_property_free(vp);
212 }
213 break;
214 }
215
216 }
217 search = search->next;
218 }
219 }
220 }
221
222 static void remove_email_prop(GSList* list, EmailType type) {
223 VCardProperty* vp = NULL;
224 GSList* search = list;
225
226 if (search) {
227 while (search) {
228 vp = (VCardProperty*) search->data;
229 if (vp) {
230 gchar* email = (gchar*)vp->value;
231 switch (type) {
232 case EMAIL_DEFAULT:
233 case EMAIL_HOME:
234 if (g_strstr_len(email, -1, "TYPE=HOME")) {
235 list = g_slist_remove(list, vp);
236 vcard_property_free(vp);
237 }
238 break;
239 case EMAIL_WORK:
240 if (g_strstr_len(email, -1, "TYPE=WORK")) {
241 list = g_slist_remove(list, vp);
242 vcard_property_free(vp);
243 }
244 break;
245 case EMAIL_OTHER:
246 if (g_strstr_len(email, -1, "TYPE=OTHER")) {
247 list = g_slist_remove(list, vp);
248 vcard_property_free(vp);
249 }
250 break;
251 }
252
253 }
254 search = search->next;
255 }
256 }
257 }
258
259 gchar* VCard_get_as_string(VCard* object) {
260 gchar* card = NULL;
261 if (object == NULL) return NULL;
262
263 if (object && object->vcard) {
264 gchar* version = vcard_version_2_str(object->version);
265 gchar* s = g_strdup_printf("BEGIN:VCARD\nVERSION:%s", version);
266 g_free(version);
267 g_hash_table_foreach(object->vcard, hash_table_cb, &s);
268 card = g_strdup_printf("%s\nEND:VCARD", s);
269 g_free(s);
270 }
271
272 return card;
273 }
274
275 void vcard_slist_property_free(gpointer data) {
276 if (data == NULL) return;
277
278 GSList* list = (GSList *) data;
279 g_slist_free_full(list, (GDestroyNotify) vcard_property_free);
280 }
281
282 void vcard_property_free(gpointer data) {
283 if (!data) return;
284 VCardProperty* vp = (VCardProperty*) data;
285 g_free(vp->name);
286 g_free(vp->value);
287 g_free(vp);
288 }
289
290 void print_slist(GSList* list) {
291 GSList* tmp = list;
292
293 while (tmp) {
294 VCardProperty* vp = (VCardProperty*) tmp->data;
295 g_print("Name: %s\n", vp->name);
296 g_print("Value: %s\n", vp->value);
297 tmp = tmp->next;
298 }
299 }
300
301 static gpointer slist_copy_func(gconstpointer src, gpointer data) {
302 const VCardProperty* vp = (const VCardProperty*) src;
303 VCardProperty* new_vp = VCardProperty_new(vp->name, vp->value);
304
305 return (gpointer) new_vp;
306 }
307
308 void VCard_free(VCard* object) {
309 if (object == NULL) return;
310
311 if (object->vcard)
312 destroy_hash_table(object->vcard);
313 g_free(object->etag);
314 g_free(object);
315 }
316
317 VCard* VCard_version_new(VCardVersion version, gboolean init) {
318 VCard* vc = g_new0(VCard, 1);
319 vc->version = version;
320 if (init) {
321 vc->vcard = init_g_hash_table(vc->version);
322 gchar* uuid = g_uuid_string_random();
323 VCardProperty* prop = VCardProperty_new("UID", g_strdup(uuid));
324 g_free(uuid);
325 GSList* uid = g_slist_prepend(NULL, prop);
326 VCard_set_property(vc, "UID", uid);
327 }
328
329 return vc;
330 }
331
332 VCard* VCard_new() {
333 return VCard_version_new(DEFAULT_VCARD_VERSION, TRUE);
334 }
335
336 GSList* VCard_new_from_text(const gchar* text, VCardVersion version, gboolean skip_broken) {
337 GSList* list = NULL;
338 VCard* vc = NULL;
339
340 if (!text || strlen(text) < 1) return NULL;
341
342 gchar** chunks = make_chunks(text);
343 for (int i = 0; i < g_strv_length(chunks); i++) {
344 vc = VCard_version_new(version, FALSE);
345
346 VCardParserResponse r = vcard_parse_text(chunks[i], &vc->version, &vc->vcard);
347 if (r != VCARD_PARSER_OK && skip_broken) {
348 VCard_free(vc);
349 continue;
350 }
351 vc->state = r;
352 list = g_slist_prepend(list, vc);
353 }
354 g_strfreev(chunks);
355
356 return list;
357 }
358
359 GSList* VCard_new_from_file(FILE* file, VCardVersion version, gboolean skip_broken) {
360 GSList* list = NULL;
361 gchar* buf = NULL;
362 size_t n = 0;
363 int buf_size = 500;
364 GString* text = g_string_new(NULL);
365
366 if (file) {
367 buf = g_new0(gchar, buf_size);
368 while ((n = fread(buf, sizeof(char), buf_size, file)) == buf_size) {
369 text = g_string_append_len(text, buf, buf_size);
370 g_free(buf);
371 buf = g_new0(gchar, buf_size);
372 }
373 if (n > 0)
374 text = g_string_append_len(text, buf, n);
375 g_free(buf);
376 buf = g_string_free_and_steal(text);
377 list = VCard_new_from_text(buf, version, skip_broken);
378 g_free(buf);
379 }
380
381 return list;
382 }
383
384 void VCard_print_list(GSList* list) {
385 VCard_print_list_fd(list, STDOUT_FILENO);
386 }
387
388 void VCard_print_list_fd(GSList* list, int fd) {
389 GSList* tmp = list;
390 if (fd > 0) {
391 while(tmp) {
392 VCard* object = (VCard*) tmp->data;
393 VCard_print_fd(object, fd);
394 if (tmp->next) {
395 ssize_t len = strlen("\n");
396 if (write(fd, "\n", len) < len)
397 g_warning(strerror(errno));
398 }
399 tmp = tmp->next;
400 }
401 }
402 }
403
404 void VCard_print(VCard* object){
405 VCard_print_fd(object, STDOUT_FILENO);
406 }
407
408 void VCard_print_fd(VCard* object, int fd) {
409 gchar *body = NULL, *s = NULL;
410
411 if (object && object->vcard && fd > 0) {
412 gchar* version = vcard_version_2_str(object->version);
413 s = g_strdup_printf("BEGIN:VCARD\nVERSION:%s", version);
414 g_free(version);
415 g_hash_table_foreach(object->vcard, hash_table_cb, &s);
416 body = g_strdup_printf("%s\nEND:VCARD", s);
417 g_free(s);
418 ssize_t len = strlen(body);
419 if (write(fd, body, len) < len)
420 g_warning(strerror(errno));
421 g_free(body);
422 }
423 }
424
425 gchar* VCard_get_state(VCard* object) {
426 gchar* message = NULL;
427
428 if (!object) return NULL;
429
430 switch (object->state) {
431 case VCARD_PARSER_OK:
432 message = g_strdup("OK");
433 break;
434 case VCARD_PARSER_VERSION_MISMATCH:
435 message = g_strdup("Version mismatch");
436 break;
437 case VCARD_PARSER_ATTRIBUTE_VERSION_MISMATCH:
438 message = g_strdup("Attribute not supported in this version");
439 break;
440 case VCARD_PARSER_BAD_FORMAT:
441 message = g_strdup("Bad input format");
442 break;
443 case VCARD_PARSER_ERROR:
444 message = g_strdup("Unknown error");
445 break;
446 default:
447 message = g_strdup("Unhandled error");
448 break;
449 }
450
451 return message;
452 }
453
454 GSList* VCard_get_property(VCard* object, const gchar* property) {
455 GSList* values = NULL;
456 GSList* tmp = NULL;
457 GSList *iter = NULL;
458 VCardProperty* vp = NULL;
459
460 if (object && object->vcard && property) {
461 tmp = g_hash_table_lookup(object->vcard, property);
462 for (iter = tmp; iter; iter = g_slist_next(iter)) {
463 vp = (VCardProperty*) iter->data;
464 VCardProperty* prop = VCardProperty_new(vp->name, vp->value);
465 values = g_slist_prepend(values, prop);
466 }
467 }
468
469 return values;
470 }
471
472 void VCard_set_property(VCard* object, const gchar* property, GSList* props) {
473 GSList *values = NULL;
474
475 if (object && object->vcard && property && props) {
476 //print_slist(props);
477 values = g_hash_table_lookup(object->vcard, property);
478 if (values) {
479 /* Remove before adding new */
480 g_hash_table_remove(object->vcard, property);
481 }
482 g_hash_table_replace(object->vcard, g_strdup(property), props);
483 }
484 }
485
486 void VCard_set_etag(VCard* vcard, const gchar* etag) {
487 if (vcard == NULL) return;
488
489 if (vcard->etag)
490 g_free(vcard->etag);
491
492 vcard->etag = g_strdup(etag);
493 }
494
495 void VCard_set_name(VCard* vcard, const gchar* firstname, const gchar* lastname) {
496 GSList *fn_value = NULL;
497 GSList *n_value = NULL;
498
499 if (vcard == NULL) return;
500
501 if (firstname == NULL || lastname == NULL) {
502 VCard_set_property(vcard, "N", NULL);
503 VCard_set_property(vcard, "FN", NULL);
504 } else {
505 gchar* name = g_strconcat(firstname, " ", lastname, NULL);
506 VCardProperty* prop = VCardProperty_new("FN", name);
507 fn_value = g_slist_prepend(fn_value, prop);
508 VCard_set_property(vcard, "FN", fn_value);
509 g_free(name);
510 name = g_strconcat(lastname, ";", firstname, ";", NULL);
511 prop = VCardProperty_new("N", name);
512 n_value = g_slist_prepend(n_value, prop);
513 VCard_set_property(vcard, "N", n_value);
514 g_free(name);
515 }
516 }
517
518 void VCard_set_company(VCard* vcard, const gchar* company) {
519 GSList* org_value = NULL;
520 if (vcard == NULL) return;
521
522 if (company == NULL) {
523 VCard_set_property(vcard, "ORG", NULL);
524 }
525
526 VCardProperty* prop = VCardProperty_new("ORG", company);
527 org_value = g_slist_prepend(org_value, prop);
528 VCard_set_property(vcard, "ORG", org_value);
529 }
530
531 void VCard_set_telefon(VCard* vcard, TelefonType type, const gchar* number) {
532 gchar* tel = NULL;
533 GSList* values = NULL;
534 if (vcard == NULL) return;
535
536 GSList* tel_value = VCard_get_property(vcard, "TEL");
537 if (number == NULL) {
538 if (tel_value) {
539 remove_tel_prop(tel_value, type);
540 VCard_set_property(vcard, "TEL", tel_value);
541 }
542 } else {
543 switch (type) {
544 case TEL_DEFAULT:
545 case TEL_MOBIL:
546 tel = g_strconcat("TYPE=MOBIL,VOICE:", number, NULL);
547 break;
548 case TEL_HOME:
549 tel = g_strconcat("TYPE=HOME,VOICE:", number, NULL);
550 break;
551 case TEL_WORK:
552 tel = g_strconcat("TYPE=WORK,VOICE:", number, NULL);
553 break;
554 }
555 if (tel_value) {
556 values = g_slist_copy_deep(tel_value, slist_copy_func, NULL);
557 }
558 VCardProperty* prop = VCardProperty_new("TEL", tel);
559 values = g_slist_prepend(values, prop);
560 VCard_set_property(vcard, "TEL", values);
561 g_free(tel);
562 }
563 }
564
565 void VCard_set_address(VCard* vcard, AddressType type, const gchar* address, const gchar* state, const gchar* city, const gchar* zip, const gchar* country) {
566 gchar* addr = NULL;
567 GSList* values = NULL;
568 if (vcard == NULL) return;
569
570 GSList* addr_value = VCard_get_property(vcard, "ADR");
571 if (address == NULL || city == NULL || zip == NULL || country == NULL) {
572 if (addr_value) {
573 remove_adr_prop(addr_value, type);
574 VCard_set_property(vcard, "ADR", addr_value);
575 }
576 } else {
577 gchar* state = NULL;
578 if (state)
579 state = g_strconcat(state, ";", NULL);
580 else
581 state = g_strdup("");
582
583 switch (type) {
584 case ADDR_DEFAULT:
585 case ADDR_HOME:
586 addr = g_strdup_printf("TYPE=HOME:;;%s;%s;%s;%s;%s;", address, city, zip, state, country);
587 //, address, ";", city, ";", zip, ";", state, ";", country, ";" , NULL);
588 break;
589 case ADDR_WORK:
590 addr = g_strconcat("TYPE=WORK:;;", address, ";", city, ";", zip, ";", state, country, ";" , NULL);
591 break;
592 case ADDR_OTHER:
593 addr = g_strconcat("TYPE=OTHER:;;", address, ";", city, ";", zip, ";", state, country, ";" , NULL);
594 break;
595 }
596 g_free(state);
597 if (addr_value) {
598 values = g_slist_copy_deep(addr_value, slist_copy_func, NULL);
599 }
600 VCardProperty* prop = VCardProperty_new("ADR", addr);
601 values = g_slist_prepend(values, prop);
602 VCard_set_property(vcard, "ADR", values);
603 g_free(addr);
604 }
605 }
606
607 void VCard_set_photo_uri(VCard* vcard, PhotoType type, const gchar* uri) {
608 gchar* photo = NULL;
609 if (vcard == NULL) return;
610
611 GSList* photo_value = VCard_get_property(vcard, "PHOTO");
612 if (uri == NULL) {
613 if (photo_value) {
614 VCard_set_property(vcard, "PHOTO", NULL);
615 }
616 } else {
617 switch (type) {
618 case PHOTO_DEFAULT:
619 case PHOTO_JPG:
620 photo = g_strconcat("VALUE=URI;TYPE=", "JPG:;", uri, NULL);
621 break;
622 case PHOTO_GIF:
623 photo = g_strconcat("VALUE=URI;TYPE=", "GIF:;", uri, NULL);
624 break;
625 case PHOTO_PNG:
626 photo = g_strconcat("VALUE=URI;TYPE=", "PNG:;", uri, NULL);
627 break;
628 }
629 VCardProperty* prop = VCardProperty_new("PHOTO", photo);
630 photo_value = g_slist_prepend(photo_value, prop);
631 VCard_set_property(vcard, "PHOTO", photo_value);
632 g_free(photo);
633 }
634 }
635
636 void VCard_set_photo_image(VCard* vcard, PhotoType type, const gchar* image) {
637 gchar* photo = NULL;
638 if (vcard == NULL) return;
639
640 GSList* photo_value = VCard_get_property(vcard, "PHOTO");
641 if (image == NULL) {
642 if (photo_value) {
643 VCard_set_property(vcard, "PHOTO", NULL);
644 }
645 } else {
646 switch (type) {
647 case PHOTO_DEFAULT:
648 case PHOTO_JPG:
649 photo = g_strconcat("TYPE=jpeg;", "ENCODING=b:", image, NULL);
650 break;
651 case PHOTO_GIF:
652 photo = g_strconcat("TYPE=gif;", "ENCODING=b:", image, NULL);
653 break;
654 case PHOTO_PNG:
655 photo = g_strconcat("TYPE=png;", "ENCODING=b:", image, NULL);
656 break;
657 }
658 VCardProperty* prop = VCardProperty_new("PHOTO", photo);
659 photo_value = g_slist_prepend(photo_value, prop);
660 VCard_set_property(vcard, "PHOTO", photo_value);
661 g_free(photo);
662 }
663 }
664
665 gchar* VCard_get_etag(VCard* vcard) {
666 if (vcard == NULL) return NULL;
667
668 return g_strdup(vcard->etag);
669 }
670
671 gchar* VCard_get_name(VCard* vcard) {
672 gchar* res = NULL;
673 if (vcard == NULL) return NULL;
674
675 GSList* fn = VCard_get_property(vcard, "FN");
676 if (fn) {
677 res = g_strdup(fn->data);
678 vcard_slist_property_free(fn);
679 }
680 return res;
681 }
682
683 gchar* VCard_get_company(VCard* vcard) {
684 gchar* res = NULL;
685 if (vcard == NULL) return NULL;
686
687 GSList* org = VCard_get_property(vcard, "ORG");
688 if (org) {
689 res = g_strdup(org->data);
690 vcard_slist_property_free(org);
691 }
692 return res;
693 }
694
695 GSList* VCard_get_telefon(VCard* vcard, TelefonType type) {
696 GSList* tel = NULL;
697 if (vcard == NULL) return NULL;
698
699 // TODO: return only telefon according to type
700
701 tel = VCard_get_property(vcard, "TEL");
702 return tel;
703 }
704
705 GSList* VCard_get_address(VCard* vcard, AddressType type) {
706 GSList* addr = NULL;
707 if (vcard == NULL) return NULL;
708
709 // TODO: return only address according to type
710
711 addr = VCard_get_property(vcard, "ADR");
712 return addr;
713 }
714
715 gchar* VCard_get_photo(VCard* vcard) {
716 gchar* res = NULL;
717 if (vcard == NULL) return NULL;
718
719 GSList* photo = VCard_get_property(vcard, "PHOTO");
720 if (photo) {
721 res = g_strdup(photo->data);
722 vcard_slist_property_free(photo);
723 }
724 return res;
725 }
726
727 void VCard_set_email(VCard* vcard, EmailType type, const gchar* email_addr) {
728 gchar* email = NULL;
729 GSList* values = NULL;
730 if (vcard == NULL) return;
731
732 GSList* email_value = VCard_get_property(vcard, "EMAIL");
733 if (email_addr == NULL) {
734 if (email_value) {
735 remove_email_prop(email_value, type);
736 VCard_set_property(vcard, "EMAIL", email_value);
737 }
738 } else {
739 switch (type) {
740 case EMAIL_DEFAULT:
741 case EMAIL_HOME:
742 email = g_strconcat("TYPE=HOME:", email_addr, NULL);
743 break;
744 case EMAIL_WORK:
745 email = g_strconcat("TYPE=WORK:", email_addr, NULL);
746 break;
747 case EMAIL_OTHER:
748 email = g_strconcat("TYPE=OTHER:", email_addr, NULL);
749 break;
750 }
751 if (email_value) {
752 //print_slist(email_value);
753 values = g_slist_copy_deep(email_value, slist_copy_func, NULL);
754 }
755 VCardProperty* prop = VCardProperty_new("EMAIL", email);
756 values = g_slist_prepend(values, prop);
757 VCard_set_property(vcard, "EMAIL", values);
758 g_free(email);
759 }
760 }
761
762 GSList* VCard_get_email(VCard* vcard, EmailType type) {
763 GSList* email = NULL;
764 if (vcard == NULL) return NULL;
765
766 // TODO: return only email according to type
767
768 email = VCard_get_property(vcard, "EMAIL");
769 return email;
770 }
771
This page took 1.480977 seconds and 6 git commands to generate.