4 * Functions which handle calendar objects and their processing/display.
12 * Process a calendar object. At this point it's already been deserialized by cal_process_attachment()
14 * cal: the calendar object
15 * recursion_level: Number of times we've recursed into this function
16 * msgnum: Message number on the Citadel server
17 * cal_partnum: MIME part number within that message containing the calendar object
19 void cal_process_object(icalcomponent *cal,
25 icalproperty *method = NULL;
26 icalproperty_method the_method = ICAL_METHOD_NONE;
28 struct icaltimetype t;
31 char conflict_name[256];
32 char conflict_message[256];
35 static int divcount = 0;
37 sprintf(divname, "rsvp%04x", ++divcount);
39 /* Leading HTML for the display of this object */
40 if (recursion_level == 0) {
41 wprintf("<div class=\"mimepart\">\n");
44 /* Look for a method */
45 method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
47 /* See what we need to do with this */
49 the_method = icalproperty_get_method(method);
52 wprintf("<div id=\"%s_title\">", divname);
53 wprintf("<img src=\"static/calarea_48x.gif\">");
56 case ICAL_METHOD_REQUEST:
57 title = _("Meeting invitation");
59 case ICAL_METHOD_REPLY:
60 title = _("Attendee's reply to your invitation");
62 case ICAL_METHOD_PUBLISH:
63 title = _("Published event");
66 title = _("This is an unknown type of calendar item.");
71 wprintf(" %s",title);
76 p = icalcomponent_get_first_property(cal, ICAL_SUMMARY_PROPERTY);
79 wprintf(_("Summary:"));
81 escputs((char *)icalproperty_get_comment(p));
85 p = icalcomponent_get_first_property(cal, ICAL_LOCATION_PROPERTY);
88 wprintf(_("Location:"));
90 escputs((char *)icalproperty_get_comment(p));
95 * Only show start/end times if we're actually looking at the VEVENT
96 * component. Otherwise it shows bogus dates for things like timezone.
98 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
100 p = icalcomponent_get_first_property(cal, ICAL_DTSTART_PROPERTY);
102 t = icalproperty_get_dtstart(p);
107 memset(&d_tm, 0, sizeof d_tm);
108 d_tm.tm_year = t.year - 1900;
109 d_tm.tm_mon = t.month - 1;
110 d_tm.tm_mday = t.day;
111 wc_strftime(d_str, sizeof d_str, "%x", &d_tm);
114 wprintf("</dt><dd>%s</dd>", d_str);
117 tt = icaltime_as_timet(t);
118 webcit_fmt_date(buf, tt, 0);
120 wprintf(_("Starting date/time:"));
121 wprintf("</dt><dd>%s</dd>", buf);
125 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
127 t = icalproperty_get_dtend(p);
128 tt = icaltime_as_timet(t);
129 webcit_fmt_date(buf, tt, 0);
131 wprintf(_("Ending date/time:"));
132 wprintf("</dt><dd>%s</dd>", buf);
137 p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
140 wprintf(_("Description:"));
141 wprintf("</dt><dd>");
142 escputs((char *)icalproperty_get_comment(p));
146 /* If the component has attendees, iterate through them. */
147 for (p = icalcomponent_get_first_property(cal, ICAL_ATTENDEE_PROPERTY);
149 p = icalcomponent_get_next_property(cal, ICAL_ATTENDEE_PROPERTY)) {
151 wprintf(_("Attendee:"));
152 wprintf("</dt><dd>");
153 safestrncpy(buf, icalproperty_get_attendee(p), sizeof buf);
154 if (!strncasecmp(buf, "MAILTO:", 7)) {
156 /** screen name or email address */
157 strcpy(buf, &buf[7]);
162 /** participant status */
163 partstat_as_string(buf, p);
169 /* If the component has subcomponents, recurse through them. */
170 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
172 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
173 /* Recursively process subcomponent */
174 cal_process_object(c, recursion_level+1, msgnum, cal_partnum);
177 /* If this is a REQUEST, display conflicts and buttons */
178 if (the_method == ICAL_METHOD_REQUEST) {
180 /* Check for conflicts */
181 lprintf(9, "Checking server calendar for conflicts...\n");
182 serv_printf("ICAL conflicts|%ld|%s|", msgnum, cal_partnum);
183 serv_getln(buf, sizeof buf);
185 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
186 extract_token(conflict_name, buf, 3, '|', sizeof conflict_name);
187 is_update = extract_int(buf, 4);
190 snprintf(conflict_message, sizeof conflict_message,
191 _("This is an update of '%s' which is already in your calendar."), conflict_name);
194 snprintf(conflict_message, sizeof conflict_message,
195 _("This event would conflict with '%s' which is already in your calendar."), conflict_name);
204 wprintf("</dt><dd>");
205 escputs(conflict_message);
209 lprintf(9, "...done.\n");
213 /* Display the Accept/Decline buttons */
214 wprintf("<p id=\"%s_question\">"
216 " <span class=\"button_link\"> "
217 "<a href=\"javascript:RespondToInvitation('%s_question','%s_title','%ld','%s','Accept');\">%s</a>"
218 "</span> <span class=\"button_link\">"
219 "<a href=\"javascript:RespondToInvitation('%s_question','%s_title','%ld','%s','Tentative');\">%s</a>"
220 "</span> <span class=\"button_link\">"
221 "<a href=\"javascript:RespondToInvitation('%s_question','%s_title','%ld','%s','Decline');\">%s</a>"
224 _("How would you like to respond to this invitation?"),
225 divname, divname, msgnum, cal_partnum, _("Accept"),
226 divname, divname, msgnum, cal_partnum, _("Tentative"),
227 divname, divname, msgnum, cal_partnum, _("Decline")
232 /* If this is a REPLY, display update button */
233 if (the_method == ICAL_METHOD_REPLY) {
235 /* In the future, if we want to validate this object before
236 * continuing, we can do it this way:
237 serv_printf("ICAL whatever|%ld|%s|", msgnum, cal_partnum);
238 serv_getln(buf, sizeof buf);
242 /* Display the update buttons */
243 wprintf("<p id=\"%s_question\" >"
245 " <span class=\"button_link\"> "
246 "<a href=\"javascript:HandleRSVP('%s_question','%s_title','%ld','%s','Update');\">%s</a>"
247 "</span> <span class=\"button_link\">"
248 "<a href=\"javascript:HandleRSVP('%s_question','%s_title','%ld','%s','Ignore');\">%s</a>"
251 _("Click <i>Update</i> to accept this reply and update your calendar."),
252 divname, divname, msgnum, cal_partnum, _("Update"),
253 divname, divname, msgnum, cal_partnum, _("Ignore")
258 /* Trailing HTML for the display of this object */
259 if (recursion_level == 0) {
260 wprintf("<p> </p></div>\n");
266 * \brief process calendar mail atachment
267 * Deserialize a calendar object in a message so it can be processed.
268 * (This is the main entry point for these things)
269 * \param part_source the part of the message we want to parse
270 * \param msgnum number of the mesage in our db
271 * \param cal_partnum the number of the calendar item
273 void cal_process_attachment(char *part_source, long msgnum, char *cal_partnum)
277 cal = icalcomponent_new_from_string(part_source);
280 wprintf(_("There was an error parsing this calendar item."));
286 cal_process_object(cal, 0, msgnum, cal_partnum);
288 /* Free the memory we obtained from libical's constructor */
289 icalcomponent_free(cal);
296 * \brief accept/decline meeting
297 * Respond to a meeting request
299 void respond_to_request(void)
303 begin_ajax_response();
305 serv_printf("ICAL respond|%s|%s|%s|",
310 serv_getln(buf, sizeof buf);
313 wprintf("<img src=\"static/calarea_48x.gif\"><span>");
314 if (!strcasecmp(bstr("sc"), "accept")) {
315 wprintf(_("You have accepted this meeting invitation. "
316 "It has been entered into your calendar.")
318 } else if (!strcasecmp(bstr("sc"), "tentative")) {
319 wprintf(_("You have tentatively accepted this meeting invitation. "
320 "It has been 'pencilled in' to your calendar.")
322 } else if (!strcasecmp(bstr("sc"), "decline")) {
323 wprintf(_("You have declined this meeting invitation. "
324 "It has <b>not</b> been entered into your calendar.")
328 wprintf(_("A reply has been sent to the meeting organizer."));
331 wprintf("<img align=\"center\" src=\"static/error.gif\"><span>");
332 wprintf("%s\n", &buf[4]);
342 * \brief Handle an incoming RSVP
344 void handle_rsvp(void)
348 begin_ajax_response();
350 serv_printf("ICAL handle_rsvp|%s|%s|%s|",
355 serv_getln(buf, sizeof buf);
358 wprintf("<img src=\"static/calarea_48x.gif\"><span>");
359 if (!strcasecmp(bstr("sc"), "update")) {
360 wprintf(_("Your calendar has been updated to reflect this RSVP."));
361 } else if (!strcasecmp(bstr("sc"), "ignore")) {
362 wprintf(_("You have chosen to ignore this RSVP. "
363 "Your calendar has <b>not</b> been updated.")
368 wprintf("<img src=\"static/error.gif\"><span> %s\n", &buf[4]);
378 /*-----------------------------------------------------------------------**/
383 * \defgroup MsgDisplayHandlers Display handlers for message reading
384 * \ingroup Calendaring
389 int Flathash(const char *str, long len)
391 if (len != sizeof (int))
393 else return *(int*)str;
399 * \brief clean up ical memory
400 * todo this could get trouble with future ical versions
402 void delete_cal(void *vCal)
404 disp_cal *Cal = (disp_cal*) vCal;
405 icalcomponent_free(Cal->cal);
411 * This is the meat-and-bones of the first part of our two-phase calendar display.
412 * As we encounter calendar items in messages being read from the server, we break out
413 * any iCalendar objects and store them in a hash table. Later on, the second phase will
414 * use this hash table to render the calendar for display.
416 void display_individual_cal(icalcomponent *cal, long msgnum, char *from, int unread)
418 icalproperty *ps = NULL;
419 struct icaltimetype t;
420 struct wcsession *WCC = WC;
424 if (WCC->disp_cal_items == NULL)
425 WCC->disp_cal_items = NewHash(0, Flathash);
427 Cal = (disp_cal*) malloc(sizeof(disp_cal));
428 memset(Cal, 0, sizeof(disp_cal));
430 Cal->cal = icalcomponent_new_clone(cal);
431 Cal->unread = unread;
433 Cal->from = (char*)malloc(len+ 1);
434 memcpy(Cal->from, from, len + 1);
435 ical_dezonify(Cal->cal);
436 Cal->cal_msgnum = msgnum;
438 /* Precalculate the starting date and time of this event, and store it in our top-level
439 * structure. Later, when we are rendering the calendar, we can just peek at these values
440 * without having to break apart every calendar item.
442 ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
444 t = icalproperty_get_dtstart(ps);
445 Cal->event_start = icaltime_as_timet(t);
448 /* Do the same for the ending date and time. It makes the day view much easier to render. */
449 ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
451 t = icalproperty_get_dtstart(ps);
452 Cal->event_end = icaltime_as_timet(t);
455 /* Store it in the hash list. */
456 Put(WCC->disp_cal_items,
457 (char*) &Cal->event_start,
458 sizeof(Cal->event_start),
464 /* handle recurring events (unfinished) */
467 * Just let libical iterate the recurrence, and keep looping back to the top of this function,
468 * adding new hash entries that all point back to the same msgnum, until either the iteration
469 * stops or some outer bound is reached. The display code *should* automatically do the right
470 * thing (but we'll have to see).
472 icalproperty *rrule = icalcomponent_get_first_property(Cal->cal, ICAL_RRULE_PROPERTY);
474 struct icalrecurrencetype recur = icalproperty_get_rrule(rrule);
476 lprintf(9, "recurrence detected -- need to handle this\n");
480 #endif /* TECH_PREVIEW */
487 * Display a task by itself (for editing)
489 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, char *from, int unread)
491 icalcomponent *vtodo;
493 struct icaltimetype IcalTime;
495 int created_new_vtodo = 0;
496 icalproperty_status todoStatus;
500 if (supplied_vtodo != NULL) {
501 vtodo = supplied_vtodo;
504 * If we're looking at a fully encapsulated VCALENDAR
505 * rather than a VTODO component, attempt to use the first
506 * relevant VTODO subcomponent. If there is none, the
507 * NULL returned by icalcomponent_get_first_component() will
508 * tell the next iteration of this function to create a
511 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
512 display_edit_individual_task(
513 icalcomponent_get_first_component(
514 vtodo, ICAL_VTODO_COMPONENT
523 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
524 created_new_vtodo = 1;
527 // TODO: Can we take all this and move it into a template?
528 output_headers(1, 1, 1, 0, 0, 0);
529 wprintf("<!-- start task edit form -->");
530 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
531 // Get summary early for title
532 wprintf("<div class=\"box\">\n");
533 wprintf("<div class=\"boxlabel\">");
534 wprintf(_("Edit task"));
537 escputs((char *)icalproperty_get_comment(p));
541 wprintf("<div class=\"boxcontent\">\n");
542 wprintf("<FORM METHOD=\"POST\" action=\"save_task\">\n");
543 wprintf("<div style=\"display: none;\">\n ");
544 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
545 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
548 wprintf("<table class=\"calendar_background\"><tr><td>");
549 wprintf("<TABLE STYLE=\"border: none;\">\n");
552 wprintf(_("Summary:"));
554 "<INPUT TYPE=\"text\" NAME=\"summary\" "
555 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
556 p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
558 escputs((char *)icalproperty_get_comment(p));
560 wprintf("\"></TD></TR>\n");
563 wprintf(_("Start date:"));
564 wprintf("</TD><TD>");
565 p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
566 wprintf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodtstart\" ID=\"nodtstart\" VALUE=\"NODTSTART\" ");
568 wprintf("CHECKED=\"CHECKED\"");
571 wprintf(_("No date"));
577 IcalTime = icalproperty_get_dtstart(p);
580 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
581 display_icaltimetype_as_webform(&IcalTime, "dtstart");
582 wprintf("</TD></TR>\n");
585 wprintf(_("Due date:"));
586 wprintf("</TD><TD>");
587 p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
588 wprintf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodue\" ID=\"nodue\" VALUE=\"NODUE\"");
590 wprintf("CHECKED=\"CHECKED\"");
593 wprintf(_("No date"));
598 IcalTime = icalproperty_get_due(p);
601 IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
602 display_icaltimetype_as_webform(&IcalTime, "due");
604 wprintf("</TD></TR>\n");
605 todoStatus = icalcomponent_get_status(vtodo);
606 wprintf("<TR><TD>\n");
607 wprintf(_("Completed:"));
608 wprintf("</TD><TD>");
609 wprintf("<INPUT TYPE=\"CHECKBOX\" NAME=\"status\" VALUE=\"COMPLETED\"");
610 if (todoStatus == ICAL_STATUS_COMPLETED) {
611 wprintf(" CHECKED=\"CHECKED\"");
614 wprintf("</TD></TR>");
615 // start category field
616 p = icalcomponent_get_first_property(vtodo, ICAL_CATEGORIES_PROPERTY);
618 wprintf(_("Category:"));
619 wprintf("</TD><TD>");
620 wprintf("<INPUT TYPE=\"text\" NAME=\"category\" MAXLENGTH=\"32\" SIZE=\"32\" VALUE=\"");
622 escputs((char *)icalproperty_get_categories(p));
625 wprintf("</TD></TR>\n ");
626 // end category field
628 wprintf(_("Description:"));
629 wprintf("</TD><TD>");
630 wprintf("<TEXTAREA NAME=\"description\" "
631 "ROWS=\"10\" COLS=\"80\">\n"
633 p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
635 escputs((char *)icalproperty_get_comment(p));
637 wprintf("</TEXTAREA></TD></TR></TABLE>\n");
639 wprintf("<SPAN STYLE=\"text-align: center;\">"
640 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
642 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
644 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
650 wprintf("</td></tr></table>");
651 wprintf("</FORM>\n");
652 wprintf("</div></div></div>\n");
653 wprintf("<!-- end task edit form -->");
656 if (created_new_vtodo) {
657 icalcomponent_free(vtodo);
662 * \brief Save an edited task
663 * \param supplied_vtodo the task to save
664 * \param msgnum number of the mesage in our db
666 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread)
669 int delete_existing = 0;
671 icalcomponent *vtodo, *encaps;
672 int created_new_vtodo = 0;
675 struct icaltimetype t;
677 if (supplied_vtodo != NULL) {
678 vtodo = supplied_vtodo;
680 * If we're looking at a fully encapsulated VCALENDAR
681 * rather than a VTODO component, attempt to use the first
682 * relevant VTODO subcomponent. If there is none, the
683 * NULL returned by icalcomponent_get_first_component() will
684 * tell the next iteration of this function to create a
687 if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
688 save_individual_task(
689 icalcomponent_get_first_component(
690 vtodo, ICAL_VTODO_COMPONENT),
697 vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
698 created_new_vtodo = 1;
701 if (havebstr("save_button")) {
703 /** Replace values in the component with ones from the form */
705 while (prop = icalcomponent_get_first_property(vtodo,
706 ICAL_SUMMARY_PROPERTY), prop != NULL) {
707 icalcomponent_remove_property(vtodo, prop);
708 icalproperty_free(prop);
710 if (havebstr("summary")) {
712 icalcomponent_add_property(vtodo,
713 icalproperty_new_summary(bstr("summary")));
715 icalcomponent_add_property(vtodo,
716 icalproperty_new_summary("Untitled Task"));
719 while (prop = icalcomponent_get_first_property(vtodo,
720 ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
721 icalcomponent_remove_property(vtodo, prop);
722 icalproperty_free(prop);
724 if (havebstr("description")) {
725 icalcomponent_add_property(vtodo,
726 icalproperty_new_description(bstr("description")));
729 while (prop = icalcomponent_get_first_property(vtodo,
730 ICAL_DTSTART_PROPERTY), prop != NULL) {
731 icalcomponent_remove_property(vtodo, prop);
732 icalproperty_free(prop);
734 if (IsEmptyStr(bstr("nodtstart"))) {
735 icaltime_from_webform(&t, "dtstart");
736 icalcomponent_add_property(vtodo,
737 icalproperty_new_dtstart(t)
740 while(prop = icalcomponent_get_first_property(vtodo,
741 ICAL_STATUS_PROPERTY), prop != NULL) {
742 icalcomponent_remove_property(vtodo,prop);
743 icalproperty_free(prop);
745 if (havebstr("status")) {
746 icalproperty_status taskStatus = icalproperty_string_to_status(
748 icalcomponent_set_status(vtodo, taskStatus);
750 while (prop = icalcomponent_get_first_property(vtodo,
751 ICAL_CATEGORIES_PROPERTY), prop != NULL) {
752 icalcomponent_remove_property(vtodo,prop);
753 icalproperty_free(prop);
755 if (!IsEmptyStr(bstr("category"))) {
756 prop = icalproperty_new_categories(bstr("category"));
757 icalcomponent_add_property(vtodo,prop);
759 while (prop = icalcomponent_get_first_property(vtodo,
760 ICAL_DUE_PROPERTY), prop != NULL) {
761 icalcomponent_remove_property(vtodo, prop);
762 icalproperty_free(prop);
764 if (IsEmptyStr(bstr("nodue"))) {
765 icaltime_from_webform(&t, "due");
766 icalcomponent_add_property(vtodo,
767 icalproperty_new_due(t)
770 /** Give this task a UID if it doesn't have one. */
771 lprintf(9, "Give this task a UID if it doesn't have one.\n");
772 if (icalcomponent_get_first_property(vtodo,
773 ICAL_UID_PROPERTY) == NULL) {
775 icalcomponent_add_property(vtodo,
776 icalproperty_new_uid(buf)
780 /** Increment the sequence ID */
781 lprintf(9, "Increment the sequence ID\n");
782 while (prop = icalcomponent_get_first_property(vtodo,
783 ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
784 i = icalproperty_get_sequence(prop);
785 lprintf(9, "Sequence was %d\n", i);
786 if (i > sequence) sequence = i;
787 icalcomponent_remove_property(vtodo, prop);
788 icalproperty_free(prop);
791 lprintf(9, "New sequence is %d. Adding...\n", sequence);
792 icalcomponent_add_property(vtodo,
793 icalproperty_new_sequence(sequence)
797 * Encapsulate event into full VCALENDAR component. Clone it first,
798 * for two reasons: one, it's easier to just free the whole thing
799 * when we're done instead of unbundling, but more importantly, we
800 * can't encapsulate something that may already be encapsulated
803 lprintf(9, "Encapsulating into a full VCALENDAR component\n");
804 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo));
806 /* Serialize it and save it to the message base */
807 serv_puts("ENT0 1|||4");
808 serv_getln(buf, sizeof buf);
810 serv_puts("Content-type: text/calendar");
812 serv_puts(icalcomponent_as_ical_string(encaps));
816 * Probably not necessary; the server will see the UID
817 * of the object and delete the old one anyway, but
822 icalcomponent_free(encaps);
826 * If the user clicked 'Delete' then explicitly delete the message.
828 if (havebstr("delete_button")) {
832 if ( (delete_existing) && (msgnum > 0L) ) {
833 serv_printf("DELE %ld", lbstr("msgnum"));
834 serv_getln(buf, sizeof buf);
837 if (created_new_vtodo) {
838 icalcomponent_free(vtodo);
841 /** Go back to the task list */
848 * \brief generic item handler
849 * Code common to all display handlers. Given a message number and a MIME
850 * type, we load the message and hunt for that MIME type. If found, we load
851 * the relevant part, deserialize it into a libical component, filter it for
852 * the requested object type, and feed it to the specified handler.
853 * \param mimetype mimetyp of our object
854 * \param which_kind sort of ical type
855 * \param msgnum number of the mesage in our db
856 * \param callback a funcion \todo
859 void display_using_handler(long msgnum, int unread,
860 icalcomponent_kind which_kind,
861 void (*callback)(icalcomponent *, long, char*, int)
866 char mime_partnum[256];
867 char mime_filename[256];
868 char mime_content_type[256];
869 char mime_disposition[256];
871 char relevant_partnum[256];
872 char *relevant_source = NULL;
873 icalcomponent *cal, *c;
875 relevant_partnum[0] = '\0';
876 sprintf(buf, "MSG4 %ld", msgnum); /* we need the mime headers */
878 serv_getln(buf, sizeof buf);
879 if (buf[0] != '1') return;
881 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
882 if (!strncasecmp(buf, "part=", 5)) {
883 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
884 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
885 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
886 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
887 mime_length = extract_int(&buf[5], 5);
889 if ( (!strcasecmp(mime_content_type, "text/calendar"))
890 || (!strcasecmp(mime_content_type, "application/ics"))
891 || (!strcasecmp(mime_content_type, "text/vtodo"))
893 strcpy(relevant_partnum, mime_partnum);
896 else if (!strncasecmp(buf, "from=", 4)) {
897 extract_token(from, buf, 1, '=', sizeof(from));
901 if (!IsEmptyStr(relevant_partnum)) {
902 relevant_source = load_mimepart(msgnum, relevant_partnum);
903 if (relevant_source != NULL) {
905 cal = icalcomponent_new_from_string(relevant_source);
910 /** Simple components of desired type */
911 if (icalcomponent_isa(cal) == which_kind) {
912 callback(cal, msgnum, from, unread);
915 /** Subcomponents of desired type */
916 for (c = icalcomponent_get_first_component(cal,
919 c = icalcomponent_get_next_component(cal,
921 callback(c, msgnum, from, unread);
923 icalcomponent_free(cal);
925 free(relevant_source);
928 icalmemory_free_ring();
932 * \brief display whole calendar
933 * \param msgnum number of the mesage in our db
935 void display_calendar(long msgnum, int unread) {
936 display_using_handler(msgnum, unread,
937 ICAL_VEVENT_COMPONENT,
938 display_individual_cal);
942 * \brief display whole taksview
943 * \param msgnum number of the mesage in our db
945 void display_task(long msgnum, int unread) {
946 display_using_handler(msgnum, unread,
947 ICAL_VTODO_COMPONENT,
948 display_individual_cal);
952 * \brief display the editor component for a task
954 void display_edit_task(void) {
957 /** Force change the room if we have to */
958 if (havebstr("taskrm")) {
959 gotoroom((char *)bstr("taskrm"));
962 msgnum = lbstr("msgnum");
965 display_using_handler(msgnum, 0,
966 ICAL_VTODO_COMPONENT,
967 display_edit_individual_task);
971 display_edit_individual_task(NULL, 0L, "", 0);
976 *\brief save an edited task
978 void save_task(void) {
981 msgnum = lbstr("msgnum");
983 display_using_handler(msgnum, 0,
984 ICAL_VTODO_COMPONENT,
985 save_individual_task);
988 save_individual_task(NULL, 0L, "", 0);
993 * \brief display the editor component for an event
995 void display_edit_event(void) {
998 msgnum = lbstr("msgnum");
1000 /* existing event */
1001 display_using_handler(msgnum, 0,
1002 ICAL_VEVENT_COMPONENT,
1003 display_edit_individual_event);
1007 display_edit_individual_event(NULL, 0L, "", 0);
1012 * \brief save an edited event
1014 void save_event(void) {
1017 msgnum = lbstr("msgnum");
1020 display_using_handler(msgnum, 0,
1021 ICAL_VEVENT_COMPONENT,
1022 save_individual_event);
1025 save_individual_event(NULL, 0L, "", 0);
1034 * \brief freebusy display (for client software)
1035 * \param req dunno. ?????
1037 void do_freebusy(char *req) {
1043 extract_token(who, req, 1, ' ', sizeof who);
1044 if (!strncasecmp(who, "/freebusy/", 10)) {
1045 strcpy(who, &who[10]);
1047 unescape_input(who);
1050 if ( (!strcasecmp(&who[len-4], ".vcf"))
1051 || (!strcasecmp(&who[len-4], ".ifb"))
1052 || (!strcasecmp(&who[len-4], ".vfb")) ) {
1056 lprintf(9, "freebusy requested for <%s>\n", who);
1057 serv_printf("ICAL freebusy|%s", who);
1058 serv_getln(buf, sizeof buf);
1060 if (buf[0] != '1') {
1061 wprintf("HTTP/1.1 404 %s\n", &buf[4]);
1062 output_headers(0, 0, 0, 0, 0, 0);
1063 wprintf("Content-Type: text/plain\r\n");
1065 wprintf("%s\n", &buf[4]);
1069 fb = read_server_text();
1070 http_transmit_thing(fb, strlen(fb), "text/calendar", 0);
1082 WebcitAddUrlHandler(HKEY("display_edit_task"), display_edit_task, 0);
1083 WebcitAddUrlHandler(HKEY("save_task"), save_task, 0);
1084 WebcitAddUrlHandler(HKEY("display_edit_event"), display_edit_event, 0);
1085 WebcitAddUrlHandler(HKEY("save_event"), save_event, 0);
1086 WebcitAddUrlHandler(HKEY("respond_to_request"), respond_to_request, 0);
1087 WebcitAddUrlHandler(HKEY("handle_rsvp"), handle_rsvp, 0);