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(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"));
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
,
510 v
= vcard_load((char*)vcard_source
); ///TODO
512 if (v
== NULL
) return;
514 name
= vcard_get_prop(v
, "n", 1, 0, 0);
516 Buf
= NewStrBufPlain(name
, -1);
517 Buf2
= NewStrBufPlain(NULL
, StrLength(Buf
));
518 StrBuf_RFC822_to_Utf8(Buf2
, Buf
, WC
->DefaultCharset
, NULL
);
519 this_alpha
= ChrPtr(Buf
)[0];
524 if (storename
!= NULL
) {
525 fetchname_parsed_vcard(v
, storename
);
527 else if ( (alpha
== 0)
528 || ((isalpha(alpha
)) && (tolower(alpha
) == tolower(this_alpha
)) )
529 || ((!isalpha(alpha
)) && (!isalpha(this_alpha
)))
531 display_parsed_vcard(Target
, v
, full
,msgnum
);
540 * \brief Render the address book using info we gathered during the scan
541 * \param addrbook the addressbook to render
542 * \param num_ab the number of the addressbook
544 void do_addrbook_view(addrbookent
*addrbook
, int num_ab
) {
548 static int NAMESPERPAGE
= 60;
551 char tabfirst_label
[64];
553 char tablast_label
[64];
554 char this_tablabel
[64];
559 wprintf("<br /><br /><br /><div align=\"center\"><i>");
560 wprintf(_("This address book is empty."));
561 wprintf("</i></div>\n");
566 qsort(addrbook
, num_ab
, sizeof(addrbookent
), abcmp
);
569 num_pages
= (num_ab
/ NAMESPERPAGE
) + 1;
571 tablabels
= malloc(num_pages
* sizeof (char *));
572 if (tablabels
== NULL
) {
573 wprintf("<br /><br /><br /><div align=\"center\"><i>");
574 wprintf(_("An internal error has occurred."));
575 wprintf("</i></div>\n");
579 for (i
=0; i
<num_pages
; ++i
) {
580 tabfirst
= i
* NAMESPERPAGE
;
581 tablast
= tabfirst
+ NAMESPERPAGE
- 1;
582 if (tablast
> (num_ab
- 1)) tablast
= (num_ab
- 1);
583 nametab(tabfirst_label
, 64, addrbook
[tabfirst
].ab_name
);
584 nametab(tablast_label
, 64, addrbook
[tablast
].ab_name
);
585 sprintf(this_tablabel
, "%s - %s", tabfirst_label
, tablast_label
);
586 tablabels
[i
] = strdup(this_tablabel
);
589 tabbed_dialog(num_pages
, tablabels
);
592 for (i
=0; i
<num_ab
; ++i
) {
594 if ((i
/ NAMESPERPAGE
) != page
) { /* New tab */
595 page
= (i
/ NAMESPERPAGE
);
597 wprintf("</tr></table>\n");
598 end_tab(page
-1, num_pages
);
600 begin_tab(page
, num_pages
);
601 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
605 if ((displayed
% 4) == 0) {
610 wprintf("<tr bgcolor=\"#%s\">",
611 (bg
? "DDDDDD" : "FFFFFF")
617 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
618 addrbook
[i
].ab_msgnum
);
619 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
620 vcard_n_prettyize(addrbook
[i
].ab_name
);
621 escputs(addrbook
[i
].ab_name
);
622 wprintf("</a></td>\n");
626 /* Placeholders for empty columns at end */
627 if ((num_ab
% 4) != 0) {
628 for (i
=0; i
<(4-(num_ab
% 4)); ++i
) {
629 wprintf("<td> </td>");
633 wprintf("</tr></table>\n");
634 end_tab((num_pages
-1), num_pages
);
636 begin_tab(num_pages
, num_pages
);
637 /* FIXME there ought to be something here */
638 end_tab(num_pages
, num_pages
);
640 for (i
=0; i
<num_pages
; ++i
) {
650 * Edit the vCard component of a MIME message.
651 * Supply the message number
652 * and MIME part number to fetch. Or, specify -1 for the message number
653 * to start with a blank card.
655 void do_edit_vcard(long msgnum
, char *partnum
, char *return_to
, const char *force_room
) {
657 char *serialized_vcard
= NULL
;
658 size_t total_len
= 0;
666 char middlename
[256];
680 char primary_inetemail
[256];
681 char other_inetemail
[SIZ
];
682 char extrafields
[SIZ
];
703 primary_inetemail
[0] = 0;
704 other_inetemail
[0] = 0;
710 safestrncpy(whatuser
, "", sizeof whatuser
);
713 sprintf(buf
, "MSG0 %ld|1", msgnum
);
715 serv_getln(buf
, sizeof buf
);
717 convenience_page("770000", _("Error"), &buf
[4]);
720 while (serv_getln(buf
, sizeof buf
), strcmp(buf
, "000")) {
721 if (!strncasecmp(buf
, "from=", 5)) {
722 safestrncpy(whatuser
, &buf
[5], sizeof whatuser
);
724 else if (!strncasecmp(buf
, "node=", 5)) {
725 strcat(whatuser
, " @ ");
726 strcat(whatuser
, &buf
[5]);
730 sprintf(buf
, "DLAT %ld|%s", msgnum
, partnum
);
732 serv_getln(buf
, sizeof buf
);
734 convenience_page("770000", "Error", &buf
[4]);
738 total_len
= atoi(&buf
[4]);
739 serialized_vcard
= malloc(total_len
+ 2);
741 serv_read(serialized_vcard
, total_len
);
742 serialized_vcard
[total_len
] = 0;
744 v
= vcard_load(serialized_vcard
);
745 free(serialized_vcard
);
747 /* Populate the variables for our form */
749 while (key
= vcard_get_prop(v
, "", 0, i
, 1), key
!= NULL
) {
750 value
= vcard_get_prop(v
, "", 0, i
++, 0);
752 if (!strcasecmp(key
, "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(key
, "fn")) {
761 safestrncpy(fullname
, value
, sizeof fullname
);
764 else if (!strcasecmp(key
, "title")) {
765 safestrncpy(title
, value
, sizeof title
);
768 else if (!strcasecmp(key
, "org")) {
769 safestrncpy(org
, value
, sizeof org
);
772 else if ( (!strcasecmp(key
, "adr")) || (!strncasecmp(key
, "adr;", 4)) ) {
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(key
, "tel;home")) || (!strcasecmp(key
, "tel;type=home")) ) {
783 extract_token(hometel
, value
, 0, ';', sizeof hometel
);
786 else if ( (!strcasecmp(key
, "tel;work")) || (!strcasecmp(key
, "tel;type=work")) ) {
787 extract_token(worktel
, value
, 0, ';', sizeof worktel
);
790 else if ( (!strcasecmp(key
, "tel;fax")) || (!strcasecmp(key
, "tel;type=fax")) ) {
791 extract_token(faxtel
, value
, 0, ';', sizeof faxtel
);
794 else if ( (!strcasecmp(key
, "tel;cell")) || (!strcasecmp(key
, "tel;type=cell")) ) {
795 extract_token(mobiletel
, value
, 0, ';', sizeof mobiletel
);
798 else if ( (!strcasecmp(key
, "email;internet"))
799 || (!strcasecmp(key
, "email;type=internet")) ) {
800 if (primary_inetemail
[0] == 0) {
801 safestrncpy(primary_inetemail
, value
, sizeof primary_inetemail
);
804 if (other_inetemail
[0] != 0) {
805 strcat(other_inetemail
, "\n");
807 strcat(other_inetemail
, value
);
812 strcat(extrafields
, key
);
813 strcat(extrafields
, ":");
814 strcat(extrafields
, value
);
815 strcat(extrafields
, "\n");
823 /** Display the form */
824 output_headers(1, 1, 1, 0, 0, 0);
826 svput("BOXTITLE", WCS_STRING
, _("Edit contact information"));
827 do_template("beginboxx", NULL
);
829 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
830 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC
->nonce
);
832 if (force_room
!= NULL
) {
833 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
838 wprintf("<div class=\"fix_scrollbar_bug\">"
839 "<table class=\"vcard_edit_background\"><tr><td>\n");
841 wprintf("<table border=0><tr>"
846 "<td>%s</td></tr>\n",
847 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
849 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
850 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
852 wprintf("<td><input type=\"text\" name=\"firstname\" "
853 "value=\"%s\" maxlength=\"29\"></td>",
855 wprintf("<td><input type=\"text\" name=\"middlename\" "
856 "value=\"%s\" maxlength=\"29\"></td>",
858 wprintf("<td><input type=\"text\" name=\"lastname\" "
859 "value=\"%s\" maxlength=\"29\"></td>",
861 wprintf("<td><input type=\"text\" name=\"suffix\" "
862 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
865 wprintf("<table class=\"vcard_edit_background_alt\">");
868 wprintf(_("Display name:"));
870 "<input type=\"text\" name=\"fullname\" "
871 "value=\"%s\" maxlength=\"40\"><br><br>\n",
875 wprintf(_("Title:"));
877 "<input type=\"text\" name=\"title\" "
878 "value=\"%s\" maxlength=\"40\"><br><br>\n",
882 wprintf(_("Organization:"));
884 "<input type=\"text\" name=\"org\" "
885 "value=\"%s\" maxlength=\"40\"><br><br>\n",
889 wprintf("</td><td>");
891 wprintf("<table border=0>");
893 wprintf(_("PO box:"));
895 "<input type=\"text\" name=\"pobox\" "
896 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
899 wprintf(_("Address:"));
901 "<input type=\"text\" name=\"extadr\" "
902 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
904 wprintf("<tr><td> </td><td>"
905 "<input type=\"text\" name=\"street\" "
906 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
911 "<input type=\"text\" name=\"city\" "
912 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
915 wprintf(_("State:"));
917 "<input type=\"text\" name=\"state\" "
918 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
921 wprintf(_("ZIP code:"));
923 "<input type=\"text\" name=\"zipcode\" "
924 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
927 wprintf(_("Country:"));
929 "<input type=\"text\" name=\"country\" "
930 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
932 wprintf("</table>\n");
934 wprintf("</table>\n");
936 wprintf("<table border=0><tr><td>");
937 wprintf(_("Home telephone:"));
939 "<td><input type=\"text\" name=\"hometel\" "
940 "value=\"%s\" maxlength=\"29\"></td>\n",
943 wprintf(_("Work telephone:"));
945 "<td><input type=\"text\" name=\"worktel\" "
946 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
949 wprintf(_("Mobile telephone:"));
951 "<td><input type=\"text\" name=\"mobiletel\" "
952 "value=\"%s\" maxlength=\"29\"></td>\n",
955 wprintf(_("Fax number:"));
957 "<td><input type=\"text\" name=\"faxtel\" "
958 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
961 wprintf("<table class=\"vcard_edit_background_alt\">");
964 wprintf("<table border=0><TR>"
966 wprintf(_("Primary Internet e-mail address"));
968 "<input type=\"text\" name=\"primary_inetemail\" "
969 "size=40 maxlength=60 value=\"");
970 escputs(primary_inetemail
);
972 "</td><td valign=top>");
973 wprintf(_("Internet e-mail aliases"));
975 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
976 escputs(other_inetemail
);
977 wprintf("</textarea></td></tr></table>\n");
979 wprintf("</td></tr></table>\n");
981 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
982 escputs(extrafields
);
985 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
986 urlescputs(return_to
);
989 wprintf("<div class=\"buttons\">\n"
990 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
992 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
998 wprintf("</td></tr></table>\n");
999 do_template("endbox", NULL
);
1005 * commit the edits to the citadel server
1007 void edit_vcard(void) {
1011 msgnum
= lbstr("msgnum");
1012 partnum
= bstr("partnum");
1013 do_edit_vcard(msgnum
, partnum
, "", NULL
);
1019 * parse edited vcard from the browser
1021 void submit_vcard(void) {
1023 char *serialized_vcard
;
1027 if (!havebstr("ok_button")) {
1032 if (havebstr("force_room")) {
1033 gotoroom(sbstr("force_room"));
1036 sprintf(buf
, "ENT0 1|||4||");
1038 serv_getln(buf
, sizeof buf
);
1039 if (buf
[0] != '4') {
1044 /** Make a vCard structure out of the data supplied in the form */
1046 snprintf(buf
, sizeof buf
, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1049 v
= vcard_load(buf
); /** Start with the extra fields */
1051 safestrncpy(WC
->ImportantMessage
,
1052 _("An error has occurred."),
1053 sizeof WC
->ImportantMessage
1059 snprintf(buf
, sizeof buf
, "%s;%s;%s;%s;%s",
1065 vcard_add_prop(v
, "n", buf
);
1067 vcard_add_prop(v
, "title", bstr("title"));
1068 vcard_add_prop(v
, "fn", bstr("fullname"));
1069 vcard_add_prop(v
, "org", bstr("org"));
1071 snprintf(buf
, sizeof buf
, "%s;%s;%s;%s;%s;%s;%s",
1079 vcard_add_prop(v
, "adr", buf
);
1081 vcard_add_prop(v
, "tel;home", bstr("hometel"));
1082 vcard_add_prop(v
, "tel;work", bstr("worktel"));
1083 vcard_add_prop(v
, "tel;fax", bstr("faxtel"));
1084 vcard_add_prop(v
, "tel;cell", bstr("mobiletel"));
1085 vcard_add_prop(v
, "email;internet", bstr("primary_inetemail"));
1087 for (i
=0; i
<num_tokens(bstr("other_inetemail"), '\n'); ++i
) {
1088 extract_token(buf
, bstr("other_inetemail"), i
, '\n', sizeof buf
);
1089 if (!IsEmptyStr(buf
)) {
1090 vcard_add_prop(v
, "email;internet", buf
);
1094 serialized_vcard
= vcard_serialize(v
);
1096 if (serialized_vcard
== NULL
) {
1097 safestrncpy(WC
->ImportantMessage
,
1098 _("An error has occurred."),
1099 sizeof WC
->ImportantMessage
1105 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1107 serv_printf("%s\r\n", serialized_vcard
);
1109 free(serialized_vcard
);
1111 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1112 select_user_to_edit(NULL
, NULL
);
1114 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1125 * Extract an embedded photo from a vCard for display on the client
1127 void display_vcard_photo_img(void)
1133 const char *contentType
;
1134 wcsession
*WCC
= WC
;
1136 msgnum
= StrTol(WCC
->UrlFragment2
);
1138 vcard
= load_mimepart(msgnum
,"1");
1139 v
= vcard_load(vcard
);
1141 photosrc
= vcard_get_prop(v
, "PHOTO", 1,0,0);
1142 FlushStrBuf(WCC
->WBuf
);
1143 StrBufAppendBufPlain(WCC
->WBuf
, photosrc
, -1, 0);
1144 if (StrBufDecodeBase64(WCC
->WBuf
) <= 0) {
1145 FlushStrBuf(WCC
->WBuf
);
1147 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1148 output_headers(0, 0, 0, 0, 0, 0);
1149 hprintf("Content-Type: text/plain\r\n");
1150 wprintf(_("Could Not decode vcard photo\n"));
1154 contentType
= GuessMimeType(ChrPtr(WCC
->WBuf
), StrLength(WCC
->WBuf
));
1155 http_transmit_thing(contentType
, 0);
1166 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard
, 0);
1167 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard
, 0);
1168 WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img
, NEED_URL
);