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 StrBuf *FoundCharset = NewStrBuf();
116 wc_mime_attachment *Mime;
117 wc_mime_attachment *VCMime = NULL;
119 if (namebuf == NULL) return;
121 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
122 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
123 Msg->MsgBody->msgnum = Msg->msgnum;
125 load_message(Msg, FoundCharset, &Error);
127 /* look up the vcard... */
128 it = GetNewHashPos(Msg->AllAttach, 0);
129 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
132 Mime = (wc_mime_attachment*) vMime;
133 if ((strcmp(ChrPtr(Mime->ContentType),
134 "text/x-vcard") == 0) ||
135 (strcmp(ChrPtr(Mime->ContentType),
146 MimeLoadData(VCMime);
148 /* Grab the name off the card */
149 display_vcard(WC->WBuf, VCMime->Data, 0, 0, namebuf, Msg->msgnum);
151 if (*namebuf != NULL) {
152 lastfirst_firstlast(*namebuf);
154 len = strlen(*namebuf);
155 for (i=0; i<len; ++i) {
156 if ((*namebuf)[i] != ';') return;
159 (*namebuf) = strdup(_("(no name)"));
162 (*namebuf) = strdup(_("(no name)"));
169 * \brief Turn a vCard "n" (name) field into something displayable.
170 * \param name the name field to convert
172 void vcard_n_prettyize(char *name)
177 original_name = strdup(name);
178 len = strlen(original_name);
179 for (i=0; i<5; ++i) {
181 if (original_name[len-1] == ' ') {
182 original_name[--len] = 0;
184 if (original_name[len-1] == ';') {
185 original_name[--len] = 0;
191 for (i=0; i<len; ++i) {
192 if (original_name[i] == ';') {
197 name[j++] = original_name[i];
208 * \brief preparse a vcard name
209 * display_vcard() calls this after parsing the textual vCard into
210 * our 'struct vCard' data object.
211 * This gets called instead of display_parsed_vcard() if we are only looking
212 * to extract the person's name instead of displaying the card.
213 * \param v the vcard to retrieve the name from
214 * \param storename where to put the name at
216 void fetchname_parsed_vcard(struct vCard *v, char **storename) {
226 name = vcard_get_prop(v, "n", 1, 0, 0);
229 prop = vcard_get_prop(v, "n", 1, 0, 1);
230 n = num_tokens(prop, ';');
232 for (j=0; j<n; ++j) {
233 extract_token(buf, prop, j, ';', sizeof buf);
234 if (!strcasecmp(buf, "encoding=quoted-printable")) {
237 if (!strcasecmp(buf, "encoding=base64")) {
242 // %ff can become 6 bytes in utf8
243 *storename = malloc(len * 2 + 3);
244 j = CtdlDecodeQuotedPrintable(
250 // ff will become one byte..
251 *storename = malloc(len + 50);
257 *storename = strdup(name);
259 /* vcard_n_prettyize(storename); */
267 * \brief html print a vcard
268 * display_vcard() calls this after parsing the textual vCard into
269 * our 'struct vCard' data object.
271 * Set 'full' to nonzero to display the full card, otherwise it will only
272 * show a summary line.
274 * This code is a bit ugly, so perhaps an explanation is due: we do this
275 * in two passes through the vCard fields. On the first pass, we process
276 * fields we understand, and then render them in a pretty fashion at the
277 * end. Then we make a second pass, outputting all the fields we don't
278 * understand in a simple two-column name/value format.
279 * \param v the vCard to display
280 * \param full display all items of the vcard?
281 * \param msgnum Citadel message pointer
283 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, long msgnum) {
289 char *thisname, *thisvalue;
290 char firsttoken[SIZ];
299 strcpy(fullname, "");
306 StrBufAppendPrintf(Target, "<TD>");
307 name = vcard_get_prop(v, "fn", 1, 0, 0);
309 StrEscAppend(Target, NULL, name, 0, 0);
311 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
312 strcpy(fullname, name);
313 vcard_n_prettyize(fullname);
314 StrEscAppend(Target, NULL, fullname, 0, 0);
317 StrBufAppendPrintf(Target, " ");
319 StrBufAppendPrintf(Target, "</TD>");
323 StrBufAppendPrintf(Target, "<div align=center>"
324 "<table bgcolor=#aaaaaa width=50%%>");
325 for (pass=1; pass<=2; ++pass) {
327 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
329 thisname = strdup(v->prop[i].name);
330 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
332 for (j=0; j<num_tokens(thisname, ';'); ++j) {
333 extract_token(buf, thisname, j, ';', sizeof buf);
334 if (!strcasecmp(buf, "encoding=quoted-printable")) {
336 remove_token(thisname, j, ';');
338 if (!strcasecmp(buf, "encoding=base64")) {
340 remove_token(thisname, j, ';');
344 len = strlen(v->prop[i].value);
345 /* if we have some untagged QP, detect it here. */
346 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
347 utf8ify_rfc822_string(v->prop[i].value);
350 // %ff can become 6 bytes in utf8
351 thisvalue = malloc(len * 2 + 3);
352 j = CtdlDecodeQuotedPrintable(
353 thisvalue, v->prop[i].value,
358 // ff will become one byte..
359 thisvalue = malloc(len + 50);
361 thisvalue, v->prop[i].value,
362 strlen(v->prop[i].value) );
365 thisvalue = strdup(v->prop[i].value);
368 /** Various fields we may encounter ***/
370 /** N is name, but only if there's no FN already there */
371 if (!strcasecmp(firsttoken, "n")) {
372 if (IsEmptyStr(fullname)) {
373 strcpy(fullname, thisvalue);
374 vcard_n_prettyize(fullname);
378 /** FN (full name) is a true 'display name' field */
379 else if (!strcasecmp(firsttoken, "fn")) {
380 strcpy(fullname, thisvalue);
384 else if (!strcasecmp(firsttoken, "title")) {
385 strcpy(title, thisvalue);
389 else if (!strcasecmp(firsttoken, "org")) {
390 strcpy(org, thisvalue);
393 else if (!strcasecmp(firsttoken, "email")) {
395 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
397 "<a href=\"display_enter"
398 "?force_room=_MAIL_?recp=");
400 len = strlen(mailto);
401 urlesc(&mailto[len], SIZ - len, "\"");
402 len = strlen(mailto);
403 urlesc(&mailto[len], SIZ - len, fullname);
404 len = strlen(mailto);
405 urlesc(&mailto[len], SIZ - len, "\" <");
406 len = strlen(mailto);
407 urlesc(&mailto[len], SIZ - len, thisvalue);
408 len = strlen(mailto);
409 urlesc(&mailto[len], SIZ - len, ">");
411 strcat(mailto, "\">");
412 len = strlen(mailto);
413 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
414 strcat(mailto, "</A>");
416 else if (!strcasecmp(firsttoken, "tel")) {
417 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
418 strcat(phone, thisvalue);
419 for (j=0; j<num_tokens(thisname, ';'); ++j) {
420 extract_token(buf, thisname, j, ';', sizeof buf);
421 if (!strcasecmp(buf, "tel"))
423 else if (!strcasecmp(buf, "work"))
424 strcat(phone, _(" (work)"));
425 else if (!strcasecmp(buf, "home"))
426 strcat(phone, _(" (home)"));
427 else if (!strcasecmp(buf, "cell"))
428 strcat(phone, _(" (cell)"));
436 else if (!strcasecmp(firsttoken, "adr")) {
438 StrBufAppendPrintf(Target, "<TR><TD>");
439 StrBufAppendPrintf(Target, _("Address:"));
440 StrBufAppendPrintf(Target, "</TD><TD>");
441 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
442 extract_token(buf, thisvalue, j, ';', sizeof buf);
443 if (!IsEmptyStr(buf)) {
444 StrEscAppend(Target, NULL, buf, 0, 0);
445 if (j<3) StrBufAppendPrintf(Target, "<br />");
446 else StrBufAppendPrintf(Target, " ");
449 StrBufAppendPrintf(Target, "</TD></TR>\n");
452 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
453 // Only output on second pass
454 StrBufAppendPrintf(Target, "<tr><td>");
455 StrBufAppendPrintf(Target, _("Photo:"));
456 StrBufAppendPrintf(Target, "</td><td>");
457 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
458 StrBufAppendPrintf(Target, "</td></tr>\n");
460 else if (!strcasecmp(firsttoken, "version")) {
463 else if (!strcasecmp(firsttoken, "rev")) {
466 else if (!strcasecmp(firsttoken, "label")) {
471 /*** Don't show extra fields. They're ugly.
473 StrBufAppendPrintf(Target, "<TR><TD>");
474 StrEscAppend(Target, NULL, thisname, 0, 0);
475 StrBufAppendPrintf(Target, "</TD><TD>");
476 StrEscAppend(Target, NULL, thisvalue, 0, 0);
477 StrBufAppendPrintf(Target, "</TD></TR>\n");
487 StrBufAppendPrintf(Target, "<TR BGCOLOR=\"#AAAAAA\">"
488 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
489 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
490 "<FONT SIZE=+1><B>");
491 StrEscAppend(Target, NULL, fullname, 0, 0);
492 StrBufAppendPrintf(Target, "</B></FONT>");
493 if (!IsEmptyStr(title)) {
494 StrBufAppendPrintf(Target, "<div align=right>");
495 StrEscAppend(Target, NULL, title, 0, 0);
496 StrBufAppendPrintf(Target, "</div>");
498 if (!IsEmptyStr(org)) {
499 StrBufAppendPrintf(Target, "<div align=right>");
500 StrEscAppend(Target, NULL, org, 0, 0);
501 StrBufAppendPrintf(Target, "</div>");
503 StrBufAppendPrintf(Target, "</TD></TR>\n");
505 if (!IsEmptyStr(phone)) {
506 StrBufAppendPrintf(Target, "<tr><td>");
507 StrBufAppendPrintf(Target, _("Telephone:"));
508 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
510 if (!IsEmptyStr(mailto)) {
511 StrBufAppendPrintf(Target, "<tr><td>");
512 StrBufAppendPrintf(Target, _("E-mail:"));
513 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
519 StrBufAppendPrintf(Target, "</table></div>\n");
525 * \brief Display a textual vCard
526 * (Converts to a vCard object and then calls the actual display function)
527 * Set 'full' to nonzero to display the whole card instead of a one-liner.
528 * Or, if "storename" is non-NULL, just store the person's name in that
529 * buffer instead of displaying the card at all.
530 * \param vcard_source the buffer containing the vcard text
531 * \param alpha what???
532 * \param full should we usse all lines?
533 * \param storename where to store???
534 * \param msgnum Citadel message pointer
536 void display_vcard(StrBuf *Target,
537 StrBuf *vcard_source,
549 v = VCardLoad(vcard_source);
551 if (v == NULL) return;
553 name = vcard_get_prop(v, "n", 1, 0, 0);
555 Buf = NewStrBufPlain(name, -1);
556 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
557 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
558 this_alpha = ChrPtr(Buf)[0];
563 if (storename != NULL) {
564 fetchname_parsed_vcard(v, storename);
566 else if ( (alpha == 0)
567 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
568 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
570 display_parsed_vcard(Target, v, full,msgnum);
579 * \brief Render the address book using info we gathered during the scan
580 * \param addrbook the addressbook to render
581 * \param num_ab the number of the addressbook
583 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
587 static int NAMESPERPAGE = 60;
590 char tabfirst_label[64];
592 char tablast_label[64];
593 char this_tablabel[64];
598 wprintf("<br /><br /><br /><div align=\"center\"><i>");
599 wprintf(_("This address book is empty."));
600 wprintf("</i></div>\n");
605 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
608 num_pages = (num_ab / NAMESPERPAGE) + 1;
610 tablabels = malloc(num_pages * sizeof (char *));
611 if (tablabels == NULL) {
612 wprintf("<br /><br /><br /><div align=\"center\"><i>");
613 wprintf(_("An internal error has occurred."));
614 wprintf("</i></div>\n");
618 for (i=0; i<num_pages; ++i) {
619 tabfirst = i * NAMESPERPAGE;
620 tablast = tabfirst + NAMESPERPAGE - 1;
621 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
622 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
623 nametab(tablast_label, 64, addrbook[tablast].ab_name);
624 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
625 tablabels[i] = strdup(this_tablabel);
628 tabbed_dialog(num_pages, tablabels);
631 for (i=0; i<num_ab; ++i) {
633 if ((i / NAMESPERPAGE) != page) { /* New tab */
634 page = (i / NAMESPERPAGE);
636 wprintf("</tr></table>\n");
637 end_tab(page-1, num_pages);
639 begin_tab(page, num_pages);
640 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
644 if ((displayed % 4) == 0) {
649 wprintf("<tr bgcolor=\"#%s\">",
650 (bg ? "DDDDDD" : "FFFFFF")
656 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
657 addrbook[i].ab_msgnum);
658 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
659 vcard_n_prettyize(addrbook[i].ab_name);
660 escputs(addrbook[i].ab_name);
661 wprintf("</a></td>\n");
665 /* Placeholders for empty columns at end */
666 if ((num_ab % 4) != 0) {
667 for (i=0; i<(4-(num_ab % 4)); ++i) {
668 wprintf("<td> </td>");
672 wprintf("</tr></table>\n");
673 end_tab((num_pages-1), num_pages);
675 begin_tab(num_pages, num_pages);
676 /* FIXME there ought to be something here */
677 end_tab(num_pages, num_pages);
679 for (i=0; i<num_pages; ++i) {
689 * Edit the vCard component of a MIME message.
690 * Supply the message number
691 * and MIME part number to fetch. Or, specify -1 for the message number
692 * to start with a blank card.
694 void do_edit_vcard(long msgnum, char *partnum,
695 message_summary *VCMsg,
696 wc_mime_attachment *VCAtt,
698 const char *force_room) {
701 size_t total_len = 0;
709 char middlename[256];
723 char primary_inetemail[256];
724 char other_inetemail[SIZ];
725 char extrafields[SIZ];
746 primary_inetemail[0] = 0;
747 other_inetemail[0] = 0;
753 safestrncpy(whatuser, "", sizeof whatuser);
756 ((VCMsg != NULL) && (VCAtt != NULL)))
758 if ((VCMsg == NULL) && (VCAtt == NULL)) {
759 sprintf(buf, "MSG0 %ld|1", msgnum);
761 serv_getln(buf, sizeof buf);
763 convenience_page("770000", _("Error"), &buf[4]);
766 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
767 if (!strncasecmp(buf, "from=", 5)) {
768 safestrncpy(whatuser, &buf[5], sizeof whatuser);
770 else if (!strncasecmp(buf, "node=", 5)) {
771 strcat(whatuser, " @ ");
772 strcat(whatuser, &buf[5]);
776 serv_printf(buf, "DLAT %ld|%s", msgnum, partnum);
777 StrBuf_ServGetln(Buf);
778 if (GetServerStatus(Buf, NULL) != 6) {
779 convenience_page("770000", "Error", &(ChrPtr(Buf)[4]));
783 StrBufCutLeft(Buf, 4);
784 total_len = StrBufExtract_long(Buf, 0, '|');
786 StrBuf_ServGetBLOBBuffered(Buf, total_len);
791 v = VCardLoad(VCAtt->Data);
795 /* Populate the variables for our form */
797 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
798 char prp[256]; /* property name */
799 char prm[256]; /* parameters */
801 value = vcard_get_prop(v, "", 0, i++, 0);
804 extract_token(prp, key, 0, ';', sizeof prp);
805 safestrncpy(prm, key, sizeof prm);
806 remove_token(prm, 0, ';');
808 if (!strcasecmp(prp, "n")) {
809 extract_token(lastname, value, 0, ';', sizeof lastname);
810 extract_token(firstname, value, 1, ';', sizeof firstname);
811 extract_token(middlename, value, 2, ';', sizeof middlename);
812 extract_token(prefix, value, 3, ';', sizeof prefix);
813 extract_token(suffix, value, 4, ';', sizeof suffix);
816 else if (!strcasecmp(prp, "fn")) {
817 safestrncpy(fullname, value, sizeof fullname);
820 else if (!strcasecmp(prp, "title")) {
821 safestrncpy(title, value, sizeof title);
824 else if (!strcasecmp(prp, "org")) {
825 safestrncpy(org, value, sizeof org);
828 else if (!strcasecmp(prp, "adr")) {
829 extract_token(pobox, value, 0, ';', sizeof pobox);
830 extract_token(extadr, value, 1, ';', sizeof extadr);
831 extract_token(street, value, 2, ';', sizeof street);
832 extract_token(city, value, 3, ';', sizeof city);
833 extract_token(state, value, 4, ';', sizeof state);
834 extract_token(zipcode, value, 5, ';', sizeof zipcode);
835 extract_token(country, value, 6, ';', sizeof country);
838 else if (!strcasecmp(prp, "tel")) {
840 if (bmstrcasestr(prm, "home")) {
841 extract_token(hometel, value, 0, ';', sizeof hometel);
843 else if (bmstrcasestr(prm, "work")) {
844 extract_token(worktel, value, 0, ';', sizeof worktel);
846 else if (bmstrcasestr(prm, "fax")) {
847 extract_token(faxtel, value, 0, ';', sizeof faxtel);
849 else if (bmstrcasestr(prm, "cell")) {
850 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
852 else { /* Missing or unknown type; put it in the home phone */
853 extract_token(hometel, value, 0, ';', sizeof hometel);
857 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
858 if (primary_inetemail[0] == 0) {
859 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
862 if (other_inetemail[0] != 0) {
863 strcat(other_inetemail, "\n");
865 strcat(other_inetemail, value);
869 /* Unrecognized properties are preserved here so we don't discard them
870 * just because the vCard was edited with WebCit.
873 strcat(extrafields, key);
874 strcat(extrafields, ":");
875 strcat(extrafields, value);
876 strcat(extrafields, "\n");
884 /** Display the form */
885 output_headers(1, 1, 1, 0, 0, 0);
887 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
888 do_template("beginboxx", NULL);
890 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
891 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
893 if (force_room != NULL) {
894 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
899 wprintf("<div class=\"fix_scrollbar_bug\">"
900 "<table class=\"vcard_edit_background\"><tr><td>\n");
902 wprintf("<table border=0><tr>"
907 "<td>%s</td></tr>\n",
908 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
910 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
911 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
913 wprintf("<td><input type=\"text\" name=\"firstname\" "
914 "value=\"%s\" maxlength=\"29\"></td>",
916 wprintf("<td><input type=\"text\" name=\"middlename\" "
917 "value=\"%s\" maxlength=\"29\"></td>",
919 wprintf("<td><input type=\"text\" name=\"lastname\" "
920 "value=\"%s\" maxlength=\"29\"></td>",
922 wprintf("<td><input type=\"text\" name=\"suffix\" "
923 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
926 wprintf("<table class=\"vcard_edit_background_alt\">");
929 wprintf(_("Display name:"));
931 "<input type=\"text\" name=\"fullname\" "
932 "value=\"%s\" maxlength=\"40\"><br><br>\n",
936 wprintf(_("Title:"));
938 "<input type=\"text\" name=\"title\" "
939 "value=\"%s\" maxlength=\"40\"><br><br>\n",
943 wprintf(_("Organization:"));
945 "<input type=\"text\" name=\"org\" "
946 "value=\"%s\" maxlength=\"40\"><br><br>\n",
950 wprintf("</td><td>");
952 wprintf("<table border=0>");
954 wprintf(_("PO box:"));
956 "<input type=\"text\" name=\"pobox\" "
957 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
960 wprintf(_("Address:"));
962 "<input type=\"text\" name=\"extadr\" "
963 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
965 wprintf("<tr><td> </td><td>"
966 "<input type=\"text\" name=\"street\" "
967 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
972 "<input type=\"text\" name=\"city\" "
973 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
976 wprintf(_("State:"));
978 "<input type=\"text\" name=\"state\" "
979 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
982 wprintf(_("ZIP code:"));
984 "<input type=\"text\" name=\"zipcode\" "
985 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
988 wprintf(_("Country:"));
990 "<input type=\"text\" name=\"country\" "
991 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
993 wprintf("</table>\n");
995 wprintf("</table>\n");
997 wprintf("<table border=0><tr><td>");
998 wprintf(_("Home telephone:"));
1000 "<td><input type=\"text\" name=\"hometel\" "
1001 "value=\"%s\" maxlength=\"29\"></td>\n",
1004 wprintf(_("Work telephone:"));
1006 "<td><input type=\"text\" name=\"worktel\" "
1007 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
1009 wprintf("<tr><td>");
1010 wprintf(_("Mobile telephone:"));
1012 "<td><input type=\"text\" name=\"mobiletel\" "
1013 "value=\"%s\" maxlength=\"29\"></td>\n",
1016 wprintf(_("Fax number:"));
1018 "<td><input type=\"text\" name=\"faxtel\" "
1019 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
1022 wprintf("<table class=\"vcard_edit_background_alt\">");
1023 wprintf("<tr><td>");
1025 wprintf("<table border=0><TR>"
1027 wprintf(_("Primary Internet e-mail address"));
1029 "<input type=\"text\" name=\"primary_inetemail\" "
1030 "size=40 maxlength=60 value=\"");
1031 escputs(primary_inetemail);
1033 "</td><td valign=top>");
1034 wprintf(_("Internet e-mail aliases"));
1036 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
1037 escputs(other_inetemail);
1038 wprintf("</textarea></td></tr></table>\n");
1040 wprintf("</td></tr></table>\n");
1042 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
1043 escputs(extrafields);
1046 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
1047 urlescputs(return_to);
1050 wprintf("<div class=\"buttons\">\n"
1051 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1053 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1059 wprintf("</td></tr></table>\n");
1060 do_template("endbox", NULL);
1066 * commit the edits to the citadel server
1068 void edit_vcard(void) {
1072 msgnum = lbstr("msgnum");
1073 partnum = bstr("partnum");
1074 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1080 * parse edited vcard from the browser
1082 void submit_vcard(void) {
1083 wcsession *WCC = WC;
1085 char *serialized_vcard;
1090 if (!havebstr("ok_button")) {
1095 if (havebstr("force_room")) {
1096 if (gotoroom(sbstr("force_room")) != 200) {
1097 StrBufAppendBufPlain(WCC->ImportantMsg,
1098 _("Unable to enter the room to save your message"),
1100 StrBufAppendBufPlain(WCC->ImportantMsg,
1102 StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
1103 StrBufAppendBufPlain(WCC->ImportantMsg,
1106 StrBufAppendBufPlain(WCC->ImportantMsg,
1109 /// todo: call the master dispatcher again...
1110 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1111 select_user_to_edit(NULL);
1113 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1123 sprintf(buf, "ENT0 1|||4||");
1125 serv_getln(buf, sizeof buf);
1126 if (buf[0] != '4') {
1131 /** Make a vCard structure out of the data supplied in the form */
1133 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1136 v = VCardLoad(Buf); /** Start with the extra fields */
1139 safestrncpy(WCC->ImportantMessage,
1140 _("An error has occurred."),
1141 sizeof WCC->ImportantMessage
1147 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1153 vcard_add_prop(v, "n", buf);
1155 vcard_add_prop(v, "title", bstr("title"));
1156 vcard_add_prop(v, "fn", bstr("fullname"));
1157 vcard_add_prop(v, "org", bstr("org"));
1159 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1167 vcard_add_prop(v, "adr", buf);
1169 vcard_add_prop(v, "tel;home", bstr("hometel"));
1170 vcard_add_prop(v, "tel;work", bstr("worktel"));
1171 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1172 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1173 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1175 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1176 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1177 if (!IsEmptyStr(buf)) {
1178 vcard_add_prop(v, "email;internet", buf);
1182 serialized_vcard = vcard_serialize(v);
1184 if (serialized_vcard == NULL) {
1185 safestrncpy(WCC->ImportantMessage,
1186 _("An error has occurred."),
1187 sizeof WCC->ImportantMessage
1193 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1195 serv_printf("%s\r\n", serialized_vcard);
1197 free(serialized_vcard);
1199 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1200 select_user_to_edit(NULL);
1202 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1213 * Extract an embedded photo from a vCard for display on the client
1215 void display_vcard_photo_img(void)
1221 const char *contentType;
1222 wcsession *WCC = WC;
1224 msgnum = StrTol(WCC->UrlFragment2);
1226 vcard = load_mimepart(msgnum,"1");
1227 v = VCardLoad(vcard);
1229 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1230 FlushStrBuf(WCC->WBuf);
1231 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1232 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1233 FlushStrBuf(WCC->WBuf);
1235 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1236 output_headers(0, 0, 0, 0, 0, 0);
1237 hprintf("Content-Type: text/plain\r\n");
1238 wprintf(_("Could Not decode vcard photo\n"));
1242 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1243 http_transmit_thing(contentType, 0);
1254 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard, 0);
1255 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard, 0);
1256 WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img, NEED_URL);