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 char *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(WC->wc_roomname, USERCONFIGROOM))
65 || (!strcasecmp(&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"));
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 char *vcard_source = NULL;
118 message_summary summ;/// TODO this will lak
120 if (namebuf == NULL) return;
123 memset(&summ, 0, sizeof(summ));
124 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
126 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
128 serv_getln(buf, sizeof buf);
129 if (buf[0] != '1') return;
131 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
132 if (!strncasecmp(buf, "part=", 5)) {
133 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
134 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
135 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
136 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
137 mime_length = extract_int(&buf[5], 5);
139 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
140 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
141 strcpy(vcard_partnum, mime_partnum);
147 if (!IsEmptyStr(vcard_partnum)) {
148 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
149 if (vcard_source != NULL) {
151 /* Grab the name off the card */
152 display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
158 lastfirst_firstlast(namebuf);
160 len = strlen(namebuf);
161 for (i=0; i<len; ++i) {
162 if (namebuf[i] != ';') return;
164 strcpy(namebuf, _("(no name)"));
170 * \brief Turn a vCard "n" (name) field into something displayable.
171 * \param name the name field to convert
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 * \brief 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.
214 * \param v the vcard to retrieve the name from
215 * \param storename where to put the name at
217 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
220 strcpy(storename, "");
222 name = vcard_get_prop(v, "n", 1, 0, 0);
224 strcpy(storename, name);
225 /* vcard_n_prettyize(storename); */
233 * \brief html print a vcard
234 * display_vcard() calls this after parsing the textual vCard into
235 * our 'struct vCard' data object.
237 * Set 'full' to nonzero to display the full card, otherwise it will only
238 * show a summary line.
240 * This code is a bit ugly, so perhaps an explanation is due: we do this
241 * in two passes through the vCard fields. On the first pass, we process
242 * fields we understand, and then render them in a pretty fashion at the
243 * end. Then we make a second pass, outputting all the fields we don't
244 * understand in a simple two-column name/value format.
245 * \param v the vCard to display
246 * \param full display all items of the vcard?
247 * \param msgnum Citadel message pointer
249 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, long msgnum) {
255 char *thisname, *thisvalue;
256 char firsttoken[SIZ];
265 strcpy(fullname, "");
272 StrBufAppendPrintf(Target, "<TD>");
273 name = vcard_get_prop(v, "fn", 1, 0, 0);
275 StrEscAppend(Target, NULL, name, 0, 0);
277 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
278 strcpy(fullname, name);
279 vcard_n_prettyize(fullname);
280 StrEscAppend(Target, NULL, fullname, 0, 0);
283 StrBufAppendPrintf(Target, " ");
285 StrBufAppendPrintf(Target, "</TD>");
289 StrBufAppendPrintf(Target, "<div align=center>"
290 "<table bgcolor=#aaaaaa width=50%%>");
291 for (pass=1; pass<=2; ++pass) {
293 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
295 thisname = strdup(v->prop[i].name);
296 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
298 for (j=0; j<num_tokens(thisname, ';'); ++j) {
299 extract_token(buf, thisname, j, ';', sizeof buf);
300 if (!strcasecmp(buf, "encoding=quoted-printable")) {
302 remove_token(thisname, j, ';');
304 if (!strcasecmp(buf, "encoding=base64")) {
306 remove_token(thisname, j, ';');
310 len = strlen(v->prop[i].value);
311 /* if we have some untagged QP, detect it here. */
312 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
313 utf8ify_rfc822_string(v->prop[i].value);
316 // %ff can become 6 bytes in utf8
317 thisvalue = malloc(len * 2 + 3);
318 j = CtdlDecodeQuotedPrintable(
319 thisvalue, v->prop[i].value,
324 // ff will become one byte..
325 thisvalue = malloc(len + 50);
327 thisvalue, v->prop[i].value,
328 strlen(v->prop[i].value) );
331 thisvalue = strdup(v->prop[i].value);
334 /** Various fields we may encounter ***/
336 /** N is name, but only if there's no FN already there */
337 if (!strcasecmp(firsttoken, "n")) {
338 if (IsEmptyStr(fullname)) {
339 strcpy(fullname, thisvalue);
340 vcard_n_prettyize(fullname);
344 /** FN (full name) is a true 'display name' field */
345 else if (!strcasecmp(firsttoken, "fn")) {
346 strcpy(fullname, thisvalue);
350 else if (!strcasecmp(firsttoken, "title")) {
351 strcpy(title, thisvalue);
355 else if (!strcasecmp(firsttoken, "org")) {
356 strcpy(org, thisvalue);
359 else if (!strcasecmp(firsttoken, "email")) {
361 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
363 "<a href=\"display_enter"
364 "?force_room=_MAIL_?recp=");
366 len = strlen(mailto);
367 urlesc(&mailto[len], SIZ - len, "\"");
368 len = strlen(mailto);
369 urlesc(&mailto[len], SIZ - len, fullname);
370 len = strlen(mailto);
371 urlesc(&mailto[len], SIZ - len, "\" <");
372 len = strlen(mailto);
373 urlesc(&mailto[len], SIZ - len, thisvalue);
374 len = strlen(mailto);
375 urlesc(&mailto[len], SIZ - len, ">");
377 strcat(mailto, "\">");
378 len = strlen(mailto);
379 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
380 strcat(mailto, "</A>");
382 else if (!strcasecmp(firsttoken, "tel")) {
383 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
384 strcat(phone, thisvalue);
385 for (j=0; j<num_tokens(thisname, ';'); ++j) {
386 extract_token(buf, thisname, j, ';', sizeof buf);
387 if (!strcasecmp(buf, "tel"))
389 else if (!strcasecmp(buf, "work"))
390 strcat(phone, _(" (work)"));
391 else if (!strcasecmp(buf, "home"))
392 strcat(phone, _(" (home)"));
393 else if (!strcasecmp(buf, "cell"))
394 strcat(phone, _(" (cell)"));
402 else if (!strcasecmp(firsttoken, "adr")) {
404 StrBufAppendPrintf(Target, "<TR><TD>");
405 StrBufAppendPrintf(Target, _("Address:"));
406 StrBufAppendPrintf(Target, "</TD><TD>");
407 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
408 extract_token(buf, thisvalue, j, ';', sizeof buf);
409 if (!IsEmptyStr(buf)) {
410 StrEscAppend(Target, NULL, buf, 0, 0);
411 if (j<3) StrBufAppendPrintf(Target, "<br />");
412 else StrBufAppendPrintf(Target, " ");
415 StrBufAppendPrintf(Target, "</TD></TR>\n");
418 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
419 // Only output on second pass
420 StrBufAppendPrintf(Target, "<tr><td>");
421 StrBufAppendPrintf(Target, _("Photo:"));
422 StrBufAppendPrintf(Target, "</td><td>");
423 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
424 StrBufAppendPrintf(Target, "</td></tr>\n");
426 else if (!strcasecmp(firsttoken, "version")) {
429 else if (!strcasecmp(firsttoken, "rev")) {
432 else if (!strcasecmp(firsttoken, "label")) {
437 /*** Don't show extra fields. They're ugly.
439 StrBufAppendPrintf(Target, "<TR><TD>");
440 StrEscAppend(Target, NULL, thisname, 0, 0);
441 StrBufAppendPrintf(Target, "</TD><TD>");
442 StrEscAppend(Target, NULL, thisvalue, 0, 0);
443 StrBufAppendPrintf(Target, "</TD></TR>\n");
453 StrBufAppendPrintf(Target, "<TR BGCOLOR=\"#AAAAAA\">"
454 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
455 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
456 "<FONT SIZE=+1><B>");
457 StrEscAppend(Target, NULL, fullname, 0, 0);
458 StrBufAppendPrintf(Target, "</B></FONT>");
459 if (!IsEmptyStr(title)) {
460 StrBufAppendPrintf(Target, "<div align=right>");
461 StrEscAppend(Target, NULL, title, 0, 0);
462 StrBufAppendPrintf(Target, "</div>");
464 if (!IsEmptyStr(org)) {
465 StrBufAppendPrintf(Target, "<div align=right>");
466 StrEscAppend(Target, NULL, org, 0, 0);
467 StrBufAppendPrintf(Target, "</div>");
469 StrBufAppendPrintf(Target, "</TD></TR>\n");
471 if (!IsEmptyStr(phone)) {
472 StrBufAppendPrintf(Target, "<tr><td>");
473 StrBufAppendPrintf(Target, _("Telephone:"));
474 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
476 if (!IsEmptyStr(mailto)) {
477 StrBufAppendPrintf(Target, "<tr><td>");
478 StrBufAppendPrintf(Target, _("E-mail:"));
479 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
485 StrBufAppendPrintf(Target, "</table></div>\n");
491 * \brief Display a textual vCard
492 * (Converts to a vCard object and then calls the actual display function)
493 * Set 'full' to nonzero to display the whole card instead of a one-liner.
494 * Or, if "storename" is non-NULL, just store the person's name in that
495 * buffer instead of displaying the card at all.
496 * \param vcard_source the buffer containing the vcard text
497 * \param alpha what???
498 * \param full should we usse all lines?
499 * \param storename where to store???
500 * \param msgnum Citadel message pointer
502 void display_vcard(StrBuf *Target, const char *vcard_source, char alpha, int full, char *storename,
509 v = vcard_load((char*)vcard_source); ///TODO
511 if (v == NULL) return;
513 name = vcard_get_prop(v, "n", 1, 0, 0);
515 utf8ify_rfc822_string(name);
520 if (storename != NULL) {
521 fetchname_parsed_vcard(v, storename);
523 else if ( (alpha == 0)
524 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
525 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
527 display_parsed_vcard(Target, v, full,msgnum);
536 * \brief Render the address book using info we gathered during the scan
537 * \param addrbook the addressbook to render
538 * \param num_ab the number of the addressbook
540 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
544 static int NAMESPERPAGE = 60;
547 char tabfirst_label[64];
549 char tablast_label[64];
550 char this_tablabel[64];
555 wprintf("<br /><br /><br /><div align=\"center\"><i>");
556 wprintf(_("This address book is empty."));
557 wprintf("</i></div>\n");
562 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
565 num_pages = (num_ab / NAMESPERPAGE) + 1;
567 tablabels = malloc(num_pages * sizeof (char *));
568 if (tablabels == NULL) {
569 wprintf("<br /><br /><br /><div align=\"center\"><i>");
570 wprintf(_("An internal error has occurred."));
571 wprintf("</i></div>\n");
575 for (i=0; i<num_pages; ++i) {
576 tabfirst = i * NAMESPERPAGE;
577 tablast = tabfirst + NAMESPERPAGE - 1;
578 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
579 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
580 nametab(tablast_label, 64, addrbook[tablast].ab_name);
581 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
582 tablabels[i] = strdup(this_tablabel);
585 tabbed_dialog(num_pages, tablabels);
588 for (i=0; i<num_ab; ++i) {
590 if ((i / NAMESPERPAGE) != page) { /* New tab */
591 page = (i / NAMESPERPAGE);
593 wprintf("</tr></table>\n");
594 end_tab(page-1, num_pages);
596 begin_tab(page, num_pages);
597 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
601 if ((displayed % 4) == 0) {
606 wprintf("<tr bgcolor=\"#%s\">",
607 (bg ? "DDDDDD" : "FFFFFF")
613 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
614 addrbook[i].ab_msgnum);
615 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
616 vcard_n_prettyize(addrbook[i].ab_name);
617 escputs(addrbook[i].ab_name);
618 wprintf("</a></td>\n");
622 /* Placeholders for empty columns at end */
623 if ((num_ab % 4) != 0) {
624 for (i=0; i<(4-(num_ab % 4)); ++i) {
625 wprintf("<td> </td>");
629 wprintf("</tr></table>\n");
630 end_tab((num_pages-1), num_pages);
632 begin_tab(num_pages, num_pages);
633 /* FIXME there ought to be something here */
634 end_tab(num_pages, num_pages);
636 for (i=0; i<num_pages; ++i) {
646 * Edit the vCard component of a MIME message.
647 * Supply the message number
648 * and MIME part number to fetch. Or, specify -1 for the message number
649 * to start with a blank card.
651 void do_edit_vcard(long msgnum, char *partnum, char *return_to, char *force_room) {
653 char *serialized_vcard = NULL;
654 size_t total_len = 0;
662 char middlename[256];
676 char primary_inetemail[256];
677 char other_inetemail[SIZ];
678 char extrafields[SIZ];
699 primary_inetemail[0] = 0;
700 other_inetemail[0] = 0;
706 safestrncpy(whatuser, "", sizeof whatuser);
709 sprintf(buf, "MSG0 %ld|1", msgnum);
711 serv_getln(buf, sizeof buf);
713 convenience_page("770000", _("Error"), &buf[4]);
716 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
717 if (!strncasecmp(buf, "from=", 5)) {
718 safestrncpy(whatuser, &buf[5], sizeof whatuser);
720 else if (!strncasecmp(buf, "node=", 5)) {
721 strcat(whatuser, " @ ");
722 strcat(whatuser, &buf[5]);
726 sprintf(buf, "DLAT %ld|%s", msgnum, partnum);
728 serv_getln(buf, sizeof buf);
730 convenience_page("770000", "Error", &buf[4]);
734 total_len = atoi(&buf[4]);
735 serialized_vcard = malloc(total_len + 2);
737 serv_read(serialized_vcard, total_len);
738 serialized_vcard[total_len] = 0;
740 v = vcard_load(serialized_vcard);
741 free(serialized_vcard);
743 /* Populate the variables for our form */
745 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
746 value = vcard_get_prop(v, "", 0, i++, 0);
748 if (!strcasecmp(key, "n")) {
749 extract_token(lastname, value, 0, ';', sizeof lastname);
750 extract_token(firstname, value, 1, ';', sizeof firstname);
751 extract_token(middlename, value, 2, ';', sizeof middlename);
752 extract_token(prefix, value, 3, ';', sizeof prefix);
753 extract_token(suffix, value, 4, ';', sizeof suffix);
756 else if (!strcasecmp(key, "fn")) {
757 safestrncpy(fullname, value, sizeof fullname);
760 else if (!strcasecmp(key, "title")) {
761 safestrncpy(title, value, sizeof title);
764 else if (!strcasecmp(key, "org")) {
765 safestrncpy(org, value, sizeof org);
768 else if ( (!strcasecmp(key, "adr")) || (!strncasecmp(key, "adr;", 4)) ) {
769 extract_token(pobox, value, 0, ';', sizeof pobox);
770 extract_token(extadr, value, 1, ';', sizeof extadr);
771 extract_token(street, value, 2, ';', sizeof street);
772 extract_token(city, value, 3, ';', sizeof city);
773 extract_token(state, value, 4, ';', sizeof state);
774 extract_token(zipcode, value, 5, ';', sizeof zipcode);
775 extract_token(country, value, 6, ';', sizeof country);
778 else if ( (!strcasecmp(key, "tel;home")) || (!strcasecmp(key, "tel;type=home")) ) {
779 extract_token(hometel, value, 0, ';', sizeof hometel);
782 else if ( (!strcasecmp(key, "tel;work")) || (!strcasecmp(key, "tel;type=work")) ) {
783 extract_token(worktel, value, 0, ';', sizeof worktel);
786 else if ( (!strcasecmp(key, "tel;fax")) || (!strcasecmp(key, "tel;type=fax")) ) {
787 extract_token(faxtel, value, 0, ';', sizeof faxtel);
790 else if ( (!strcasecmp(key, "tel;cell")) || (!strcasecmp(key, "tel;type=cell")) ) {
791 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
794 else if ( (!strcasecmp(key, "email;internet"))
795 || (!strcasecmp(key, "email;type=internet")) ) {
796 if (primary_inetemail[0] == 0) {
797 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
800 if (other_inetemail[0] != 0) {
801 strcat(other_inetemail, "\n");
803 strcat(other_inetemail, value);
808 strcat(extrafields, key);
809 strcat(extrafields, ":");
810 strcat(extrafields, value);
811 strcat(extrafields, "\n");
819 /** Display the form */
820 output_headers(1, 1, 1, 0, 0, 0);
822 svput("BOXTITLE", WCS_STRING, _("Edit contact information"));
823 do_template("beginboxx", NULL);
825 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
826 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
828 if (force_room != NULL) {
829 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
834 wprintf("<div class=\"fix_scrollbar_bug\">"
835 "<table class=\"vcard_edit_background\"><tr><td>\n");
837 wprintf("<table border=0><tr>"
842 "<td>%s</td></tr>\n",
843 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
845 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
846 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
848 wprintf("<td><input type=\"text\" name=\"firstname\" "
849 "value=\"%s\" maxlength=\"29\"></td>",
851 wprintf("<td><input type=\"text\" name=\"middlename\" "
852 "value=\"%s\" maxlength=\"29\"></td>",
854 wprintf("<td><input type=\"text\" name=\"lastname\" "
855 "value=\"%s\" maxlength=\"29\"></td>",
857 wprintf("<td><input type=\"text\" name=\"suffix\" "
858 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
861 wprintf("<table class=\"vcard_edit_background_alt\">");
864 wprintf(_("Display name:"));
866 "<input type=\"text\" name=\"fullname\" "
867 "value=\"%s\" maxlength=\"40\"><br><br>\n",
871 wprintf(_("Title:"));
873 "<input type=\"text\" name=\"title\" "
874 "value=\"%s\" maxlength=\"40\"><br><br>\n",
878 wprintf(_("Organization:"));
880 "<input type=\"text\" name=\"org\" "
881 "value=\"%s\" maxlength=\"40\"><br><br>\n",
885 wprintf("</td><td>");
887 wprintf("<table border=0>");
889 wprintf(_("PO box:"));
891 "<input type=\"text\" name=\"pobox\" "
892 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
895 wprintf(_("Address:"));
897 "<input type=\"text\" name=\"extadr\" "
898 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
900 wprintf("<tr><td> </td><td>"
901 "<input type=\"text\" name=\"street\" "
902 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
907 "<input type=\"text\" name=\"city\" "
908 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
911 wprintf(_("State:"));
913 "<input type=\"text\" name=\"state\" "
914 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
917 wprintf(_("ZIP code:"));
919 "<input type=\"text\" name=\"zipcode\" "
920 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
923 wprintf(_("Country:"));
925 "<input type=\"text\" name=\"country\" "
926 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
928 wprintf("</table>\n");
930 wprintf("</table>\n");
932 wprintf("<table border=0><tr><td>");
933 wprintf(_("Home telephone:"));
935 "<td><input type=\"text\" name=\"hometel\" "
936 "value=\"%s\" maxlength=\"29\"></td>\n",
939 wprintf(_("Work telephone:"));
941 "<td><input type=\"text\" name=\"worktel\" "
942 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
945 wprintf(_("Mobile telephone:"));
947 "<td><input type=\"text\" name=\"mobiletel\" "
948 "value=\"%s\" maxlength=\"29\"></td>\n",
951 wprintf(_("Fax number:"));
953 "<td><input type=\"text\" name=\"faxtel\" "
954 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
957 wprintf("<table class=\"vcard_edit_background_alt\">");
960 wprintf("<table border=0><TR>"
962 wprintf(_("Primary Internet e-mail address"));
964 "<input type=\"text\" name=\"primary_inetemail\" "
965 "size=40 maxlength=60 value=\"");
966 escputs(primary_inetemail);
968 "</td><td valign=top>");
969 wprintf(_("Internet e-mail aliases"));
971 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
972 escputs(other_inetemail);
973 wprintf("</textarea></td></tr></table>\n");
975 wprintf("</td></tr></table>\n");
977 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
978 escputs(extrafields);
981 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
982 urlescputs(return_to);
985 wprintf("<div class=\"buttons\">\n"
986 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
988 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
994 wprintf("</td></tr></table>\n");
995 do_template("endbox", NULL);
1001 * commit the edits to the citadel server
1003 void edit_vcard(void) {
1007 msgnum = lbstr("msgnum");
1008 partnum = bstr("partnum");
1009 do_edit_vcard(msgnum, partnum, "", NULL);
1015 * parse edited vcard from the browser
1017 void submit_vcard(void) {
1019 char *serialized_vcard;
1023 if (!havebstr("ok_button")) {
1028 if (havebstr("force_room")) {
1029 gotoroom(bstr("force_room"));
1032 sprintf(buf, "ENT0 1|||4||");
1034 serv_getln(buf, sizeof buf);
1035 if (buf[0] != '4') {
1040 /** Make a vCard structure out of the data supplied in the form */
1042 snprintf(buf, sizeof buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1045 v = vcard_load(buf); /** Start with the extra fields */
1047 safestrncpy(WC->ImportantMessage,
1048 _("An error has occurred."),
1049 sizeof WC->ImportantMessage
1055 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1061 vcard_add_prop(v, "n", buf);
1063 vcard_add_prop(v, "title", bstr("title"));
1064 vcard_add_prop(v, "fn", bstr("fullname"));
1065 vcard_add_prop(v, "org", bstr("org"));
1067 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1075 vcard_add_prop(v, "adr", buf);
1077 vcard_add_prop(v, "tel;home", bstr("hometel"));
1078 vcard_add_prop(v, "tel;work", bstr("worktel"));
1079 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1080 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1081 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1083 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1084 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1085 if (!IsEmptyStr(buf)) {
1086 vcard_add_prop(v, "email;internet", buf);
1090 serialized_vcard = vcard_serialize(v);
1092 if (serialized_vcard == NULL) {
1093 safestrncpy(WC->ImportantMessage,
1094 _("An error has occurred."),
1095 sizeof WC->ImportantMessage
1101 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1103 serv_printf("%s\r\n", serialized_vcard);
1105 free(serialized_vcard);
1107 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1108 select_user_to_edit(NULL, NULL);
1110 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1121 * Extract an embedded photo from a vCard for display on the client
1123 void display_vcard_photo_img(void)
1129 const char *contentType;
1130 struct wcsession *WCC = WC;
1132 msgnum = StrTol(WCC->UrlFragment2);
1134 vcard = load_mimepart(msgnum,"1");
1135 v = vcard_load(vcard);
1137 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1138 FlushStrBuf(WCC->WBuf);
1139 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1140 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1141 FlushStrBuf(WCC->WBuf);
1143 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1144 output_headers(0, 0, 0, 0, 0, 0);
1145 hprintf("Content-Type: text/plain\r\n");
1146 wprintf(_("Could Not decode vcard photo\n"));
1150 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1151 http_transmit_thing(contentType, 0);
1162 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard, 0);
1163 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard, 0);
1164 WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img, NEED_URL);