2 * Copyright (c) 1996-2011 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 as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "webserver.h"
26 {HKEY("n")}, /* N is name, but only if there's no FN already there */
27 {HKEY("fn")}, /* FN (full name) is a true 'display name' field */
28 {HKEY("title")}, /* title */
29 {HKEY("org")}, /* organization */
61 HashList *VCToEnum = NULL;
64 * Record compare function for sorting address book indices
66 int abcmp(const void *ab1, const void *ab2) {
68 (((const addrbookent *)ab1)->ab_name),
69 (((const addrbookent *)ab2)->ab_name)
75 * Helper function for do_addrbook_view()
76 * Converts a name into a three-letter tab label
78 void nametab(char *tabbuf, long len, char *name) {
79 stresc(tabbuf, len, name, 0, 0);
80 tabbuf[0] = toupper(tabbuf[0]);
81 tabbuf[1] = tolower(tabbuf[1]);
82 tabbuf[2] = tolower(tabbuf[2]);
88 * If it's an old "Firstname Lastname" style record, try to convert it.
90 void lastfirst_firstlast(char *namebuf) {
95 if (namebuf == NULL) return;
96 if (strchr(namebuf, ';') != NULL) return;
98 i = num_tokens(namebuf, ' ');
101 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
102 remove_token(namebuf, i-1, ' ');
103 strcpy(firstname, namebuf);
104 sprintf(namebuf, "%s; %s", lastname, firstname);
109 wc_mime_attachment *load_vcard(message_summary *Msg)
112 StrBuf *FoundCharset = NewStrBuf();
117 wc_mime_attachment *Mime;
118 wc_mime_attachment *VCMime = NULL;
120 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
121 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
122 Msg->MsgBody->msgnum = Msg->msgnum;
124 load_message(Msg, FoundCharset, &Error);
126 FreeStrBuf(&FoundCharset);
127 /* look up the vcard... */
128 it = GetNewHashPos(Msg->AllAttach, 0);
129 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
132 Mime = (wc_mime_attachment*) vMime;
133 if ((strcmp(ChrPtr(Mime->ContentType),
134 "text/x-vcard") == 0) ||
135 (strcmp(ChrPtr(Mime->ContentType),
146 MimeLoadData(VCMime);
151 * fetch the display name off a vCard
153 void fetch_ab_name(message_summary *Msg, char **namebuf) {
156 wc_mime_attachment *VCMime = NULL;
158 if (namebuf == NULL) return;
160 VCMime = load_vcard(Msg);
164 /* Grab the name off the card */
165 display_vcard(WC->WBuf, VCMime, 0, 0, namebuf, Msg->msgnum);
167 if (*namebuf != NULL) {
168 lastfirst_firstlast(*namebuf);
170 len = strlen(*namebuf);
171 for (i=0; i<len; ++i) {
172 if ((*namebuf)[i] != ';') return;
175 (*namebuf) = strdup(_("(no name)"));
178 (*namebuf) = strdup(_("(no name)"));
185 * Turn a vCard "n" (name) field into something displayable.
187 void vcard_n_prettyize(char *name)
192 original_name = strdup(name);
193 len = strlen(original_name);
194 for (i=0; i<5; ++i) {
196 if (original_name[len-1] == ' ') {
197 original_name[--len] = 0;
199 if (original_name[len-1] == ';') {
200 original_name[--len] = 0;
206 for (i=0; i<len; ++i) {
207 if (original_name[i] == ';') {
212 name[j++] = original_name[i];
223 * preparse a vcard name
224 * display_vcard() calls this after parsing the textual vCard into
225 * our 'struct vCard' data object.
226 * This gets called instead of display_parsed_vcard() if we are only looking
227 * to extract the person's name instead of displaying the card.
229 void fetchname_parsed_vcard(struct vCard *v, char **storename) {
239 name = vcard_get_prop(v, "n", 1, 0, 0);
242 prop = vcard_get_prop(v, "n", 1, 0, 1);
243 n = num_tokens(prop, ';');
245 for (j=0; j<n; ++j) {
246 extract_token(buf, prop, j, ';', sizeof buf);
247 if (!strcasecmp(buf, "encoding=quoted-printable")) {
250 if (!strcasecmp(buf, "encoding=base64")) {
255 /* %ff can become 6 bytes in utf8 */
256 *storename = malloc(len * 2 + 3);
257 j = CtdlDecodeQuotedPrintable(
263 /* ff will become one byte.. */
264 *storename = malloc(len + 50);
274 *storename = malloc(len + 3); /* \0 + eventualy missing ', '*/
275 memcpy(*storename, name, len + 1);
277 /* vcard_n_prettyize(storename); */
286 * display_vcard() calls this after parsing the textual vCard into
287 * our 'struct vCard' data object.
289 * Set 'full' to nonzero to display the full card, otherwise it will only
290 * show a summary line.
292 * This code is a bit ugly, so perhaps an explanation is due: we do this
293 * in two passes through the vCard fields. On the first pass, we process
294 * fields we understand, and then render them in a pretty fashion at the
295 * end. Then we make a second pass, outputting all the fields we don't
296 * understand in a simple two-column name/value format.
297 * v the vCard to display
298 * full display all items of the vcard?
299 * msgnum Citadel message pointer
301 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
308 char *thisname, *thisvalue;
309 char firsttoken[SIZ];
318 strcpy(fullname, "");
325 StrBufAppendPrintf(Target, "<td>");
326 name = vcard_get_prop(v, "fn", 1, 0, 0);
328 StrEscAppend(Target, NULL, name, 0, 0);
330 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
331 strcpy(fullname, name);
332 vcard_n_prettyize(fullname);
333 StrEscAppend(Target, NULL, fullname, 0, 0);
336 StrBufAppendPrintf(Target, " ");
338 StrBufAppendPrintf(Target, "</td>");
342 StrBufAppendPrintf(Target, "<div align=\"center\">"
343 "<table bgcolor=\"#aaaaaa\" width=\"50%%\">");
344 for (pass=1; pass<=2; ++pass) {
346 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
348 thisname = strdup(v->prop[i].name);
349 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
351 for (j=0; j<num_tokens(thisname, ';'); ++j) {
352 extract_token(buf, thisname, j, ';', sizeof buf);
353 if (!strcasecmp(buf, "encoding=quoted-printable")) {
355 remove_token(thisname, j, ';');
357 if (!strcasecmp(buf, "encoding=base64")) {
359 remove_token(thisname, j, ';');
363 len = strlen(v->prop[i].value);
364 /* if we have some untagged QP, detect it here. */
365 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
366 utf8ify_rfc822_string(&v->prop[i].value);
369 // %ff can become 6 bytes in utf8
370 thisvalue = malloc(len * 2 + 3);
371 j = CtdlDecodeQuotedPrintable(
372 thisvalue, v->prop[i].value,
377 // ff will become one byte..
378 thisvalue = malloc(len + 50);
380 thisvalue, v->prop[i].value,
381 strlen(v->prop[i].value) );
384 thisvalue = strdup(v->prop[i].value);
387 /* Various fields we may encounter ***/
389 /* N is name, but only if there's no FN already there */
390 if (!strcasecmp(firsttoken, "n")) {
391 if (IsEmptyStr(fullname)) {
392 strcpy(fullname, thisvalue);
393 vcard_n_prettyize(fullname);
397 /* FN (full name) is a true 'display name' field */
398 else if (!strcasecmp(firsttoken, "fn")) {
399 strcpy(fullname, thisvalue);
403 else if (!strcasecmp(firsttoken, "title")) {
404 strcpy(title, thisvalue);
408 else if (!strcasecmp(firsttoken, "org")) {
409 strcpy(org, thisvalue);
412 else if (!strcasecmp(firsttoken, "email")) {
414 if (!IsEmptyStr(mailto)) strcat(mailto, "<br>");
416 "<a href=\"display_enter"
417 "?force_room=_MAIL_?recp=");
419 len = strlen(mailto);
420 urlesc(&mailto[len], SIZ - len, "\"");
421 len = strlen(mailto);
422 urlesc(&mailto[len], SIZ - len, fullname);
423 len = strlen(mailto);
424 urlesc(&mailto[len], SIZ - len, "\" <");
425 len = strlen(mailto);
426 urlesc(&mailto[len], SIZ - len, thisvalue);
427 len = strlen(mailto);
428 urlesc(&mailto[len], SIZ - len, ">");
430 strcat(mailto, "\">");
431 len = strlen(mailto);
432 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
433 strcat(mailto, "</A>");
435 else if (!strcasecmp(firsttoken, "tel")) {
436 if (!IsEmptyStr(phone)) strcat(phone, "<br>");
437 strcat(phone, thisvalue);
438 for (j=0; j<num_tokens(thisname, ';'); ++j) {
439 extract_token(buf, thisname, j, ';', sizeof buf);
440 if (!strcasecmp(buf, "tel"))
442 else if (!strcasecmp(buf, "work"))
443 strcat(phone, _(" (work)"));
444 else if (!strcasecmp(buf, "home"))
445 strcat(phone, _(" (home)"));
446 else if (!strcasecmp(buf, "cell"))
447 strcat(phone, _(" (cell)"));
455 else if (!strcasecmp(firsttoken, "adr")) {
457 StrBufAppendPrintf(Target, "<tr><td>");
458 StrBufAppendPrintf(Target, _("Address:"));
459 StrBufAppendPrintf(Target, "</td><td>");
460 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
461 extract_token(buf, thisvalue, j, ';', sizeof buf);
462 if (!IsEmptyStr(buf)) {
463 StrEscAppend(Target, NULL, buf, 0, 0);
464 if (j<3) StrBufAppendPrintf(Target, "<br>");
465 else StrBufAppendPrintf(Target, " ");
468 StrBufAppendPrintf(Target, "</td></tr>\n");
471 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
472 // Only output on second pass
473 StrBufAppendPrintf(Target, "<tr><td>");
474 StrBufAppendPrintf(Target, _("Photo:"));
475 StrBufAppendPrintf(Target, "</td><td>");
476 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
477 StrBufAppendPrintf(Target, "</td></tr>\n");
479 else if (!strcasecmp(firsttoken, "version")) {
482 else if (!strcasecmp(firsttoken, "rev")) {
485 else if (!strcasecmp(firsttoken, "label")) {
490 /*** Don't show extra fields. They're ugly.
492 StrBufAppendPrintf(Target, "<TR><TD>");
493 StrEscAppend(Target, NULL, thisname, 0, 0);
494 StrBufAppendPrintf(Target, "</TD><TD>");
495 StrEscAppend(Target, NULL, thisvalue, 0, 0);
496 StrBufAppendPrintf(Target, "</TD></TR>\n");
506 StrBufAppendPrintf(Target, "<tr bgcolor=\"#aaaaaa\">"
507 "<td colspan=2 bgcolor=\"#ffffff\">"
508 "<img align=\"center\" src=\"static/webcit_icons/essen/32x32/contact.png\">"
509 "<font size=\"+1\"><b>");
510 StrEscAppend(Target, NULL, fullname, 0, 0);
511 StrBufAppendPrintf(Target, "</b></font>");
512 if (!IsEmptyStr(title)) {
513 StrBufAppendPrintf(Target, "<div align=\"right>\"");
514 StrEscAppend(Target, NULL, title, 0, 0);
515 StrBufAppendPrintf(Target, "</div>");
517 if (!IsEmptyStr(org)) {
518 StrBufAppendPrintf(Target, "<div align=\"right\">");
519 StrEscAppend(Target, NULL, org, 0, 0);
520 StrBufAppendPrintf(Target, "</div>");
522 StrBufAppendPrintf(Target, "</td></tr>\n");
524 if (!IsEmptyStr(phone)) {
525 StrBufAppendPrintf(Target, "<tr><td>");
526 StrBufAppendPrintf(Target, _("Telephone:"));
527 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
529 if (!IsEmptyStr(mailto)) {
530 StrBufAppendPrintf(Target, "<tr><td>");
531 StrBufAppendPrintf(Target, _("E-mail:"));
532 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
538 StrBufAppendPrintf(Target, "</table></div>\n");
543 * display_vcard() calls this after parsing the textual vCard into
544 * our 'struct vCard' data object.
546 * Set 'full' to nonzero to display the full card, otherwise it will only
547 * show a summary line.
549 * This code is a bit ugly, so perhaps an explanation is due: we do this
550 * in two passes through the vCard fields. On the first pass, we process
551 * fields we understand, and then render them in a pretty fashion at the
552 * end. Then we make a second pass, outputting all the fields we don't
553 * understand in a simple two-column name/value format.
554 * v the vCard to display
555 * full display all items of the vcard?
556 * msgnum Citadel message pointer
558 void parse_vcard(StrBuf *Target, struct vCard *v, HashList *VC, int full, wc_mime_attachment *Mime)
566 StrBuf *thisname = NULL;
567 char firsttoken[SIZ];
571 thisname = NewStrBuf();
572 for (i=0; i<(v->numprops); ++i) {
575 StrBufPlain(thisname, v->prop[i].name, -1);
576 StrBufLowerCase(thisname);
578 /*len = */extract_token(firsttoken, ChrPtr(thisname), 0, ';', sizeof firsttoken);
580 for (j=0; j<num_tokens(ChrPtr(thisname), ';'); ++j) {
581 extract_token(buf, ChrPtr(thisname), j, ';', sizeof buf);
582 if (!strcasecmp(buf, "encoding=quoted-printable")) {
584 /* remove_token(thisname, j, ';');*/
586 if (!strcasecmp(buf, "encoding=base64")) {
588 /* remove_token(thisname, j, ';');*/
592 /* copy over the payload into a StrBuf */
593 Val = NewStrBufPlain(v->prop[i].value, -1);
595 /* if we have some untagged QP, detect it here. */
596 if (is_qp || (strstr(v->prop[i].value, "=?")!=NULL)){
598 StrBuf_RFC822_to_Utf8(Swap, Val, NULL, NULL); /* default charset, current charset */
605 StrBufDecodeBase64(Val);
608 syslog(1, "%s [%s][%s]",
612 if (GetHash(VCToEnum, firsttoken, strlen(firsttoken), &V))
615 Put(VC, IKEY(evc), Val, HFreeStrBuf);
616 syslog(1, "[%ul]\n", evc);
622 TODO: check for layer II
625 long max = num_tokens(thisname, ';');
626 firsttoken[len] = '_';
628 for (j = 0; j < max; j++) {
631 extract_token(buf, thisname, j, ';', sizeof (buf));
632 if (!strcasecmp(buf, "tel"))
634 else if (!strcasecmp(buf, "work"))
635 strcat(phone, _(" (work)"));
636 else if (!strcasecmp(buf, "home"))
637 strcat(phone, _(" (home)"));
638 else if (!strcasecmp(buf, "cell"))
639 strcat(phone, _(" (cell)"));
658 void tmplput_VCARD_ITEM(StrBuf *Target, WCTemplputParams *TP)
664 evc = GetTemplateTokenNumber(Target, TP, 0, -1);
667 if (GetHash(VC, IKEY(evc), &vStr))
669 StrBufAppendTemplate(Target, TP,
677 void new_vcard (StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
680 WCTemplputParams SubTP;
682 memset(&SubTP, 0, sizeof(WCTemplputParams));
685 VC = NewHash(0, Flathash);
686 parse_vcard(Target, v, VC, full, Mime);
688 SubTP.Filter.ContextType = CTX_VCARD;
691 DoTemplate(HKEY("test_vcard"), Target, &SubTP);
698 * Display a textual vCard
699 * (Converts to a vCard object and then calls the actual display function)
700 * Set 'full' to nonzero to display the whole card instead of a one-liner.
701 * Or, if "storename" is non-NULL, just store the person's name in that
702 * buffer instead of displaying the card at all.
704 * vcard_source the buffer containing the vcard text
705 * alpha Display only if name begins with this letter of the alphabet
706 * full Display the full vCard (otherwise just the display name)
707 * storename If not NULL, also store the display name here
708 * msgnum Citadel message pointer
710 void display_vcard(StrBuf *Target,
711 wc_mime_attachment *Mime,
723 v = VCardLoad(Mime->Data);
725 if (v == NULL) return;
727 name = vcard_get_prop(v, "n", 1, 0, 0);
729 Buf = NewStrBufPlain(name, -1);
730 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
731 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
732 this_alpha = ChrPtr(Buf)[0];
737 if (storename != NULL) {
738 fetchname_parsed_vcard(v, storename);
740 else if ((alpha == 0) ||
741 ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha))) ||
742 ((!isalpha(alpha)) && (!isalpha(this_alpha)))
746 new_vcard (Target, v, full, Mime);
748 display_parsed_vcard(Target, v, full, Mime);
758 * Render the address book using info we gathered during the scan
760 * addrbook the addressbook to render
761 * num_ab the number of the addressbook
763 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
767 static int NAMESPERPAGE = 60;
770 char tabfirst_label[64];
772 char tablast_label[64];
773 char this_tablabel[64];
778 wc_printf("<br><br><br><div align=\"center\"><i>");
779 wc_printf(_("This address book is empty."));
780 wc_printf("</i></div>\n");
785 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
788 num_pages = (num_ab / NAMESPERPAGE) + 1;
790 tablabels = malloc(num_pages * sizeof (char *));
791 if (tablabels == NULL) {
792 wc_printf("<br><br><br><div align=\"center\"><i>");
793 wc_printf(_("An internal error has occurred."));
794 wc_printf("</i></div>\n");
798 for (i=0; i<num_pages; ++i) {
799 tabfirst = i * NAMESPERPAGE;
800 tablast = tabfirst + NAMESPERPAGE - 1;
801 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
802 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
803 nametab(tablast_label, 64, addrbook[tablast].ab_name);
804 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
805 tablabels[i] = strdup(this_tablabel);
808 tabbed_dialog(num_pages, tablabels);
811 for (i=0; i<num_ab; ++i) {
813 if ((i / NAMESPERPAGE) != page) { /* New tab */
814 page = (i / NAMESPERPAGE);
816 wc_printf("</tr></table>\n");
817 end_tab(page-1, num_pages);
819 begin_tab(page, num_pages);
820 wc_printf("<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" width=\"100%%\">\n");
824 if ((displayed % 4) == 0) {
826 wc_printf("</tr>\n");
829 wc_printf("<tr bgcolor=\"#%s\">",
830 (bg ? "dddddd" : "ffffff")
836 wc_printf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
837 addrbook[i].ab_msgnum);
838 wc_printf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
839 vcard_n_prettyize(addrbook[i].ab_name);
840 escputs(addrbook[i].ab_name);
841 wc_printf("</a></td>\n");
845 /* Placeholders for empty columns at end */
846 if ((num_ab % 4) != 0) {
847 for (i=0; i<(4-(num_ab % 4)); ++i) {
848 wc_printf("<td> </td>");
852 wc_printf("</tr></table>\n");
853 end_tab((num_pages-1), num_pages);
855 begin_tab(num_pages, num_pages);
856 /* FIXME there ought to be something here */
857 end_tab(num_pages, num_pages);
859 for (i=0; i<num_pages; ++i) {
869 * Edit the vCard component of a MIME message.
870 * Supply the message number
871 * and MIME part number to fetch. Or, specify -1 for the message number
872 * to start with a blank card.
874 void do_edit_vcard(long msgnum, char *partnum,
875 message_summary *VCMsg,
876 wc_mime_attachment *VCAtt,
877 const char *return_to,
878 const char *force_room) {
879 message_summary *Msg = NULL;
880 wc_mime_attachment *VCMime = NULL;
888 char middlename[256];
902 char primary_inetemail[256];
903 char other_inetemail[SIZ];
904 char extrafields[SIZ];
925 primary_inetemail[0] = 0;
926 other_inetemail[0] = 0;
932 safestrncpy(whatuser, "", sizeof whatuser);
935 ((VCMsg != NULL) && (VCAtt != NULL)))
937 if ((VCMsg == NULL) && (VCAtt == NULL)) {
939 Msg = (message_summary *) malloc(sizeof(message_summary));
940 memset(Msg, 0, sizeof(message_summary));
941 Msg->msgnum = msgnum;
942 VCMime = load_vcard(Msg);
943 if (VCMime == NULL) {
944 convenience_page("770000", _("Error"), "");///TODO: important message
945 DestroyMessageSummary(Msg);
949 v = VCardLoad(VCMime->Data);
952 v = VCardLoad(VCAtt->Data);
955 /* Populate the variables for our form */
957 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
958 char prp[256]; /* property name */
959 char prm[256]; /* parameters */
961 value = vcard_get_prop(v, "", 0, i++, 0);
964 extract_token(prp, key, 0, ';', sizeof prp);
965 safestrncpy(prm, key, sizeof prm);
966 remove_token(prm, 0, ';');
968 if (!strcasecmp(prp, "n")) {
969 extract_token(lastname, value, 0, ';', sizeof lastname);
970 extract_token(firstname, value, 1, ';', sizeof firstname);
971 extract_token(middlename, value, 2, ';', sizeof middlename);
972 extract_token(prefix, value, 3, ';', sizeof prefix);
973 extract_token(suffix, value, 4, ';', sizeof suffix);
976 else if (!strcasecmp(prp, "fn")) {
977 safestrncpy(fullname, value, sizeof fullname);
980 else if (!strcasecmp(prp, "title")) {
981 safestrncpy(title, value, sizeof title);
984 else if (!strcasecmp(prp, "org")) {
985 safestrncpy(org, value, sizeof org);
988 else if (!strcasecmp(prp, "adr")) {
989 extract_token(pobox, value, 0, ';', sizeof pobox);
990 extract_token(extadr, value, 1, ';', sizeof extadr);
991 extract_token(street, value, 2, ';', sizeof street);
992 extract_token(city, value, 3, ';', sizeof city);
993 extract_token(state, value, 4, ';', sizeof state);
994 extract_token(zipcode, value, 5, ';', sizeof zipcode);
995 extract_token(country, value, 6, ';', sizeof country);
998 else if (!strcasecmp(prp, "tel")) {
1000 if (bmstrcasestr(prm, "home")) {
1001 extract_token(hometel, value, 0, ';', sizeof hometel);
1003 else if (bmstrcasestr(prm, "work")) {
1004 extract_token(worktel, value, 0, ';', sizeof worktel);
1006 else if (bmstrcasestr(prm, "fax")) {
1007 extract_token(faxtel, value, 0, ';', sizeof faxtel);
1009 else if (bmstrcasestr(prm, "cell")) {
1010 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
1012 else { /* Missing or unknown type; put it in the home phone */
1013 extract_token(hometel, value, 0, ';', sizeof hometel);
1017 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
1018 if (primary_inetemail[0] == 0) {
1019 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
1022 if (other_inetemail[0] != 0) {
1023 strcat(other_inetemail, "\n");
1025 strcat(other_inetemail, value);
1029 /* Unrecognized properties are preserved here so we don't discard them
1030 * just because the vCard was edited with WebCit.
1033 strcat(extrafields, key);
1034 strcat(extrafields, ":");
1035 strcat(extrafields, value);
1036 strcat(extrafields, "\n");
1044 /* Display the form */
1045 output_headers(1, 1, 1, 0, 0, 0);
1047 do_template("box_begin_1");
1048 StrBufAppendBufPlain(WC->WBuf, _("Edit contact information"), -1, 0);
1049 do_template("box_begin_2");
1051 wc_printf("<form method=\"POST\" action=\"submit_vcard\">\n");
1052 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1054 if (force_room != NULL) {
1055 wc_printf("<input type=\"hidden\" name=\"force_room\" value=\"");
1056 escputs(force_room);
1060 wc_printf("<table class=\"vcard_edit_background\"><tr><td>\n");
1062 wc_printf("<table border=\"0\"><tr>"
1067 "<td>%s</td></tr>\n",
1068 _("Prefix"), _("First Name"), _("Middle Name"), _("Last Name"), _("Suffix")
1070 wc_printf("<tr><td><input type=\"text\" name=\"prefix\" "
1071 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
1073 wc_printf("<td><input type=\"text\" name=\"firstname\" "
1074 "value=\"%s\" maxlength=\"29\"></td>",
1076 wc_printf("<td><input type=\"text\" name=\"middlename\" "
1077 "value=\"%s\" maxlength=\"29\"></td>",
1079 wc_printf("<td><input type=\"text\" name=\"lastname\" "
1080 "value=\"%s\" maxlength=\"29\"></td>",
1082 wc_printf("<td><input type=\"text\" name=\"suffix\" "
1083 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
1086 wc_printf("<table class=\"vcard_edit_background_alt\">");
1087 wc_printf("<tr><td>");
1089 wc_printf(_("Display name:"));
1091 "<input type=\"text\" name=\"fullname\" "
1092 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1096 wc_printf(_("Title:"));
1098 "<input type=\"text\" name=\"title\" "
1099 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1103 wc_printf(_("Organization:"));
1105 "<input type=\"text\" name=\"org\" "
1106 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1110 wc_printf("</td><td>");
1112 wc_printf("<table border=\"0\">");
1113 wc_printf("<tr><td>");
1114 wc_printf(_("PO box:"));
1115 wc_printf("</td><td>"
1116 "<input type=\"text\" name=\"pobox\" "
1117 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1119 wc_printf("<tr><td>");
1120 wc_printf(_("Address:"));
1121 wc_printf("</td><td>"
1122 "<input type=\"text\" name=\"extadr\" "
1123 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1125 wc_printf("<tr><td> </td><td>"
1126 "<input type=\"text\" name=\"street\" "
1127 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1129 wc_printf("<tr><td>");
1130 wc_printf(_("City:"));
1131 wc_printf("</td><td>"
1132 "<input type=\"text\" name=\"city\" "
1133 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1135 wc_printf("<tr><td>");
1136 wc_printf(_("State:"));
1137 wc_printf("</td><td>"
1138 "<input type=\"text\" name=\"state\" "
1139 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1141 wc_printf("<tr><td>");
1142 wc_printf(_("ZIP code:"));
1143 wc_printf("</td><td>"
1144 "<input type=\"text\" name=\"zipcode\" "
1145 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
1147 wc_printf("<tr><td>");
1148 wc_printf(_("Country:"));
1149 wc_printf("</td><td>"
1150 "<input type=\"text\" name=\"country\" "
1151 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
1153 wc_printf("</table>\n");
1155 wc_printf("</table>\n");
1157 wc_printf("<table border=0><tr><td>");
1158 wc_printf(_("Home telephone:"));
1160 "<td><input type=\"text\" name=\"hometel\" "
1161 "value=\"%s\" maxlength=\"29\"></td>\n",
1164 wc_printf(_("Work telephone:"));
1166 "<td><input type=\"text\" name=\"worktel\" "
1167 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1169 wc_printf("<tr><td>");
1170 wc_printf(_("Mobile telephone:"));
1172 "<td><input type=\"text\" name=\"mobiletel\" "
1173 "value=\"%s\" maxlength=\"29\"></td>\n",
1176 wc_printf(_("Fax number:"));
1178 "<td><input type=\"text\" name=\"faxtel\" "
1179 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
1182 wc_printf("<table class=\"vcard_edit_background_alt\">");
1183 wc_printf("<tr><td>");
1185 wc_printf("<table border=0><TR>"
1187 wc_printf(_("Primary Internet e-mail address"));
1189 "<input type=\"text\" name=\"primary_inetemail\" "
1190 "size=40 maxlength=60 value=\"");
1191 escputs(primary_inetemail);
1193 "</td><td valign=top>");
1194 wc_printf(_("Internet e-mail aliases"));
1196 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
1197 escputs(other_inetemail);
1198 wc_printf("</textarea></td></tr></table>\n");
1200 wc_printf("</td></tr></table>\n");
1202 wc_printf("<input type=\"hidden\" name=\"extrafields\" value=\"");
1203 escputs(extrafields);
1206 wc_printf("<input type=\"hidden\" name=\"return_to\" value=\"");
1210 wc_printf("<div class=\"buttons\">\n"
1211 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1213 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1219 wc_printf("</td></tr></table>\n");
1220 do_template("box_end");
1223 DestroyMessageSummary(Msg);
1229 * commit the edits to the citadel server
1231 void edit_vcard(void) {
1235 msgnum = lbstr("msgnum");
1236 partnum = bstr("partnum");
1237 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1243 * parse edited vcard from the browser
1245 void submit_vcard(void) {
1247 char *serialized_vcard;
1250 const StrBuf *ForceRoom;
1253 if (!havebstr("ok_button")) {
1254 readloop(readnew, eUseDefault);
1258 if (havebstr("force_room")) {
1259 ForceRoom = sbstr("force_room");
1260 if (gotoroom(ForceRoom) != 200) {
1261 AppendImportantMessage(_("Unable to enter the room to save your message"), -1);
1262 AppendImportantMessage(HKEY(": "));
1263 AppendImportantMessage(SKEY(ForceRoom));
1264 AppendImportantMessage(HKEY("; "));
1265 AppendImportantMessage(_("Aborting."), -1);
1267 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1268 select_user_to_edit(NULL);
1270 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1273 else if (!IsEmptyStr(bstr("return_to"))) {
1274 http_redirect(bstr("return_to"));
1277 readloop(readnew, eUseDefault);
1284 serv_write(HKEY("ENT0 1|||4||||||1\n"));
1285 if (!StrBuf_ServGetln(Buf) && (GetServerStatus(Buf, NULL) != 4))
1291 /* Make a vCard structure out of the data supplied in the form */
1292 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1295 v = VCardLoad(Buf); /* Start with the extra fields */
1297 AppendImportantMessage(_("An error has occurred."), -1);
1303 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1309 vcard_add_prop(v, "n", buf);
1311 vcard_add_prop(v, "title", bstr("title"));
1312 vcard_add_prop(v, "fn", bstr("fullname"));
1313 vcard_add_prop(v, "org", bstr("org"));
1315 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1323 vcard_add_prop(v, "adr", buf);
1325 vcard_add_prop(v, "tel;home", bstr("hometel"));
1326 vcard_add_prop(v, "tel;work", bstr("worktel"));
1327 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1328 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1329 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1331 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1332 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1333 if (!IsEmptyStr(buf)) {
1334 vcard_add_prop(v, "email;internet", buf);
1338 serialized_vcard = vcard_serialize(v);
1340 if (serialized_vcard == NULL) {
1341 AppendImportantMessage(_("An error has occurred."), -1);
1347 serv_write(HKEY("Content-type: text/x-vcard; charset=UTF-8\n"));
1348 serv_write(HKEY("\n"));
1349 serv_printf("%s\r\n", serialized_vcard);
1350 serv_write(HKEY("000\n"));
1351 free(serialized_vcard);
1353 StrBuf_ServGetln(Buf);
1355 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1356 select_user_to_edit(NULL);
1358 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1361 else if (!IsEmptyStr(bstr("return_to"))) {
1362 http_redirect(bstr("return_to"));
1365 readloop(readnew, eUseDefault);
1373 * Extract an embedded photo from a vCard for display on the client
1375 void display_vcard_photo_img(void)
1381 const char *contentType;
1382 wcsession *WCC = WC;
1384 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1386 vcard = load_mimepart(msgnum,"1");
1387 v = VCardLoad(vcard);
1389 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1390 FlushStrBuf(WCC->WBuf);
1391 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1392 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1393 FlushStrBuf(WCC->WBuf);
1395 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1396 output_headers(0, 0, 0, 0, 0, 0);
1397 hprintf("Content-Type: text/plain\r\n");
1399 wc_printf(_("Could Not decode vcard photo\n"));
1403 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1404 http_transmit_thing(contentType, 0);
1409 typedef struct _vcardview_struct {
1411 addrbookent *addrbook;
1416 int vcard_GetParamsGetServerCall(SharedMessageStatus *Stat,
1417 void **ViewSpecific,
1422 vcardview_struct *VS;
1424 VS = (vcardview_struct*) malloc (sizeof(vcardview_struct));
1425 memset(VS, 0, sizeof(vcardview_struct));
1426 *ViewSpecific = (void*)VS;
1428 VS->is_singlecard = ibstr("is_singlecard");
1429 if (VS->is_singlecard != 1) {
1430 if (oper == do_search) {
1431 snprintf(cmd, len, "MSGS SEARCH|%s", bstr("query"));
1434 strcpy(cmd, "MSGS ALL");
1436 Stat->maxmsgs = 9999999;
1441 int vcard_LoadMsgFromServer(SharedMessageStatus *Stat,
1442 void **ViewSpecific,
1443 message_summary* Msg,
1447 vcardview_struct *VS;
1450 VS = (vcardview_struct*) *ViewSpecific;
1453 fetch_ab_name(Msg, &ab_name);
1454 if (ab_name == NULL)
1457 VS->addrbook = realloc(VS->addrbook,
1458 (sizeof(addrbookent) * VS->num_ab) );
1459 safestrncpy(VS->addrbook[VS->num_ab-1].ab_name, ab_name,
1460 sizeof(VS->addrbook[VS->num_ab-1].ab_name));
1461 VS->addrbook[VS->num_ab-1].ab_msgnum = Msg->msgnum;
1467 int vcard_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
1470 vcardview_struct *VS;
1472 VS = (vcardview_struct*) *ViewSpecific;
1473 if (VS->is_singlecard)
1474 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1476 do_addrbook_view(VS->addrbook, VS->num_ab); /* Render the address book */
1480 int vcard_Cleanup(void **ViewSpecific)
1482 vcardview_struct *VS;
1484 VS = (vcardview_struct*) *ViewSpecific;
1487 (VS->addrbook != NULL))
1495 ServerStartModule_VCARD
1498 VCToEnum = NewHash(0, NULL);
1503 ServerShutdownModule_VCARD
1506 DeleteHash(&VCToEnum);
1513 RegisterReadLoopHandlerset(
1515 vcard_GetParamsGetServerCall,
1518 vcard_LoadMsgFromServer,
1519 vcard_RenderView_or_Tail,
1521 WebcitAddUrlHandler(HKEY("edit_vcard"), "", 0, edit_vcard, 0);
1522 WebcitAddUrlHandler(HKEY("submit_vcard"), "", 0, submit_vcard, 0);
1523 WebcitAddUrlHandler(HKEY("vcardphoto"), "", 0, display_vcard_photo_img, NEED_URL);
1525 Put(VCToEnum, HKEY("n"), (void*)VC_n, reference_free_handler);
1526 Put(VCToEnum, HKEY("fn"), (void*)VC_fn, reference_free_handler);
1527 Put(VCToEnum, HKEY("title"), (void*)VC_title, reference_free_handler);
1528 Put(VCToEnum, HKEY("org"), (void*)VC_org, reference_free_handler);
1529 Put(VCToEnum, HKEY("email"), (void*)VC_email, reference_free_handler);
1530 Put(VCToEnum, HKEY("tel"), (void*)VC_tel, reference_free_handler);
1531 Put(VCToEnum, HKEY("tel_tel"), (void*)VC_tel_tel, reference_free_handler);
1532 Put(VCToEnum, HKEY("tel_work"), (void*)VC_tel_work, reference_free_handler);
1533 Put(VCToEnum, HKEY("tel_home"), (void*)VC_tel_home, reference_free_handler);
1534 Put(VCToEnum, HKEY("tel_cell"), (void*)VC_tel_cell, reference_free_handler);
1535 Put(VCToEnum, HKEY("adr"), (void*)VC_adr, reference_free_handler);
1536 Put(VCToEnum, HKEY("photo"), (void*)VC_photo, reference_free_handler);
1537 Put(VCToEnum, HKEY("version"), (void*)VC_version, reference_free_handler);
1538 Put(VCToEnum, HKEY("rev"), (void*)VC_rev, reference_free_handler);
1539 Put(VCToEnum, HKEY("label"), (void*)VC_label, reference_free_handler);
1542 RegisterNamespace("VC", 1, 2, tmplput_VCARD_ITEM, NULL, CTX_VCARD);
1544 REGISTERTokenParamDefine(VC_n);
1545 REGISTERTokenParamDefine(VC_fn);
1546 REGISTERTokenParamDefine(VC_title);
1547 REGISTERTokenParamDefine(VC_org);
1548 REGISTERTokenParamDefine(VC_email);
1549 REGISTERTokenParamDefine(VC_tel);
1550 REGISTERTokenParamDefine(VC_tel_tel);
1551 REGISTERTokenParamDefine(VC_tel_work);
1552 REGISTERTokenParamDefine(VC_tel_home);
1553 REGISTERTokenParamDefine(VC_tel_cell);
1554 REGISTERTokenParamDefine(VC_adr);
1555 REGISTERTokenParamDefine(VC_photo);
1556 REGISTERTokenParamDefine(VC_version);
1557 REGISTERTokenParamDefine(VC_rev);
1558 REGISTERTokenParamDefine(VC_label);