9 * \brief Record compare function for sorting address book indices
10 * \param ab1 adressbook one
11 * \param ab2 adressbook two
13 int abcmp(const void *ab1, const void *ab2) {
15 (((const addrbookent *)ab1)->ab_name),
16 (((const addrbookent *)ab2)->ab_name)
22 * \brief Helper function for do_addrbook_view()
23 * Converts a name into a three-letter tab label
24 * \param tabbuf the tabbuffer to add name to
25 * \param name the name to add to the tabbuffer
27 void nametab(char *tabbuf, long len, char *name) {
28 stresc(tabbuf, len, name, 0, 0);
29 tabbuf[0] = toupper(tabbuf[0]);
30 tabbuf[1] = tolower(tabbuf[1]);
31 tabbuf[2] = tolower(tabbuf[2]);
37 * \brief display the adressbook overview
38 * \param msgnum the citadel message number
39 * \param alpha what????
41 void display_addressbook(long msgnum, char alpha) {
43 /* char mime_partnum[SIZ]; */
44 /* char mime_filename[SIZ]; */
45 /* char mime_content_type[SIZ]; */
46 ///char mime_disposition[SIZ];
48 char vcard_partnum[SIZ];
49 StrBuf *vcard_source = NULL;
50 message_summary summ;////TODO: this will leak
52 memset(&summ, 0, sizeof(summ));
53 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
54 ///Load Message headers
56 if (!IsEmptyStr(vcard_partnum)) {
57 vcard_source = load_mimepart(msgnum, vcard_partnum);
58 if (vcard_source != NULL) {
60 /** Display the summary line */
61 display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL, msgnum);
63 /** If it's my vCard I can edit it */
64 if ( (!strcasecmp(ChrPtr(WC->wc_roomname), USERCONFIGROOM))
65 || (!strcasecmp(&(ChrPtr(WC->wc_roomname)[11]), USERCONFIGROOM))
66 || (WC->wc_view == VIEW_ADDRESSBOOK)
68 wprintf("<a href=\"edit_vcard?"
69 "msgnum=%ld&partnum=%s\">",
70 msgnum, vcard_partnum);
71 wprintf("[%s]</a>", _("edit"));
74 FreeStrBuf(&vcard_source);
83 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
84 * \param namebuf name to analyze, reverse if nescessary
86 void lastfirst_firstlast(char *namebuf) {
91 if (namebuf == NULL) return;
92 if (strchr(namebuf, ';') != NULL) return;
94 i = num_tokens(namebuf, ' ');
97 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
98 remove_token(namebuf, i-1, ' ');
99 strcpy(firstname, namebuf);
100 sprintf(namebuf, "%s; %s", lastname, firstname);
104 * \brief fetch what??? name
105 * \param msgnum the citadel message number
106 * \param namebuf where to put the name in???
108 void fetch_ab_name(message_summary *Msg, char **namebuf) {
110 char mime_partnum[SIZ];
111 char mime_filename[SIZ];
112 char mime_content_type[SIZ];
113 char mime_disposition[SIZ];
115 char vcard_partnum[SIZ];
116 StrBuf *vcard_source = NULL;
118 message_summary summ;/// TODO this will lak
120 if (namebuf == NULL) return;
122 memset(&summ, 0, sizeof(summ));
123 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
125 serv_printf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
126 serv_getln(buf, sizeof buf);
127 if (buf[0] != '1') return;
129 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
130 if (!strncasecmp(buf, "part=", 5)) {
131 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
132 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
133 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
134 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
135 mime_length = extract_int(&buf[5], 5);
137 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
138 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
139 strcpy(vcard_partnum, mime_partnum);
145 if (!IsEmptyStr(vcard_partnum)) {
146 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
147 if (vcard_source != NULL) {
149 /* Grab the name off the card */
150 display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
152 FreeStrBuf(&vcard_source);
155 if (*namebuf != NULL) {
156 lastfirst_firstlast(*namebuf);
158 len = strlen(*namebuf);
159 for (i=0; i<len; ++i) {
160 if ((*namebuf)[i] != ';') return;
163 (*namebuf) = strdup(_("(no name)"));
166 (*namebuf) = strdup(_("(no name)"));
173 * \brief Turn a vCard "n" (name) field into something displayable.
174 * \param name the name field to convert
176 void vcard_n_prettyize(char *name)
181 original_name = strdup(name);
182 len = strlen(original_name);
183 for (i=0; i<5; ++i) {
185 if (original_name[len-1] == ' ') {
186 original_name[--len] = 0;
188 if (original_name[len-1] == ';') {
189 original_name[--len] = 0;
195 for (i=0; i<len; ++i) {
196 if (original_name[i] == ';') {
201 name[j++] = original_name[i];
212 * \brief preparse a vcard name
213 * display_vcard() calls this after parsing the textual vCard into
214 * our 'struct vCard' data object.
215 * This gets called instead of display_parsed_vcard() if we are only looking
216 * to extract the person's name instead of displaying the card.
217 * \param v the vcard to retrieve the name from
218 * \param storename where to put the name at
220 void fetchname_parsed_vcard(struct vCard *v, char **storename) {
230 name = vcard_get_prop(v, "n", 1, 0, 0);
233 prop = vcard_get_prop(v, "n", 1, 0, 1);
234 n = num_tokens(prop, ';');
236 for (j=0; j<n; ++j) {
237 extract_token(buf, prop, j, ';', sizeof buf);
238 if (!strcasecmp(buf, "encoding=quoted-printable")) {
241 if (!strcasecmp(buf, "encoding=base64")) {
246 // %ff can become 6 bytes in utf8
247 *storename = malloc(len * 2 + 3);
248 j = CtdlDecodeQuotedPrintable(
254 // ff will become one byte..
255 *storename = malloc(len + 50);
261 *storename = strdup(name);
263 /* vcard_n_prettyize(storename); */
271 * \brief html print a vcard
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 * \param v the vCard to display
284 * \param full display all items of the vcard?
285 * \param 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 * \brief 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.
534 * \param vcard_source the buffer containing the vcard text
535 * \param alpha what???
536 * \param full should we usse all lines?
537 * \param storename where to store???
538 * \param msgnum Citadel message pointer
540 void display_vcard(StrBuf *Target,
541 StrBuf *vcard_source,
553 v = VCardLoad(vcard_source);
555 if (v == NULL) return;
557 name = vcard_get_prop(v, "n", 1, 0, 0);
559 Buf = NewStrBufPlain(name, -1);
560 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
561 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
562 this_alpha = ChrPtr(Buf)[0];
567 if (storename != NULL) {
568 fetchname_parsed_vcard(v, storename);
570 else if ( (alpha == 0)
571 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
572 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
574 display_parsed_vcard(Target, v, full,msgnum);
583 * \brief Render the address book using info we gathered during the scan
584 * \param addrbook the addressbook to render
585 * \param num_ab the number of the addressbook
587 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
591 static int NAMESPERPAGE = 60;
594 char tabfirst_label[64];
596 char tablast_label[64];
597 char this_tablabel[64];
602 wprintf("<br /><br /><br /><div align=\"center\"><i>");
603 wprintf(_("This address book is empty."));
604 wprintf("</i></div>\n");
609 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
612 num_pages = (num_ab / NAMESPERPAGE) + 1;
614 tablabels = malloc(num_pages * sizeof (char *));
615 if (tablabels == NULL) {
616 wprintf("<br /><br /><br /><div align=\"center\"><i>");
617 wprintf(_("An internal error has occurred."));
618 wprintf("</i></div>\n");
622 for (i=0; i<num_pages; ++i) {
623 tabfirst = i * NAMESPERPAGE;
624 tablast = tabfirst + NAMESPERPAGE - 1;
625 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
626 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
627 nametab(tablast_label, 64, addrbook[tablast].ab_name);
628 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
629 tablabels[i] = strdup(this_tablabel);
632 tabbed_dialog(num_pages, tablabels);
635 for (i=0; i<num_ab; ++i) {
637 if ((i / NAMESPERPAGE) != page) { /* New tab */
638 page = (i / NAMESPERPAGE);
640 wprintf("</tr></table>\n");
641 end_tab(page-1, num_pages);
643 begin_tab(page, num_pages);
644 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
648 if ((displayed % 4) == 0) {
653 wprintf("<tr bgcolor=\"#%s\">",
654 (bg ? "DDDDDD" : "FFFFFF")
660 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
661 addrbook[i].ab_msgnum);
662 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
663 vcard_n_prettyize(addrbook[i].ab_name);
664 escputs(addrbook[i].ab_name);
665 wprintf("</a></td>\n");
669 /* Placeholders for empty columns at end */
670 if ((num_ab % 4) != 0) {
671 for (i=0; i<(4-(num_ab % 4)); ++i) {
672 wprintf("<td> </td>");
676 wprintf("</tr></table>\n");
677 end_tab((num_pages-1), num_pages);
679 begin_tab(num_pages, num_pages);
680 /* FIXME there ought to be something here */
681 end_tab(num_pages, num_pages);
683 for (i=0; i<num_pages; ++i) {
693 * Edit the vCard component of a MIME message.
694 * Supply the message number
695 * and MIME part number to fetch. Or, specify -1 for the message number
696 * to start with a blank card.
698 void do_edit_vcard(long msgnum, char *partnum,
699 message_summary *VCMsg,
700 wc_mime_attachment *VCAtt,
702 const char *force_room) {
705 size_t total_len = 0;
713 char middlename[256];
727 char primary_inetemail[256];
728 char other_inetemail[SIZ];
729 char extrafields[SIZ];
750 primary_inetemail[0] = 0;
751 other_inetemail[0] = 0;
757 safestrncpy(whatuser, "", sizeof whatuser);
760 ((VCMsg != NULL) && (VCAtt != NULL)))
762 if ((VCMsg == NULL) && (VCAtt == NULL)) {
763 sprintf(buf, "MSG0 %ld|1", msgnum);
765 serv_getln(buf, sizeof buf);
767 convenience_page("770000", _("Error"), &buf[4]);
770 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
771 if (!strncasecmp(buf, "from=", 5)) {
772 safestrncpy(whatuser, &buf[5], sizeof whatuser);
774 else if (!strncasecmp(buf, "node=", 5)) {
775 strcat(whatuser, " @ ");
776 strcat(whatuser, &buf[5]);
780 serv_printf(buf, "DLAT %ld|%s", msgnum, partnum);
781 StrBuf_ServGetlnBuffered(Buf);
782 if (GetServerStatus(Buf, NULL) != 6) {
783 convenience_page("770000", "Error", &(ChrPtr(Buf)[4]));
787 StrBufCutLeft(Buf, 4);
788 total_len = StrBufExtract_long(Buf, 0, '|');
790 StrBuf_ServGetBLOBBuffered(Buf, total_len);
795 v = VCardLoad(VCAtt->Data);
799 /* Populate the variables for our form */
801 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
802 char prp[256]; /* property name */
803 char prm[256]; /* parameters */
805 value = vcard_get_prop(v, "", 0, i++, 0);
808 extract_token(prp, key, 0, ';', sizeof prp);
809 safestrncpy(prm, key, sizeof prm);
810 remove_token(prm, 0, ';');
812 if (!strcasecmp(prp, "n")) {
813 extract_token(lastname, value, 0, ';', sizeof lastname);
814 extract_token(firstname, value, 1, ';', sizeof firstname);
815 extract_token(middlename, value, 2, ';', sizeof middlename);
816 extract_token(prefix, value, 3, ';', sizeof prefix);
817 extract_token(suffix, value, 4, ';', sizeof suffix);
820 else if (!strcasecmp(prp, "fn")) {
821 safestrncpy(fullname, value, sizeof fullname);
824 else if (!strcasecmp(prp, "title")) {
825 safestrncpy(title, value, sizeof title);
828 else if (!strcasecmp(prp, "org")) {
829 safestrncpy(org, value, sizeof org);
832 else if (!strcasecmp(prp, "adr")) {
833 extract_token(pobox, value, 0, ';', sizeof pobox);
834 extract_token(extadr, value, 1, ';', sizeof extadr);
835 extract_token(street, value, 2, ';', sizeof street);
836 extract_token(city, value, 3, ';', sizeof city);
837 extract_token(state, value, 4, ';', sizeof state);
838 extract_token(zipcode, value, 5, ';', sizeof zipcode);
839 extract_token(country, value, 6, ';', sizeof country);
842 else if (!strcasecmp(prp, "tel")) {
844 if (bmstrcasestr(prm, "home")) {
845 extract_token(hometel, value, 0, ';', sizeof hometel);
847 else if (bmstrcasestr(prm, "work")) {
848 extract_token(worktel, value, 0, ';', sizeof worktel);
850 else if (bmstrcasestr(prm, "fax")) {
851 extract_token(faxtel, value, 0, ';', sizeof faxtel);
853 else if (bmstrcasestr(prm, "cell")) {
854 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
856 else { /* Missing or unknown type; put it in the home phone */
857 extract_token(hometel, value, 0, ';', sizeof hometel);
861 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
862 if (primary_inetemail[0] == 0) {
863 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
866 if (other_inetemail[0] != 0) {
867 strcat(other_inetemail, "\n");
869 strcat(other_inetemail, value);
873 /* Unrecognized properties are preserved here so we don't discard them
874 * just because the vCard was edited with WebCit.
877 strcat(extrafields, key);
878 strcat(extrafields, ":");
879 strcat(extrafields, value);
880 strcat(extrafields, "\n");
888 /** Display the form */
889 output_headers(1, 1, 1, 0, 0, 0);
891 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
892 do_template("beginboxx", NULL);
894 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
895 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
897 if (force_room != NULL) {
898 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
903 wprintf("<div class=\"fix_scrollbar_bug\">"
904 "<table class=\"vcard_edit_background\"><tr><td>\n");
906 wprintf("<table border=0><tr>"
911 "<td>%s</td></tr>\n",
912 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
914 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
915 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
917 wprintf("<td><input type=\"text\" name=\"firstname\" "
918 "value=\"%s\" maxlength=\"29\"></td>",
920 wprintf("<td><input type=\"text\" name=\"middlename\" "
921 "value=\"%s\" maxlength=\"29\"></td>",
923 wprintf("<td><input type=\"text\" name=\"lastname\" "
924 "value=\"%s\" maxlength=\"29\"></td>",
926 wprintf("<td><input type=\"text\" name=\"suffix\" "
927 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
930 wprintf("<table class=\"vcard_edit_background_alt\">");
933 wprintf(_("Display name:"));
935 "<input type=\"text\" name=\"fullname\" "
936 "value=\"%s\" maxlength=\"40\"><br><br>\n",
940 wprintf(_("Title:"));
942 "<input type=\"text\" name=\"title\" "
943 "value=\"%s\" maxlength=\"40\"><br><br>\n",
947 wprintf(_("Organization:"));
949 "<input type=\"text\" name=\"org\" "
950 "value=\"%s\" maxlength=\"40\"><br><br>\n",
954 wprintf("</td><td>");
956 wprintf("<table border=0>");
958 wprintf(_("PO box:"));
960 "<input type=\"text\" name=\"pobox\" "
961 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
964 wprintf(_("Address:"));
966 "<input type=\"text\" name=\"extadr\" "
967 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
969 wprintf("<tr><td> </td><td>"
970 "<input type=\"text\" name=\"street\" "
971 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
976 "<input type=\"text\" name=\"city\" "
977 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
980 wprintf(_("State:"));
982 "<input type=\"text\" name=\"state\" "
983 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
986 wprintf(_("ZIP code:"));
988 "<input type=\"text\" name=\"zipcode\" "
989 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
992 wprintf(_("Country:"));
994 "<input type=\"text\" name=\"country\" "
995 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
997 wprintf("</table>\n");
999 wprintf("</table>\n");
1001 wprintf("<table border=0><tr><td>");
1002 wprintf(_("Home telephone:"));
1004 "<td><input type=\"text\" name=\"hometel\" "
1005 "value=\"%s\" maxlength=\"29\"></td>\n",
1008 wprintf(_("Work telephone:"));
1010 "<td><input type=\"text\" name=\"worktel\" "
1011 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1013 wprintf("<tr><td>");
1014 wprintf(_("Mobile telephone:"));
1016 "<td><input type=\"text\" name=\"mobiletel\" "
1017 "value=\"%s\" maxlength=\"29\"></td>\n",
1020 wprintf(_("Fax number:"));
1022 "<td><input type=\"text\" name=\"faxtel\" "
1023 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
1026 wprintf("<table class=\"vcard_edit_background_alt\">");
1027 wprintf("<tr><td>");
1029 wprintf("<table border=0><TR>"
1031 wprintf(_("Primary Internet e-mail address"));
1033 "<input type=\"text\" name=\"primary_inetemail\" "
1034 "size=40 maxlength=60 value=\"");
1035 escputs(primary_inetemail);
1037 "</td><td valign=top>");
1038 wprintf(_("Internet e-mail aliases"));
1040 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
1041 escputs(other_inetemail);
1042 wprintf("</textarea></td></tr></table>\n");
1044 wprintf("</td></tr></table>\n");
1046 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
1047 escputs(extrafields);
1050 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
1051 urlescputs(return_to);
1054 wprintf("<div class=\"buttons\">\n"
1055 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1057 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1063 wprintf("</td></tr></table>\n");
1064 do_template("endbox", NULL);
1070 * commit the edits to the citadel server
1072 void edit_vcard(void) {
1076 msgnum = lbstr("msgnum");
1077 partnum = bstr("partnum");
1078 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1084 * parse edited vcard from the browser
1086 void submit_vcard(void) {
1087 wcsession *WCC = WC;
1089 char *serialized_vcard;
1094 if (!havebstr("ok_button")) {
1099 if (havebstr("force_room")) {
1100 if (gotoroom(sbstr("force_room")) != 200) {
1101 StrBufAppendBufPlain(WCC->ImportantMsg,
1102 _("Unable to enter the room to save your message"),
1104 StrBufAppendBufPlain(WCC->ImportantMsg,
1106 StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
1107 StrBufAppendBufPlain(WCC->ImportantMsg,
1110 StrBufAppendBufPlain(WCC->ImportantMsg,
1113 /// todo: call the master dispatcher again...
1114 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1115 select_user_to_edit(NULL, NULL);
1117 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1127 sprintf(buf, "ENT0 1|||4||");
1129 serv_getln(buf, sizeof buf);
1130 if (buf[0] != '4') {
1135 /** Make a vCard structure out of the data supplied in the form */
1137 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1140 v = VCardLoad(Buf); /** Start with the extra fields */
1143 safestrncpy(WCC->ImportantMessage,
1144 _("An error has occurred."),
1145 sizeof WCC->ImportantMessage
1151 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1157 vcard_add_prop(v, "n", buf);
1159 vcard_add_prop(v, "title", bstr("title"));
1160 vcard_add_prop(v, "fn", bstr("fullname"));
1161 vcard_add_prop(v, "org", bstr("org"));
1163 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1171 vcard_add_prop(v, "adr", buf);
1173 vcard_add_prop(v, "tel;home", bstr("hometel"));
1174 vcard_add_prop(v, "tel;work", bstr("worktel"));
1175 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1176 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1177 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1179 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1180 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1181 if (!IsEmptyStr(buf)) {
1182 vcard_add_prop(v, "email;internet", buf);
1186 serialized_vcard = vcard_serialize(v);
1188 if (serialized_vcard == NULL) {
1189 safestrncpy(WCC->ImportantMessage,
1190 _("An error has occurred."),
1191 sizeof WCC->ImportantMessage
1197 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1199 serv_printf("%s\r\n", serialized_vcard);
1201 free(serialized_vcard);
1203 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1204 select_user_to_edit(NULL, NULL);
1206 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1217 * Extract an embedded photo from a vCard for display on the client
1219 void display_vcard_photo_img(void)
1225 const char *contentType;
1226 wcsession *WCC = WC;
1228 msgnum = StrTol(WCC->UrlFragment2);
1230 vcard = load_mimepart(msgnum,"1");
1231 v = VCardLoad(vcard);
1233 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1234 FlushStrBuf(WCC->WBuf);
1235 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1236 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1237 FlushStrBuf(WCC->WBuf);
1239 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1240 output_headers(0, 0, 0, 0, 0, 0);
1241 hprintf("Content-Type: text/plain\r\n");
1242 wprintf(_("Could Not decode vcard photo\n"));
1246 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1247 http_transmit_thing(contentType, 0);
1258 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard, 0);
1259 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard, 0);
1260 WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img, NEED_URL);