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->wc_roomname), USERCONFIGROOM))
56 || (!strcasecmp(&(ChrPtr(WC->wc_roomname)[11]), USERCONFIGROOM))
57 || (WC->wc_view == VIEW_ADDRESSBOOK)
59 wprintf("<a href=\"edit_vcard?"
60 "msgnum=%ld&partnum=%s\">",
61 msgnum, vcard_partnum);
62 wprintf("[%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);
256 *storename = strdup(name);
258 /* vcard_n_prettyize(storename); */
267 * display_vcard() calls this after parsing the textual vCard into
268 * our 'struct vCard' data object.
270 * Set 'full' to nonzero to display the full card, otherwise it will only
271 * show a summary line.
273 * This code is a bit ugly, so perhaps an explanation is due: we do this
274 * in two passes through the vCard fields. On the first pass, we process
275 * fields we understand, and then render them in a pretty fashion at the
276 * end. Then we make a second pass, outputting all the fields we don't
277 * understand in a simple two-column name/value format.
278 * v the vCard to display
279 * full display all items of the vcard?
280 * msgnum Citadel message pointer
282 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, long msgnum) {
288 char *thisname, *thisvalue;
289 char firsttoken[SIZ];
298 strcpy(fullname, "");
305 StrBufAppendPrintf(Target, "<TD>");
306 name = vcard_get_prop(v, "fn", 1, 0, 0);
308 StrEscAppend(Target, NULL, name, 0, 0);
310 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
311 strcpy(fullname, name);
312 vcard_n_prettyize(fullname);
313 StrEscAppend(Target, NULL, fullname, 0, 0);
316 StrBufAppendPrintf(Target, " ");
318 StrBufAppendPrintf(Target, "</TD>");
322 StrBufAppendPrintf(Target, "<div align=center>"
323 "<table bgcolor=#aaaaaa width=50%%>");
324 for (pass=1; pass<=2; ++pass) {
326 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
328 thisname = strdup(v->prop[i].name);
329 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
331 for (j=0; j<num_tokens(thisname, ';'); ++j) {
332 extract_token(buf, thisname, j, ';', sizeof buf);
333 if (!strcasecmp(buf, "encoding=quoted-printable")) {
335 remove_token(thisname, j, ';');
337 if (!strcasecmp(buf, "encoding=base64")) {
339 remove_token(thisname, j, ';');
343 len = strlen(v->prop[i].value);
344 /* if we have some untagged QP, detect it here. */
345 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
346 utf8ify_rfc822_string(v->prop[i].value);
349 // %ff can become 6 bytes in utf8
350 thisvalue = malloc(len * 2 + 3);
351 j = CtdlDecodeQuotedPrintable(
352 thisvalue, v->prop[i].value,
357 // ff will become one byte..
358 thisvalue = malloc(len + 50);
360 thisvalue, v->prop[i].value,
361 strlen(v->prop[i].value) );
364 thisvalue = strdup(v->prop[i].value);
367 /** Various fields we may encounter ***/
369 /** N is name, but only if there's no FN already there */
370 if (!strcasecmp(firsttoken, "n")) {
371 if (IsEmptyStr(fullname)) {
372 strcpy(fullname, thisvalue);
373 vcard_n_prettyize(fullname);
377 /** FN (full name) is a true 'display name' field */
378 else if (!strcasecmp(firsttoken, "fn")) {
379 strcpy(fullname, thisvalue);
383 else if (!strcasecmp(firsttoken, "title")) {
384 strcpy(title, thisvalue);
388 else if (!strcasecmp(firsttoken, "org")) {
389 strcpy(org, thisvalue);
392 else if (!strcasecmp(firsttoken, "email")) {
394 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
396 "<a href=\"display_enter"
397 "?force_room=_MAIL_?recp=");
399 len = strlen(mailto);
400 urlesc(&mailto[len], SIZ - len, "\"");
401 len = strlen(mailto);
402 urlesc(&mailto[len], SIZ - len, fullname);
403 len = strlen(mailto);
404 urlesc(&mailto[len], SIZ - len, "\" <");
405 len = strlen(mailto);
406 urlesc(&mailto[len], SIZ - len, thisvalue);
407 len = strlen(mailto);
408 urlesc(&mailto[len], SIZ - len, ">");
410 strcat(mailto, "\">");
411 len = strlen(mailto);
412 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
413 strcat(mailto, "</A>");
415 else if (!strcasecmp(firsttoken, "tel")) {
416 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
417 strcat(phone, thisvalue);
418 for (j=0; j<num_tokens(thisname, ';'); ++j) {
419 extract_token(buf, thisname, j, ';', sizeof buf);
420 if (!strcasecmp(buf, "tel"))
422 else if (!strcasecmp(buf, "work"))
423 strcat(phone, _(" (work)"));
424 else if (!strcasecmp(buf, "home"))
425 strcat(phone, _(" (home)"));
426 else if (!strcasecmp(buf, "cell"))
427 strcat(phone, _(" (cell)"));
435 else if (!strcasecmp(firsttoken, "adr")) {
437 StrBufAppendPrintf(Target, "<TR><TD>");
438 StrBufAppendPrintf(Target, _("Address:"));
439 StrBufAppendPrintf(Target, "</TD><TD>");
440 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
441 extract_token(buf, thisvalue, j, ';', sizeof buf);
442 if (!IsEmptyStr(buf)) {
443 StrEscAppend(Target, NULL, buf, 0, 0);
444 if (j<3) StrBufAppendPrintf(Target, "<br />");
445 else StrBufAppendPrintf(Target, " ");
448 StrBufAppendPrintf(Target, "</TD></TR>\n");
451 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
452 // Only output on second pass
453 StrBufAppendPrintf(Target, "<tr><td>");
454 StrBufAppendPrintf(Target, _("Photo:"));
455 StrBufAppendPrintf(Target, "</td><td>");
456 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
457 StrBufAppendPrintf(Target, "</td></tr>\n");
459 else if (!strcasecmp(firsttoken, "version")) {
462 else if (!strcasecmp(firsttoken, "rev")) {
465 else if (!strcasecmp(firsttoken, "label")) {
470 /*** Don't show extra fields. They're ugly.
472 StrBufAppendPrintf(Target, "<TR><TD>");
473 StrEscAppend(Target, NULL, thisname, 0, 0);
474 StrBufAppendPrintf(Target, "</TD><TD>");
475 StrEscAppend(Target, NULL, thisvalue, 0, 0);
476 StrBufAppendPrintf(Target, "</TD></TR>\n");
486 StrBufAppendPrintf(Target, "<TR BGCOLOR=\"#AAAAAA\">"
487 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
488 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
489 "<FONT SIZE=+1><B>");
490 StrEscAppend(Target, NULL, fullname, 0, 0);
491 StrBufAppendPrintf(Target, "</B></FONT>");
492 if (!IsEmptyStr(title)) {
493 StrBufAppendPrintf(Target, "<div align=right>");
494 StrEscAppend(Target, NULL, title, 0, 0);
495 StrBufAppendPrintf(Target, "</div>");
497 if (!IsEmptyStr(org)) {
498 StrBufAppendPrintf(Target, "<div align=right>");
499 StrEscAppend(Target, NULL, org, 0, 0);
500 StrBufAppendPrintf(Target, "</div>");
502 StrBufAppendPrintf(Target, "</TD></TR>\n");
504 if (!IsEmptyStr(phone)) {
505 StrBufAppendPrintf(Target, "<tr><td>");
506 StrBufAppendPrintf(Target, _("Telephone:"));
507 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
509 if (!IsEmptyStr(mailto)) {
510 StrBufAppendPrintf(Target, "<tr><td>");
511 StrBufAppendPrintf(Target, _("E-mail:"));
512 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
518 StrBufAppendPrintf(Target, "</table></div>\n");
524 * \brief Display a textual vCard
525 * (Converts to a vCard object and then calls the actual display function)
526 * Set 'full' to nonzero to display the whole card instead of a one-liner.
527 * Or, if "storename" is non-NULL, just store the person's name in that
528 * buffer instead of displaying the card at all.
529 * \param vcard_source the buffer containing the vcard text
530 * \param alpha what???
531 * \param full should we usse all lines?
532 * \param storename where to store???
533 * \param msgnum Citadel message pointer
535 void display_vcard(StrBuf *Target,
536 StrBuf *vcard_source,
548 v = VCardLoad(vcard_source);
550 if (v == NULL) return;
552 name = vcard_get_prop(v, "n", 1, 0, 0);
554 Buf = NewStrBufPlain(name, -1);
555 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
556 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
557 this_alpha = ChrPtr(Buf)[0];
562 if (storename != NULL) {
563 fetchname_parsed_vcard(v, storename);
565 else if ( (alpha == 0)
566 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
567 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
569 display_parsed_vcard(Target, v, full,msgnum);
578 * \brief Render the address book using info we gathered during the scan
579 * \param addrbook the addressbook to render
580 * \param num_ab the number of the addressbook
582 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
586 static int NAMESPERPAGE = 60;
589 char tabfirst_label[64];
591 char tablast_label[64];
592 char this_tablabel[64];
597 wprintf("<br /><br /><br /><div align=\"center\"><i>");
598 wprintf(_("This address book is empty."));
599 wprintf("</i></div>\n");
604 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
607 num_pages = (num_ab / NAMESPERPAGE) + 1;
609 tablabels = malloc(num_pages * sizeof (char *));
610 if (tablabels == NULL) {
611 wprintf("<br /><br /><br /><div align=\"center\"><i>");
612 wprintf(_("An internal error has occurred."));
613 wprintf("</i></div>\n");
617 for (i=0; i<num_pages; ++i) {
618 tabfirst = i * NAMESPERPAGE;
619 tablast = tabfirst + NAMESPERPAGE - 1;
620 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
621 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
622 nametab(tablast_label, 64, addrbook[tablast].ab_name);
623 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
624 tablabels[i] = strdup(this_tablabel);
627 tabbed_dialog(num_pages, tablabels);
630 for (i=0; i<num_ab; ++i) {
632 if ((i / NAMESPERPAGE) != page) { /* New tab */
633 page = (i / NAMESPERPAGE);
635 wprintf("</tr></table>\n");
636 end_tab(page-1, num_pages);
638 begin_tab(page, num_pages);
639 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
643 if ((displayed % 4) == 0) {
648 wprintf("<tr bgcolor=\"#%s\">",
649 (bg ? "DDDDDD" : "FFFFFF")
655 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
656 addrbook[i].ab_msgnum);
657 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
658 vcard_n_prettyize(addrbook[i].ab_name);
659 escputs(addrbook[i].ab_name);
660 wprintf("</a></td>\n");
664 /* Placeholders for empty columns at end */
665 if ((num_ab % 4) != 0) {
666 for (i=0; i<(4-(num_ab % 4)); ++i) {
667 wprintf("<td> </td>");
671 wprintf("</tr></table>\n");
672 end_tab((num_pages-1), num_pages);
674 begin_tab(num_pages, num_pages);
675 /* FIXME there ought to be something here */
676 end_tab(num_pages, num_pages);
678 for (i=0; i<num_pages; ++i) {
688 * Edit the vCard component of a MIME message.
689 * Supply the message number
690 * and MIME part number to fetch. Or, specify -1 for the message number
691 * to start with a blank card.
693 void do_edit_vcard(long msgnum, char *partnum,
694 message_summary *VCMsg,
695 wc_mime_attachment *VCAtt,
697 const char *force_room) {
698 message_summary *Msg = NULL;
699 wc_mime_attachment *VCMime = NULL;
707 char middlename[256];
721 char primary_inetemail[256];
722 char other_inetemail[SIZ];
723 char extrafields[SIZ];
744 primary_inetemail[0] = 0;
745 other_inetemail[0] = 0;
751 safestrncpy(whatuser, "", sizeof whatuser);
754 ((VCMsg != NULL) && (VCAtt != NULL)))
756 if ((VCMsg == NULL) && (VCAtt == NULL)) {
758 Msg = (message_summary *) malloc(sizeof(message_summary));
759 memset(Msg, 0, sizeof(message_summary));
760 Msg->msgnum = msgnum;
761 VCMime = load_vcard(Msg);
762 if (VCMime == NULL) {
763 convenience_page("770000", _("Error"), "");///TODO: important message
764 DestroyMessageSummary(Msg);
768 v = VCardLoad(VCMime->Data);
771 v = VCardLoad(VCAtt->Data);
774 /* Populate the variables for our form */
776 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
777 char prp[256]; /* property name */
778 char prm[256]; /* parameters */
780 value = vcard_get_prop(v, "", 0, i++, 0);
783 extract_token(prp, key, 0, ';', sizeof prp);
784 safestrncpy(prm, key, sizeof prm);
785 remove_token(prm, 0, ';');
787 if (!strcasecmp(prp, "n")) {
788 extract_token(lastname, value, 0, ';', sizeof lastname);
789 extract_token(firstname, value, 1, ';', sizeof firstname);
790 extract_token(middlename, value, 2, ';', sizeof middlename);
791 extract_token(prefix, value, 3, ';', sizeof prefix);
792 extract_token(suffix, value, 4, ';', sizeof suffix);
795 else if (!strcasecmp(prp, "fn")) {
796 safestrncpy(fullname, value, sizeof fullname);
799 else if (!strcasecmp(prp, "title")) {
800 safestrncpy(title, value, sizeof title);
803 else if (!strcasecmp(prp, "org")) {
804 safestrncpy(org, value, sizeof org);
807 else if (!strcasecmp(prp, "adr")) {
808 extract_token(pobox, value, 0, ';', sizeof pobox);
809 extract_token(extadr, value, 1, ';', sizeof extadr);
810 extract_token(street, value, 2, ';', sizeof street);
811 extract_token(city, value, 3, ';', sizeof city);
812 extract_token(state, value, 4, ';', sizeof state);
813 extract_token(zipcode, value, 5, ';', sizeof zipcode);
814 extract_token(country, value, 6, ';', sizeof country);
817 else if (!strcasecmp(prp, "tel")) {
819 if (bmstrcasestr(prm, "home")) {
820 extract_token(hometel, value, 0, ';', sizeof hometel);
822 else if (bmstrcasestr(prm, "work")) {
823 extract_token(worktel, value, 0, ';', sizeof worktel);
825 else if (bmstrcasestr(prm, "fax")) {
826 extract_token(faxtel, value, 0, ';', sizeof faxtel);
828 else if (bmstrcasestr(prm, "cell")) {
829 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
831 else { /* Missing or unknown type; put it in the home phone */
832 extract_token(hometel, value, 0, ';', sizeof hometel);
836 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
837 if (primary_inetemail[0] == 0) {
838 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
841 if (other_inetemail[0] != 0) {
842 strcat(other_inetemail, "\n");
844 strcat(other_inetemail, value);
848 /* Unrecognized properties are preserved here so we don't discard them
849 * just because the vCard was edited with WebCit.
852 strcat(extrafields, key);
853 strcat(extrafields, ":");
854 strcat(extrafields, value);
855 strcat(extrafields, "\n");
863 /* Display the form */
864 output_headers(1, 1, 1, 0, 0, 0);
866 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
867 do_template("beginboxx", NULL);
869 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
870 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
872 if (force_room != NULL) {
873 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
878 wprintf("<div class=\"fix_scrollbar_bug\">"
879 "<table class=\"vcard_edit_background\"><tr><td>\n");
881 wprintf("<table border=0><tr>"
886 "<td>%s</td></tr>\n",
887 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
889 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
890 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
892 wprintf("<td><input type=\"text\" name=\"firstname\" "
893 "value=\"%s\" maxlength=\"29\"></td>",
895 wprintf("<td><input type=\"text\" name=\"middlename\" "
896 "value=\"%s\" maxlength=\"29\"></td>",
898 wprintf("<td><input type=\"text\" name=\"lastname\" "
899 "value=\"%s\" maxlength=\"29\"></td>",
901 wprintf("<td><input type=\"text\" name=\"suffix\" "
902 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
905 wprintf("<table class=\"vcard_edit_background_alt\">");
908 wprintf(_("Display name:"));
910 "<input type=\"text\" name=\"fullname\" "
911 "value=\"%s\" maxlength=\"40\"><br><br>\n",
915 wprintf(_("Title:"));
917 "<input type=\"text\" name=\"title\" "
918 "value=\"%s\" maxlength=\"40\"><br><br>\n",
922 wprintf(_("Organization:"));
924 "<input type=\"text\" name=\"org\" "
925 "value=\"%s\" maxlength=\"40\"><br><br>\n",
929 wprintf("</td><td>");
931 wprintf("<table border=0>");
933 wprintf(_("PO box:"));
935 "<input type=\"text\" name=\"pobox\" "
936 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
939 wprintf(_("Address:"));
941 "<input type=\"text\" name=\"extadr\" "
942 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
944 wprintf("<tr><td> </td><td>"
945 "<input type=\"text\" name=\"street\" "
946 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
951 "<input type=\"text\" name=\"city\" "
952 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
955 wprintf(_("State:"));
957 "<input type=\"text\" name=\"state\" "
958 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
961 wprintf(_("ZIP code:"));
963 "<input type=\"text\" name=\"zipcode\" "
964 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
967 wprintf(_("Country:"));
969 "<input type=\"text\" name=\"country\" "
970 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
972 wprintf("</table>\n");
974 wprintf("</table>\n");
976 wprintf("<table border=0><tr><td>");
977 wprintf(_("Home telephone:"));
979 "<td><input type=\"text\" name=\"hometel\" "
980 "value=\"%s\" maxlength=\"29\"></td>\n",
983 wprintf(_("Work telephone:"));
985 "<td><input type=\"text\" name=\"worktel\" "
986 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
989 wprintf(_("Mobile telephone:"));
991 "<td><input type=\"text\" name=\"mobiletel\" "
992 "value=\"%s\" maxlength=\"29\"></td>\n",
995 wprintf(_("Fax number:"));
997 "<td><input type=\"text\" name=\"faxtel\" "
998 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
1001 wprintf("<table class=\"vcard_edit_background_alt\">");
1002 wprintf("<tr><td>");
1004 wprintf("<table border=0><TR>"
1006 wprintf(_("Primary Internet e-mail address"));
1008 "<input type=\"text\" name=\"primary_inetemail\" "
1009 "size=40 maxlength=60 value=\"");
1010 escputs(primary_inetemail);
1012 "</td><td valign=top>");
1013 wprintf(_("Internet e-mail aliases"));
1015 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
1016 escputs(other_inetemail);
1017 wprintf("</textarea></td></tr></table>\n");
1019 wprintf("</td></tr></table>\n");
1021 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
1022 escputs(extrafields);
1025 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
1026 urlescputs(return_to);
1029 wprintf("<div class=\"buttons\">\n"
1030 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1032 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1038 wprintf("</td></tr></table>\n");
1039 do_template("endbox", NULL);
1042 DestroyMessageSummary(Msg);
1048 * commit the edits to the citadel server
1050 void edit_vcard(void) {
1054 msgnum = lbstr("msgnum");
1055 partnum = bstr("partnum");
1056 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1062 * parse edited vcard from the browser
1064 void submit_vcard(void) {
1065 wcsession *WCC = WC;
1067 char *serialized_vcard;
1072 if (!havebstr("ok_button")) {
1077 if (havebstr("force_room")) {
1078 if (gotoroom(sbstr("force_room")) != 200) {
1079 StrBufAppendBufPlain(WCC->ImportantMsg,
1080 _("Unable to enter the room to save your message"),
1082 StrBufAppendBufPlain(WCC->ImportantMsg,
1084 StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
1085 StrBufAppendBufPlain(WCC->ImportantMsg,
1088 StrBufAppendBufPlain(WCC->ImportantMsg,
1091 /// todo: call the master dispatcher again...
1092 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1093 select_user_to_edit(NULL);
1095 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1105 sprintf(buf, "ENT0 1|||4||");
1107 serv_getln(buf, sizeof buf);
1108 if (buf[0] != '4') {
1113 /* Make a vCard structure out of the data supplied in the form */
1115 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1118 v = VCardLoad(Buf); /** Start with the extra fields */
1121 safestrncpy(WCC->ImportantMessage,
1122 _("An error has occurred."),
1123 sizeof WCC->ImportantMessage
1129 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1135 vcard_add_prop(v, "n", buf);
1137 vcard_add_prop(v, "title", bstr("title"));
1138 vcard_add_prop(v, "fn", bstr("fullname"));
1139 vcard_add_prop(v, "org", bstr("org"));
1141 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1149 vcard_add_prop(v, "adr", buf);
1151 vcard_add_prop(v, "tel;home", bstr("hometel"));
1152 vcard_add_prop(v, "tel;work", bstr("worktel"));
1153 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1154 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1155 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1157 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1158 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1159 if (!IsEmptyStr(buf)) {
1160 vcard_add_prop(v, "email;internet", buf);
1164 serialized_vcard = vcard_serialize(v);
1166 if (serialized_vcard == NULL) {
1167 safestrncpy(WCC->ImportantMessage,
1168 _("An error has occurred."),
1169 sizeof WCC->ImportantMessage
1175 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1177 serv_printf("%s\r\n", serialized_vcard);
1179 free(serialized_vcard);
1181 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1182 select_user_to_edit(NULL);
1184 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1195 * Extract an embedded photo from a vCard for display on the client
1197 void display_vcard_photo_img(void)
1203 const char *contentType;
1204 wcsession *WCC = WC;
1206 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1208 vcard = load_mimepart(msgnum,"1");
1209 v = VCardLoad(vcard);
1211 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1212 FlushStrBuf(WCC->WBuf);
1213 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1214 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1215 FlushStrBuf(WCC->WBuf);
1217 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1218 output_headers(0, 0, 0, 0, 0, 0);
1219 hprintf("Content-Type: text/plain\r\n");
1220 wprintf(_("Could Not decode vcard photo\n"));
1224 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1225 http_transmit_thing(contentType, 0);
1236 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard, 0);
1237 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard, 0);
1238 WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img, NEED_URL);