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 * display the adressbook overview
35 void display_addressbook(long msgnum, char alpha) {
37 /* char mime_partnum[SIZ]; */
38 ///char mime_disposition[SIZ];
40 char vcard_partnum[SIZ];
41 StrBuf *vcard_source = NULL;
42 message_summary summ;////TODO: this will leak
44 memset(&summ, 0, sizeof(summ));
45 // safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
46 // Load Message headers
47 if (!IsEmptyStr(vcard_partnum)) {
48 vcard_source = load_mimepart(msgnum, vcard_partnum);
49 if (vcard_source != NULL) {
51 /* Display the summary line */
52 display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL, msgnum);
54 /* If it's my vCard I can edit it */
55 if ( (!strcasecmp(ChrPtr(WC->CurRoom.name), USERCONFIGROOM))
56 || (!strcasecmp(&(ChrPtr(WC->CurRoom.name)[11]), USERCONFIGROOM))
57 || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
59 wc_printf("<a href=\"edit_vcard?"
60 "msgnum=%ld&partnum=%s\">",
61 msgnum, vcard_partnum);
62 wc_printf("[%s]</a>", _("edit"));
65 FreeStrBuf(&vcard_source);
74 * If it's an old "Firstname Lastname" style record, try to convert it.
76 void lastfirst_firstlast(char *namebuf) {
81 if (namebuf == NULL) return;
82 if (strchr(namebuf, ';') != NULL) return;
84 i = num_tokens(namebuf, ' ');
87 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
88 remove_token(namebuf, i-1, ' ');
89 strcpy(firstname, namebuf);
90 sprintf(namebuf, "%s; %s", lastname, firstname);
95 wc_mime_attachment *load_vcard(message_summary *Msg)
98 StrBuf *FoundCharset = NewStrBuf();
103 wc_mime_attachment *Mime;
104 wc_mime_attachment *VCMime = NULL;
106 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
107 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
108 Msg->MsgBody->msgnum = Msg->msgnum;
110 load_message(Msg, FoundCharset, &Error);
112 FreeStrBuf(&FoundCharset);
113 /* look up the vcard... */
114 it = GetNewHashPos(Msg->AllAttach, 0);
115 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
118 Mime = (wc_mime_attachment*) vMime;
119 if ((strcmp(ChrPtr(Mime->ContentType),
120 "text/x-vcard") == 0) ||
121 (strcmp(ChrPtr(Mime->ContentType),
132 MimeLoadData(VCMime);
137 * fetch the display name off a vCard
139 void fetch_ab_name(message_summary *Msg, char **namebuf) {
142 wc_mime_attachment *VCMime = NULL;
144 if (namebuf == NULL) return;
146 VCMime = load_vcard(Msg);
150 /* Grab the name off the card */
151 display_vcard(WC->WBuf, VCMime->Data, 0, 0, namebuf, Msg->msgnum);
153 if (*namebuf != NULL) {
154 lastfirst_firstlast(*namebuf);
156 len = strlen(*namebuf);
157 for (i=0; i<len; ++i) {
158 if ((*namebuf)[i] != ';') return;
161 (*namebuf) = strdup(_("(no name)"));
164 (*namebuf) = strdup(_("(no name)"));
171 * Turn a vCard "n" (name) field into something displayable.
173 void vcard_n_prettyize(char *name)
178 original_name = strdup(name);
179 len = strlen(original_name);
180 for (i=0; i<5; ++i) {
182 if (original_name[len-1] == ' ') {
183 original_name[--len] = 0;
185 if (original_name[len-1] == ';') {
186 original_name[--len] = 0;
192 for (i=0; i<len; ++i) {
193 if (original_name[i] == ';') {
198 name[j++] = original_name[i];
209 * preparse a vcard name
210 * display_vcard() calls this after parsing the textual vCard into
211 * our 'struct vCard' data object.
212 * This gets called instead of display_parsed_vcard() if we are only looking
213 * to extract the person's name instead of displaying the card.
215 void fetchname_parsed_vcard(struct vCard *v, char **storename) {
225 name = vcard_get_prop(v, "n", 1, 0, 0);
228 prop = vcard_get_prop(v, "n", 1, 0, 1);
229 n = num_tokens(prop, ';');
231 for (j=0; j<n; ++j) {
232 extract_token(buf, prop, j, ';', sizeof buf);
233 if (!strcasecmp(buf, "encoding=quoted-printable")) {
236 if (!strcasecmp(buf, "encoding=base64")) {
241 // %ff can become 6 bytes in utf8
242 *storename = malloc(len * 2 + 3);
243 j = CtdlDecodeQuotedPrintable(
249 // ff will become one byte..
250 *storename = malloc(len + 50);
260 *storename = malloc(len + 3); /* \0 + eventualy missing ', '*/
261 memcpy(*storename, name, len + 1);
263 /* vcard_n_prettyize(storename); */
272 * display_vcard() calls this after parsing the textual vCard into
273 * our 'struct vCard' data object.
275 * Set 'full' to nonzero to display the full card, otherwise it will only
276 * show a summary line.
278 * This code is a bit ugly, so perhaps an explanation is due: we do this
279 * in two passes through the vCard fields. On the first pass, we process
280 * fields we understand, and then render them in a pretty fashion at the
281 * end. Then we make a second pass, outputting all the fields we don't
282 * understand in a simple two-column name/value format.
283 * v the vCard to display
284 * full display all items of the vcard?
285 * msgnum Citadel message pointer
287 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, long msgnum) {
293 char *thisname, *thisvalue;
294 char firsttoken[SIZ];
303 strcpy(fullname, "");
310 StrBufAppendPrintf(Target, "<TD>");
311 name = vcard_get_prop(v, "fn", 1, 0, 0);
313 StrEscAppend(Target, NULL, name, 0, 0);
315 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
316 strcpy(fullname, name);
317 vcard_n_prettyize(fullname);
318 StrEscAppend(Target, NULL, fullname, 0, 0);
321 StrBufAppendPrintf(Target, " ");
323 StrBufAppendPrintf(Target, "</TD>");
327 StrBufAppendPrintf(Target, "<div align=center>"
328 "<table bgcolor=#aaaaaa width=50%%>");
329 for (pass=1; pass<=2; ++pass) {
331 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
333 thisname = strdup(v->prop[i].name);
334 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
336 for (j=0; j<num_tokens(thisname, ';'); ++j) {
337 extract_token(buf, thisname, j, ';', sizeof buf);
338 if (!strcasecmp(buf, "encoding=quoted-printable")) {
340 remove_token(thisname, j, ';');
342 if (!strcasecmp(buf, "encoding=base64")) {
344 remove_token(thisname, j, ';');
348 len = strlen(v->prop[i].value);
349 /* if we have some untagged QP, detect it here. */
350 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
351 utf8ify_rfc822_string(&v->prop[i].value);
354 // %ff can become 6 bytes in utf8
355 thisvalue = malloc(len * 2 + 3);
356 j = CtdlDecodeQuotedPrintable(
357 thisvalue, v->prop[i].value,
362 // ff will become one byte..
363 thisvalue = malloc(len + 50);
365 thisvalue, v->prop[i].value,
366 strlen(v->prop[i].value) );
369 thisvalue = strdup(v->prop[i].value);
372 /* Various fields we may encounter ***/
374 /* N is name, but only if there's no FN already there */
375 if (!strcasecmp(firsttoken, "n")) {
376 if (IsEmptyStr(fullname)) {
377 strcpy(fullname, thisvalue);
378 vcard_n_prettyize(fullname);
382 /* FN (full name) is a true 'display name' field */
383 else if (!strcasecmp(firsttoken, "fn")) {
384 strcpy(fullname, thisvalue);
388 else if (!strcasecmp(firsttoken, "title")) {
389 strcpy(title, thisvalue);
393 else if (!strcasecmp(firsttoken, "org")) {
394 strcpy(org, thisvalue);
397 else if (!strcasecmp(firsttoken, "email")) {
399 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
401 "<a href=\"display_enter"
402 "?force_room=_MAIL_?recp=");
404 len = strlen(mailto);
405 urlesc(&mailto[len], SIZ - len, "\"");
406 len = strlen(mailto);
407 urlesc(&mailto[len], SIZ - len, fullname);
408 len = strlen(mailto);
409 urlesc(&mailto[len], SIZ - len, "\" <");
410 len = strlen(mailto);
411 urlesc(&mailto[len], SIZ - len, thisvalue);
412 len = strlen(mailto);
413 urlesc(&mailto[len], SIZ - len, ">");
415 strcat(mailto, "\">");
416 len = strlen(mailto);
417 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
418 strcat(mailto, "</A>");
420 else if (!strcasecmp(firsttoken, "tel")) {
421 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
422 strcat(phone, thisvalue);
423 for (j=0; j<num_tokens(thisname, ';'); ++j) {
424 extract_token(buf, thisname, j, ';', sizeof buf);
425 if (!strcasecmp(buf, "tel"))
427 else if (!strcasecmp(buf, "work"))
428 strcat(phone, _(" (work)"));
429 else if (!strcasecmp(buf, "home"))
430 strcat(phone, _(" (home)"));
431 else if (!strcasecmp(buf, "cell"))
432 strcat(phone, _(" (cell)"));
440 else if (!strcasecmp(firsttoken, "adr")) {
442 StrBufAppendPrintf(Target, "<TR><TD>");
443 StrBufAppendPrintf(Target, _("Address:"));
444 StrBufAppendPrintf(Target, "</TD><TD>");
445 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
446 extract_token(buf, thisvalue, j, ';', sizeof buf);
447 if (!IsEmptyStr(buf)) {
448 StrEscAppend(Target, NULL, buf, 0, 0);
449 if (j<3) StrBufAppendPrintf(Target, "<br />");
450 else StrBufAppendPrintf(Target, " ");
453 StrBufAppendPrintf(Target, "</TD></TR>\n");
456 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
457 // Only output on second pass
458 StrBufAppendPrintf(Target, "<tr><td>");
459 StrBufAppendPrintf(Target, _("Photo:"));
460 StrBufAppendPrintf(Target, "</td><td>");
461 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
462 StrBufAppendPrintf(Target, "</td></tr>\n");
464 else if (!strcasecmp(firsttoken, "version")) {
467 else if (!strcasecmp(firsttoken, "rev")) {
470 else if (!strcasecmp(firsttoken, "label")) {
475 /*** Don't show extra fields. They're ugly.
477 StrBufAppendPrintf(Target, "<TR><TD>");
478 StrEscAppend(Target, NULL, thisname, 0, 0);
479 StrBufAppendPrintf(Target, "</TD><TD>");
480 StrEscAppend(Target, NULL, thisvalue, 0, 0);
481 StrBufAppendPrintf(Target, "</TD></TR>\n");
491 StrBufAppendPrintf(Target, "<TR BGCOLOR=\"#AAAAAA\">"
492 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
493 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
494 "<FONT SIZE=+1><B>");
495 StrEscAppend(Target, NULL, fullname, 0, 0);
496 StrBufAppendPrintf(Target, "</B></FONT>");
497 if (!IsEmptyStr(title)) {
498 StrBufAppendPrintf(Target, "<div align=right>");
499 StrEscAppend(Target, NULL, title, 0, 0);
500 StrBufAppendPrintf(Target, "</div>");
502 if (!IsEmptyStr(org)) {
503 StrBufAppendPrintf(Target, "<div align=right>");
504 StrEscAppend(Target, NULL, org, 0, 0);
505 StrBufAppendPrintf(Target, "</div>");
507 StrBufAppendPrintf(Target, "</TD></TR>\n");
509 if (!IsEmptyStr(phone)) {
510 StrBufAppendPrintf(Target, "<tr><td>");
511 StrBufAppendPrintf(Target, _("Telephone:"));
512 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
514 if (!IsEmptyStr(mailto)) {
515 StrBufAppendPrintf(Target, "<tr><td>");
516 StrBufAppendPrintf(Target, _("E-mail:"));
517 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
523 StrBufAppendPrintf(Target, "</table></div>\n");
529 * Display a textual vCard
530 * (Converts to a vCard object and then calls the actual display function)
531 * Set 'full' to nonzero to display the whole card instead of a one-liner.
532 * Or, if "storename" is non-NULL, just store the person's name in that
533 * buffer instead of displaying the card at all.
535 * vcard_source the buffer containing the vcard text
536 * alpha Display only if name begins with this letter of the alphabet
537 * full Display the full vCard (otherwise just the display name)
538 * storename If not NULL, also store the display name here
539 * msgnum Citadel message pointer
541 void display_vcard(StrBuf *Target,
542 StrBuf *vcard_source,
554 v = VCardLoad(vcard_source);
556 if (v == NULL) return;
558 name = vcard_get_prop(v, "n", 1, 0, 0);
560 Buf = NewStrBufPlain(name, -1);
561 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
562 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
563 this_alpha = ChrPtr(Buf)[0];
568 if (storename != NULL) {
569 fetchname_parsed_vcard(v, storename);
573 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)))
574 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
576 display_parsed_vcard(Target, v, full,msgnum);
585 * Render the address book using info we gathered during the scan
587 * addrbook the addressbook to render
588 * num_ab the number of the addressbook
590 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
594 static int NAMESPERPAGE = 60;
597 char tabfirst_label[64];
599 char tablast_label[64];
600 char this_tablabel[64];
605 wc_printf("<br /><br /><br /><div align=\"center\"><i>");
606 wc_printf(_("This address book is empty."));
607 wc_printf("</i></div>\n");
612 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
615 num_pages = (num_ab / NAMESPERPAGE) + 1;
617 tablabels = malloc(num_pages * sizeof (char *));
618 if (tablabels == NULL) {
619 wc_printf("<br /><br /><br /><div align=\"center\"><i>");
620 wc_printf(_("An internal error has occurred."));
621 wc_printf("</i></div>\n");
625 for (i=0; i<num_pages; ++i) {
626 tabfirst = i * NAMESPERPAGE;
627 tablast = tabfirst + NAMESPERPAGE - 1;
628 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
629 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
630 nametab(tablast_label, 64, addrbook[tablast].ab_name);
631 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
632 tablabels[i] = strdup(this_tablabel);
635 tabbed_dialog(num_pages, tablabels);
638 for (i=0; i<num_ab; ++i) {
640 if ((i / NAMESPERPAGE) != page) { /* New tab */
641 page = (i / NAMESPERPAGE);
643 wc_printf("</tr></table>\n");
644 end_tab(page-1, num_pages);
646 begin_tab(page, num_pages);
647 wc_printf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
651 if ((displayed % 4) == 0) {
653 wc_printf("</tr>\n");
656 wc_printf("<tr bgcolor=\"#%s\">",
657 (bg ? "DDDDDD" : "FFFFFF")
663 wc_printf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
664 addrbook[i].ab_msgnum);
665 wc_printf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
666 vcard_n_prettyize(addrbook[i].ab_name);
667 escputs(addrbook[i].ab_name);
668 wc_printf("</a></td>\n");
672 /* Placeholders for empty columns at end */
673 if ((num_ab % 4) != 0) {
674 for (i=0; i<(4-(num_ab % 4)); ++i) {
675 wc_printf("<td> </td>");
679 wc_printf("</tr></table>\n");
680 end_tab((num_pages-1), num_pages);
682 begin_tab(num_pages, num_pages);
683 /* FIXME there ought to be something here */
684 end_tab(num_pages, num_pages);
686 for (i=0; i<num_pages; ++i) {
696 * Edit the vCard component of a MIME message.
697 * Supply the message number
698 * and MIME part number to fetch. Or, specify -1 for the message number
699 * to start with a blank card.
701 void do_edit_vcard(long msgnum, char *partnum,
702 message_summary *VCMsg,
703 wc_mime_attachment *VCAtt,
704 const char *return_to,
705 const char *force_room) {
706 message_summary *Msg = NULL;
707 wc_mime_attachment *VCMime = NULL;
715 char middlename[256];
729 char primary_inetemail[256];
730 char other_inetemail[SIZ];
731 char extrafields[SIZ];
752 primary_inetemail[0] = 0;
753 other_inetemail[0] = 0;
759 safestrncpy(whatuser, "", sizeof whatuser);
762 ((VCMsg != NULL) && (VCAtt != NULL)))
764 if ((VCMsg == NULL) && (VCAtt == NULL)) {
766 Msg = (message_summary *) malloc(sizeof(message_summary));
767 memset(Msg, 0, sizeof(message_summary));
768 Msg->msgnum = msgnum;
769 VCMime = load_vcard(Msg);
770 if (VCMime == NULL) {
771 convenience_page("770000", _("Error"), "");///TODO: important message
772 DestroyMessageSummary(Msg);
776 v = VCardLoad(VCMime->Data);
779 v = VCardLoad(VCAtt->Data);
782 /* Populate the variables for our form */
784 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
785 char prp[256]; /* property name */
786 char prm[256]; /* parameters */
788 value = vcard_get_prop(v, "", 0, i++, 0);
791 extract_token(prp, key, 0, ';', sizeof prp);
792 safestrncpy(prm, key, sizeof prm);
793 remove_token(prm, 0, ';');
795 if (!strcasecmp(prp, "n")) {
796 extract_token(lastname, value, 0, ';', sizeof lastname);
797 extract_token(firstname, value, 1, ';', sizeof firstname);
798 extract_token(middlename, value, 2, ';', sizeof middlename);
799 extract_token(prefix, value, 3, ';', sizeof prefix);
800 extract_token(suffix, value, 4, ';', sizeof suffix);
803 else if (!strcasecmp(prp, "fn")) {
804 safestrncpy(fullname, value, sizeof fullname);
807 else if (!strcasecmp(prp, "title")) {
808 safestrncpy(title, value, sizeof title);
811 else if (!strcasecmp(prp, "org")) {
812 safestrncpy(org, value, sizeof org);
815 else if (!strcasecmp(prp, "adr")) {
816 extract_token(pobox, value, 0, ';', sizeof pobox);
817 extract_token(extadr, value, 1, ';', sizeof extadr);
818 extract_token(street, value, 2, ';', sizeof street);
819 extract_token(city, value, 3, ';', sizeof city);
820 extract_token(state, value, 4, ';', sizeof state);
821 extract_token(zipcode, value, 5, ';', sizeof zipcode);
822 extract_token(country, value, 6, ';', sizeof country);
825 else if (!strcasecmp(prp, "tel")) {
827 if (bmstrcasestr(prm, "home")) {
828 extract_token(hometel, value, 0, ';', sizeof hometel);
830 else if (bmstrcasestr(prm, "work")) {
831 extract_token(worktel, value, 0, ';', sizeof worktel);
833 else if (bmstrcasestr(prm, "fax")) {
834 extract_token(faxtel, value, 0, ';', sizeof faxtel);
836 else if (bmstrcasestr(prm, "cell")) {
837 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
839 else { /* Missing or unknown type; put it in the home phone */
840 extract_token(hometel, value, 0, ';', sizeof hometel);
844 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
845 if (primary_inetemail[0] == 0) {
846 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
849 if (other_inetemail[0] != 0) {
850 strcat(other_inetemail, "\n");
852 strcat(other_inetemail, value);
856 /* Unrecognized properties are preserved here so we don't discard them
857 * just because the vCard was edited with WebCit.
860 strcat(extrafields, key);
861 strcat(extrafields, ":");
862 strcat(extrafields, value);
863 strcat(extrafields, "\n");
871 /* Display the form */
872 output_headers(1, 1, 1, 0, 0, 0);
874 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
875 do_template("beginboxx", NULL);
877 wc_printf("<form method=\"POST\" action=\"submit_vcard\">\n");
878 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
880 if (force_room != NULL) {
881 wc_printf("<input type=\"hidden\" name=\"force_room\" value=\"");
886 wc_printf("<div class=\"fix_scrollbar_bug\">"
887 "<table class=\"vcard_edit_background\"><tr><td>\n");
889 wc_printf("<table border=0><tr>"
894 "<td>%s</td></tr>\n",
895 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
897 wc_printf("<tr><td><input type=\"text\" name=\"prefix\" "
898 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
900 wc_printf("<td><input type=\"text\" name=\"firstname\" "
901 "value=\"%s\" maxlength=\"29\"></td>",
903 wc_printf("<td><input type=\"text\" name=\"middlename\" "
904 "value=\"%s\" maxlength=\"29\"></td>",
906 wc_printf("<td><input type=\"text\" name=\"lastname\" "
907 "value=\"%s\" maxlength=\"29\"></td>",
909 wc_printf("<td><input type=\"text\" name=\"suffix\" "
910 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
913 wc_printf("<table class=\"vcard_edit_background_alt\">");
914 wc_printf("<tr><td>");
916 wc_printf(_("Display name:"));
918 "<input type=\"text\" name=\"fullname\" "
919 "value=\"%s\" maxlength=\"40\"><br><br>\n",
923 wc_printf(_("Title:"));
925 "<input type=\"text\" name=\"title\" "
926 "value=\"%s\" maxlength=\"40\"><br><br>\n",
930 wc_printf(_("Organization:"));
932 "<input type=\"text\" name=\"org\" "
933 "value=\"%s\" maxlength=\"40\"><br><br>\n",
937 wc_printf("</td><td>");
939 wc_printf("<table border=0>");
940 wc_printf("<tr><td>");
941 wc_printf(_("PO box:"));
942 wc_printf("</td><td>"
943 "<input type=\"text\" name=\"pobox\" "
944 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
946 wc_printf("<tr><td>");
947 wc_printf(_("Address:"));
948 wc_printf("</td><td>"
949 "<input type=\"text\" name=\"extadr\" "
950 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
952 wc_printf("<tr><td> </td><td>"
953 "<input type=\"text\" name=\"street\" "
954 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
956 wc_printf("<tr><td>");
957 wc_printf(_("City:"));
958 wc_printf("</td><td>"
959 "<input type=\"text\" name=\"city\" "
960 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
962 wc_printf("<tr><td>");
963 wc_printf(_("State:"));
964 wc_printf("</td><td>"
965 "<input type=\"text\" name=\"state\" "
966 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
968 wc_printf("<tr><td>");
969 wc_printf(_("ZIP code:"));
970 wc_printf("</td><td>"
971 "<input type=\"text\" name=\"zipcode\" "
972 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
974 wc_printf("<tr><td>");
975 wc_printf(_("Country:"));
976 wc_printf("</td><td>"
977 "<input type=\"text\" name=\"country\" "
978 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
980 wc_printf("</table>\n");
982 wc_printf("</table>\n");
984 wc_printf("<table border=0><tr><td>");
985 wc_printf(_("Home telephone:"));
987 "<td><input type=\"text\" name=\"hometel\" "
988 "value=\"%s\" maxlength=\"29\"></td>\n",
991 wc_printf(_("Work telephone:"));
993 "<td><input type=\"text\" name=\"worktel\" "
994 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
996 wc_printf("<tr><td>");
997 wc_printf(_("Mobile telephone:"));
999 "<td><input type=\"text\" name=\"mobiletel\" "
1000 "value=\"%s\" maxlength=\"29\"></td>\n",
1003 wc_printf(_("Fax number:"));
1005 "<td><input type=\"text\" name=\"faxtel\" "
1006 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
1009 wc_printf("<table class=\"vcard_edit_background_alt\">");
1010 wc_printf("<tr><td>");
1012 wc_printf("<table border=0><TR>"
1014 wc_printf(_("Primary Internet e-mail address"));
1016 "<input type=\"text\" name=\"primary_inetemail\" "
1017 "size=40 maxlength=60 value=\"");
1018 escputs(primary_inetemail);
1019 wc_printf("\"><br />"
1020 "</td><td valign=top>");
1021 wc_printf(_("Internet e-mail aliases"));
1023 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
1024 escputs(other_inetemail);
1025 wc_printf("</textarea></td></tr></table>\n");
1027 wc_printf("</td></tr></table>\n");
1029 wc_printf("<input type=\"hidden\" name=\"extrafields\" value=\"");
1030 escputs(extrafields);
1033 wc_printf("<input type=\"hidden\" name=\"return_to\" value=\"");
1037 wc_printf("<div class=\"buttons\">\n"
1038 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1040 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1046 wc_printf("</td></tr></table>\n");
1047 do_template("endbox", NULL);
1050 DestroyMessageSummary(Msg);
1056 * commit the edits to the citadel server
1058 void edit_vcard(void) {
1062 msgnum = lbstr("msgnum");
1063 partnum = bstr("partnum");
1064 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1070 * parse edited vcard from the browser
1072 void submit_vcard(void) {
1073 wcsession *WCC = WC;
1075 char *serialized_vcard;
1080 if (!havebstr("ok_button")) {
1085 if (havebstr("force_room")) {
1086 if (gotoroom(sbstr("force_room")) != 200) {
1087 StrBufAppendBufPlain(WCC->ImportantMsg,
1088 _("Unable to enter the room to save your message"),
1090 StrBufAppendBufPlain(WCC->ImportantMsg,
1092 StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
1093 StrBufAppendBufPlain(WCC->ImportantMsg,
1096 StrBufAppendBufPlain(WCC->ImportantMsg,
1100 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1101 select_user_to_edit(NULL);
1103 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1106 else if (!IsEmptyStr(bstr("return_to"))) {
1107 http_redirect(bstr("return_to"));
1116 sprintf(buf, "ENT0 1|||4||");
1118 serv_getln(buf, sizeof buf);
1119 if (buf[0] != '4') {
1124 /* Make a vCard structure out of the data supplied in the form */
1126 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1129 v = VCardLoad(Buf); /* Start with the extra fields */
1132 safestrncpy(WCC->ImportantMessage,
1133 _("An error has occurred."),
1134 sizeof WCC->ImportantMessage
1140 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1146 vcard_add_prop(v, "n", buf);
1148 vcard_add_prop(v, "title", bstr("title"));
1149 vcard_add_prop(v, "fn", bstr("fullname"));
1150 vcard_add_prop(v, "org", bstr("org"));
1152 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1160 vcard_add_prop(v, "adr", buf);
1162 vcard_add_prop(v, "tel;home", bstr("hometel"));
1163 vcard_add_prop(v, "tel;work", bstr("worktel"));
1164 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1165 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1166 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1168 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1169 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1170 if (!IsEmptyStr(buf)) {
1171 vcard_add_prop(v, "email;internet", buf);
1175 serialized_vcard = vcard_serialize(v);
1177 if (serialized_vcard == NULL) {
1178 safestrncpy(WCC->ImportantMessage,
1179 _("An error has occurred."),
1180 sizeof WCC->ImportantMessage
1186 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1188 serv_printf("%s\r\n", serialized_vcard);
1190 free(serialized_vcard);
1192 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1193 select_user_to_edit(NULL);
1195 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1198 else if (!IsEmptyStr(bstr("return_to"))) {
1199 http_redirect(bstr("return_to"));
1209 * Extract an embedded photo from a vCard for display on the client
1211 void display_vcard_photo_img(void)
1217 const char *contentType;
1218 wcsession *WCC = WC;
1220 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1222 vcard = load_mimepart(msgnum,"1");
1223 v = VCardLoad(vcard);
1225 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1226 FlushStrBuf(WCC->WBuf);
1227 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1228 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1229 FlushStrBuf(WCC->WBuf);
1231 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1232 output_headers(0, 0, 0, 0, 0, 0);
1233 hprintf("Content-Type: text/plain\r\n");
1235 wc_printf(_("Could Not decode vcard photo\n"));
1239 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1240 http_transmit_thing(contentType, 0);
1245 typedef struct _vcardview_struct {
1247 addrbookent *addrbook;
1252 int vcard_GetParamsGetServerCall(SharedMessageStatus *Stat,
1253 void **ViewSpecific,
1258 vcardview_struct *VS;
1260 VS = (vcardview_struct*) malloc (sizeof(vcardview_struct));
1261 memset(VS, 0, sizeof(vcardview_struct));
1262 *ViewSpecific = (void*)VS;
1264 VS->is_singlecard = ibstr("is_singlecard");
1265 if (VS->is_singlecard != 1) {
1266 if (oper == do_search) {
1267 snprintf(cmd, len, "MSGS SEARCH|%s", bstr("query"));
1270 strcpy(cmd, "MSGS ALL");
1272 Stat->maxmsgs = 9999999;
1277 int vcard_LoadMsgFromServer(SharedMessageStatus *Stat,
1278 void **ViewSpecific,
1279 message_summary* Msg,
1283 vcardview_struct *VS;
1286 VS = (vcardview_struct*) *ViewSpecific;
1289 fetch_ab_name(Msg, &ab_name);
1290 if (ab_name == NULL)
1293 VS->addrbook = realloc(VS->addrbook,
1294 (sizeof(addrbookent) * VS->num_ab) );
1295 safestrncpy(VS->addrbook[VS->num_ab-1].ab_name, ab_name,
1296 sizeof(VS->addrbook[VS->num_ab-1].ab_name));
1297 VS->addrbook[VS->num_ab-1].ab_msgnum = Msg->msgnum;
1303 int vcard_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
1306 vcardview_struct *VS;
1308 VS = (vcardview_struct*) *ViewSpecific;
1309 if (VS->is_singlecard)
1310 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1312 do_addrbook_view(VS->addrbook, VS->num_ab); /* Render the address book */
1316 int vcard_Cleanup(void **ViewSpecific)
1318 vcardview_struct *VS;
1320 VS = (vcardview_struct*) *ViewSpecific;
1323 (VS->addrbook != NULL))
1334 RegisterReadLoopHandlerset(
1336 vcard_GetParamsGetServerCall,
1338 vcard_LoadMsgFromServer,
1339 vcard_RenderView_or_Tail,
1341 WebcitAddUrlHandler(HKEY("edit_vcard"), "", 0, edit_vcard, 0);
1342 WebcitAddUrlHandler(HKEY("submit_vcard"), "", 0, submit_vcard, 0);
1343 WebcitAddUrlHandler(HKEY("vcardphoto"), "", 0, display_vcard_photo_img, NEED_URL);