2 * Copyright (c) 1996-2012 by the citadel.org team
4 * This program is open source software. You can redistribute it and/or
5 * modify it under the terms of the GNU General Public License, version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
14 #include "webserver.h"
17 CtxType CTX_VCARD = CTX_NONE;
20 {HKEY("n")}, /* N is name, but only if there's no FN already there */
21 {HKEY("fn")}, /* FN (full name) is a true 'display name' field */
22 {HKEY("title")}, /* title */
23 {HKEY("org")}, /* organization */
55 HashList *VCToEnum = NULL;
58 * Record compare function for sorting address book indices
60 int abcmp(const void *ab1, const void *ab2) {
62 (((const addrbookent *)ab1)->ab_name),
63 (((const addrbookent *)ab2)->ab_name)
69 * Helper function for do_addrbook_view()
70 * Converts a name into a three-letter tab label
72 void nametab(char *tabbuf, long len, char *name) {
73 stresc(tabbuf, len, name, 0, 0);
74 tabbuf[0] = toupper(tabbuf[0]);
75 tabbuf[1] = tolower(tabbuf[1]);
76 tabbuf[2] = tolower(tabbuf[2]);
82 * If it's an old "Firstname Lastname" style record, try to convert it.
84 void lastfirst_firstlast(char *namebuf) {
89 if (namebuf == NULL) return;
90 if (strchr(namebuf, ';') != NULL) return;
92 i = num_tokens(namebuf, ' ');
95 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
96 remove_token(namebuf, i-1, ' ');
97 strcpy(firstname, namebuf);
98 sprintf(namebuf, "%s; %s", lastname, firstname);
103 wc_mime_attachment *load_vcard(message_summary *Msg)
106 StrBuf *FoundCharset = NewStrBuf();
111 wc_mime_attachment *Mime;
112 wc_mime_attachment *VCMime = NULL;
114 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
115 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
116 Msg->MsgBody->msgnum = Msg->msgnum;
118 load_message(Msg, FoundCharset, &Error);
120 FreeStrBuf(&FoundCharset);
121 /* look up the vcard... */
122 it = GetNewHashPos(Msg->AllAttach, 0);
123 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
126 Mime = (wc_mime_attachment*) vMime;
127 if ((strcmp(ChrPtr(Mime->ContentType),
128 "text/x-vcard") == 0) ||
129 (strcmp(ChrPtr(Mime->ContentType),
140 MimeLoadData(VCMime);
145 * fetch the display name off a vCard
147 void fetch_ab_name(message_summary *Msg, char **namebuf) {
150 wc_mime_attachment *VCMime = NULL;
152 if (namebuf == NULL) return;
154 VCMime = load_vcard(Msg);
158 /* Grab the name off the card */
159 display_vcard(WC->WBuf, VCMime, 0, 0, namebuf, Msg->msgnum);
161 if (*namebuf != NULL) {
162 lastfirst_firstlast(*namebuf);
164 len = strlen(*namebuf);
165 for (i=0; i<len; ++i) {
166 if ((*namebuf)[i] != ';') return;
169 (*namebuf) = strdup(_("(no name)"));
172 (*namebuf) = strdup(_("(no name)"));
179 * Turn a vCard "n" (name) field into something displayable.
181 void vcard_n_prettyize(char *name)
186 original_name = strdup(name);
187 len = strlen(original_name);
188 for (i=0; i<5; ++i) {
190 if (original_name[len-1] == ' ') {
191 original_name[--len] = 0;
193 if (original_name[len-1] == ';') {
194 original_name[--len] = 0;
200 for (i=0; i<len; ++i) {
201 if (original_name[i] == ';') {
206 name[j++] = original_name[i];
217 * preparse a vcard name
218 * display_vcard() calls this after parsing the textual vCard into
219 * our 'struct vCard' data object.
220 * This gets called instead of display_parsed_vcard() if we are only looking
221 * to extract the person's name instead of displaying the card.
223 void fetchname_parsed_vcard(struct vCard *v, char **storename) {
233 name = vcard_get_prop(v, "n", 1, 0, 0);
236 prop = vcard_get_prop(v, "n", 1, 0, 1);
237 n = num_tokens(prop, ';');
239 for (j=0; j<n; ++j) {
240 extract_token(buf, prop, j, ';', sizeof buf);
241 if (!strcasecmp(buf, "encoding=quoted-printable")) {
244 if (!strcasecmp(buf, "encoding=base64")) {
249 /* %ff can become 6 bytes in utf8 */
250 *storename = malloc(len * 2 + 3);
251 j = CtdlDecodeQuotedPrintable(
257 /* ff will become one byte.. */
258 *storename = malloc(len + 50);
268 *storename = malloc(len + 3); /* \0 + eventualy missing ', '*/
269 memcpy(*storename, name, len + 1);
271 /* vcard_n_prettyize(storename); */
280 * display_vcard() calls this after parsing the textual vCard into
281 * our 'struct vCard' data object.
283 * Set 'full' to nonzero to display the full card, otherwise it will only
284 * show a summary line.
286 * This code is a bit ugly, so perhaps an explanation is due: we do this
287 * in two passes through the vCard fields. On the first pass, we process
288 * fields we understand, and then render them in a pretty fashion at the
289 * end. Then we make a second pass, outputting all the fields we don't
290 * understand in a simple two-column name/value format.
291 * v the vCard to display
292 * full display all items of the vcard?
293 * msgnum Citadel message pointer
295 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
302 char *thisname, *thisvalue;
303 char firsttoken[SIZ];
312 strcpy(fullname, "");
319 StrBufAppendPrintf(Target, "<td>");
320 name = vcard_get_prop(v, "fn", 1, 0, 0);
322 StrEscAppend(Target, NULL, name, 0, 0);
324 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
325 strcpy(fullname, name);
326 vcard_n_prettyize(fullname);
327 StrEscAppend(Target, NULL, fullname, 0, 0);
330 StrBufAppendPrintf(Target, " ");
332 StrBufAppendPrintf(Target, "</td>");
336 StrBufAppendPrintf(Target, "<div align=\"center\">"
337 "<table bgcolor=\"#aaaaaa\" width=\"50%%\">");
338 for (pass=1; pass<=2; ++pass) {
340 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
342 thisname = strdup(v->prop[i].name);
343 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
345 for (j=0; j<num_tokens(thisname, ';'); ++j) {
346 extract_token(buf, thisname, j, ';', sizeof buf);
347 if (!strcasecmp(buf, "encoding=quoted-printable")) {
349 remove_token(thisname, j, ';');
351 if (!strcasecmp(buf, "encoding=base64")) {
353 remove_token(thisname, j, ';');
357 len = strlen(v->prop[i].value);
358 /* if we have some untagged QP, detect it here. */
359 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
360 utf8ify_rfc822_string(&v->prop[i].value);
363 // %ff can become 6 bytes in utf8
364 thisvalue = malloc(len * 2 + 3);
365 j = CtdlDecodeQuotedPrintable(
366 thisvalue, v->prop[i].value,
371 // ff will become one byte..
372 thisvalue = malloc(len + 50);
374 thisvalue, v->prop[i].value,
375 strlen(v->prop[i].value) );
378 thisvalue = strdup(v->prop[i].value);
381 /* Various fields we may encounter ***/
383 /* N is name, but only if there's no FN already there */
384 if (!strcasecmp(firsttoken, "n")) {
385 if (IsEmptyStr(fullname)) {
386 strcpy(fullname, thisvalue);
387 vcard_n_prettyize(fullname);
391 /* FN (full name) is a true 'display name' field */
392 else if (!strcasecmp(firsttoken, "fn")) {
393 strcpy(fullname, thisvalue);
397 else if (!strcasecmp(firsttoken, "title")) {
398 strcpy(title, thisvalue);
402 else if (!strcasecmp(firsttoken, "org")) {
403 strcpy(org, thisvalue);
406 else if (!strcasecmp(firsttoken, "email")) {
408 if (!IsEmptyStr(mailto)) strcat(mailto, "<br>");
410 "<a href=\"display_enter"
411 "?force_room=_MAIL_?recp=");
413 len = strlen(mailto);
414 urlesc(&mailto[len], SIZ - len, "\"");
415 len = strlen(mailto);
416 urlesc(&mailto[len], SIZ - len, fullname);
417 len = strlen(mailto);
418 urlesc(&mailto[len], SIZ - len, "\" <");
419 len = strlen(mailto);
420 urlesc(&mailto[len], SIZ - len, thisvalue);
421 len = strlen(mailto);
422 urlesc(&mailto[len], SIZ - len, ">");
424 strcat(mailto, "\">");
425 len = strlen(mailto);
426 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
427 strcat(mailto, "</A>");
429 else if (!strcasecmp(firsttoken, "tel")) {
430 if (!IsEmptyStr(phone)) strcat(phone, "<br>");
431 strcat(phone, thisvalue);
432 for (j=0; j<num_tokens(thisname, ';'); ++j) {
433 extract_token(buf, thisname, j, ';', sizeof buf);
434 if (!strcasecmp(buf, "tel"))
436 else if (!strcasecmp(buf, "work"))
437 strcat(phone, _(" (work)"));
438 else if (!strcasecmp(buf, "home"))
439 strcat(phone, _(" (home)"));
440 else if (!strcasecmp(buf, "cell"))
441 strcat(phone, _(" (cell)"));
449 else if (!strcasecmp(firsttoken, "adr")) {
451 StrBufAppendPrintf(Target, "<tr><td>");
452 StrBufAppendPrintf(Target, _("Address:"));
453 StrBufAppendPrintf(Target, "</td><td>");
454 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
455 extract_token(buf, thisvalue, j, ';', sizeof buf);
456 if (!IsEmptyStr(buf)) {
457 StrEscAppend(Target, NULL, buf, 0, 0);
458 if (j<3) StrBufAppendPrintf(Target, "<br>");
459 else StrBufAppendPrintf(Target, " ");
462 StrBufAppendPrintf(Target, "</td></tr>\n");
465 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
466 // Only output on second pass
467 StrBufAppendPrintf(Target, "<tr><td>");
468 StrBufAppendPrintf(Target, _("Photo:"));
469 StrBufAppendPrintf(Target, "</td><td>");
470 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
471 StrBufAppendPrintf(Target, "</td></tr>\n");
473 else if (!strcasecmp(firsttoken, "version")) {
476 else if (!strcasecmp(firsttoken, "rev")) {
479 else if (!strcasecmp(firsttoken, "label")) {
484 /*** Don't show extra fields. They're ugly.
486 StrBufAppendPrintf(Target, "<TR><TD>");
487 StrEscAppend(Target, NULL, thisname, 0, 0);
488 StrBufAppendPrintf(Target, "</TD><TD>");
489 StrEscAppend(Target, NULL, thisvalue, 0, 0);
490 StrBufAppendPrintf(Target, "</TD></TR>\n");
500 StrBufAppendPrintf(Target, "<tr bgcolor=\"#aaaaaa\">"
501 "<td colspan=2 bgcolor=\"#ffffff\">"
502 "<img align=\"center\" src=\"static/webcit_icons/essen/32x32/contact.png\">"
503 "<font size=\"+1\"><b>");
504 StrEscAppend(Target, NULL, fullname, 0, 0);
505 StrBufAppendPrintf(Target, "</b></font>");
506 if (!IsEmptyStr(title)) {
507 StrBufAppendPrintf(Target, "<div align=\"right>\"");
508 StrEscAppend(Target, NULL, title, 0, 0);
509 StrBufAppendPrintf(Target, "</div>");
511 if (!IsEmptyStr(org)) {
512 StrBufAppendPrintf(Target, "<div align=\"right\">");
513 StrEscAppend(Target, NULL, org, 0, 0);
514 StrBufAppendPrintf(Target, "</div>");
516 StrBufAppendPrintf(Target, "</td></tr>\n");
518 if (!IsEmptyStr(phone)) {
519 StrBufAppendPrintf(Target, "<tr><td>");
520 StrBufAppendPrintf(Target, _("Telephone:"));
521 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
523 if (!IsEmptyStr(mailto)) {
524 StrBufAppendPrintf(Target, "<tr><td>");
525 StrBufAppendPrintf(Target, _("E-mail:"));
526 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
532 StrBufAppendPrintf(Target, "</table></div>\n");
537 * display_vcard() calls this after parsing the textual vCard into
538 * our 'struct vCard' data object.
540 * Set 'full' to nonzero to display the full card, otherwise it will only
541 * show a summary line.
543 * This code is a bit ugly, so perhaps an explanation is due: we do this
544 * in two passes through the vCard fields. On the first pass, we process
545 * fields we understand, and then render them in a pretty fashion at the
546 * end. Then we make a second pass, outputting all the fields we don't
547 * understand in a simple two-column name/value format.
548 * v the vCard to display
549 * full display all items of the vcard?
550 * msgnum Citadel message pointer
552 void parse_vcard(StrBuf *Target, struct vCard *v, HashList *VC, int full, wc_mime_attachment *Mime)
560 StrBuf *thisname = NULL;
561 char firsttoken[SIZ];
565 thisname = NewStrBuf();
566 for (i=0; i<(v->numprops); ++i) {
569 StrBufPlain(thisname, v->prop[i].name, -1);
570 StrBufLowerCase(thisname);
572 /*len = */extract_token(firsttoken, ChrPtr(thisname), 0, ';', sizeof firsttoken);
574 for (j=0; j<num_tokens(ChrPtr(thisname), ';'); ++j) {
575 extract_token(buf, ChrPtr(thisname), j, ';', sizeof buf);
576 if (!strcasecmp(buf, "encoding=quoted-printable")) {
578 /* remove_token(thisname, j, ';');*/
580 if (!strcasecmp(buf, "encoding=base64")) {
582 /* remove_token(thisname, j, ';');*/
586 /* copy over the payload into a StrBuf */
587 Val = NewStrBufPlain(v->prop[i].value, -1);
589 /* if we have some untagged QP, detect it here. */
590 if (is_qp || (strstr(v->prop[i].value, "=?")!=NULL)){
592 StrBuf_RFC822_to_Utf8(Swap, Val, NULL, NULL); /* default charset, current charset */
599 StrBufDecodeBase64(Val);
602 syslog(LOG_DEBUG, "%s [%s][%s]",
606 if (GetHash(VCToEnum, firsttoken, strlen(firsttoken), &V))
609 Put(VC, IKEY(evc), Val, HFreeStrBuf);
610 syslog(LOG_DEBUG, "[%ul]\n", evc);
614 syslog(LOG_DEBUG, "[]\n");
616 TODO: check for layer II
619 long max = num_tokens(thisname, ';');
620 firsttoken[len] = '_';
622 for (j = 0; j < max; j++) {
625 extract_token(buf, thisname, j, ';', sizeof (buf));
626 if (!strcasecmp(buf, "tel"))
628 else if (!strcasecmp(buf, "work"))
629 strcat(phone, _(" (work)"));
630 else if (!strcasecmp(buf, "home"))
631 strcat(phone, _(" (home)"));
632 else if (!strcasecmp(buf, "cell"))
633 strcat(phone, _(" (cell)"));
652 void tmplput_VCARD_ITEM(StrBuf *Target, WCTemplputParams *TP)
654 HashList *VC = CTX(CTX_VCARD);
658 evc = GetTemplateTokenNumber(Target, TP, 0, -1);
661 if (GetHash(VC, IKEY(evc), &vStr))
663 StrBufAppendTemplate(Target, TP,
671 void new_vcard (StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
674 WCTemplputParams SubTP;
676 memset(&SubTP, 0, sizeof(WCTemplputParams));
679 VC = NewHash(0, Flathash);
680 parse_vcard(Target, v, VC, full, Mime);
682 SubTP.Filter.ContextType = CTX_VCARD;
685 DoTemplate(HKEY("test_vcard"), Target, &SubTP);
692 * Display a textual vCard
693 * (Converts to a vCard object and then calls the actual display function)
694 * Set 'full' to nonzero to display the whole card instead of a one-liner.
695 * Or, if "storename" is non-NULL, just store the person's name in that
696 * buffer instead of displaying the card at all.
698 * vcard_source the buffer containing the vcard text
699 * alpha Display only if name begins with this letter of the alphabet
700 * full Display the full vCard (otherwise just the display name)
701 * storename If not NULL, also store the display name here
702 * msgnum Citadel message pointer
704 void display_vcard(StrBuf *Target,
705 wc_mime_attachment *Mime,
717 v = VCardLoad(Mime->Data);
719 if (v == NULL) return;
721 name = vcard_get_prop(v, "n", 1, 0, 0);
723 Buf = NewStrBufPlain(name, -1);
724 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
725 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
726 this_alpha = ChrPtr(Buf)[0];
731 if (storename != NULL) {
732 fetchname_parsed_vcard(v, storename);
734 else if ((alpha == 0) ||
735 ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha))) ||
736 ((!isalpha(alpha)) && (!isalpha(this_alpha)))
740 new_vcard (Target, v, full, Mime);
742 display_parsed_vcard(Target, v, full, Mime);
752 * Render the address book using info we gathered during the scan
754 * addrbook the addressbook to render
755 * num_ab the number of the addressbook
757 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
761 static int NAMESPERPAGE = 60;
764 char tabfirst_label[64];
766 char tablast_label[64];
767 char this_tablabel[64];
772 wc_printf("<br><br><br><div align=\"center\"><i>");
773 wc_printf(_("This address book is empty."));
774 wc_printf("</i></div>\n");
779 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
782 num_pages = (num_ab / NAMESPERPAGE) + 1;
784 tablabels = malloc(num_pages * sizeof (char *));
785 if (tablabels == NULL) {
786 wc_printf("<br><br><br><div align=\"center\"><i>");
787 wc_printf(_("An internal error has occurred."));
788 wc_printf("</i></div>\n");
792 for (i=0; i<num_pages; ++i) {
793 tabfirst = i * NAMESPERPAGE;
794 tablast = tabfirst + NAMESPERPAGE - 1;
795 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
796 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
797 nametab(tablast_label, 64, addrbook[tablast].ab_name);
798 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
799 tablabels[i] = strdup(this_tablabel);
802 tabbed_dialog(num_pages, tablabels);
805 for (i=0; i<num_ab; ++i) {
807 if ((i / NAMESPERPAGE) != page) { /* New tab */
808 page = (i / NAMESPERPAGE);
810 wc_printf("</tr></table>\n");
811 end_tab(page-1, num_pages);
813 begin_tab(page, num_pages);
814 wc_printf("<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" width=\"100%%\">\n");
818 if ((displayed % 4) == 0) {
820 wc_printf("</tr>\n");
823 wc_printf("<tr bgcolor=\"#%s\">",
824 (bg ? "dddddd" : "ffffff")
830 wc_printf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
831 addrbook[i].ab_msgnum);
832 wc_printf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
833 vcard_n_prettyize(addrbook[i].ab_name);
834 escputs(addrbook[i].ab_name);
835 wc_printf("</a></td>\n");
839 /* Placeholders for empty columns at end */
840 if ((num_ab % 4) != 0) {
841 for (i=0; i<(4-(num_ab % 4)); ++i) {
842 wc_printf("<td> </td>");
846 wc_printf("</tr></table>\n");
847 end_tab((num_pages-1), num_pages);
849 begin_tab(num_pages, num_pages);
850 /* FIXME there ought to be something here */
851 end_tab(num_pages, num_pages);
853 for (i=0; i<num_pages; ++i) {
863 * Edit the vCard component of a MIME message.
864 * Supply the message number
865 * and MIME part number to fetch. Or, specify -1 for the message number
866 * to start with a blank card.
868 void do_edit_vcard(long msgnum, char *partnum,
869 message_summary *VCMsg,
870 wc_mime_attachment *VCAtt,
871 const char *return_to,
872 const char *force_room) {
874 message_summary *Msg = NULL;
875 wc_mime_attachment *VCMime = NULL;
883 char middlename[256];
897 char primary_inetemail[256];
898 char other_inetemail[SIZ];
899 char extrafields[SIZ];
920 primary_inetemail[0] = 0;
921 other_inetemail[0] = 0;
927 safestrncpy(whatuser, "", sizeof whatuser);
930 ((VCMsg != NULL) && (VCAtt != NULL)))
932 if ((VCMsg == NULL) && (VCAtt == NULL)) {
934 Msg = (message_summary *) malloc(sizeof(message_summary));
935 memset(Msg, 0, sizeof(message_summary));
936 Msg->msgnum = msgnum;
937 VCMime = load_vcard(Msg);
938 if (VCMime == NULL) {
939 convenience_page("770000", _("Error"), "");///TODO: important message
940 DestroyMessageSummary(Msg);
944 v = VCardLoad(VCMime->Data);
947 v = VCardLoad(VCAtt->Data);
950 /* Populate the variables for our form */
952 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
953 char prp[256]; /* property name */
954 char prm[256]; /* parameters */
956 value = vcard_get_prop(v, "", 0, i++, 0);
959 extract_token(prp, key, 0, ';', sizeof prp);
960 safestrncpy(prm, key, sizeof prm);
961 remove_token(prm, 0, ';');
963 if (!strcasecmp(prp, "n")) {
964 extract_token(lastname, value, 0, ';', sizeof lastname);
965 extract_token(firstname, value, 1, ';', sizeof firstname);
966 extract_token(middlename, value, 2, ';', sizeof middlename);
967 extract_token(prefix, value, 3, ';', sizeof prefix);
968 extract_token(suffix, value, 4, ';', sizeof suffix);
971 else if (!strcasecmp(prp, "fn")) {
972 safestrncpy(fullname, value, sizeof fullname);
975 else if (!strcasecmp(prp, "title")) {
976 safestrncpy(title, value, sizeof title);
979 else if (!strcasecmp(prp, "org")) {
980 safestrncpy(org, value, sizeof org);
983 else if (!strcasecmp(prp, "adr")) {
984 extract_token(pobox, value, 0, ';', sizeof pobox);
985 extract_token(extadr, value, 1, ';', sizeof extadr);
986 extract_token(street, value, 2, ';', sizeof street);
987 extract_token(city, value, 3, ';', sizeof city);
988 extract_token(state, value, 4, ';', sizeof state);
989 extract_token(zipcode, value, 5, ';', sizeof zipcode);
990 extract_token(country, value, 6, ';', sizeof country);
993 else if (!strcasecmp(prp, "tel")) {
995 if (bmstrcasestr(prm, "home")) {
996 extract_token(hometel, value, 0, ';', sizeof hometel);
998 else if (bmstrcasestr(prm, "work")) {
999 extract_token(worktel, value, 0, ';', sizeof worktel);
1001 else if (bmstrcasestr(prm, "fax")) {
1002 extract_token(faxtel, value, 0, ';', sizeof faxtel);
1004 else if (bmstrcasestr(prm, "cell")) {
1005 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
1007 else { /* Missing or unknown type; put it in the home phone */
1008 extract_token(hometel, value, 0, ';', sizeof hometel);
1012 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
1013 if (primary_inetemail[0] == 0) {
1014 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
1017 if (other_inetemail[0] != 0) {
1018 strcat(other_inetemail, "\n");
1020 strcat(other_inetemail, value);
1024 /* Unrecognized properties are preserved here so we don't discard them
1025 * just because the vCard was edited with WebCit.
1028 strcat(extrafields, key);
1029 strcat(extrafields, ":");
1030 strcat(extrafields, value);
1031 strcat(extrafields, "\n");
1039 /* Display the form */
1040 output_headers(1, 1, 1, 0, 0, 0);
1042 do_template("box_begin_1");
1043 StrBufAppendBufPlain(WC->WBuf, _("Edit contact information"), -1, 0);
1044 do_template("box_begin_2");
1046 wc_printf("<form method=\"POST\" action=\"submit_vcard\">\n");
1047 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1049 if (force_room != NULL) {
1050 wc_printf("<input type=\"hidden\" name=\"force_room\" value=\"");
1051 escputs(force_room);
1056 wc_printf("<input type=\"hidden\" name=\"go\" value=\"");
1057 StrEscAppend(WCC->WBuf, WCC->CurRoom.name, NULL, 0, 0);
1061 wc_printf("<table class=\"vcard_edit_background\"><tr><td>\n");
1063 wc_printf("<table border=\"0\"><tr>"
1068 "<td>%s</td></tr>\n",
1069 _("Prefix"), _("First Name"), _("Middle Name"), _("Last Name"), _("Suffix")
1071 wc_printf("<tr><td><input type=\"text\" name=\"prefix\" "
1072 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
1074 wc_printf("<td><input type=\"text\" name=\"firstname\" "
1075 "value=\"%s\" maxlength=\"29\"></td>",
1077 wc_printf("<td><input type=\"text\" name=\"middlename\" "
1078 "value=\"%s\" maxlength=\"29\"></td>",
1080 wc_printf("<td><input type=\"text\" name=\"lastname\" "
1081 "value=\"%s\" maxlength=\"29\"></td>",
1083 wc_printf("<td><input type=\"text\" name=\"suffix\" "
1084 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
1087 wc_printf("<table class=\"vcard_edit_background_alt\">");
1088 wc_printf("<tr><td>");
1090 wc_printf(_("Display name:"));
1092 "<input type=\"text\" name=\"fullname\" "
1093 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1097 wc_printf(_("Title:"));
1099 "<input type=\"text\" name=\"title\" "
1100 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1104 wc_printf(_("Organization:"));
1106 "<input type=\"text\" name=\"org\" "
1107 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1111 wc_printf("</td><td>");
1113 wc_printf("<table border=\"0\">");
1114 wc_printf("<tr><td>");
1115 wc_printf(_("PO box:"));
1116 wc_printf("</td><td>"
1117 "<input type=\"text\" name=\"pobox\" "
1118 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1120 wc_printf("<tr><td>");
1121 wc_printf(_("Address:"));
1122 wc_printf("</td><td>"
1123 "<input type=\"text\" name=\"extadr\" "
1124 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1126 wc_printf("<tr><td> </td><td>"
1127 "<input type=\"text\" name=\"street\" "
1128 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1130 wc_printf("<tr><td>");
1131 wc_printf(_("City:"));
1132 wc_printf("</td><td>"
1133 "<input type=\"text\" name=\"city\" "
1134 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1136 wc_printf("<tr><td>");
1137 wc_printf(_("State:"));
1138 wc_printf("</td><td>"
1139 "<input type=\"text\" name=\"state\" "
1140 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1142 wc_printf("<tr><td>");
1143 wc_printf(_("ZIP code:"));
1144 wc_printf("</td><td>"
1145 "<input type=\"text\" name=\"zipcode\" "
1146 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
1148 wc_printf("<tr><td>");
1149 wc_printf(_("Country:"));
1150 wc_printf("</td><td>"
1151 "<input type=\"text\" name=\"country\" "
1152 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
1154 wc_printf("</table>\n");
1156 wc_printf("</table>\n");
1158 wc_printf("<table border=0><tr><td>");
1159 wc_printf(_("Home telephone:"));
1161 "<td><input type=\"text\" name=\"hometel\" "
1162 "value=\"%s\" maxlength=\"29\"></td>\n",
1165 wc_printf(_("Work telephone:"));
1167 "<td><input type=\"text\" name=\"worktel\" "
1168 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1170 wc_printf("<tr><td>");
1171 wc_printf(_("Mobile telephone:"));
1173 "<td><input type=\"text\" name=\"mobiletel\" "
1174 "value=\"%s\" maxlength=\"29\"></td>\n",
1177 wc_printf(_("Fax number:"));
1179 "<td><input type=\"text\" name=\"faxtel\" "
1180 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
1183 wc_printf("<table class=\"vcard_edit_background_alt\">");
1184 wc_printf("<tr><td>");
1186 wc_printf("<table border=0><TR>"
1188 wc_printf(_("Primary Internet e-mail address"));
1190 "<input type=\"text\" name=\"primary_inetemail\" "
1191 "size=40 maxlength=60 value=\"");
1192 escputs(primary_inetemail);
1194 "</td><td valign=top>");
1195 wc_printf(_("Internet e-mail aliases"));
1197 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
1198 escputs(other_inetemail);
1199 wc_printf("</textarea></td></tr></table>\n");
1201 wc_printf("</td></tr></table>\n");
1203 wc_printf("<input type=\"hidden\" name=\"extrafields\" value=\"");
1204 escputs(extrafields);
1207 wc_printf("<input type=\"hidden\" name=\"return_to\" value=\"");
1211 wc_printf("<div class=\"buttons\">\n"
1212 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1214 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1220 wc_printf("</td></tr></table>\n");
1221 do_template("box_end");
1224 DestroyMessageSummary(Msg);
1230 * commit the edits to the citadel server
1232 void edit_vcard(void) {
1236 msgnum = lbstr("msgnum");
1237 partnum = bstr("partnum");
1238 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1244 * parse edited vcard from the browser
1246 void submit_vcard(void) {
1248 char *serialized_vcard;
1251 const StrBuf *ForceRoom;
1254 if (!havebstr("ok_button")) {
1255 readloop(readnew, eUseDefault);
1259 if (havebstr("force_room")) {
1260 ForceRoom = sbstr("force_room");
1261 if (gotoroom(ForceRoom) != 200) {
1262 AppendImportantMessage(_("Unable to enter the room to save your message"), -1);
1263 AppendImportantMessage(HKEY(": "));
1264 AppendImportantMessage(SKEY(ForceRoom));
1265 AppendImportantMessage(HKEY("; "));
1266 AppendImportantMessage(_("Aborting."), -1);
1268 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1269 select_user_to_edit(NULL);
1271 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1274 else if (!IsEmptyStr(bstr("return_to"))) {
1275 http_redirect(bstr("return_to"));
1278 readloop(readnew, eUseDefault);
1285 serv_write(HKEY("ENT0 1|||4\n"));
1286 if (!StrBuf_ServGetln(Buf) && (GetServerStatus(Buf, NULL) != 4))
1292 /* Make a vCard structure out of the data supplied in the form */
1293 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1296 v = VCardLoad(Buf); /* Start with the extra fields */
1298 AppendImportantMessage(_("An error has occurred."), -1);
1304 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1310 vcard_add_prop(v, "n", buf);
1312 vcard_add_prop(v, "title", bstr("title"));
1313 vcard_add_prop(v, "fn", bstr("fullname"));
1314 vcard_add_prop(v, "org", bstr("org"));
1316 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1324 vcard_add_prop(v, "adr", buf);
1326 vcard_add_prop(v, "tel;home", bstr("hometel"));
1327 vcard_add_prop(v, "tel;work", bstr("worktel"));
1328 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1329 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1330 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1332 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1333 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1334 if (!IsEmptyStr(buf)) {
1335 vcard_add_prop(v, "email;internet", buf);
1339 serialized_vcard = vcard_serialize(v);
1341 if (serialized_vcard == NULL) {
1342 AppendImportantMessage(_("An error has occurred."), -1);
1348 serv_write(HKEY("Content-type: text/x-vcard; charset=UTF-8\n"));
1349 serv_write(HKEY("\n"));
1350 serv_printf("%s\r\n", serialized_vcard);
1351 serv_write(HKEY("000\n"));
1352 free(serialized_vcard);
1354 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1355 select_user_to_edit(NULL);
1357 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1360 else if (!IsEmptyStr(bstr("return_to"))) {
1361 http_redirect(bstr("return_to"));
1364 readloop(readnew, eUseDefault);
1372 * Extract an embedded photo from a vCard for display on the client
1374 void display_vcard_photo_img(void)
1380 const char *contentType;
1381 wcsession *WCC = WC;
1383 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1385 vcard = load_mimepart(msgnum,"1");
1386 v = VCardLoad(vcard);
1388 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1389 FlushStrBuf(WCC->WBuf);
1390 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1391 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1392 FlushStrBuf(WCC->WBuf);
1394 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1395 output_headers(0, 0, 0, 0, 0, 0);
1396 hprintf("Content-Type: text/plain\r\n");
1398 wc_printf(_("Could Not decode vcard photo\n"));
1402 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1403 http_transmit_thing(contentType, 0);
1408 typedef struct _vcardview_struct {
1410 addrbookent *addrbook;
1415 int vcard_GetParamsGetServerCall(SharedMessageStatus *Stat,
1416 void **ViewSpecific,
1423 vcardview_struct *VS;
1425 VS = (vcardview_struct*) malloc (sizeof(vcardview_struct));
1426 memset(VS, 0, sizeof(vcardview_struct));
1427 *ViewSpecific = (void*)VS;
1429 VS->is_singlecard = ibstr("is_singlecard");
1430 if (VS->is_singlecard != 1) {
1431 if (oper == do_search) {
1432 snprintf(cmd, len, "MSGS SEARCH|%s", bstr("query"));
1435 strcpy(cmd, "MSGS ALL");
1437 Stat->maxmsgs = 9999999;
1442 int vcard_LoadMsgFromServer(SharedMessageStatus *Stat,
1443 void **ViewSpecific,
1444 message_summary* Msg,
1448 vcardview_struct *VS;
1451 VS = (vcardview_struct*) *ViewSpecific;
1454 fetch_ab_name(Msg, &ab_name);
1455 if (ab_name == NULL)
1458 VS->addrbook = realloc(VS->addrbook,
1459 (sizeof(addrbookent) * VS->num_ab) );
1460 safestrncpy(VS->addrbook[VS->num_ab-1].ab_name, ab_name,
1461 sizeof(VS->addrbook[VS->num_ab-1].ab_name));
1462 VS->addrbook[VS->num_ab-1].ab_msgnum = Msg->msgnum;
1468 int vcard_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
1471 vcardview_struct *VS;
1473 VS = (vcardview_struct*) *ViewSpecific;
1474 if (VS->is_singlecard)
1475 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1477 do_addrbook_view(VS->addrbook, VS->num_ab); /* Render the address book */
1481 int vcard_Cleanup(void **ViewSpecific)
1483 vcardview_struct *VS;
1485 VS = (vcardview_struct*) *ViewSpecific;
1488 (VS->addrbook != NULL))
1496 ServerStartModule_VCARD
1499 VCToEnum = NewHash(0, NULL);
1504 ServerShutdownModule_VCARD
1507 DeleteHash(&VCToEnum);
1514 RegisterCTX(CTX_VCARD);
1515 RegisterReadLoopHandlerset(
1517 vcard_GetParamsGetServerCall,
1521 vcard_LoadMsgFromServer,
1522 vcard_RenderView_or_Tail,
1524 WebcitAddUrlHandler(HKEY("edit_vcard"), "", 0, edit_vcard, 0);
1525 WebcitAddUrlHandler(HKEY("submit_vcard"), "", 0, submit_vcard, 0);
1526 WebcitAddUrlHandler(HKEY("vcardphoto"), "", 0, display_vcard_photo_img, NEED_URL);
1528 Put(VCToEnum, HKEY("n"), (void*)VC_n, reference_free_handler);
1529 Put(VCToEnum, HKEY("fn"), (void*)VC_fn, reference_free_handler);
1530 Put(VCToEnum, HKEY("title"), (void*)VC_title, reference_free_handler);
1531 Put(VCToEnum, HKEY("org"), (void*)VC_org, reference_free_handler);
1532 Put(VCToEnum, HKEY("email"), (void*)VC_email, reference_free_handler);
1533 Put(VCToEnum, HKEY("tel"), (void*)VC_tel, reference_free_handler);
1534 Put(VCToEnum, HKEY("tel_tel"), (void*)VC_tel_tel, reference_free_handler);
1535 Put(VCToEnum, HKEY("tel_work"), (void*)VC_tel_work, reference_free_handler);
1536 Put(VCToEnum, HKEY("tel_home"), (void*)VC_tel_home, reference_free_handler);
1537 Put(VCToEnum, HKEY("tel_cell"), (void*)VC_tel_cell, reference_free_handler);
1538 Put(VCToEnum, HKEY("adr"), (void*)VC_adr, reference_free_handler);
1539 Put(VCToEnum, HKEY("photo"), (void*)VC_photo, reference_free_handler);
1540 Put(VCToEnum, HKEY("version"), (void*)VC_version, reference_free_handler);
1541 Put(VCToEnum, HKEY("rev"), (void*)VC_rev, reference_free_handler);
1542 Put(VCToEnum, HKEY("label"), (void*)VC_label, reference_free_handler);
1545 RegisterNamespace("VC", 1, 2, tmplput_VCARD_ITEM, NULL, CTX_VCARD);
1547 REGISTERTokenParamDefine(VC_n);
1548 REGISTERTokenParamDefine(VC_fn);
1549 REGISTERTokenParamDefine(VC_title);
1550 REGISTERTokenParamDefine(VC_org);
1551 REGISTERTokenParamDefine(VC_email);
1552 REGISTERTokenParamDefine(VC_tel);
1553 REGISTERTokenParamDefine(VC_tel_tel);
1554 REGISTERTokenParamDefine(VC_tel_work);
1555 REGISTERTokenParamDefine(VC_tel_home);
1556 REGISTERTokenParamDefine(VC_tel_cell);
1557 REGISTERTokenParamDefine(VC_adr);
1558 REGISTERTokenParamDefine(VC_photo);
1559 REGISTERTokenParamDefine(VC_version);
1560 REGISTERTokenParamDefine(VC_rev);
1561 REGISTERTokenParamDefine(VC_label);