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;
122 memset(&summ
, 0, sizeof(summ
));
123 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
125 sprintf(buf
, "MSG0 %ld|0", Msg
->msgnum
); /** unfortunately we need the mime info now */
127 serv_getln(buf
, sizeof buf
);
128 if (buf
[0] != '1') return;
130 while (serv_getln(buf
, sizeof buf
), strcmp(buf
, "000")) {
131 if (!strncasecmp(buf
, "part=", 5)) {
132 extract_token(mime_filename
, &buf
[5], 1, '|', sizeof mime_filename
);
133 extract_token(mime_partnum
, &buf
[5], 2, '|', sizeof mime_partnum
);
134 extract_token(mime_disposition
, &buf
[5], 3, '|', sizeof mime_disposition
);
135 extract_token(mime_content_type
, &buf
[5], 4, '|', sizeof mime_content_type
);
136 mime_length
= extract_int(&buf
[5], 5);
138 if ( (!strcasecmp(mime_content_type
, "text/x-vcard"))
139 || (!strcasecmp(mime_content_type
, "text/vcard")) ) {
140 strcpy(vcard_partnum
, mime_partnum
);
146 if (!IsEmptyStr(vcard_partnum
)) {
147 vcard_source
= load_mimepart(Msg
->msgnum
, vcard_partnum
);
148 if (vcard_source
!= NULL
) {
150 /* Grab the name off the card */
151 display_vcard(WC
->WBuf
, vcard_source
, 0, 0, namebuf
, Msg
->msgnum
);
156 if (*namebuf
!= NULL
) {
157 lastfirst_firstlast(*namebuf
);
159 len
= strlen(*namebuf
);
160 for (i
=0; i
<len
; ++i
) {
161 if ((*namebuf
)[i
] != ';') return;
164 (*namebuf
) = strdup(_("(no name)"));
167 (*namebuf
) = strdup(_("(no name)"));
174 * \brief Turn a vCard "n" (name) field into something displayable.
175 * \param name the name field to convert
177 void vcard_n_prettyize(char *name
)
182 original_name
= strdup(name
);
183 len
= strlen(original_name
);
184 for (i
=0; i
<5; ++i
) {
186 if (original_name
[len
-1] == ' ') {
187 original_name
[--len
] = 0;
189 if (original_name
[len
-1] == ';') {
190 original_name
[--len
] = 0;
196 for (i
=0; i
<len
; ++i
) {
197 if (original_name
[i
] == ';') {
202 name
[j
++] = original_name
[i
];
213 * \brief preparse a vcard name
214 * display_vcard() calls this after parsing the textual vCard into
215 * our 'struct vCard' data object.
216 * This gets called instead of display_parsed_vcard() if we are only looking
217 * to extract the person's name instead of displaying the card.
218 * \param v the vcard to retrieve the name from
219 * \param storename where to put the name at
221 void fetchname_parsed_vcard(struct vCard
*v
, char **storename
) {
231 name
= vcard_get_prop(v
, "n", 1, 0, 0);
234 prop
= vcard_get_prop(v
, "n", 1, 0, 1);
235 n
= num_tokens(prop
, ';');
237 for (j
=0; j
<n
; ++j
) {
238 extract_token(buf
, prop
, j
, ';', sizeof buf
);
239 if (!strcasecmp(buf
, "encoding=quoted-printable")) {
242 if (!strcasecmp(buf
, "encoding=base64")) {
247 // %ff can become 6 bytes in utf8
248 *storename
= malloc(len
* 2 + 3);
249 j
= CtdlDecodeQuotedPrintable(
255 // ff will become one byte..
256 *storename
= malloc(len
+ 50);
262 *storename
= strdup(name
);
264 /* vcard_n_prettyize(storename); */
272 * \brief html print a vcard
273 * display_vcard() calls this after parsing the textual vCard into
274 * our 'struct vCard' data object.
276 * Set 'full' to nonzero to display the full card, otherwise it will only
277 * show a summary line.
279 * This code is a bit ugly, so perhaps an explanation is due: we do this
280 * in two passes through the vCard fields. On the first pass, we process
281 * fields we understand, and then render them in a pretty fashion at the
282 * end. Then we make a second pass, outputting all the fields we don't
283 * understand in a simple two-column name/value format.
284 * \param v the vCard to display
285 * \param full display all items of the vcard?
286 * \param msgnum Citadel message pointer
288 void display_parsed_vcard(StrBuf
*Target
, struct vCard
*v
, int full
, long msgnum
) {
294 char *thisname
, *thisvalue
;
295 char firsttoken
[SIZ
];
304 strcpy(fullname
, "");
311 StrBufAppendPrintf(Target
, "<TD>");
312 name
= vcard_get_prop(v
, "fn", 1, 0, 0);
314 StrEscAppend(Target
, NULL
, name
, 0, 0);
316 else if (name
= vcard_get_prop(v
, "n", 1, 0, 0), name
!= NULL
) {
317 strcpy(fullname
, name
);
318 vcard_n_prettyize(fullname
);
319 StrEscAppend(Target
, NULL
, fullname
, 0, 0);
322 StrBufAppendPrintf(Target
, " ");
324 StrBufAppendPrintf(Target
, "</TD>");
328 StrBufAppendPrintf(Target
, "<div align=center>"
329 "<table bgcolor=#aaaaaa width=50%%>");
330 for (pass
=1; pass
<=2; ++pass
) {
332 if (v
->numprops
) for (i
=0; i
<(v
->numprops
); ++i
) {
334 thisname
= strdup(v
->prop
[i
].name
);
335 extract_token(firsttoken
, thisname
, 0, ';', sizeof firsttoken
);
337 for (j
=0; j
<num_tokens(thisname
, ';'); ++j
) {
338 extract_token(buf
, thisname
, j
, ';', sizeof buf
);
339 if (!strcasecmp(buf
, "encoding=quoted-printable")) {
341 remove_token(thisname
, j
, ';');
343 if (!strcasecmp(buf
, "encoding=base64")) {
345 remove_token(thisname
, j
, ';');
349 len
= strlen(v
->prop
[i
].value
);
350 /* if we have some untagged QP, detect it here. */
351 if (!is_qp
&& (strstr(v
->prop
[i
].value
, "=?")!=NULL
))
352 utf8ify_rfc822_string(v
->prop
[i
].value
);
355 // %ff can become 6 bytes in utf8
356 thisvalue
= malloc(len
* 2 + 3);
357 j
= CtdlDecodeQuotedPrintable(
358 thisvalue
, v
->prop
[i
].value
,
363 // ff will become one byte..
364 thisvalue
= malloc(len
+ 50);
366 thisvalue
, v
->prop
[i
].value
,
367 strlen(v
->prop
[i
].value
) );
370 thisvalue
= strdup(v
->prop
[i
].value
);
373 /** Various fields we may encounter ***/
375 /** N is name, but only if there's no FN already there */
376 if (!strcasecmp(firsttoken
, "n")) {
377 if (IsEmptyStr(fullname
)) {
378 strcpy(fullname
, thisvalue
);
379 vcard_n_prettyize(fullname
);
383 /** FN (full name) is a true 'display name' field */
384 else if (!strcasecmp(firsttoken
, "fn")) {
385 strcpy(fullname
, thisvalue
);
389 else if (!strcasecmp(firsttoken
, "title")) {
390 strcpy(title
, thisvalue
);
394 else if (!strcasecmp(firsttoken
, "org")) {
395 strcpy(org
, thisvalue
);
398 else if (!strcasecmp(firsttoken
, "email")) {
400 if (!IsEmptyStr(mailto
)) strcat(mailto
, "<br />");
402 "<a href=\"display_enter"
403 "?force_room=_MAIL_?recp=");
405 len
= strlen(mailto
);
406 urlesc(&mailto
[len
], SIZ
- len
, "\"");
407 len
= strlen(mailto
);
408 urlesc(&mailto
[len
], SIZ
- len
, fullname
);
409 len
= strlen(mailto
);
410 urlesc(&mailto
[len
], SIZ
- len
, "\" <");
411 len
= strlen(mailto
);
412 urlesc(&mailto
[len
], SIZ
- len
, thisvalue
);
413 len
= strlen(mailto
);
414 urlesc(&mailto
[len
], SIZ
- len
, ">");
416 strcat(mailto
, "\">");
417 len
= strlen(mailto
);
418 stresc(mailto
+len
, SIZ
- len
, thisvalue
, 1, 1);
419 strcat(mailto
, "</A>");
421 else if (!strcasecmp(firsttoken
, "tel")) {
422 if (!IsEmptyStr(phone
)) strcat(phone
, "<br />");
423 strcat(phone
, thisvalue
);
424 for (j
=0; j
<num_tokens(thisname
, ';'); ++j
) {
425 extract_token(buf
, thisname
, j
, ';', sizeof buf
);
426 if (!strcasecmp(buf
, "tel"))
428 else if (!strcasecmp(buf
, "work"))
429 strcat(phone
, _(" (work)"));
430 else if (!strcasecmp(buf
, "home"))
431 strcat(phone
, _(" (home)"));
432 else if (!strcasecmp(buf
, "cell"))
433 strcat(phone
, _(" (cell)"));
441 else if (!strcasecmp(firsttoken
, "adr")) {
443 StrBufAppendPrintf(Target
, "<TR><TD>");
444 StrBufAppendPrintf(Target
, _("Address:"));
445 StrBufAppendPrintf(Target
, "</TD><TD>");
446 for (j
=0; j
<num_tokens(thisvalue
, ';'); ++j
) {
447 extract_token(buf
, thisvalue
, j
, ';', sizeof buf
);
448 if (!IsEmptyStr(buf
)) {
449 StrEscAppend(Target
, NULL
, buf
, 0, 0);
450 if (j
<3) StrBufAppendPrintf(Target
, "<br />");
451 else StrBufAppendPrintf(Target
, " ");
454 StrBufAppendPrintf(Target
, "</TD></TR>\n");
457 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
458 // Only output on second pass
459 StrBufAppendPrintf(Target, "<tr><td>");
460 StrBufAppendPrintf(Target, _("Photo:"));
461 StrBufAppendPrintf(Target, "</td><td>");
462 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
463 StrBufAppendPrintf(Target, "</td></tr>\n");
465 else if (!strcasecmp(firsttoken
, "version")) {
468 else if (!strcasecmp(firsttoken
, "rev")) {
471 else if (!strcasecmp(firsttoken
, "label")) {
476 /*** Don't show extra fields. They're ugly.
478 StrBufAppendPrintf(Target, "<TR><TD>");
479 StrEscAppend(Target, NULL, thisname, 0, 0);
480 StrBufAppendPrintf(Target, "</TD><TD>");
481 StrEscAppend(Target, NULL, thisvalue, 0, 0);
482 StrBufAppendPrintf(Target, "</TD></TR>\n");
492 StrBufAppendPrintf(Target
, "<TR BGCOLOR=\"#AAAAAA\">"
493 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
494 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
495 "<FONT SIZE=+1><B>");
496 StrEscAppend(Target
, NULL
, fullname
, 0, 0);
497 StrBufAppendPrintf(Target
, "</B></FONT>");
498 if (!IsEmptyStr(title
)) {
499 StrBufAppendPrintf(Target
, "<div align=right>");
500 StrEscAppend(Target
, NULL
, title
, 0, 0);
501 StrBufAppendPrintf(Target
, "</div>");
503 if (!IsEmptyStr(org
)) {
504 StrBufAppendPrintf(Target
, "<div align=right>");
505 StrEscAppend(Target
, NULL
, org
, 0, 0);
506 StrBufAppendPrintf(Target
, "</div>");
508 StrBufAppendPrintf(Target
, "</TD></TR>\n");
510 if (!IsEmptyStr(phone
)) {
511 StrBufAppendPrintf(Target
, "<tr><td>");
512 StrBufAppendPrintf(Target
, _("Telephone:"));
513 StrBufAppendPrintf(Target
, "</td><td>%s</td></tr>\n", phone
);
515 if (!IsEmptyStr(mailto
)) {
516 StrBufAppendPrintf(Target
, "<tr><td>");
517 StrBufAppendPrintf(Target
, _("E-mail:"));
518 StrBufAppendPrintf(Target
, "</td><td>%s</td></tr>\n", mailto
);
524 StrBufAppendPrintf(Target
, "</table></div>\n");
530 * \brief Display a textual vCard
531 * (Converts to a vCard object and then calls the actual display function)
532 * Set 'full' to nonzero to display the whole card instead of a one-liner.
533 * Or, if "storename" is non-NULL, just store the person's name in that
534 * buffer instead of displaying the card at all.
535 * \param vcard_source the buffer containing the vcard text
536 * \param alpha what???
537 * \param full should we usse all lines?
538 * \param storename where to store???
539 * \param msgnum Citadel message pointer
541 void display_vcard(StrBuf
*Target
,
542 const char *vcard_source
,
554 v
= vcard_load((char*)vcard_source
); ///TODO
556 if (v
== NULL
) return;
558 name
= vcard_get_prop(v
, "n", 1, 0, 0);
560 Buf
= NewStrBufPlain(name
, -1);
561 Buf2
= NewStrBufPlain(NULL
, StrLength(Buf
));
562 StrBuf_RFC822_to_Utf8(Buf2
, Buf
, WC
->DefaultCharset
, NULL
);
563 this_alpha
= ChrPtr(Buf
)[0];
568 if (storename
!= NULL
) {
569 fetchname_parsed_vcard(v
, storename
);
571 else if ( (alpha
== 0)
572 || ((isalpha(alpha
)) && (tolower(alpha
) == tolower(this_alpha
)) )
573 || ((!isalpha(alpha
)) && (!isalpha(this_alpha
)))
575 display_parsed_vcard(Target
, v
, full
,msgnum
);
584 * \brief Render the address book using info we gathered during the scan
585 * \param addrbook the addressbook to render
586 * \param num_ab the number of the addressbook
588 void do_addrbook_view(addrbookent
*addrbook
, int num_ab
) {
592 static int NAMESPERPAGE
= 60;
595 char tabfirst_label
[64];
597 char tablast_label
[64];
598 char this_tablabel
[64];
603 wprintf("<br /><br /><br /><div align=\"center\"><i>");
604 wprintf(_("This address book is empty."));
605 wprintf("</i></div>\n");
610 qsort(addrbook
, num_ab
, sizeof(addrbookent
), abcmp
);
613 num_pages
= (num_ab
/ NAMESPERPAGE
) + 1;
615 tablabels
= malloc(num_pages
* sizeof (char *));
616 if (tablabels
== NULL
) {
617 wprintf("<br /><br /><br /><div align=\"center\"><i>");
618 wprintf(_("An internal error has occurred."));
619 wprintf("</i></div>\n");
623 for (i
=0; i
<num_pages
; ++i
) {
624 tabfirst
= i
* NAMESPERPAGE
;
625 tablast
= tabfirst
+ NAMESPERPAGE
- 1;
626 if (tablast
> (num_ab
- 1)) tablast
= (num_ab
- 1);
627 nametab(tabfirst_label
, 64, addrbook
[tabfirst
].ab_name
);
628 nametab(tablast_label
, 64, addrbook
[tablast
].ab_name
);
629 sprintf(this_tablabel
, "%s - %s", tabfirst_label
, tablast_label
);
630 tablabels
[i
] = strdup(this_tablabel
);
633 tabbed_dialog(num_pages
, tablabels
);
636 for (i
=0; i
<num_ab
; ++i
) {
638 if ((i
/ NAMESPERPAGE
) != page
) { /* New tab */
639 page
= (i
/ NAMESPERPAGE
);
641 wprintf("</tr></table>\n");
642 end_tab(page
-1, num_pages
);
644 begin_tab(page
, num_pages
);
645 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
649 if ((displayed
% 4) == 0) {
654 wprintf("<tr bgcolor=\"#%s\">",
655 (bg
? "DDDDDD" : "FFFFFF")
661 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
662 addrbook
[i
].ab_msgnum
);
663 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
664 vcard_n_prettyize(addrbook
[i
].ab_name
);
665 escputs(addrbook
[i
].ab_name
);
666 wprintf("</a></td>\n");
670 /* Placeholders for empty columns at end */
671 if ((num_ab
% 4) != 0) {
672 for (i
=0; i
<(4-(num_ab
% 4)); ++i
) {
673 wprintf("<td> </td>");
677 wprintf("</tr></table>\n");
678 end_tab((num_pages
-1), num_pages
);
680 begin_tab(num_pages
, num_pages
);
681 /* FIXME there ought to be something here */
682 end_tab(num_pages
, num_pages
);
684 for (i
=0; i
<num_pages
; ++i
) {
694 * Edit the vCard component of a MIME message.
695 * Supply the message number
696 * and MIME part number to fetch. Or, specify -1 for the message number
697 * to start with a blank card.
699 void do_edit_vcard(long msgnum
, char *partnum
, char *return_to
, const char *force_room
) {
701 char *serialized_vcard
= NULL
;
702 size_t total_len
= 0;
710 char middlename
[256];
724 char primary_inetemail
[256];
725 char other_inetemail
[SIZ
];
726 char extrafields
[SIZ
];
747 primary_inetemail
[0] = 0;
748 other_inetemail
[0] = 0;
754 safestrncpy(whatuser
, "", sizeof whatuser
);
757 sprintf(buf
, "MSG0 %ld|1", msgnum
);
759 serv_getln(buf
, sizeof buf
);
761 convenience_page("770000", _("Error"), &buf
[4]);
764 while (serv_getln(buf
, sizeof buf
), strcmp(buf
, "000")) {
765 if (!strncasecmp(buf
, "from=", 5)) {
766 safestrncpy(whatuser
, &buf
[5], sizeof whatuser
);
768 else if (!strncasecmp(buf
, "node=", 5)) {
769 strcat(whatuser
, " @ ");
770 strcat(whatuser
, &buf
[5]);
774 sprintf(buf
, "DLAT %ld|%s", msgnum
, partnum
);
776 serv_getln(buf
, sizeof buf
);
778 convenience_page("770000", "Error", &buf
[4]);
782 total_len
= atoi(&buf
[4]);
783 serialized_vcard
= malloc(total_len
+ 2);
785 serv_read(serialized_vcard
, total_len
);
786 serialized_vcard
[total_len
] = 0;
788 v
= vcard_load(serialized_vcard
);
789 free(serialized_vcard
);
791 /* Populate the variables for our form */
793 while (key
= vcard_get_prop(v
, "", 0, i
, 1), key
!= NULL
) {
794 value
= vcard_get_prop(v
, "", 0, i
++, 0);
796 if (!strcasecmp(key
, "n")) {
797 extract_token(lastname
, value
, 0, ';', sizeof lastname
);
798 extract_token(firstname
, value
, 1, ';', sizeof firstname
);
799 extract_token(middlename
, value
, 2, ';', sizeof middlename
);
800 extract_token(prefix
, value
, 3, ';', sizeof prefix
);
801 extract_token(suffix
, value
, 4, ';', sizeof suffix
);
804 else if (!strcasecmp(key
, "fn")) {
805 safestrncpy(fullname
, value
, sizeof fullname
);
808 else if (!strcasecmp(key
, "title")) {
809 safestrncpy(title
, value
, sizeof title
);
812 else if (!strcasecmp(key
, "org")) {
813 safestrncpy(org
, value
, sizeof org
);
816 else if ( (!strcasecmp(key
, "adr")) || (!strncasecmp(key
, "adr;", 4)) ) {
817 extract_token(pobox
, value
, 0, ';', sizeof pobox
);
818 extract_token(extadr
, value
, 1, ';', sizeof extadr
);
819 extract_token(street
, value
, 2, ';', sizeof street
);
820 extract_token(city
, value
, 3, ';', sizeof city
);
821 extract_token(state
, value
, 4, ';', sizeof state
);
822 extract_token(zipcode
, value
, 5, ';', sizeof zipcode
);
823 extract_token(country
, value
, 6, ';', sizeof country
);
826 else if ( (!strcasecmp(key
, "tel;home")) || (!strcasecmp(key
, "tel;type=home")) ) {
827 extract_token(hometel
, value
, 0, ';', sizeof hometel
);
830 else if ( (!strcasecmp(key
, "tel;work")) || (!strcasecmp(key
, "tel;type=work")) ) {
831 extract_token(worktel
, value
, 0, ';', sizeof worktel
);
834 else if ( (!strcasecmp(key
, "tel;fax")) || (!strcasecmp(key
, "tel;type=fax")) ) {
835 extract_token(faxtel
, value
, 0, ';', sizeof faxtel
);
838 else if ( (!strcasecmp(key
, "tel;cell")) || (!strcasecmp(key
, "tel;type=cell")) ) {
839 extract_token(mobiletel
, value
, 0, ';', sizeof mobiletel
);
842 else if ( (!strcasecmp(key
, "email;internet"))
843 || (!strcasecmp(key
, "email;type=internet")) ) {
844 if (primary_inetemail
[0] == 0) {
845 safestrncpy(primary_inetemail
, value
, sizeof primary_inetemail
);
848 if (other_inetemail
[0] != 0) {
849 strcat(other_inetemail
, "\n");
851 strcat(other_inetemail
, value
);
856 strcat(extrafields
, key
);
857 strcat(extrafields
, ":");
858 strcat(extrafields
, value
);
859 strcat(extrafields
, "\n");
867 /** Display the form */
868 output_headers(1, 1, 1, 0, 0, 0);
870 svput("BOXTITLE", WCS_STRING
, _("Edit contact information"));
871 do_template("beginboxx", NULL
);
873 wprintf("<form method=\"POST\" action=\"submit_vcard\">\n");
874 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC
->nonce
);
876 if (force_room
!= NULL
) {
877 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
882 wprintf("<div class=\"fix_scrollbar_bug\">"
883 "<table class=\"vcard_edit_background\"><tr><td>\n");
885 wprintf("<table border=0><tr>"
890 "<td>%s</td></tr>\n",
891 _("Prefix"), _("First"), _("Middle"), _("Last"), _("Suffix")
893 wprintf("<tr><td><input type=\"text\" name=\"prefix\" "
894 "value=\"%s\" maxlength=\"5\" size=\"5\"></td>",
896 wprintf("<td><input type=\"text\" name=\"firstname\" "
897 "value=\"%s\" maxlength=\"29\"></td>",
899 wprintf("<td><input type=\"text\" name=\"middlename\" "
900 "value=\"%s\" maxlength=\"29\"></td>",
902 wprintf("<td><input type=\"text\" name=\"lastname\" "
903 "value=\"%s\" maxlength=\"29\"></td>",
905 wprintf("<td><input type=\"text\" name=\"suffix\" "
906 "value=\"%s\" maxlength=\"10\" size=\"10\"></td></tr></table>\n",
909 wprintf("<table class=\"vcard_edit_background_alt\">");
912 wprintf(_("Display name:"));
914 "<input type=\"text\" name=\"fullname\" "
915 "value=\"%s\" maxlength=\"40\"><br><br>\n",
919 wprintf(_("Title:"));
921 "<input type=\"text\" name=\"title\" "
922 "value=\"%s\" maxlength=\"40\"><br><br>\n",
926 wprintf(_("Organization:"));
928 "<input type=\"text\" name=\"org\" "
929 "value=\"%s\" maxlength=\"40\"><br><br>\n",
933 wprintf("</td><td>");
935 wprintf("<table border=0>");
937 wprintf(_("PO box:"));
939 "<input type=\"text\" name=\"pobox\" "
940 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
943 wprintf(_("Address:"));
945 "<input type=\"text\" name=\"extadr\" "
946 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
948 wprintf("<tr><td> </td><td>"
949 "<input type=\"text\" name=\"street\" "
950 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
955 "<input type=\"text\" name=\"city\" "
956 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
959 wprintf(_("State:"));
961 "<input type=\"text\" name=\"state\" "
962 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
965 wprintf(_("ZIP code:"));
967 "<input type=\"text\" name=\"zipcode\" "
968 "value=\"%s\" maxlength=\"10\"></td></tr>\n",
971 wprintf(_("Country:"));
973 "<input type=\"text\" name=\"country\" "
974 "value=\"%s\" maxlength=\"29\" width=\"5\"></td></tr>\n",
976 wprintf("</table>\n");
978 wprintf("</table>\n");
980 wprintf("<table border=0><tr><td>");
981 wprintf(_("Home telephone:"));
983 "<td><input type=\"text\" name=\"hometel\" "
984 "value=\"%s\" maxlength=\"29\"></td>\n",
987 wprintf(_("Work telephone:"));
989 "<td><input type=\"text\" name=\"worktel\" "
990 "value=\"%s\" maxlength=\"29\"></td></tr>\n",
993 wprintf(_("Mobile telephone:"));
995 "<td><input type=\"text\" name=\"mobiletel\" "
996 "value=\"%s\" maxlength=\"29\"></td>\n",
999 wprintf(_("Fax number:"));
1001 "<td><input type=\"text\" name=\"faxtel\" "
1002 "value=\"%s\" maxlength=\"29\"></td></tr></table>\n",
1005 wprintf("<table class=\"vcard_edit_background_alt\">");
1006 wprintf("<tr><td>");
1008 wprintf("<table border=0><TR>"
1010 wprintf(_("Primary Internet e-mail address"));
1012 "<input type=\"text\" name=\"primary_inetemail\" "
1013 "size=40 maxlength=60 value=\"");
1014 escputs(primary_inetemail
);
1016 "</td><td valign=top>");
1017 wprintf(_("Internet e-mail aliases"));
1019 "<textarea name=\"other_inetemail\" rows=5 cols=40 width=40>");
1020 escputs(other_inetemail
);
1021 wprintf("</textarea></td></tr></table>\n");
1023 wprintf("</td></tr></table>\n");
1025 wprintf("<input type=\"hidden\" name=\"extrafields\" value=\"");
1026 escputs(extrafields
);
1029 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"");
1030 urlescputs(return_to
);
1033 wprintf("<div class=\"buttons\">\n"
1034 "<input type=\"submit\" name=\"ok_button\" value=\"%s\">"
1036 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">"
1042 wprintf("</td></tr></table>\n");
1043 do_template("endbox", NULL
);
1049 * commit the edits to the citadel server
1051 void edit_vcard(void) {
1055 msgnum
= lbstr("msgnum");
1056 partnum
= bstr("partnum");
1057 do_edit_vcard(msgnum
, partnum
, "", NULL
);
1063 * parse edited vcard from the browser
1065 void submit_vcard(void) {
1067 char *serialized_vcard
;
1071 if (!havebstr("ok_button")) {
1076 if (havebstr("force_room")) {
1077 gotoroom(sbstr("force_room"));
1080 sprintf(buf
, "ENT0 1|||4||");
1082 serv_getln(buf
, sizeof buf
);
1083 if (buf
[0] != '4') {
1088 /** Make a vCard structure out of the data supplied in the form */
1090 snprintf(buf
, sizeof buf
, "begin:vcard\r\n%s\r\nend:vcard\r\n",
1093 v
= vcard_load(buf
); /** Start with the extra fields */
1095 safestrncpy(WC
->ImportantMessage
,
1096 _("An error has occurred."),
1097 sizeof WC
->ImportantMessage
1103 snprintf(buf
, sizeof buf
, "%s;%s;%s;%s;%s",
1109 vcard_add_prop(v
, "n", buf
);
1111 vcard_add_prop(v
, "title", bstr("title"));
1112 vcard_add_prop(v
, "fn", bstr("fullname"));
1113 vcard_add_prop(v
, "org", bstr("org"));
1115 snprintf(buf
, sizeof buf
, "%s;%s;%s;%s;%s;%s;%s",
1123 vcard_add_prop(v
, "adr", buf
);
1125 vcard_add_prop(v
, "tel;home", bstr("hometel"));
1126 vcard_add_prop(v
, "tel;work", bstr("worktel"));
1127 vcard_add_prop(v
, "tel;fax", bstr("faxtel"));
1128 vcard_add_prop(v
, "tel;cell", bstr("mobiletel"));
1129 vcard_add_prop(v
, "email;internet", bstr("primary_inetemail"));
1131 for (i
=0; i
<num_tokens(bstr("other_inetemail"), '\n'); ++i
) {
1132 extract_token(buf
, bstr("other_inetemail"), i
, '\n', sizeof buf
);
1133 if (!IsEmptyStr(buf
)) {
1134 vcard_add_prop(v
, "email;internet", buf
);
1138 serialized_vcard
= vcard_serialize(v
);
1140 if (serialized_vcard
== NULL
) {
1141 safestrncpy(WC
->ImportantMessage
,
1142 _("An error has occurred."),
1143 sizeof WC
->ImportantMessage
1149 serv_puts("Content-type: text/x-vcard; charset=UTF-8");
1151 serv_printf("%s\r\n", serialized_vcard
);
1153 free(serialized_vcard
);
1155 if (!strcmp(bstr("return_to"), "select_user_to_edit")) {
1156 select_user_to_edit(NULL
, NULL
);
1158 else if (!strcmp(bstr("return_to"), "do_welcome")) {
1169 * Extract an embedded photo from a vCard for display on the client
1171 void display_vcard_photo_img(void)
1177 const char *contentType
;
1178 wcsession
*WCC
= WC
;
1180 msgnum
= StrTol(WCC
->UrlFragment2
);
1182 vcard
= load_mimepart(msgnum
,"1");
1183 v
= vcard_load(vcard
);
1185 photosrc
= vcard_get_prop(v
, "PHOTO", 1,0,0);
1186 FlushStrBuf(WCC
->WBuf
);
1187 StrBufAppendBufPlain(WCC
->WBuf
, photosrc
, -1, 0);
1188 if (StrBufDecodeBase64(WCC
->WBuf
) <= 0) {
1189 FlushStrBuf(WCC
->WBuf
);
1191 hprintf("HTTP/1.1 500 %s\n","Unable to get photo");
1192 output_headers(0, 0, 0, 0, 0, 0);
1193 hprintf("Content-Type: text/plain\r\n");
1194 wprintf(_("Could Not decode vcard photo\n"));
1198 contentType
= GuessMimeType(ChrPtr(WCC
->WBuf
), StrLength(WCC
->WBuf
));
1199 http_transmit_thing(contentType
, 0);
1210 WebcitAddUrlHandler(HKEY("edit_vcard"), edit_vcard
, 0);
1211 WebcitAddUrlHandler(HKEY("submit_vcard"), submit_vcard
, 0);
1212 WebcitAddUrlHandler(HKEY("vcardphoto"), display_vcard_photo_img
, NEED_URL
);