9 {HKEY("n")}, /* N is name, but only if there's no FN already there */
10 {HKEY("fn")}, /* FN (full name) is a true 'display name' field */
11 {HKEY("title")}, /* title */
12 {HKEY("org")}, /* organization */
44 HashList *VCToEnum = NULL;
47 * Record compare function for sorting address book indices
49 int abcmp(const void *ab1, const void *ab2) {
51 (((const addrbookent *)ab1)->ab_name),
52 (((const addrbookent *)ab2)->ab_name)
58 * Helper function for do_addrbook_view()
59 * Converts a name into a three-letter tab label
61 void nametab(char *tabbuf, long len, char *name) {
62 stresc(tabbuf, len, name, 0, 0);
63 tabbuf[0] = toupper(tabbuf[0]);
64 tabbuf[1] = tolower(tabbuf[1]);
65 tabbuf[2] = tolower(tabbuf[2]);
71 * If it's an old "Firstname Lastname" style record, try to convert it.
73 void lastfirst_firstlast(char *namebuf) {
78 if (namebuf == NULL) return;
79 if (strchr(namebuf, ';') != NULL) return;
81 i = num_tokens(namebuf, ' ');
84 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
85 remove_token(namebuf, i-1, ' ');
86 strcpy(firstname, namebuf);
87 sprintf(namebuf, "%s; %s", lastname, firstname);
92 wc_mime_attachment *load_vcard(message_summary *Msg)
95 StrBuf *FoundCharset = NewStrBuf();
100 wc_mime_attachment *Mime;
101 wc_mime_attachment *VCMime = NULL;
103 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
104 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
105 Msg->MsgBody->msgnum = Msg->msgnum;
107 load_message(Msg, FoundCharset, &Error);
109 FreeStrBuf(&FoundCharset);
110 /* look up the vcard... */
111 it = GetNewHashPos(Msg->AllAttach, 0);
112 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
115 Mime = (wc_mime_attachment*) vMime;
116 if ((strcmp(ChrPtr(Mime->ContentType),
117 "text/x-vcard") == 0) ||
118 (strcmp(ChrPtr(Mime->ContentType),
129 MimeLoadData(VCMime);
134 * fetch the display name off a vCard
136 void fetch_ab_name(message_summary *Msg, char **namebuf) {
139 wc_mime_attachment *VCMime = NULL;
141 if (namebuf == NULL) return;
143 VCMime = load_vcard(Msg);
147 /* Grab the name off the card */
148 display_vcard(WC->WBuf, VCMime, 0, 0, namebuf, Msg->msgnum);
150 if (*namebuf != NULL) {
151 lastfirst_firstlast(*namebuf);
153 len = strlen(*namebuf);
154 for (i=0; i<len; ++i) {
155 if ((*namebuf)[i] != ';') return;
158 (*namebuf) = strdup(_("(no name)"));
161 (*namebuf) = strdup(_("(no name)"));
168 * Turn a vCard "n" (name) field into something displayable.
170 void vcard_n_prettyize(char *name)
175 original_name = strdup(name);
176 len = strlen(original_name);
177 for (i=0; i<5; ++i) {
179 if (original_name[len-1] == ' ') {
180 original_name[--len] = 0;
182 if (original_name[len-1] == ';') {
183 original_name[--len] = 0;
189 for (i=0; i<len; ++i) {
190 if (original_name[i] == ';') {
195 name[j++] = original_name[i];
206 * preparse a vcard name
207 * display_vcard() calls this after parsing the textual vCard into
208 * our 'struct vCard' data object.
209 * This gets called instead of display_parsed_vcard() if we are only looking
210 * to extract the person's name instead of displaying the card.
212 void fetchname_parsed_vcard(struct vCard *v, char **storename) {
222 name = vcard_get_prop(v, "n", 1, 0, 0);
225 prop = vcard_get_prop(v, "n", 1, 0, 1);
226 n = num_tokens(prop, ';');
228 for (j=0; j<n; ++j) {
229 extract_token(buf, prop, j, ';', sizeof buf);
230 if (!strcasecmp(buf, "encoding=quoted-printable")) {
233 if (!strcasecmp(buf, "encoding=base64")) {
238 // %ff can become 6 bytes in utf8
239 *storename = malloc(len * 2 + 3);
240 j = CtdlDecodeQuotedPrintable(
246 // ff will become one byte..
247 *storename = malloc(len + 50);
257 *storename = malloc(len + 3); /* \0 + eventualy missing ', '*/
258 memcpy(*storename, name, len + 1);
260 /* vcard_n_prettyize(storename); */
269 * display_vcard() calls this after parsing the textual vCard into
270 * our 'struct vCard' data object.
272 * Set 'full' to nonzero to display the full card, otherwise it will only
273 * show a summary line.
275 * This code is a bit ugly, so perhaps an explanation is due: we do this
276 * in two passes through the vCard fields. On the first pass, we process
277 * fields we understand, and then render them in a pretty fashion at the
278 * end. Then we make a second pass, outputting all the fields we don't
279 * understand in a simple two-column name/value format.
280 * v the vCard to display
281 * full display all items of the vcard?
282 * msgnum Citadel message pointer
284 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
291 char *thisname, *thisvalue;
292 char firsttoken[SIZ];
301 strcpy(fullname, "");
308 StrBufAppendPrintf(Target, "<td>");
309 name = vcard_get_prop(v, "fn", 1, 0, 0);
311 StrEscAppend(Target, NULL, name, 0, 0);
313 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
314 strcpy(fullname, name);
315 vcard_n_prettyize(fullname);
316 StrEscAppend(Target, NULL, fullname, 0, 0);
319 StrBufAppendPrintf(Target, " ");
321 StrBufAppendPrintf(Target, "</td>");
325 StrBufAppendPrintf(Target, "<div align=\"center\">"
326 "<table bgcolor=\"#aaaaaa\" width=\"50%%\">");
327 for (pass=1; pass<=2; ++pass) {
329 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
331 thisname = strdup(v->prop[i].name);
332 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
334 for (j=0; j<num_tokens(thisname, ';'); ++j) {
335 extract_token(buf, thisname, j, ';', sizeof buf);
336 if (!strcasecmp(buf, "encoding=quoted-printable")) {
338 remove_token(thisname, j, ';');
340 if (!strcasecmp(buf, "encoding=base64")) {
342 remove_token(thisname, j, ';');
346 len = strlen(v->prop[i].value);
347 /* if we have some untagged QP, detect it here. */
348 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
349 utf8ify_rfc822_string(&v->prop[i].value);
352 // %ff can become 6 bytes in utf8
353 thisvalue = malloc(len * 2 + 3);
354 j = CtdlDecodeQuotedPrintable(
355 thisvalue, v->prop[i].value,
360 // ff will become one byte..
361 thisvalue = malloc(len + 50);
363 thisvalue, v->prop[i].value,
364 strlen(v->prop[i].value) );
367 thisvalue = strdup(v->prop[i].value);
370 /* Various fields we may encounter ***/
372 /* N is name, but only if there's no FN already there */
373 if (!strcasecmp(firsttoken, "n")) {
374 if (IsEmptyStr(fullname)) {
375 strcpy(fullname, thisvalue);
376 vcard_n_prettyize(fullname);
380 /* FN (full name) is a true 'display name' field */
381 else if (!strcasecmp(firsttoken, "fn")) {
382 strcpy(fullname, thisvalue);
386 else if (!strcasecmp(firsttoken, "title")) {
387 strcpy(title, thisvalue);
391 else if (!strcasecmp(firsttoken, "org")) {
392 strcpy(org, thisvalue);
395 else if (!strcasecmp(firsttoken, "email")) {
397 if (!IsEmptyStr(mailto)) strcat(mailto, "<br>");
399 "<a href=\"display_enter"
400 "?force_room=_MAIL_?recp=");
402 len = strlen(mailto);
403 urlesc(&mailto[len], SIZ - len, "\"");
404 len = strlen(mailto);
405 urlesc(&mailto[len], SIZ - len, fullname);
406 len = strlen(mailto);
407 urlesc(&mailto[len], SIZ - len, "\" <");
408 len = strlen(mailto);
409 urlesc(&mailto[len], SIZ - len, thisvalue);
410 len = strlen(mailto);
411 urlesc(&mailto[len], SIZ - len, ">");
413 strcat(mailto, "\">");
414 len = strlen(mailto);
415 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
416 strcat(mailto, "</A>");
418 else if (!strcasecmp(firsttoken, "tel")) {
419 if (!IsEmptyStr(phone)) strcat(phone, "<br>");
420 strcat(phone, thisvalue);
421 for (j=0; j<num_tokens(thisname, ';'); ++j) {
422 extract_token(buf, thisname, j, ';', sizeof buf);
423 if (!strcasecmp(buf, "tel"))
425 else if (!strcasecmp(buf, "work"))
426 strcat(phone, _(" (work)"));
427 else if (!strcasecmp(buf, "home"))
428 strcat(phone, _(" (home)"));
429 else if (!strcasecmp(buf, "cell"))
430 strcat(phone, _(" (cell)"));
438 else if (!strcasecmp(firsttoken, "adr")) {
440 StrBufAppendPrintf(Target, "<tr><td>");
441 StrBufAppendPrintf(Target, _("Address:"));
442 StrBufAppendPrintf(Target, "</td><td>");
443 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
444 extract_token(buf, thisvalue, j, ';', sizeof buf);
445 if (!IsEmptyStr(buf)) {
446 StrEscAppend(Target, NULL, buf, 0, 0);
447 if (j<3) StrBufAppendPrintf(Target, "<br>");
448 else StrBufAppendPrintf(Target, " ");
451 StrBufAppendPrintf(Target, "</td></tr>\n");
454 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
455 // Only output on second pass
456 StrBufAppendPrintf(Target, "<tr><td>");
457 StrBufAppendPrintf(Target, _("Photo:"));
458 StrBufAppendPrintf(Target, "</td><td>");
459 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
460 StrBufAppendPrintf(Target, "</td></tr>\n");
462 else if (!strcasecmp(firsttoken, "version")) {
465 else if (!strcasecmp(firsttoken, "rev")) {
468 else if (!strcasecmp(firsttoken, "label")) {
473 /*** Don't show extra fields. They're ugly.
475 StrBufAppendPrintf(Target, "<TR><TD>");
476 StrEscAppend(Target, NULL, thisname, 0, 0);
477 StrBufAppendPrintf(Target, "</TD><TD>");
478 StrEscAppend(Target, NULL, thisvalue, 0, 0);
479 StrBufAppendPrintf(Target, "</TD></TR>\n");
489 StrBufAppendPrintf(Target, "<tr bgcolor=\"#aaaaaa\">"
490 "<td colspan=2 bgcolor=\"#ffffff\">"
491 "<img align=\"center\" src=\"static/viewcontacts_48x.gif\">"
492 "<font size=\"+1\"><b>");
493 StrEscAppend(Target, NULL, fullname, 0, 0);
494 StrBufAppendPrintf(Target, "</b></font>");
495 if (!IsEmptyStr(title)) {
496 StrBufAppendPrintf(Target, "<div align=\"right>\"");
497 StrEscAppend(Target, NULL, title, 0, 0);
498 StrBufAppendPrintf(Target, "</div>");
500 if (!IsEmptyStr(org)) {
501 StrBufAppendPrintf(Target, "<div align=\"right\">");
502 StrEscAppend(Target, NULL, org, 0, 0);
503 StrBufAppendPrintf(Target, "</div>");
505 StrBufAppendPrintf(Target, "</td></tr>\n");
507 if (!IsEmptyStr(phone)) {
508 StrBufAppendPrintf(Target, "<tr><td>");
509 StrBufAppendPrintf(Target, _("Telephone:"));
510 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
512 if (!IsEmptyStr(mailto)) {
513 StrBufAppendPrintf(Target, "<tr><td>");
514 StrBufAppendPrintf(Target, _("E-mail:"));
515 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
521 StrBufAppendPrintf(Target, "</table></div>\n");
526 * display_vcard() calls this after parsing the textual vCard into
527 * our 'struct vCard' data object.
529 * Set 'full' to nonzero to display the full card, otherwise it will only
530 * show a summary line.
532 * This code is a bit ugly, so perhaps an explanation is due: we do this
533 * in two passes through the vCard fields. On the first pass, we process
534 * fields we understand, and then render them in a pretty fashion at the
535 * end. Then we make a second pass, outputting all the fields we don't
536 * understand in a simple two-column name/value format.
537 * v the vCard to display
538 * full display all items of the vcard?
539 * msgnum Citadel message pointer
541 void parse_vcard(StrBuf *Target, struct vCard *v, HashList *VC, int full, wc_mime_attachment *Mime)
550 StrBuf *thisname = NULL;
551 char *thisvalue = NULL;
552 char firsttoken[SIZ];
558 thisname = NewStrBuf();
559 for (i=0; i<(v->numprops); ++i) {
563 StrBufPlain(thisname, v->prop[i].name, -1);
564 StrBufLowerCase(thisname);
566 len = extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
568 for (j=0; j<num_tokens(thisname, ';'); ++j) {
569 extract_token(buf, thisname, j, ';', sizeof buf);
570 if (!strcasecmp(buf, "encoding=quoted-printable")) {
572 remove_token(thisname, j, ';');
574 if (!strcasecmp(buf, "encoding=base64")) {
576 remove_token(thisname, j, ';');
580 /* copy over the payload into a StrBuf */
581 Val = NewStrBufPlain(v->prop[i].value, -1);
583 /* if we have some untagged QP, detect it here. */
584 if (is_qp || (strstr(v->prop[i].value, "=?")!=NULL)){
586 StrBuf_RFC822_to_Utf8(Swap, Val, NULL, NULL); /* default charset, current charset */
593 StrBufDecodeBase64(Val);
596 lprintf(1, "%s [%s][%s]",
600 if (GetHash(VCToEnum, firsttoken, strlen(firsttoken), &V))
603 Put(VC, IKEY(evc), Val, HFreeStrBuf);
604 lprintf(1, "[%ld]\n", evc);
610 TODO: check for layer II
613 long max = num_tokens(thisname, ';');
614 firsttoken[len] = '_';
616 for (j = 0; j < max; j++) {
619 extract_token(buf, thisname, j, ';', sizeof (buf));
620 if (!strcasecmp(buf, "tel"))
622 else if (!strcasecmp(buf, "work"))
623 strcat(phone, _(" (work)"));
624 else if (!strcasecmp(buf, "home"))
625 strcat(phone, _(" (home)"));
626 else if (!strcasecmp(buf, "cell"))
627 strcat(phone, _(" (cell)"));
646 void tmplput_VCARD_ITEM(StrBuf *Target, WCTemplputParams *TP)
652 evc = GetTemplateTokenNumber(Target, TP, 0, -1);
655 if (GetHash(VC, IKEY(evc), &vStr))
657 StrBufAppendTemplate(Target, TP,
665 void new_vcard (StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
668 WCTemplputParams SubTP;
670 memset(&SubTP, 0, sizeof(WCTemplputParams));
673 VC = NewHash(0, Flathash);
674 parse_vcard(Target, v, VC, full, Mime);
676 SubTP.Filter.ContextType = CTX_VCARD;
679 DoTemplate(HKEY("test_vcard"), Target, &SubTP);
686 * Display a textual vCard
687 * (Converts to a vCard object and then calls the actual display function)
688 * Set 'full' to nonzero to display the whole card instead of a one-liner.
689 * Or, if "storename" is non-NULL, just store the person's name in that
690 * buffer instead of displaying the card at all.
692 * vcard_source the buffer containing the vcard text
693 * alpha Display only if name begins with this letter of the alphabet
694 * full Display the full vCard (otherwise just the display name)
695 * storename If not NULL, also store the display name here
696 * msgnum Citadel message pointer
698 void display_vcard(StrBuf *Target,
699 wc_mime_attachment *Mime,
711 v = VCardLoad(Mime->Data);
713 if (v == NULL) return;
715 name = vcard_get_prop(v, "n", 1, 0, 0);
717 Buf = NewStrBufPlain(name, -1);
718 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
719 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
720 this_alpha = ChrPtr(Buf)[0];
725 if (storename != NULL) {
726 fetchname_parsed_vcard(v, storename);
728 else if ((alpha == 0) ||
729 ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha))) ||
730 ((!isalpha(alpha)) && (!isalpha(this_alpha)))
734 new_vcard (Target, v, full, Mime);
736 display_parsed_vcard(Target, v, full, Mime);
746 * Render the address book using info we gathered during the scan
748 * addrbook the addressbook to render
749 * num_ab the number of the addressbook
751 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
755 static int NAMESPERPAGE = 60;
758 char tabfirst_label[64];
760 char tablast_label[64];
761 char this_tablabel[64];
766 wc_printf("<br><br><br><div align=\"center\"><i>");
767 wc_printf(_("This address book is empty."));
768 wc_printf("</i></div>\n");
773 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
776 num_pages = (num_ab / NAMESPERPAGE) + 1;
778 tablabels = malloc(num_pages * sizeof (char *));
779 if (tablabels == NULL) {
780 wc_printf("<br><br><br><div align=\"center\"><i>");
781 wc_printf(_("An internal error has occurred."));
782 wc_printf("</i></div>\n");
786 for (i=0; i<num_pages; ++i) {
787 tabfirst = i * NAMESPERPAGE;
788 tablast = tabfirst + NAMESPERPAGE - 1;
789 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
790 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
791 nametab(tablast_label, 64, addrbook[tablast].ab_name);
792 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
793 tablabels[i] = strdup(this_tablabel);
796 tabbed_dialog(num_pages, tablabels);
799 for (i=0; i<num_ab; ++i) {
801 if ((i / NAMESPERPAGE) != page) { /* New tab */
802 page = (i / NAMESPERPAGE);
804 wc_printf("</tr></table>\n");
805 end_tab(page-1, num_pages);
807 begin_tab(page, num_pages);
808 wc_printf("<table border=\"0\" cellspacing=\"0\" cellpadding=\"3\" width=\"100%%\">\n");
812 if ((displayed % 4) == 0) {
814 wc_printf("</tr>\n");
817 wc_printf("<tr bgcolor=\"#%s\">",
818 (bg ? "dddddd" : "ffffff")
824 wc_printf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
825 addrbook[i].ab_msgnum);
826 wc_printf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
827 vcard_n_prettyize(addrbook[i].ab_name);
828 escputs(addrbook[i].ab_name);
829 wc_printf("</a></td>\n");
833 /* Placeholders for empty columns at end */
834 if ((num_ab % 4) != 0) {
835 for (i=0; i<(4-(num_ab % 4)); ++i) {
836 wc_printf("<td> </td>");
840 wc_printf("</tr></table>\n");
841 end_tab((num_pages-1), num_pages);
843 begin_tab(num_pages, num_pages);
844 /* FIXME there ought to be something here */
845 end_tab(num_pages, num_pages);
847 for (i=0; i<num_pages; ++i) {
857 * Edit the vCard component of a MIME message.
858 * Supply the message number
859 * and MIME part number to fetch. Or, specify -1 for the message number
860 * to start with a blank card.
862 void do_edit_vcard(long msgnum, char *partnum,
863 message_summary *VCMsg,
864 wc_mime_attachment *VCAtt,
865 const char *return_to,
866 const char *force_room) {
867 message_summary *Msg = NULL;
868 wc_mime_attachment *VCMime = NULL;
876 char middlename[256];
890 char primary_inetemail[256];
891 char other_inetemail[SIZ];
892 char extrafields[SIZ];
913 primary_inetemail[0] = 0;
914 other_inetemail[0] = 0;
920 safestrncpy(whatuser, "", sizeof whatuser);
923 ((VCMsg != NULL) && (VCAtt != NULL)))
925 if ((VCMsg == NULL) && (VCAtt == NULL)) {
927 Msg = (message_summary *) malloc(sizeof(message_summary));
928 memset(Msg, 0, sizeof(message_summary));
929 Msg->msgnum = msgnum;
930 VCMime = load_vcard(Msg);
931 if (VCMime == NULL) {
932 convenience_page("770000", _("Error"), "");///TODO: important message
933 DestroyMessageSummary(Msg);
937 v = VCardLoad(VCMime->Data);
940 v = VCardLoad(VCAtt->Data);
943 /* Populate the variables for our form */
945 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
946 char prp[256]; /* property name */
947 char prm[256]; /* parameters */
949 value = vcard_get_prop(v, "", 0, i++, 0);
952 extract_token(prp, key, 0, ';', sizeof prp);
953 safestrncpy(prm, key, sizeof prm);
954 remove_token(prm, 0, ';');
956 if (!strcasecmp(prp, "n")) {
957 extract_token(lastname, value, 0, ';', sizeof lastname);
958 extract_token(firstname, value, 1, ';', sizeof firstname);
959 extract_token(middlename, value, 2, ';', sizeof middlename);
960 extract_token(prefix, value, 3, ';', sizeof prefix);
961 extract_token(suffix, value, 4, ';', sizeof suffix);
964 else if (!strcasecmp(prp, "fn")) {
965 safestrncpy(fullname, value, sizeof fullname);
968 else if (!strcasecmp(prp, "title")) {
969 safestrncpy(title, value, sizeof title);
972 else if (!strcasecmp(prp, "org")) {
973 safestrncpy(org, value, sizeof org);
976 else if (!strcasecmp(prp, "adr")) {
977 extract_token(pobox, value, 0, ';', sizeof pobox);
978 extract_token(extadr, value, 1, ';', sizeof extadr);
979 extract_token(street, value, 2, ';', sizeof street);
980 extract_token(city, value, 3, ';', sizeof city);
981 extract_token(state, value, 4, ';', sizeof state);
982 extract_token(zipcode, value, 5, ';', sizeof zipcode);
983 extract_token(country, value, 6, ';', sizeof country);
986 else if (!strcasecmp(prp, "tel")) {
988 if (bmstrcasestr(prm, "home")) {
989 extract_token(hometel, value, 0, ';', sizeof hometel);
991 else if (bmstrcasestr(prm, "work")) {
992 extract_token(worktel, value, 0, ';', sizeof worktel);
994 else if (bmstrcasestr(prm, "fax")) {
995 extract_token(faxtel, value, 0, ';', sizeof faxtel);
997 else if (bmstrcasestr(prm, "cell")) {
998 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
1000 else { /* Missing or unknown type; put it in the home phone */
1001 extract_token(hometel, value, 0, ';', sizeof hometel);
1005 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
1006 if (primary_inetemail[0] == 0) {
1007 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
1010 if (other_inetemail[0] != 0) {
1011 strcat(other_inetemail, "\n");
1013 strcat(other_inetemail, value);
1017 /* Unrecognized properties are preserved here so we don't discard them
1018 * just because the vCard was edited with WebCit.
1021 strcat(extrafields, key);
1022 strcat(extrafields, ":");
1023 strcat(extrafields, value);
1024 strcat(extrafields, "\n");
1032 /* Display the form */
1033 output_headers(1, 1, 1, 0, 0, 0);
1035 do_template("beginbox_1", NULL);
1036 StrBufAppendBufPlain(WC->WBuf, _("Edit contact information"), -1, 0);
1037 do_template("beginbox_2", NULL);
1039 wc_printf("<form method=\"POST\" action=\"submit_vcard\">\n");
1040 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
1042 if (force_room != NULL) {
1043 wc_printf("<input type=\"hidden\" name=\"force_room\" value=\"");
1044 escputs(force_room);
1048 wc_printf("<table class=\"vcard_edit_background\"><tr><td>\n");
1050 wc_printf("<table border=\"0\"><tr>"
1055 "<td>%s</td></tr>\n",
1056 _("Prefix"), _("First Name"), _("Middle Name"), _("Last Name"), _("Suffix")
1058 wc_printf("<tr><td><input type=\"text\" name=\"prefix\" "
1059 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
1061 wc_printf("<td><input type=\"text\" name=\"firstname\" "
1062 "value=\"%s\" maxlength=\"29\"></td>",
1064 wc_printf("<td><input type=\"text\" name=\"middlename\" "
1065 "value=\"%s\" maxlength=\"29\"></td>",
1067 wc_printf("<td><input type=\"text\" name=\"lastname\" "
1068 "value=\"%s\" maxlength=\"29\"></td>",
1070 wc_printf("<td><input type=\"text\" name=\"suffix\" "
1071 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
1074 wc_printf("<table class=\"vcard_edit_background_alt\">");
1075 wc_printf("<tr><td>");
1077 wc_printf(_("Display name:"));
1079 "<input type=\"text\" name=\"fullname\" "
1080 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1084 wc_printf(_("Title:"));
1086 "<input type=\"text\" name=\"title\" "
1087 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1091 wc_printf(_("Organization:"));
1093 "<input type=\"text\" name=\"org\" "
1094 "value=\"%s\" maxlength=\"40\"><br><br>\n",
1098 wc_printf("</td><td>");
1100 wc_printf("<table border=\"0\">");
1101 wc_printf("<tr><td>");
1102 wc_printf(_("PO box:"));
1103 wc_printf("</td><td>"
1104 "<input type=\"text\" name=\"pobox\" "
1105 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1107 wc_printf("<tr><td>");
1108 wc_printf(_("Address:"));
1109 wc_printf("</td><td>"
1110 "<input type=\"text\" name=\"extadr\" "
1111 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1113 wc_printf("<tr><td> </td><td>"
1114 "<input type=\"text\" name=\"street\" "
1115 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1117 wc_printf("<tr><td>");
1118 wc_printf(_("City:"));
1119 wc_printf("</td><td>"
1120 "<input type=\"text\" name=\"city\" "
1121 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1123 wc_printf("<tr><td>");
1124 wc_printf(_("State:"));
1125 wc_printf("</td><td>"
1126 "<input type=\"text\" name=\"state\" "
1127 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1129 wc_printf("<tr><td>");
1130 wc_printf(_("ZIP code:"));
1131 wc_printf("</td><td>"
1132 "<input type=\"text\" name=\"zipcode\" "
1133 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
1135 wc_printf("<tr><td>");
1136 wc_printf(_("Country:"));
1137 wc_printf("</td><td>"
1138 "<input type=\"text\" name=\"country\" "
1139 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
1141 wc_printf("</table>\n");
1143 wc_printf("</table>\n");
1145 wc_printf("<table border=0><tr><td>");
1146 wc_printf(_("Home telephone:"));
1148 "<td><input type=\"text\" name=\"hometel\" "
1149 "value=\"%s\" maxlength=\"29\"></td>\n",
1152 wc_printf(_("Work telephone:"));
1154 "<td><input type=\"text\" name=\"worktel\" "
1155 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1157 wc_printf("<tr><td>");
1158 wc_printf(_("Mobile telephone:"));
1160 "<td><input type=\"text\" name=\"mobiletel\" "
1161 "value=\"%s\" maxlength=\"29\"></td>\n",
1164 wc_printf(_("Fax number:"));
1166 "<td><input type=\"text\" name=\"faxtel\" "
1167 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
1170 wc_printf("<table class=\"vcard_edit_background_alt\">");
1171 wc_printf("<tr><td>");
1173 wc_printf("<table border=0><TR>"
1175 wc_printf(_("Primary Internet e-mail address"));
1177 "<input type=\"text\" name=\"primary_inetemail\" "
1178 "size=40 maxlength=60 value=\"");
1179 escputs(primary_inetemail);
1181 "</td><td valign=top>");
1182 wc_printf(_("Internet e-mail aliases"));
1184 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
1185 escputs(other_inetemail);
1186 wc_printf("</textarea></td></tr></table>\n");
1188 wc_printf("</td></tr></table>\n");
1190 wc_printf("<input type=\"hidden\" name=\"extrafields\" value=\"");
1191 escputs(extrafields);
1194 wc_printf("<input type=\"hidden\" name=\"return_to\" value=\"");
1198 wc_printf("<div class=\"buttons\">\n"
1199 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1201 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1207 wc_printf("</td></tr></table>\n");
1208 do_template("endbox", NULL);
1211 DestroyMessageSummary(Msg);
1217 * commit the edits to the citadel server
1219 void edit_vcard(void) {
1223 msgnum = lbstr("msgnum");
1224 partnum = bstr("partnum");
1225 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1231 * parse edited vcard from the browser
1233 void submit_vcard(void) {
1234 wcsession *WCC = WC;
1236 char *serialized_vcard;
1241 if (!havebstr("ok_button")) {
1242 readloop(readnew, eUseDefault);
1246 if (havebstr("force_room")) {
1247 if (gotoroom(sbstr("force_room")) != 200) {
1248 StrBufAppendBufPlain(WCC->ImportantMsg,
1249 _("Unable to enter the room to save your message"),
1251 StrBufAppendBufPlain(WCC->ImportantMsg,
1253 StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
1254 StrBufAppendBufPlain(WCC->ImportantMsg,
1257 StrBufAppendBufPlain(WCC->ImportantMsg,
1261 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1262 select_user_to_edit(NULL);
1264 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1267 else if (!IsEmptyStr(bstr("return_to"))) {
1268 http_redirect(bstr("return_to"));
1271 readloop(readnew, eUseDefault);
1277 sprintf(buf, "ENT0 1|||4||");
1279 serv_getln(buf, sizeof buf);
1280 if (buf[0] != '4') {
1285 /* Make a vCard structure out of the data supplied in the form */
1287 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1290 v = VCardLoad(Buf); /* Start with the extra fields */
1293 safestrncpy(WCC->ImportantMessage,
1294 _("An error has occurred."),
1295 sizeof WCC->ImportantMessage
1301 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1307 vcard_add_prop(v, "n", buf);
1309 vcard_add_prop(v, "title", bstr("title"));
1310 vcard_add_prop(v, "fn", bstr("fullname"));
1311 vcard_add_prop(v, "org", bstr("org"));
1313 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1321 vcard_add_prop(v, "adr", buf);
1323 vcard_add_prop(v, "tel;home", bstr("hometel"));
1324 vcard_add_prop(v, "tel;work", bstr("worktel"));
1325 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1326 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1327 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1329 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1330 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1331 if (!IsEmptyStr(buf)) {
1332 vcard_add_prop(v, "email;internet", buf);
1336 serialized_vcard = vcard_serialize(v);
1338 if (serialized_vcard == NULL) {
1339 safestrncpy(WCC->ImportantMessage,
1340 _("An error has occurred."),
1341 sizeof WCC->ImportantMessage
1347 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1349 serv_printf("%s\r\n", serialized_vcard);
1351 free(serialized_vcard);
1353 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1354 select_user_to_edit(NULL);
1356 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1359 else if (!IsEmptyStr(bstr("return_to"))) {
1360 http_redirect(bstr("return_to"));
1363 readloop(readnew, eUseDefault);
1370 * Extract an embedded photo from a vCard for display on the client
1372 void display_vcard_photo_img(void)
1378 const char *contentType;
1379 wcsession *WCC = WC;
1381 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1383 vcard = load_mimepart(msgnum,"1");
1384 v = VCardLoad(vcard);
1386 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1387 FlushStrBuf(WCC->WBuf);
1388 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1389 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1390 FlushStrBuf(WCC->WBuf);
1392 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1393 output_headers(0, 0, 0, 0, 0, 0);
1394 hprintf("Content-Type: text/plain\r\n");
1396 wc_printf(_("Could Not decode vcard photo\n"));
1400 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1401 http_transmit_thing(contentType, 0);
1406 typedef struct _vcardview_struct {
1408 addrbookent *addrbook;
1413 int vcard_GetParamsGetServerCall(SharedMessageStatus *Stat,
1414 void **ViewSpecific,
1419 vcardview_struct *VS;
1421 VS = (vcardview_struct*) malloc (sizeof(vcardview_struct));
1422 memset(VS, 0, sizeof(vcardview_struct));
1423 *ViewSpecific = (void*)VS;
1425 VS->is_singlecard = ibstr("is_singlecard");
1426 if (VS->is_singlecard != 1) {
1427 if (oper == do_search) {
1428 snprintf(cmd, len, "MSGS SEARCH|%s", bstr("query"));
1431 strcpy(cmd, "MSGS ALL");
1433 Stat->maxmsgs = 9999999;
1438 int vcard_LoadMsgFromServer(SharedMessageStatus *Stat,
1439 void **ViewSpecific,
1440 message_summary* Msg,
1444 vcardview_struct *VS;
1447 VS = (vcardview_struct*) *ViewSpecific;
1450 fetch_ab_name(Msg, &ab_name);
1451 if (ab_name == NULL)
1454 VS->addrbook = realloc(VS->addrbook,
1455 (sizeof(addrbookent) * VS->num_ab) );
1456 safestrncpy(VS->addrbook[VS->num_ab-1].ab_name, ab_name,
1457 sizeof(VS->addrbook[VS->num_ab-1].ab_name));
1458 VS->addrbook[VS->num_ab-1].ab_msgnum = Msg->msgnum;
1464 int vcard_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
1467 vcardview_struct *VS;
1469 VS = (vcardview_struct*) *ViewSpecific;
1470 if (VS->is_singlecard)
1471 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1473 do_addrbook_view(VS->addrbook, VS->num_ab); /* Render the address book */
1477 int vcard_Cleanup(void **ViewSpecific)
1479 vcardview_struct *VS;
1481 VS = (vcardview_struct*) *ViewSpecific;
1484 (VS->addrbook != NULL))
1492 ServerStartModule_VCARD
1495 VCToEnum = NewHash(0, NULL);
1500 ServerShutdownModule_VCARD
1503 DeleteHash(&VCToEnum);
1510 RegisterReadLoopHandlerset(
1512 vcard_GetParamsGetServerCall,
1515 vcard_LoadMsgFromServer,
1516 vcard_RenderView_or_Tail,
1518 WebcitAddUrlHandler(HKEY("edit_vcard"), "", 0, edit_vcard, 0);
1519 WebcitAddUrlHandler(HKEY("submit_vcard"), "", 0, submit_vcard, 0);
1520 WebcitAddUrlHandler(HKEY("vcardphoto"), "", 0, display_vcard_photo_img, NEED_URL);
1522 Put(VCToEnum, HKEY("n"), (void*)VC_n, reference_free_handler);
1523 Put(VCToEnum, HKEY("fn"), (void*)VC_fn, reference_free_handler);
1524 Put(VCToEnum, HKEY("title"), (void*)VC_title, reference_free_handler);
1525 Put(VCToEnum, HKEY("org"), (void*)VC_org, reference_free_handler);
1526 Put(VCToEnum, HKEY("email"), (void*)VC_email, reference_free_handler);
1527 Put(VCToEnum, HKEY("tel"), (void*)VC_tel, reference_free_handler);
1528 Put(VCToEnum, HKEY("tel_tel"), (void*)VC_tel_tel, reference_free_handler);
1529 Put(VCToEnum, HKEY("tel_work"), (void*)VC_tel_work, reference_free_handler);
1530 Put(VCToEnum, HKEY("tel_home"), (void*)VC_tel_home, reference_free_handler);
1531 Put(VCToEnum, HKEY("tel_cell"), (void*)VC_tel_cell, reference_free_handler);
1532 Put(VCToEnum, HKEY("adr"), (void*)VC_adr, reference_free_handler);
1533 Put(VCToEnum, HKEY("photo"), (void*)VC_photo, reference_free_handler);
1534 Put(VCToEnum, HKEY("version"), (void*)VC_version, reference_free_handler);
1535 Put(VCToEnum, HKEY("rev"), (void*)VC_rev, reference_free_handler);
1536 Put(VCToEnum, HKEY("label"), (void*)VC_label, reference_free_handler);
1539 RegisterNamespace("VC", 1, 2, tmplput_VCARD_ITEM, NULL, CTX_VCARD);
1541 REGISTERTokenParamDefine(VC_n);
1542 REGISTERTokenParamDefine(VC_fn);
1543 REGISTERTokenParamDefine(VC_title);
1544 REGISTERTokenParamDefine(VC_org);
1545 REGISTERTokenParamDefine(VC_email);
1546 REGISTERTokenParamDefine(VC_tel);
1547 REGISTERTokenParamDefine(VC_tel_tel);
1548 REGISTERTokenParamDefine(VC_tel_work);
1549 REGISTERTokenParamDefine(VC_tel_home);
1550 REGISTERTokenParamDefine(VC_tel_cell);
1551 REGISTERTokenParamDefine(VC_adr);
1552 REGISTERTokenParamDefine(VC_photo);
1553 REGISTERTokenParamDefine(VC_version);
1554 REGISTERTokenParamDefine(VC_rev);
1555 REGISTERTokenParamDefine(VC_label);