6 * Record compare function for sorting address book indices
8 int abcmp(const void *ab1, const void *ab2) {
10 (((const addrbookent *)ab1)->ab_name),
11 (((const addrbookent *)ab2)->ab_name)
17 * Helper function for do_addrbook_view()
18 * Converts a name into a three-letter tab label
20 void nametab(char *tabbuf, long len, char *name) {
21 stresc(tabbuf, len, name, 0, 0);
22 tabbuf[0] = toupper(tabbuf[0]);
23 tabbuf[1] = tolower(tabbuf[1]);
24 tabbuf[2] = tolower(tabbuf[2]);
30 * If it's an old "Firstname Lastname" style record, try to convert it.
32 void lastfirst_firstlast(char *namebuf) {
37 if (namebuf == NULL) return;
38 if (strchr(namebuf, ';') != NULL) return;
40 i = num_tokens(namebuf, ' ');
43 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
44 remove_token(namebuf, i-1, ' ');
45 strcpy(firstname, namebuf);
46 sprintf(namebuf, "%s; %s", lastname, firstname);
51 wc_mime_attachment *load_vcard(message_summary *Msg)
54 StrBuf *FoundCharset = NewStrBuf();
59 wc_mime_attachment *Mime;
60 wc_mime_attachment *VCMime = NULL;
62 Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
63 memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
64 Msg->MsgBody->msgnum = Msg->msgnum;
66 load_message(Msg, FoundCharset, &Error);
68 FreeStrBuf(&FoundCharset);
69 /* look up the vcard... */
70 it = GetNewHashPos(Msg->AllAttach, 0);
71 while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
74 Mime = (wc_mime_attachment*) vMime;
75 if ((strcmp(ChrPtr(Mime->ContentType),
76 "text/x-vcard") == 0) ||
77 (strcmp(ChrPtr(Mime->ContentType),
93 * fetch the display name off a vCard
95 void fetch_ab_name(message_summary *Msg, char **namebuf) {
98 wc_mime_attachment *VCMime = NULL;
100 if (namebuf == NULL) return;
102 VCMime = load_vcard(Msg);
106 /* Grab the name off the card */
107 display_vcard(WC->WBuf, VCMime, 0, 0, namebuf, Msg->msgnum);
109 if (*namebuf != NULL) {
110 lastfirst_firstlast(*namebuf);
112 len = strlen(*namebuf);
113 for (i=0; i<len; ++i) {
114 if ((*namebuf)[i] != ';') return;
117 (*namebuf) = strdup(_("(no name)"));
120 (*namebuf) = strdup(_("(no name)"));
127 * Turn a vCard "n" (name) field into something displayable.
129 void vcard_n_prettyize(char *name)
134 original_name = strdup(name);
135 len = strlen(original_name);
136 for (i=0; i<5; ++i) {
138 if (original_name[len-1] == ' ') {
139 original_name[--len] = 0;
141 if (original_name[len-1] == ';') {
142 original_name[--len] = 0;
148 for (i=0; i<len; ++i) {
149 if (original_name[i] == ';') {
154 name[j++] = original_name[i];
165 * preparse a vcard name
166 * display_vcard() calls this after parsing the textual vCard into
167 * our 'struct vCard' data object.
168 * This gets called instead of display_parsed_vcard() if we are only looking
169 * to extract the person's name instead of displaying the card.
171 void fetchname_parsed_vcard(struct vCard *v, char **storename) {
181 name = vcard_get_prop(v, "n", 1, 0, 0);
184 prop = vcard_get_prop(v, "n", 1, 0, 1);
185 n = num_tokens(prop, ';');
187 for (j=0; j<n; ++j) {
188 extract_token(buf, prop, j, ';', sizeof buf);
189 if (!strcasecmp(buf, "encoding=quoted-printable")) {
192 if (!strcasecmp(buf, "encoding=base64")) {
197 // %ff can become 6 bytes in utf8
198 *storename = malloc(len * 2 + 3);
199 j = CtdlDecodeQuotedPrintable(
205 // ff will become one byte..
206 *storename = malloc(len + 50);
216 *storename = malloc(len + 3); /* \0 + eventualy missing ', '*/
217 memcpy(*storename, name, len + 1);
219 /* vcard_n_prettyize(storename); */
228 * display_vcard() calls this after parsing the textual vCard into
229 * our 'struct vCard' data object.
231 * Set 'full' to nonzero to display the full card, otherwise it will only
232 * show a summary line.
234 * This code is a bit ugly, so perhaps an explanation is due: we do this
235 * in two passes through the vCard fields. On the first pass, we process
236 * fields we understand, and then render them in a pretty fashion at the
237 * end. Then we make a second pass, outputting all the fields we don't
238 * understand in a simple two-column name/value format.
239 * v the vCard to display
240 * full display all items of the vcard?
241 * msgnum Citadel message pointer
243 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
250 char *thisname, *thisvalue;
251 char firsttoken[SIZ];
260 strcpy(fullname, "");
267 StrBufAppendPrintf(Target, "<TD>");
268 name = vcard_get_prop(v, "fn", 1, 0, 0);
270 StrEscAppend(Target, NULL, name, 0, 0);
272 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
273 strcpy(fullname, name);
274 vcard_n_prettyize(fullname);
275 StrEscAppend(Target, NULL, fullname, 0, 0);
278 StrBufAppendPrintf(Target, " ");
280 StrBufAppendPrintf(Target, "</TD>");
284 StrBufAppendPrintf(Target, "<div align=center>"
285 "<table bgcolor=#aaaaaa width=50%%>");
286 for (pass=1; pass<=2; ++pass) {
288 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
290 thisname = strdup(v->prop[i].name);
291 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
293 for (j=0; j<num_tokens(thisname, ';'); ++j) {
294 extract_token(buf, thisname, j, ';', sizeof buf);
295 if (!strcasecmp(buf, "encoding=quoted-printable")) {
297 remove_token(thisname, j, ';');
299 if (!strcasecmp(buf, "encoding=base64")) {
301 remove_token(thisname, j, ';');
305 len = strlen(v->prop[i].value);
306 /* if we have some untagged QP, detect it here. */
307 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
308 utf8ify_rfc822_string(&v->prop[i].value);
311 // %ff can become 6 bytes in utf8
312 thisvalue = malloc(len * 2 + 3);
313 j = CtdlDecodeQuotedPrintable(
314 thisvalue, v->prop[i].value,
319 // ff will become one byte..
320 thisvalue = malloc(len + 50);
322 thisvalue, v->prop[i].value,
323 strlen(v->prop[i].value) );
326 thisvalue = strdup(v->prop[i].value);
329 /* Various fields we may encounter ***/
331 /* N is name, but only if there's no FN already there */
332 if (!strcasecmp(firsttoken, "n")) {
333 if (IsEmptyStr(fullname)) {
334 strcpy(fullname, thisvalue);
335 vcard_n_prettyize(fullname);
339 /* FN (full name) is a true 'display name' field */
340 else if (!strcasecmp(firsttoken, "fn")) {
341 strcpy(fullname, thisvalue);
345 else if (!strcasecmp(firsttoken, "title")) {
346 strcpy(title, thisvalue);
350 else if (!strcasecmp(firsttoken, "org")) {
351 strcpy(org, thisvalue);
354 else if (!strcasecmp(firsttoken, "email")) {
356 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
358 "<a href=\"display_enter"
359 "?force_room=_MAIL_?recp=");
361 len = strlen(mailto);
362 urlesc(&mailto[len], SIZ - len, "\"");
363 len = strlen(mailto);
364 urlesc(&mailto[len], SIZ - len, fullname);
365 len = strlen(mailto);
366 urlesc(&mailto[len], SIZ - len, "\" <");
367 len = strlen(mailto);
368 urlesc(&mailto[len], SIZ - len, thisvalue);
369 len = strlen(mailto);
370 urlesc(&mailto[len], SIZ - len, ">");
372 strcat(mailto, "\">");
373 len = strlen(mailto);
374 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
375 strcat(mailto, "</A>");
377 else if (!strcasecmp(firsttoken, "tel")) {
378 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
379 strcat(phone, thisvalue);
380 for (j=0; j<num_tokens(thisname, ';'); ++j) {
381 extract_token(buf, thisname, j, ';', sizeof buf);
382 if (!strcasecmp(buf, "tel"))
384 else if (!strcasecmp(buf, "work"))
385 strcat(phone, _(" (work)"));
386 else if (!strcasecmp(buf, "home"))
387 strcat(phone, _(" (home)"));
388 else if (!strcasecmp(buf, "cell"))
389 strcat(phone, _(" (cell)"));
397 else if (!strcasecmp(firsttoken, "adr")) {
399 StrBufAppendPrintf(Target, "<TR><TD>");
400 StrBufAppendPrintf(Target, _("Address:"));
401 StrBufAppendPrintf(Target, "</TD><TD>");
402 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
403 extract_token(buf, thisvalue, j, ';', sizeof buf);
404 if (!IsEmptyStr(buf)) {
405 StrEscAppend(Target, NULL, buf, 0, 0);
406 if (j<3) StrBufAppendPrintf(Target, "<br />");
407 else StrBufAppendPrintf(Target, " ");
410 StrBufAppendPrintf(Target, "</TD></TR>\n");
413 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
414 // Only output on second pass
415 StrBufAppendPrintf(Target, "<tr><td>");
416 StrBufAppendPrintf(Target, _("Photo:"));
417 StrBufAppendPrintf(Target, "</td><td>");
418 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
419 StrBufAppendPrintf(Target, "</td></tr>\n");
421 else if (!strcasecmp(firsttoken, "version")) {
424 else if (!strcasecmp(firsttoken, "rev")) {
427 else if (!strcasecmp(firsttoken, "label")) {
432 /*** Don't show extra fields. They're ugly.
434 StrBufAppendPrintf(Target, "<TR><TD>");
435 StrEscAppend(Target, NULL, thisname, 0, 0);
436 StrBufAppendPrintf(Target, "</TD><TD>");
437 StrEscAppend(Target, NULL, thisvalue, 0, 0);
438 StrBufAppendPrintf(Target, "</TD></TR>\n");
448 StrBufAppendPrintf(Target, "<TR BGCOLOR=\"#AAAAAA\">"
449 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
450 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
451 "<FONT SIZE=+1><B>");
452 StrEscAppend(Target, NULL, fullname, 0, 0);
453 StrBufAppendPrintf(Target, "</B></FONT>");
454 if (!IsEmptyStr(title)) {
455 StrBufAppendPrintf(Target, "<div align=right>");
456 StrEscAppend(Target, NULL, title, 0, 0);
457 StrBufAppendPrintf(Target, "</div>");
459 if (!IsEmptyStr(org)) {
460 StrBufAppendPrintf(Target, "<div align=right>");
461 StrEscAppend(Target, NULL, org, 0, 0);
462 StrBufAppendPrintf(Target, "</div>");
464 StrBufAppendPrintf(Target, "</TD></TR>\n");
466 if (!IsEmptyStr(phone)) {
467 StrBufAppendPrintf(Target, "<tr><td>");
468 StrBufAppendPrintf(Target, _("Telephone:"));
469 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
471 if (!IsEmptyStr(mailto)) {
472 StrBufAppendPrintf(Target, "<tr><td>");
473 StrBufAppendPrintf(Target, _("E-mail:"));
474 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
480 StrBufAppendPrintf(Target, "</table></div>\n");
486 * Display a textual vCard
487 * (Converts to a vCard object and then calls the actual display function)
488 * Set 'full' to nonzero to display the whole card instead of a one-liner.
489 * Or, if "storename" is non-NULL, just store the person's name in that
490 * buffer instead of displaying the card at all.
492 * vcard_source the buffer containing the vcard text
493 * alpha Display only if name begins with this letter of the alphabet
494 * full Display the full vCard (otherwise just the display name)
495 * storename If not NULL, also store the display name here
496 * msgnum Citadel message pointer
498 void display_vcard(StrBuf *Target,
499 wc_mime_attachment *Mime,
511 v = VCardLoad(Mime->Data);
513 if (v == NULL) return;
515 name = vcard_get_prop(v, "n", 1, 0, 0);
517 Buf = NewStrBufPlain(name, -1);
518 Buf2 = NewStrBufPlain(NULL, StrLength(Buf));
519 StrBuf_RFC822_to_Utf8(Buf2, Buf, WC->DefaultCharset, NULL);
520 this_alpha = ChrPtr(Buf)[0];
525 if (storename != NULL) {
526 fetchname_parsed_vcard(v, storename);
528 else if ((alpha == 0) ||
529 ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha))) ||
530 ((!isalpha(alpha)) && (!isalpha(this_alpha)))
533 display_parsed_vcard(Target, v, full, Mime);
542 * Render the address book using info we gathered during the scan
544 * addrbook the addressbook to render
545 * num_ab the number of the addressbook
547 void do_addrbook_view(addrbookent *addrbook, int num_ab) {
551 static int NAMESPERPAGE = 60;
554 char tabfirst_label[64];
556 char tablast_label[64];
557 char this_tablabel[64];
562 wc_printf("<br /><br /><br /><div align=\"center\"><i>");
563 wc_printf(_("This address book is empty."));
564 wc_printf("</i></div>\n");
569 qsort(addrbook, num_ab, sizeof(addrbookent), abcmp);
572 num_pages = (num_ab / NAMESPERPAGE) + 1;
574 tablabels = malloc(num_pages * sizeof (char *));
575 if (tablabels == NULL) {
576 wc_printf("<br /><br /><br /><div align=\"center\"><i>");
577 wc_printf(_("An internal error has occurred."));
578 wc_printf("</i></div>\n");
582 for (i=0; i<num_pages; ++i) {
583 tabfirst = i * NAMESPERPAGE;
584 tablast = tabfirst + NAMESPERPAGE - 1;
585 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
586 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
587 nametab(tablast_label, 64, addrbook[tablast].ab_name);
588 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
589 tablabels[i] = strdup(this_tablabel);
592 tabbed_dialog(num_pages, tablabels);
595 for (i=0; i<num_ab; ++i) {
597 if ((i / NAMESPERPAGE) != page) { /* New tab */
598 page = (i / NAMESPERPAGE);
600 wc_printf("</tr></table>\n");
601 end_tab(page-1, num_pages);
603 begin_tab(page, num_pages);
604 wc_printf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
608 if ((displayed % 4) == 0) {
610 wc_printf("</tr>\n");
613 wc_printf("<tr bgcolor=\"#%s\">",
614 (bg ? "DDDDDD" : "FFFFFF")
620 wc_printf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
621 addrbook[i].ab_msgnum);
622 wc_printf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
623 vcard_n_prettyize(addrbook[i].ab_name);
624 escputs(addrbook[i].ab_name);
625 wc_printf("</a></td>\n");
629 /* Placeholders for empty columns at end */
630 if ((num_ab % 4) != 0) {
631 for (i=0; i<(4-(num_ab % 4)); ++i) {
632 wc_printf("<td> </td>");
636 wc_printf("</tr></table>\n");
637 end_tab((num_pages-1), num_pages);
639 begin_tab(num_pages, num_pages);
640 /* FIXME there ought to be something here */
641 end_tab(num_pages, num_pages);
643 for (i=0; i<num_pages; ++i) {
653 * Edit the vCard component of a MIME message.
654 * Supply the message number
655 * and MIME part number to fetch. Or, specify -1 for the message number
656 * to start with a blank card.
658 void do_edit_vcard(long msgnum, char *partnum,
659 message_summary *VCMsg,
660 wc_mime_attachment *VCAtt,
661 const char *return_to,
662 const char *force_room) {
663 message_summary *Msg = NULL;
664 wc_mime_attachment *VCMime = NULL;
672 char middlename[256];
686 char primary_inetemail[256];
687 char other_inetemail[SIZ];
688 char extrafields[SIZ];
709 primary_inetemail[0] = 0;
710 other_inetemail[0] = 0;
716 safestrncpy(whatuser, "", sizeof whatuser);
719 ((VCMsg != NULL) && (VCAtt != NULL)))
721 if ((VCMsg == NULL) && (VCAtt == NULL)) {
723 Msg = (message_summary *) malloc(sizeof(message_summary));
724 memset(Msg, 0, sizeof(message_summary));
725 Msg->msgnum = msgnum;
726 VCMime = load_vcard(Msg);
727 if (VCMime == NULL) {
728 convenience_page("770000", _("Error"), "");///TODO: important message
729 DestroyMessageSummary(Msg);
733 v = VCardLoad(VCMime->Data);
736 v = VCardLoad(VCAtt->Data);
739 /* Populate the variables for our form */
741 while (key = vcard_get_prop(v, "", 0, i, 1), key != NULL) {
742 char prp[256]; /* property name */
743 char prm[256]; /* parameters */
745 value = vcard_get_prop(v, "", 0, i++, 0);
748 extract_token(prp, key, 0, ';', sizeof prp);
749 safestrncpy(prm, key, sizeof prm);
750 remove_token(prm, 0, ';');
752 if (!strcasecmp(prp, "n")) {
753 extract_token(lastname, value, 0, ';', sizeof lastname);
754 extract_token(firstname, value, 1, ';', sizeof firstname);
755 extract_token(middlename, value, 2, ';', sizeof middlename);
756 extract_token(prefix, value, 3, ';', sizeof prefix);
757 extract_token(suffix, value, 4, ';', sizeof suffix);
760 else if (!strcasecmp(prp, "fn")) {
761 safestrncpy(fullname, value, sizeof fullname);
764 else if (!strcasecmp(prp, "title")) {
765 safestrncpy(title, value, sizeof title);
768 else if (!strcasecmp(prp, "org")) {
769 safestrncpy(org, value, sizeof org);
772 else if (!strcasecmp(prp, "adr")) {
773 extract_token(pobox, value, 0, ';', sizeof pobox);
774 extract_token(extadr, value, 1, ';', sizeof extadr);
775 extract_token(street, value, 2, ';', sizeof street);
776 extract_token(city, value, 3, ';', sizeof city);
777 extract_token(state, value, 4, ';', sizeof state);
778 extract_token(zipcode, value, 5, ';', sizeof zipcode);
779 extract_token(country, value, 6, ';', sizeof country);
782 else if (!strcasecmp(prp, "tel")) {
784 if (bmstrcasestr(prm, "home")) {
785 extract_token(hometel, value, 0, ';', sizeof hometel);
787 else if (bmstrcasestr(prm, "work")) {
788 extract_token(worktel, value, 0, ';', sizeof worktel);
790 else if (bmstrcasestr(prm, "fax")) {
791 extract_token(faxtel, value, 0, ';', sizeof faxtel);
793 else if (bmstrcasestr(prm, "cell")) {
794 extract_token(mobiletel, value, 0, ';', sizeof mobiletel);
796 else { /* Missing or unknown type; put it in the home phone */
797 extract_token(hometel, value, 0, ';', sizeof hometel);
801 else if ( (!strcasecmp(prp, "email")) && (bmstrcasestr(prm, "internet")) ) {
802 if (primary_inetemail[0] == 0) {
803 safestrncpy(primary_inetemail, value, sizeof primary_inetemail);
806 if (other_inetemail[0] != 0) {
807 strcat(other_inetemail, "\n");
809 strcat(other_inetemail, value);
813 /* Unrecognized properties are preserved here so we don't discard them
814 * just because the vCard was edited with WebCit.
817 strcat(extrafields, key);
818 strcat(extrafields, ":");
819 strcat(extrafields, value);
820 strcat(extrafields, "\n");
828 /* Display the form */
829 output_headers(1, 1, 1, 0, 0, 0);
831 do_template("beginbox_1", NULL);
832 StrBufAppendBufPlain(WC->WBuf, _("Edit contact information"), -1, 0);
833 do_template("beginbox_2", NULL);
835 wc_printf("<form method=\"POST\" action=\"submit_vcard\">\n");
836 wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
838 if (force_room != NULL) {
839 wc_printf("<input type=\"hidden\" name=\"force_room\" value=\"");
844 wc_printf("<table class=\"vcard_edit_background\"><tr><td>\n");
846 wc_printf("<table border=0><tr>"
851 "<td>%s</td></tr>\n",
852 _("Prefix"), _("First Name"), _("Middle Name"), _("Last Name"), _("Suffix")
854 wc_printf("<tr><td><input type=\"text\" name=\"prefix\" "
855 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
857 wc_printf("<td><input type=\"text\" name=\"firstname\" "
858 "value=\"%s\" maxlength=\"29\"></td>",
860 wc_printf("<td><input type=\"text\" name=\"middlename\" "
861 "value=\"%s\" maxlength=\"29\"></td>",
863 wc_printf("<td><input type=\"text\" name=\"lastname\" "
864 "value=\"%s\" maxlength=\"29\"></td>",
866 wc_printf("<td><input type=\"text\" name=\"suffix\" "
867 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
870 wc_printf("<table class=\"vcard_edit_background_alt\">");
871 wc_printf("<tr><td>");
873 wc_printf(_("Display name:"));
875 "<input type=\"text\" name=\"fullname\" "
876 "value=\"%s\" maxlength=\"40\"><br><br>\n",
880 wc_printf(_("Title:"));
882 "<input type=\"text\" name=\"title\" "
883 "value=\"%s\" maxlength=\"40\"><br><br>\n",
887 wc_printf(_("Organization:"));
889 "<input type=\"text\" name=\"org\" "
890 "value=\"%s\" maxlength=\"40\"><br><br>\n",
894 wc_printf("</td><td>");
896 wc_printf("<table border=0>");
897 wc_printf("<tr><td>");
898 wc_printf(_("PO box:"));
899 wc_printf("</td><td>"
900 "<input type=\"text\" name=\"pobox\" "
901 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
903 wc_printf("<tr><td>");
904 wc_printf(_("Address:"));
905 wc_printf("</td><td>"
906 "<input type=\"text\" name=\"extadr\" "
907 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
909 wc_printf("<tr><td> </td><td>"
910 "<input type=\"text\" name=\"street\" "
911 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
913 wc_printf("<tr><td>");
914 wc_printf(_("City:"));
915 wc_printf("</td><td>"
916 "<input type=\"text\" name=\"city\" "
917 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
919 wc_printf("<tr><td>");
920 wc_printf(_("State:"));
921 wc_printf("</td><td>"
922 "<input type=\"text\" name=\"state\" "
923 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
925 wc_printf("<tr><td>");
926 wc_printf(_("ZIP code:"));
927 wc_printf("</td><td>"
928 "<input type=\"text\" name=\"zipcode\" "
929 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
931 wc_printf("<tr><td>");
932 wc_printf(_("Country:"));
933 wc_printf("</td><td>"
934 "<input type=\"text\" name=\"country\" "
935 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
937 wc_printf("</table>\n");
939 wc_printf("</table>\n");
941 wc_printf("<table border=0><tr><td>");
942 wc_printf(_("Home telephone:"));
944 "<td><input type=\"text\" name=\"hometel\" "
945 "value=\"%s\" maxlength=\"29\"></td>\n",
948 wc_printf(_("Work telephone:"));
950 "<td><input type=\"text\" name=\"worktel\" "
951 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
953 wc_printf("<tr><td>");
954 wc_printf(_("Mobile telephone:"));
956 "<td><input type=\"text\" name=\"mobiletel\" "
957 "value=\"%s\" maxlength=\"29\"></td>\n",
960 wc_printf(_("Fax number:"));
962 "<td><input type=\"text\" name=\"faxtel\" "
963 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
966 wc_printf("<table class=\"vcard_edit_background_alt\">");
967 wc_printf("<tr><td>");
969 wc_printf("<table border=0><TR>"
971 wc_printf(_("Primary Internet e-mail address"));
973 "<input type=\"text\" name=\"primary_inetemail\" "
974 "size=40 maxlength=60 value=\"");
975 escputs(primary_inetemail);
976 wc_printf("\"><br />"
977 "</td><td valign=top>");
978 wc_printf(_("Internet e-mail aliases"));
980 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
981 escputs(other_inetemail);
982 wc_printf("</textarea></td></tr></table>\n");
984 wc_printf("</td></tr></table>\n");
986 wc_printf("<input type=\"hidden\" name=\"extrafields\" value=\"");
987 escputs(extrafields);
990 wc_printf("<input type=\"hidden\" name=\"return_to\" value=\"");
994 wc_printf("<div class=\"buttons\">\n"
995 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
997 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1003 wc_printf("</td></tr></table>\n");
1004 do_template("endbox", NULL);
1007 DestroyMessageSummary(Msg);
1013 * commit the edits to the citadel server
1015 void edit_vcard(void) {
1019 msgnum = lbstr("msgnum");
1020 partnum = bstr("partnum");
1021 do_edit_vcard(msgnum, partnum, NULL, NULL, "", NULL);
1027 * parse edited vcard from the browser
1029 void submit_vcard(void) {
1030 wcsession *WCC = WC;
1032 char *serialized_vcard;
1037 if (!havebstr("ok_button")) {
1038 readloop(readnew, eUseDefault);
1042 if (havebstr("force_room")) {
1043 if (gotoroom(sbstr("force_room")) != 200) {
1044 StrBufAppendBufPlain(WCC->ImportantMsg,
1045 _("Unable to enter the room to save your message"),
1047 StrBufAppendBufPlain(WCC->ImportantMsg,
1049 StrBufAppendBuf(WCC->ImportantMsg, sbstr("force_room"), 0);
1050 StrBufAppendBufPlain(WCC->ImportantMsg,
1053 StrBufAppendBufPlain(WCC->ImportantMsg,
1057 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1058 select_user_to_edit(NULL);
1060 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1063 else if (!IsEmptyStr(bstr("return_to"))) {
1064 http_redirect(bstr("return_to"));
1067 readloop(readnew, eUseDefault);
1073 sprintf(buf, "ENT0 1|||4||");
1075 serv_getln(buf, sizeof buf);
1076 if (buf[0] != '4') {
1081 /* Make a vCard structure out of the data supplied in the form */
1083 StrBufPrintf(Buf, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1086 v = VCardLoad(Buf); /* Start with the extra fields */
1089 safestrncpy(WCC->ImportantMessage,
1090 _("An error has occurred."),
1091 sizeof WCC->ImportantMessage
1097 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s",
1103 vcard_add_prop(v, "n", buf);
1105 vcard_add_prop(v, "title", bstr("title"));
1106 vcard_add_prop(v, "fn", bstr("fullname"));
1107 vcard_add_prop(v, "org", bstr("org"));
1109 snprintf(buf, sizeof buf, "%s;%s;%s;%s;%s;%s;%s",
1117 vcard_add_prop(v, "adr", buf);
1119 vcard_add_prop(v, "tel;home", bstr("hometel"));
1120 vcard_add_prop(v, "tel;work", bstr("worktel"));
1121 vcard_add_prop(v, "tel;fax", bstr("faxtel"));
1122 vcard_add_prop(v, "tel;cell", bstr("mobiletel"));
1123 vcard_add_prop(v, "email;internet", bstr("primary_inetemail"));
1125 for (i=0; i<num_tokens(bstr("other_inetemail"), '\n'); ++i) {
1126 extract_token(buf, bstr("other_inetemail"), i, '\n', sizeof buf);
1127 if (!IsEmptyStr(buf)) {
1128 vcard_add_prop(v, "email;internet", buf);
1132 serialized_vcard = vcard_serialize(v);
1134 if (serialized_vcard == NULL) {
1135 safestrncpy(WCC->ImportantMessage,
1136 _("An error has occurred."),
1137 sizeof WCC->ImportantMessage
1143 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1145 serv_printf("%s\r\n", serialized_vcard);
1147 free(serialized_vcard);
1149 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1150 select_user_to_edit(NULL);
1152 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1155 else if (!IsEmptyStr(bstr("return_to"))) {
1156 http_redirect(bstr("return_to"));
1159 readloop(readnew, eUseDefault);
1166 * Extract an embedded photo from a vCard for display on the client
1168 void display_vcard_photo_img(void)
1174 const char *contentType;
1175 wcsession *WCC = WC;
1177 msgnum = StrBufExtract_long(WCC->Hdr->HR.ReqLine, 0, '/');
1179 vcard = load_mimepart(msgnum,"1");
1180 v = VCardLoad(vcard);
1182 photosrc = vcard_get_prop(v, "PHOTO", 1,0,0);
1183 FlushStrBuf(WCC->WBuf);
1184 StrBufAppendBufPlain(WCC->WBuf, photosrc, -1, 0);
1185 if (StrBufDecodeBase64(WCC->WBuf) <= 0) {
1186 FlushStrBuf(WCC->WBuf);
1188 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1189 output_headers(0, 0, 0, 0, 0, 0);
1190 hprintf("Content-Type: text/plain\r\n");
1192 wc_printf(_("Could Not decode vcard photo\n"));
1196 contentType = GuessMimeType(ChrPtr(WCC->WBuf), StrLength(WCC->WBuf));
1197 http_transmit_thing(contentType, 0);
1202 typedef struct _vcardview_struct {
1204 addrbookent *addrbook;
1209 int vcard_GetParamsGetServerCall(SharedMessageStatus *Stat,
1210 void **ViewSpecific,
1215 vcardview_struct *VS;
1217 VS = (vcardview_struct*) malloc (sizeof(vcardview_struct));
1218 memset(VS, 0, sizeof(vcardview_struct));
1219 *ViewSpecific = (void*)VS;
1221 VS->is_singlecard = ibstr("is_singlecard");
1222 if (VS->is_singlecard != 1) {
1223 if (oper == do_search) {
1224 snprintf(cmd, len, "MSGS SEARCH|%s", bstr("query"));
1227 strcpy(cmd, "MSGS ALL");
1229 Stat->maxmsgs = 9999999;
1234 int vcard_LoadMsgFromServer(SharedMessageStatus *Stat,
1235 void **ViewSpecific,
1236 message_summary* Msg,
1240 vcardview_struct *VS;
1243 VS = (vcardview_struct*) *ViewSpecific;
1246 fetch_ab_name(Msg, &ab_name);
1247 if (ab_name == NULL)
1250 VS->addrbook = realloc(VS->addrbook,
1251 (sizeof(addrbookent) * VS->num_ab) );
1252 safestrncpy(VS->addrbook[VS->num_ab-1].ab_name, ab_name,
1253 sizeof(VS->addrbook[VS->num_ab-1].ab_name));
1254 VS->addrbook[VS->num_ab-1].ab_msgnum = Msg->msgnum;
1260 int vcard_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, long oper)
1263 vcardview_struct *VS;
1265 VS = (vcardview_struct*) *ViewSpecific;
1266 if (VS->is_singlecard)
1267 read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
1269 do_addrbook_view(VS->addrbook, VS->num_ab); /* Render the address book */
1273 int vcard_Cleanup(void **ViewSpecific)
1275 vcardview_struct *VS;
1277 VS = (vcardview_struct*) *ViewSpecific;
1280 (VS->addrbook != NULL))
1291 RegisterReadLoopHandlerset(
1293 vcard_GetParamsGetServerCall,
1296 vcard_LoadMsgFromServer,
1297 vcard_RenderView_or_Tail,
1299 WebcitAddUrlHandler(HKEY("edit_vcard"), "", 0, edit_vcard, 0);
1300 WebcitAddUrlHandler(HKEY("submit_vcard"), "", 0, submit_vcard, 0);
1301 WebcitAddUrlHandler(HKEY("vcardphoto"), "", 0, display_vcard_photo_img, NEED_URL);