9 * Record compare function for sorting address book indices
11 int abcmp(const void *ab1, const void *ab2) {
13 (((const addrbookent *)ab1)->ab_name),
14 (((const addrbookent *)ab2)->ab_name)
20 * Helper function for do_addrbook_view()
21 * Converts a name into a three-letter tab label
23 void nametab(char *tabbuf, long len, char *name) {
24 stresc(tabbuf, len, name, 0, 0);
25 tabbuf[0] = toupper(tabbuf[0]);
26 tabbuf[1] = tolower(tabbuf[1]);
27 tabbuf[2] = tolower(tabbuf[2]);
33 * If it's an old "Firstname Lastname" style record, try to convert it.
35 void lastfirst_firstlast(char *namebuf) {
40 if (namebuf == NULL) return;
41 if (strchr(namebuf, ';') != NULL) return;
43 i = num_tokens(namebuf, ' ');
46 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
47 remove_token(namebuf, i-1, ' ');
48 strcpy(firstname, namebuf);
49 sprintf(namebuf, "%s; %s", lastname, firstname);
54 wc_mime_attachment *load_vcard(message_summary *Msg)
57 StrBuf *FoundCharset = NewStrBuf();
62 wc_mime_attachment *Mime;
63 wc_mime_attachment *VCMime = NULL;
65 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
66 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
67 Msg->MsgBody->msgnum = Msg->msgnum;
69 load_message(Msg, FoundCharset, &Error);
71 FreeStrBuf(&FoundCharset);
72 /* look up the vcard... */
73 it = GetNewHashPos(Msg->AllAttach, 0);
74 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
77 Mime = (wc_mime_attachment*) vMime;
78 if ((strcmp(ChrPtr(Mime->ContentType),
79 "text/x-vcard") == 0) ||
80 (strcmp(ChrPtr(Mime->ContentType),
96 * fetch the display name off a vCard
98 void fetch_ab_name(message_summary *Msg, char **namebuf) {
101 wc_mime_attachment *VCMime = NULL;
103 if (namebuf == NULL) return;
105 VCMime = load_vcard(Msg);
109 /* Grab the name off the card */
110 display_vcard(WC->WBuf, VCMime, 0, 0, namebuf, Msg->msgnum);
112 if (*namebuf != NULL) {
113 lastfirst_firstlast(*namebuf);
115 len = strlen(*namebuf);
116 for (i=0; i<len; ++i) {
117 if ((*namebuf)[i] != ';') return;
120 (*namebuf) = strdup(_("(no name)"));
123 (*namebuf) = strdup(_("(no name)"));
130 * Turn a vCard "n" (name) field into something displayable.
132 void vcard_n_prettyize(char *name)
137 original_name = strdup(name);
138 len = strlen(original_name);
139 for (i=0; i<5; ++i) {
141 if (original_name[len-1] == ' ') {
142 original_name[--len] = 0;
144 if (original_name[len-1] == ';') {
145 original_name[--len] = 0;
151 for (i=0; i<len; ++i) {
152 if (original_name[i] == ';') {
157 name[j++] = original_name[i];
168 * preparse a vcard name
169 * display_vcard() calls this after parsing the textual vCard into
170 * our 'struct vCard' data object.
171 * This gets called instead of display_parsed_vcard() if we are only looking
172 * to extract the person's name instead of displaying the card.
174 void fetchname_parsed_vcard(struct vCard *v, char **storename) {
184 name = vcard_get_prop(v, "n", 1, 0, 0);
187 prop = vcard_get_prop(v, "n", 1, 0, 1);
188 n = num_tokens(prop, ';');
190 for (j=0; j<n; ++j) {
191 extract_token(buf, prop, j, ';', sizeof buf);
192 if (!strcasecmp(buf, "encoding=quoted-printable")) {
195 if (!strcasecmp(buf, "encoding=base64")) {
200 // %ff can become 6 bytes in utf8
201 *storename = malloc(len * 2 + 3);
202 j = CtdlDecodeQuotedPrintable(
208 // ff will become one byte..
209 *storename = malloc(len + 50);
219 *storename = malloc(len + 3); /* \0 + eventualy missing ', '*/
220 memcpy(*storename, name, len + 1);
222 /* vcard_n_prettyize(storename); */
231 * display_vcard() calls this after parsing the textual vCard into
232 * our 'struct vCard' data object.
234 * Set 'full' to nonzero to display the full card, otherwise it will only
235 * show a summary line.
237 * This code is a bit ugly, so perhaps an explanation is due: we do this
238 * in two passes through the vCard fields. On the first pass, we process
239 * fields we understand, and then render them in a pretty fashion at the
240 * end. Then we make a second pass, outputting all the fields we don't
241 * understand in a simple two-column name/value format.
242 * v the vCard to display
243 * full display all items of the vcard?
244 * msgnum Citadel message pointer
246 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
253 char *thisname, *thisvalue;
254 char firsttoken[SIZ];
263 strcpy(fullname, "");
270 StrBufAppendPrintf(Target, "<TD>");
271 name = vcard_get_prop(v, "fn", 1, 0, 0);
273 StrEscAppend(Target, NULL, name, 0, 0);
275 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
276 strcpy(fullname, name);
277 vcard_n_prettyize(fullname);
278 StrEscAppend(Target, NULL, fullname, 0, 0);
281 StrBufAppendPrintf(Target, " ");
283 StrBufAppendPrintf(Target, "</TD>");
287 StrBufAppendPrintf(Target, "<div align=center>"
288 "<table bgcolor=#aaaaaa width=50%%>");
289 for (pass=1; pass<=2; ++pass) {
291 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
293 thisname = strdup(v->prop[i].name);
294 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
296 for (j=0; j<num_tokens(thisname, ';'); ++j) {
297 extract_token(buf, thisname, j, ';', sizeof buf);
298 if (!strcasecmp(buf, "encoding=quoted-printable")) {
300 remove_token(thisname, j, ';');
302 if (!strcasecmp(buf, "encoding=base64")) {
304 remove_token(thisname, j, ';');
308 len = strlen(v->prop[i].value);
309 /* if we have some untagged QP, detect it here. */
310 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
311 utf8ify_rfc822_string(&v->prop[i].value);
314 // %ff can become 6 bytes in utf8
315 thisvalue = malloc(len * 2 + 3);
316 j = CtdlDecodeQuotedPrintable(
317 thisvalue, v->prop[i].value,
322 // ff will become one byte..
323 thisvalue = malloc(len + 50);
325 thisvalue, v->prop[i].value,
326 strlen(v->prop[i].value) );
329 thisvalue = strdup(v->prop[i].value);
332 /* Various fields we may encounter ***/
334 /* N is name, but only if there's no FN already there */
335 if (!strcasecmp(firsttoken, "n")) {
336 if (IsEmptyStr(fullname)) {
337 strcpy(fullname, thisvalue);
338 vcard_n_prettyize(fullname);
342 /* FN (full name) is a true 'display name' field */
343 else if (!strcasecmp(firsttoken, "fn")) {
344 strcpy(fullname, thisvalue);
348 else if (!strcasecmp(firsttoken, "title")) {
349 strcpy(title, thisvalue);
353 else if (!strcasecmp(firsttoken, "org")) {
354 strcpy(org, thisvalue);
357 else if (!strcasecmp(firsttoken, "email")) {
359 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
361 "<a href=\"display_enter"
362 "?force_room=_MAIL_?recp=");
364 len = strlen(mailto);
365 urlesc(&mailto[len], SIZ - len, "\"");
366 len = strlen(mailto);
367 urlesc(&mailto[len], SIZ - len, fullname);
368 len = strlen(mailto);
369 urlesc(&mailto[len], SIZ - len, "\" <");
370 len = strlen(mailto);
371 urlesc(&mailto[len], SIZ - len, thisvalue);
372 len = strlen(mailto);
373 urlesc(&mailto[len], SIZ - len, ">");
375 strcat(mailto, "\">");
376 len = strlen(mailto);
377 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
378 strcat(mailto, "</A>");
380 else if (!strcasecmp(firsttoken, "tel")) {
381 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
382 strcat(phone, thisvalue);
383 for (j=0; j<num_tokens(thisname, ';'); ++j) {
384 extract_token(buf, thisname, j, ';', sizeof buf);
385 if (!strcasecmp(buf, "tel"))
387 else if (!strcasecmp(buf, "work"))
388 strcat(phone, _(" (work)"));
389 else if (!strcasecmp(buf, "home"))
390 strcat(phone, _(" (home)"));
391 else if (!strcasecmp(buf, "cell"))
392 strcat(phone, _(" (cell)"));
400 else if (!strcasecmp(firsttoken, "adr")) {
402 StrBufAppendPrintf(Target, "<TR><TD>");
403 StrBufAppendPrintf(Target, _("Address:"));
404 StrBufAppendPrintf(Target, "</TD><TD>");
405 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
406 extract_token(buf, thisvalue, j, ';', sizeof buf);
407 if (!IsEmptyStr(buf)) {
408 StrEscAppend(Target, NULL, buf, 0, 0);
409 if (j<3) StrBufAppendPrintf(Target, "<br />");
410 else StrBufAppendPrintf(Target, " ");
413 StrBufAppendPrintf(Target, "</TD></TR>\n");
416 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
417 // Only output on second pass
418 StrBufAppendPrintf(Target, "<tr><td>");
419 StrBufAppendPrintf(Target, _("Photo:"));
420 StrBufAppendPrintf(Target, "</td><td>");
421 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
422 StrBufAppendPrintf(Target, "</td></tr>\n");
424 else if (!strcasecmp(firsttoken, "version")) {
427 else if (!strcasecmp(firsttoken, "rev")) {
430 else if (!strcasecmp(firsttoken, "label")) {
435 /*** Don't show extra fields. They're ugly.
437 StrBufAppendPrintf(Target, "<TR><TD>");
438 StrEscAppend(Target, NULL, thisname, 0, 0);
439 StrBufAppendPrintf(Target, "</TD><TD>");
440 StrEscAppend(Target, NULL, thisvalue, 0, 0);
441 StrBufAppendPrintf(Target, "</TD></TR>\n");
451 StrBufAppendPrintf(Target, "<TR BGCOLOR=\"#AAAAAA\">"
452 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
453 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
454 "<FONT SIZE=+1><B>");
455 StrEscAppend(Target, NULL, fullname, 0, 0);
456 StrBufAppendPrintf(Target, "</B></FONT>");
457 if (!IsEmptyStr(title)) {
458 StrBufAppendPrintf(Target, "<div align=right>");
459 StrEscAppend(Target, NULL, title, 0, 0);
460 StrBufAppendPrintf(Target, "</div>");
462 if (!IsEmptyStr(org)) {
463 StrBufAppendPrintf(Target, "<div align=right>");
464 StrEscAppend(Target, NULL, org, 0, 0);
465 StrBufAppendPrintf(Target, "</div>");
467 StrBufAppendPrintf(Target, "</TD></TR>\n");
469 if (!IsEmptyStr(phone)) {
470 StrBufAppendPrintf(Target, "<tr><td>");
471 StrBufAppendPrintf(Target, _("Telephone:"));
472 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
474 if (!IsEmptyStr(mailto)) {
475 StrBufAppendPrintf(Target, "<tr><td>");
476 StrBufAppendPrintf(Target, _("E-mail:"));
477 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
483 StrBufAppendPrintf(Target, "</table></div>\n");
489 * Display a textual vCard
490 * (Converts to a vCard object and then calls the actual display function)
491 * Set 'full' to nonzero to display the whole card instead of a one-liner.
492 * Or, if "storename" is non-NULL, just store the person's name in that
493 * buffer instead of displaying the card at all.
495 * vcard_source the buffer containing the vcard text
496 * alpha Display only if name begins with this letter of the alphabet
497 * full Display the full vCard (otherwise just the display name)
498 * storename If not NULL, also store the display name here
499 * msgnum Citadel message pointer
501 void display_vcard(StrBuf *Target,
502 wc_mime_attachment *Mime,
514 v = VCardLoad(Mime->Data);
516 if (v == NULL) return;
518 name = vcard_get_prop(v, "n", 1, 0, 0);
520 Buf = NewStrBufPlain(name, -1);
521 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
522 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
523 this_alpha = ChrPtr(Buf)[0];
528 if (storename != NULL) {
529 fetchname_parsed_vcard(v, storename);
531 else if ((alpha == 0) ||
532 ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha))) ||
533 ((!isalpha(alpha)) && (!isalpha(this_alpha)))
536 display_parsed_vcard(Target, v, full, Mime);
545 * Render the address book using info we gathered during the scan
547 * addrbook the addressbook to render
548 * num_ab the number of the addressbook
550 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
554 static int NAMESPERPAGE = 60;
557 char tabfirst_label[64];
559 char tablast_label[64];
560 char this_tablabel[64];
565 wc_printf("<br /><br /><br /><div align=\"center\"><i>");
566 wc_printf(_("This address book is empty."));
567 wc_printf("</i></div>\n");
572 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
575 num_pages = (num_ab / NAMESPERPAGE) + 1;
577 tablabels = malloc(num_pages * sizeof (char *));
578 if (tablabels == NULL) {
579 wc_printf("<br /><br /><br /><div align=\"center\"><i>");
580 wc_printf(_("An internal error has occurred."));
581 wc_printf("</i></div>\n");
585 for (i=0; i<num_pages; ++i) {
586 tabfirst = i * NAMESPERPAGE;
587 tablast = tabfirst + NAMESPERPAGE - 1;
588 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
589 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
590 nametab(tablast_label, 64, addrbook[tablast].ab_name);
591 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
592 tablabels[i] = strdup(this_tablabel);
595 tabbed_dialog(num_pages, tablabels);
598 for (i=0; i<num_ab; ++i) {
600 if ((i / NAMESPERPAGE) != page) { /* New tab */
601 page = (i / NAMESPERPAGE);
603 wc_printf("</tr></table>\n");
604 end_tab(page-1, num_pages);
606 begin_tab(page, num_pages);
607 wc_printf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
611 if ((displayed % 4) == 0) {
613 wc_printf("</tr>\n");
616 wc_printf("<tr bgcolor=\"#%s\">",
617 (bg ? "DDDDDD" : "FFFFFF")
623 wc_printf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
624 addrbook[i].ab_msgnum);
625 wc_printf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
626 vcard_n_prettyize(addrbook[i].ab_name);
627 escputs(addrbook[i].ab_name);
628 wc_printf("</a></td>\n");
632 /* Placeholders for empty columns at end */
633 if ((num_ab % 4) != 0) {
634 for (i=0; i<(4-(num_ab % 4)); ++i) {
635 wc_printf("<td> </td>");
639 wc_printf("</tr></table>\n");
640 end_tab((num_pages-1), num_pages);
642 begin_tab(num_pages, num_pages);
643 /* FIXME there ought to be something here */
644 end_tab(num_pages, num_pages);
646 for (i=0; i<num_pages; ++i) {
656 * Edit the vCard component of a MIME message.
657 * Supply the message number
658 * and MIME part number to fetch. Or, specify -1 for the message number
659 * to start with a blank card.
661 void do_edit_vcard(long msgnum, char *partnum,
662 message_summary *VCMsg,
663 wc_mime_attachment *VCAtt,
664 const char *return_to,
665 const char *force_room) {
666 message_summary *Msg = NULL;
667 wc_mime_attachment *VCMime = NULL;
675 char middlename[256];
689 char primary_inetemail[256];
690 char other_inetemail[SIZ];
691 char extrafields[SIZ];
712 primary_inetemail[0] = 0;
713 other_inetemail[0] = 0;
719 safestrncpy(whatuser, "", sizeof whatuser);
722 ((VCMsg != NULL) && (VCAtt != NULL)))
724 if ((VCMsg == NULL) && (VCAtt == NULL)) {
726 Msg = (message_summary *) malloc(sizeof(message_summary));
727 memset(Msg, 0, sizeof(message_summary));
728 Msg->msgnum = msgnum;
729 VCMime = load_vcard(Msg);
730 if (VCMime == NULL) {
731 convenience_page("770000", _("Error"), "");///TODO: important message
732 DestroyMessageSummary(Msg);
736 v = VCardLoad(VCMime->Data);
739 v = VCardLoad(VCAtt->Data);
742 /* Populate the variables for our form */
744 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
745 char prp[256]; /* property name */
746 char prm[256]; /* parameters */
748 value = vcard_get_prop(v, "", 0, i++, 0);
751 extract_token(prp, key, 0, ';', sizeof prp);
752 safestrncpy(prm, key, sizeof prm);
753 remove_token(prm, 0, ';');
755 if (!strcasecmp(prp, "n")) {
756 extract_token(lastname, value, 0, ';', sizeof lastname);
757 extract_token(firstname, value, 1, ';', sizeof firstname);
758 extract_token(middlename, value, 2, ';', sizeof middlename);
759 extract_token(prefix, value, 3, ';', sizeof prefix);
760 extract_token(suffix, value, 4, ';', sizeof suffix);
763 else if (!strcasecmp(prp, "fn")) {
764 safestrncpy(fullname, value, sizeof fullname);
767 else if (!strcasecmp(prp, "title")) {
768 safestrncpy(title, value, sizeof title);
771 else if (!strcasecmp(prp, "org")) {
772 safestrncpy(org, value, sizeof org);
775 else if (!strcasecmp(prp, "adr")) {
776 extract_token(pobox, value, 0, ';', sizeof pobox);
777 extract_token(extadr, value, 1, ';', sizeof extadr);
778 extract_token(street, value, 2, ';', sizeof street);
779 extract_token(city, value, 3, ';', sizeof city);
780 extract_token(state, value, 4, ';', sizeof state);
781 extract_token(zipcode, value, 5, ';', sizeof zipcode);
782 extract_token(country, value, 6, ';', sizeof country);
785 else if (!strcasecmp(prp, "tel")) {
787 if (bmstrcasestr(prm, "home")) {
788 extract_token(hometel, value, 0, ';', sizeof hometel);
790 else if (bmstrcasestr(prm, "work")) {
791 extract_token(worktel, value, 0, ';', sizeof worktel);
793 else if (bmstrcasestr(prm, "fax")) {
794 extract_token(faxtel, value, 0, ';', sizeof faxtel);
796 else if (bmstrcasestr(prm, "cell")) {
797 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
799 else { /* Missing or unknown type; put it in the home phone */
800 extract_token(hometel, value, 0, ';', sizeof hometel);
804 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
805 if (primary_inetemail[0] == 0) {
806 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
809 if (other_inetemail[0] != 0) {
810 strcat(other_inetemail, "\n");
812 strcat(other_inetemail, value);
816 /* Unrecognized properties are preserved here so we don't discard them
817 * just because the vCard was edited with WebCit.
820 strcat(extrafields, key);
821 strcat(extrafields, ":");
822 strcat(extrafields, value);
823 strcat(extrafields, "\n");
831 /* Display the form */
832 output_headers(1, 1, 1, 0, 0, 0);
834 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
835 do_template("beginboxx", NULL);
837 wc_printf("<form method=\"POST\" action=\"submit_vcard\">\n");
838 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
840 if (force_room != NULL) {
841 wc_printf("<input type=\"hidden\" name=\"force_room\" value=\"");
846 wc_printf("<div class=\"fix_scrollbar_bug\">"
847 "<table class=\"vcard_edit_background\"><tr><td>\n");
849 wc_printf("<table border=0><tr>"
854 "<td>%s</td></tr>\n",
855 _("Prefix"), _("First Name"), _("Middle Name"), _("Last Name"), _("Suffix")
857 wc_printf("<tr><td><input type=\"text\" name=\"prefix\" "
858 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
860 wc_printf("<td><input type=\"text\" name=\"firstname\" "
861 "value=\"%s\" maxlength=\"29\"></td>",
863 wc_printf("<td><input type=\"text\" name=\"middlename\" "
864 "value=\"%s\" maxlength=\"29\"></td>",
866 wc_printf("<td><input type=\"text\" name=\"lastname\" "
867 "value=\"%s\" maxlength=\"29\"></td>",
869 wc_printf("<td><input type=\"text\" name=\"suffix\" "
870 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
873 wc_printf("<table class=\"vcard_edit_background_alt\">");
874 wc_printf("<tr><td>");
876 wc_printf(_("Display name:"));
878 "<input type=\"text\" name=\"fullname\" "
879 "value=\"%s\" maxlength=\"40\"><br><br>\n",
883 wc_printf(_("Title:"));
885 "<input type=\"text\" name=\"title\" "
886 "value=\"%s\" maxlength=\"40\"><br><br>\n",
890 wc_printf(_("Organization:"));
892 "<input type=\"text\" name=\"org\" "
893 "value=\"%s\" maxlength=\"40\"><br><br>\n",
897 wc_printf("</td><td>");
899 wc_printf("<table border=0>");
900 wc_printf("<tr><td>");
901 wc_printf(_("PO box:"));
902 wc_printf("</td><td>"
903 "<input type=\"text\" name=\"pobox\" "
904 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
906 wc_printf("<tr><td>");
907 wc_printf(_("Address:"));
908 wc_printf("</td><td>"
909 "<input type=\"text\" name=\"extadr\" "
910 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
912 wc_printf("<tr><td> </td><td>"
913 "<input type=\"text\" name=\"street\" "
914 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
916 wc_printf("<tr><td>");
917 wc_printf(_("City:"));
918 wc_printf("</td><td>"
919 "<input type=\"text\" name=\"city\" "
920 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
922 wc_printf("<tr><td>");
923 wc_printf(_("State:"));
924 wc_printf("</td><td>"
925 "<input type=\"text\" name=\"state\" "
926 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
928 wc_printf("<tr><td>");
929 wc_printf(_("ZIP code:"));
930 wc_printf("</td><td>"
931 "<input type=\"text\" name=\"zipcode\" "
932 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
934 wc_printf("<tr><td>");
935 wc_printf(_("Country:"));
936 wc_printf("</td><td>"
937 "<input type=\"text\" name=\"country\" "
938 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
940 wc_printf("</table>\n");
942 wc_printf("</table>\n");
944 wc_printf("<table border=0><tr><td>");
945 wc_printf(_("Home telephone:"));
947 "<td><input type=\"text\" name=\"hometel\" "
948 "value=\"%s\" maxlength=\"29\"></td>\n",
951 wc_printf(_("Work telephone:"));
953 "<td><input type=\"text\" name=\"worktel\" "
954 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
956 wc_printf("<tr><td>");
957 wc_printf(_("Mobile telephone:"));
959 "<td><input type=\"text\" name=\"mobiletel\" "
960 "value=\"%s\" maxlength=\"29\"></td>\n",
963 wc_printf(_("Fax number:"));
965 "<td><input type=\"text\" name=\"faxtel\" "
966 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
969 wc_printf("<table class=\"vcard_edit_background_alt\">");
970 wc_printf("<tr><td>");
972 wc_printf("<table border=0><TR>"
974 wc_printf(_("Primary Internet e-mail address"));
976 "<input type=\"text\" name=\"primary_inetemail\" "
977 "size=40 maxlength=60 value=\"");
978 escputs(primary_inetemail);
979 wc_printf("\"><br />"
980 "</td><td valign=top>");
981 wc_printf(_("Internet e-mail aliases"));
983 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
984 escputs(other_inetemail);
985 wc_printf("</textarea></td></tr></table>\n");
987 wc_printf("</td></tr></table>\n");
989 wc_printf("<input type=\"hidden\" name=\"extrafields\" value=\"");
990 escputs(extrafields);
993 wc_printf("<input type=\"hidden\" name=\"return_to\" value=\"");
997 wc_printf("<div class=\"buttons\">\n"
998 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1000 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1006 wc_printf("</td></tr></table>\n");
1007 do_template("endbox", NULL);
1010 DestroyMessageSummary(Msg);
1016 * commit the edits to the citadel server
1018 void edit_vcard(void) {
1022 msgnum = lbstr("msgnum");
1023 partnum = bstr("partnum");
1024 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1030 * parse edited vcard from the browser
1032 void submit_vcard(void) {
1033 wcsession *WCC = WC;
1035 char *serialized_vcard;
1040 if (!havebstr("ok_button")) {
1041 readloop(readnew, eUseDefault);
1045 if (havebstr("force_room")) {
1046 if (gotoroom(sbstr("force_room")) != 200) {
1047 StrBufAppendBufPlain(WCC->ImportantMsg,
1048 _("Unable to enter the room to save your message"),
1050 StrBufAppendBufPlain(WCC->ImportantMsg,
1052 StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
1053 StrBufAppendBufPlain(WCC->ImportantMsg,
1056 StrBufAppendBufPlain(WCC->ImportantMsg,
1060 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1061 select_user_to_edit(NULL);
1063 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1066 else if (!IsEmptyStr(bstr("return_to"))) {
1067 http_redirect(bstr("return_to"));
1070 readloop(readnew, eUseDefault);
1076 sprintf(buf, "ENT0 1|||4||");
1078 serv_getln(buf, sizeof buf);
1079 if (buf[0] != '4') {
1084 /* Make a vCard structure out of the data supplied in the form */
1086 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1089 v = VCardLoad(Buf); /* Start with the extra fields */
1092 safestrncpy(WCC->ImportantMessage,
1093 _("An error has occurred."),
1094 sizeof WCC->ImportantMessage
1100 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1106 vcard_add_prop(v, "n", buf);
1108 vcard_add_prop(v, "title", bstr("title"));
1109 vcard_add_prop(v, "fn", bstr("fullname"));
1110 vcard_add_prop(v, "org", bstr("org"));
1112 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1120 vcard_add_prop(v, "adr", buf);
1122 vcard_add_prop(v, "tel;home", bstr("hometel"));
1123 vcard_add_prop(v, "tel;work", bstr("worktel"));
1124 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1125 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1126 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1128 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1129 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1130 if (!IsEmptyStr(buf)) {
1131 vcard_add_prop(v, "email;internet", buf);
1135 serialized_vcard = vcard_serialize(v);
1137 if (serialized_vcard == NULL) {
1138 safestrncpy(WCC->ImportantMessage,
1139 _("An error has occurred."),
1140 sizeof WCC->ImportantMessage
1146 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1148 serv_printf("%s\r\n", serialized_vcard);
1150 free(serialized_vcard);
1152 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1153 select_user_to_edit(NULL);
1155 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1158 else if (!IsEmptyStr(bstr("return_to"))) {
1159 http_redirect(bstr("return_to"));
1162 readloop(readnew, eUseDefault);
1169 * Extract an embedded photo from a vCard for display on the client
1171 void display_vcard_photo_img(void)
1177 const char *contentType;
1178 wcsession *WCC = WC;
1180 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1182 vcard = load_mimepart(msgnum,"1");
1183 v = VCardLoad(vcard);
1185 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1186 FlushStrBuf(WCC->WBuf);
1187 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1188 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1189 FlushStrBuf(WCC->WBuf);
1191 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1192 output_headers(0, 0, 0, 0, 0, 0);
1193 hprintf("Content-Type: text/plain\r\n");
1195 wc_printf(_("Could Not decode vcard photo\n"));
1199 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1200 http_transmit_thing(contentType, 0);
1205 typedef struct _vcardview_struct {
1207 addrbookent *addrbook;
1212 int vcard_GetParamsGetServerCall(SharedMessageStatus *Stat,
1213 void **ViewSpecific,
1218 vcardview_struct *VS;
1220 VS = (vcardview_struct*) malloc (sizeof(vcardview_struct));
1221 memset(VS, 0, sizeof(vcardview_struct));
1222 *ViewSpecific = (void*)VS;
1224 VS->is_singlecard = ibstr("is_singlecard");
1225 if (VS->is_singlecard != 1) {
1226 if (oper == do_search) {
1227 snprintf(cmd, len, "MSGS SEARCH|%s", bstr("query"));
1230 strcpy(cmd, "MSGS ALL");
1232 Stat->maxmsgs = 9999999;
1237 int vcard_LoadMsgFromServer(SharedMessageStatus *Stat,
1238 void **ViewSpecific,
1239 message_summary* Msg,
1243 vcardview_struct *VS;
1246 VS = (vcardview_struct*) *ViewSpecific;
1249 fetch_ab_name(Msg, &ab_name);
1250 if (ab_name == NULL)
1253 VS->addrbook = realloc(VS->addrbook,
1254 (sizeof(addrbookent) * VS->num_ab) );
1255 safestrncpy(VS->addrbook[VS->num_ab-1].ab_name, ab_name,
1256 sizeof(VS->addrbook[VS->num_ab-1].ab_name));
1257 VS->addrbook[VS->num_ab-1].ab_msgnum = Msg->msgnum;
1263 int vcard_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
1266 vcardview_struct *VS;
1268 VS = (vcardview_struct*) *ViewSpecific;
1269 if (VS->is_singlecard)
1270 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1272 do_addrbook_view(VS->addrbook, VS->num_ab); /* Render the address book */
1276 int vcard_Cleanup(void **ViewSpecific)
1278 vcardview_struct *VS;
1280 VS = (vcardview_struct*) *ViewSpecific;
1283 (VS->addrbook != NULL))
1294 RegisterReadLoopHandlerset(
1296 vcard_GetParamsGetServerCall,
1299 vcard_LoadMsgFromServer,
1300 vcard_RenderView_or_Tail,
1302 WebcitAddUrlHandler(HKEY("edit_vcard"), "", 0, edit_vcard, 0);
1303 WebcitAddUrlHandler(HKEY("submit_vcard"), "", 0, submit_vcard, 0);
1304 WebcitAddUrlHandler(HKEY("vcardphoto"), "", 0, display_vcard_photo_img, NEED_URL);