4 * This module implements iCalendar object processing and the Calendar>
5 * room on a Citadel/UX server. It handles iCalendar objects using the
6 * iTIP protocol. See RFCs 2445 and 2446.
10 #define PRODID "-//Citadel//NONSGML Citadel Calendar//EN"
14 #include <sys/types.h>
23 #include "citserver.h"
24 #include "sysdep_decls.h"
27 #include "serv_extensions.h"
32 #include "mime_parser.h"
33 #include "serv_calendar.h"
35 #ifdef CITADEL_WITH_CALENDAR_SERVICE
38 #include "ical_dezonify.h"
40 struct ical_respond_data {
41 char desired_partnum[SIZ];
45 /* Session-local data for calendaring. */
50 * Utility function to create a new VCALENDAR component with some of the
51 * required fields already set the way we like them.
53 icalcomponent *icalcomponent_new_citadel_vcalendar(void) {
54 icalcomponent *encaps;
56 encaps = icalcomponent_new_vcalendar();
58 lprintf(3, "Error at %s:%d - could not allocate component!\n",
63 /* Set the Product ID */
64 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
66 /* Set the Version Number */
67 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
74 * Utility function to encapsulate a subcomponent into a full VCALENDAR
76 icalcomponent *ical_encapsulate_subcomponent(icalcomponent *subcomp) {
77 icalcomponent *encaps;
79 /* If we're already looking at a full VCALENDAR component,
80 * don't bother ... just return itself.
82 if (icalcomponent_isa(subcomp) == ICAL_VCALENDAR_COMPONENT) {
86 /* Encapsulate the VEVENT component into a complete VCALENDAR */
87 encaps = icalcomponent_new_citadel_vcalendar();
88 if (encaps == NULL) return NULL;
90 /* Encapsulate the subcomponent inside */
91 icalcomponent_add_component(encaps, subcomp);
93 /* Convert all timestamps to UTC so we don't have to deal with
94 * stupid VTIMEZONE crap.
96 ical_dezonify(encaps);
98 /* Return the object we just created. */
106 * Write a calendar object into the specified user's calendar room.
110 void ical_write_to_cal(struct usersupp *u, icalcomponent *cal) {
114 icalcomponent *encaps;
116 if (cal == NULL) return;
118 /* If the supplied object is a subcomponent, encapsulate it in
119 * a full VCALENDAR component, and save that instead.
121 if (icalcomponent_isa(cal) != ICAL_VCALENDAR_COMPONENT) {
122 encaps = ical_encapsulate_subcomponent(
123 icalcomponent_new_clone(cal)
125 ical_write_to_cal(u, encaps);
126 icalcomponent_free(encaps);
130 strcpy(temp, tmpnam(NULL));
131 ser = icalcomponent_as_ical_string(cal);
132 if (ser == NULL) return;
134 /* Make a temp file out of it */
135 fp = fopen(temp, "w");
136 if (fp == NULL) return;
137 fwrite(ser, strlen(ser), 1, fp);
140 /* This handy API function does all the work for us.
142 CtdlWriteObject(USERCALENDARROOM, /* which room */
143 "text/calendar", /* MIME type */
144 temp, /* temp file */
147 0, /* don't delete others of this type */
155 * Add a calendar object to the user's calendar
157 * ok because it uses ical_write_to_cal()
159 void ical_add(icalcomponent *cal, int recursion_level) {
163 * The VEVENT subcomponent is the one we're interested in saving.
165 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
167 ical_write_to_cal(&CC->usersupp, cal);
171 /* If the component has subcomponents, recurse through them. */
172 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
174 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
175 /* Recursively process subcomponent */
176 ical_add(c, recursion_level+1);
184 * Send a reply to a meeting invitation.
186 * 'request' is the invitation to reply to.
187 * 'action' is the string "accept" or "decline".
189 * (Sorry about this being more than 80 columns ... there was just
190 * no easy way to break it down sensibly.)
194 void ical_send_a_reply(icalcomponent *request, char *action) {
195 icalcomponent *the_reply = NULL;
196 icalcomponent *vevent = NULL;
197 icalproperty *attendee = NULL;
198 char attendee_string[SIZ];
199 icalproperty *organizer = NULL;
200 char organizer_string[SIZ];
201 icalproperty *summary = NULL;
202 char summary_string[SIZ];
203 icalproperty *me_attend = NULL;
204 struct recptypes *recp = NULL;
205 icalparameter *partstat = NULL;
206 char *serialized_reply = NULL;
207 char *reply_message_text = NULL;
208 struct CtdlMessage *msg = NULL;
209 struct recptypes *valid = NULL;
211 strcpy(organizer_string, "");
212 strcpy(summary_string, "Calendar item");
214 if (request == NULL) {
215 lprintf(3, "ERROR: trying to reply to NULL event?\n");
219 the_reply = icalcomponent_new_clone(request);
220 if (the_reply == NULL) {
221 lprintf(3, "ERROR: cannot clone request\n");
225 /* Change the method from REQUEST to REPLY */
226 icalcomponent_set_method(the_reply, ICAL_METHOD_REPLY);
228 vevent = icalcomponent_get_first_component(the_reply, ICAL_VEVENT_COMPONENT);
229 if (vevent != NULL) {
230 /* Hunt for attendees, removing ones that aren't us.
231 * (Actually, remove them all, cloning our own one so we can
232 * re-insert it later)
234 while (attendee = icalcomponent_get_first_property(vevent,
235 ICAL_ATTENDEE_PROPERTY), (attendee != NULL)
237 if (icalproperty_get_attendee(attendee)) {
238 strcpy(attendee_string,
239 icalproperty_get_attendee(attendee) );
240 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
241 strcpy(attendee_string, &attendee_string[7]);
242 striplt(attendee_string);
243 recp = validate_recipients(attendee_string);
245 if (!strcasecmp(recp->recp_local, CC->usersupp.fullname)) {
246 if (me_attend) icalproperty_free(me_attend);
247 me_attend = icalproperty_new_clone(attendee);
254 icalcomponent_remove_property(vevent, attendee);
255 icalproperty_free(attendee);
258 /* We found our own address in the attendee list. */
260 /* Change the partstat from NEEDS-ACTION to ACCEPT or DECLINE */
261 icalproperty_remove_parameter(me_attend, ICAL_PARTSTAT_PARAMETER);
263 if (!strcasecmp(action, "accept")) {
264 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_ACCEPTED);
266 else if (!strcasecmp(action, "decline")) {
267 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_DECLINED);
269 else if (!strcasecmp(action, "tentative")) {
270 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE);
273 if (partstat) icalproperty_add_parameter(me_attend, partstat);
275 /* Now insert it back into the vevent. */
276 icalcomponent_add_property(vevent, me_attend);
279 /* Figure out who to send this thing to */
280 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
281 if (organizer != NULL) {
282 if (icalproperty_get_organizer(organizer)) {
283 strcpy(organizer_string,
284 icalproperty_get_organizer(organizer) );
287 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
288 strcpy(organizer_string, &organizer_string[7]);
289 striplt(organizer_string);
291 strcpy(organizer_string, "");
294 /* Extract the summary string -- we'll use it as the
295 * message subject for the reply
297 summary = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
298 if (summary != NULL) {
299 if (icalproperty_get_summary(summary)) {
300 strcpy(summary_string,
301 icalproperty_get_summary(summary) );
307 /* Now generate the reply message and send it out. */
308 serialized_reply = strdoop(icalcomponent_as_ical_string(the_reply));
309 icalcomponent_free(the_reply); /* don't need this anymore */
310 if (serialized_reply == NULL) return;
312 reply_message_text = mallok(strlen(serialized_reply) + SIZ);
313 if (reply_message_text != NULL) {
314 sprintf(reply_message_text,
315 "Content-type: text/calendar\r\n\r\n%s\r\n",
319 msg = CtdlMakeMessage(&CC->usersupp, organizer_string,
320 CC->quickroom.QRname, 0, FMT_RFC822,
322 summary_string, /* Use summary for subject */
326 valid = validate_recipients(organizer_string);
327 CtdlSubmitMsg(msg, valid, "");
328 CtdlFreeMessage(msg);
331 phree(serialized_reply);
337 * Callback function for mime parser that hunts for calendar content types
338 * and turns them into calendar objects
340 void ical_locate_part(char *name, char *filename, char *partnum, char *disp,
341 void *content, char *cbtype, size_t length, char *encoding,
344 struct ical_respond_data *ird = NULL;
346 ird = (struct ical_respond_data *) cbuserdata;
348 /* desired_partnum can be set to "_HUNT_" to have it just look for
349 * the first part with a content type of text/calendar. Otherwise
350 * we have to only process the right one.
352 if (strcasecmp(ird->desired_partnum, "_HUNT_")) {
353 if (strcasecmp(partnum, ird->desired_partnum)) {
358 if (strcasecmp(cbtype, "text/calendar")) {
362 if (ird->cal != NULL) {
363 icalcomponent_free(ird->cal);
367 ird->cal = icalcomponent_new_from_string(content);
368 if (ird->cal != NULL) {
369 ical_dezonify(ird->cal);
375 * Respond to a meeting request.
377 void ical_respond(long msgnum, char *partnum, char *action) {
378 struct CtdlMessage *msg;
379 struct ical_respond_data ird;
382 (strcasecmp(action, "accept"))
383 && (strcasecmp(action, "decline"))
385 cprintf("%d Action must be 'accept' or 'decline'\n",
386 ERROR + ILLEGAL_VALUE
391 msg = CtdlFetchMessage(msgnum);
393 cprintf("%d Message %ld not found.\n",
400 memset(&ird, 0, sizeof ird);
401 strcpy(ird.desired_partnum, partnum);
402 mime_parser(msg->cm_fields['M'],
404 *ical_locate_part, /* callback function */
406 (void *) &ird, /* user data */
410 /* We're done with the incoming message, because we now have a
411 * calendar object in memory.
413 CtdlFreeMessage(msg);
416 * Here is the real meat of this function. Handle the event.
418 if (ird.cal != NULL) {
419 /* Save this in the user's calendar if necessary */
420 if (!strcasecmp(action, "accept")) {
421 ical_add(ird.cal, 0);
424 /* Send a reply if necessary */
425 if (icalcomponent_get_method(ird.cal) == ICAL_METHOD_REQUEST) {
426 ical_send_a_reply(ird.cal, action);
429 /* Now that we've processed this message, we don't need it
430 * anymore. So delete it.
432 CtdlDeleteMessages(CC->quickroom.QRname, msgnum, "");
434 /* Free the memory we allocated and return a response. */
435 icalcomponent_free(ird.cal);
437 cprintf("%d ok\n", CIT_OK);
441 cprintf("%d No calendar object found\n", ERROR);
445 /* should never get here */
450 * Figure out the UID of the calendar event being referred to in a
451 * REPLY object. This function is recursive.
453 void ical_learn_uid_of_reply(char *uidbuf, icalcomponent *cal) {
454 icalcomponent *subcomponent;
457 /* If this object is a REPLY, then extract the UID. */
458 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
459 p = icalcomponent_get_first_property(cal, ICAL_UID_PROPERTY);
461 strcpy(uidbuf, icalproperty_get_comment(p));
465 /* Otherwise, recurse through any VEVENT subcomponents. We do NOT want the
466 * UID of the reply; we want the UID of the invitation being replied to.
468 for (subcomponent = icalcomponent_get_first_component(cal, ICAL_VEVENT_COMPONENT);
469 subcomponent != NULL;
470 subcomponent = icalcomponent_get_next_component(cal, ICAL_VEVENT_COMPONENT) ) {
471 ical_learn_uid_of_reply(uidbuf, subcomponent);
477 * ical_update_my_calendar_with_reply() refers to this callback function; when we
478 * locate the message containing the calendar event we're replying to, this function
479 * gets called. It basically just sticks the message number in a supplied buffer.
481 void ical_hunt_for_event_to_update(long msgnum, void *data) {
484 msgnumptr = (long *) data;
489 struct original_event_container {
494 * Callback function for mime parser that hunts for calendar content types
495 * and turns them into calendar objects (called by ical_update_my_calendar_with_reply()
496 * to fetch the object being updated)
498 void ical_locate_original_event(char *name, char *filename, char *partnum, char *disp,
499 void *content, char *cbtype, size_t length, char *encoding,
502 struct original_event_container *oec = NULL;
504 if (strcasecmp(cbtype, "text/calendar")) {
507 oec = (struct original_event_container *) cbuserdata;
508 if (oec->c != NULL) {
509 icalcomponent_free(oec->c);
511 oec->c = icalcomponent_new_from_string(content);
516 * Merge updated attendee information from a REPLY into an existing event.
518 void ical_merge_attendee_reply(icalcomponent *event, icalcomponent *reply) {
520 icalproperty *e_attendee, *r_attendee;
522 /* First things first. If we're not looking at a VEVENT component,
523 * recurse through subcomponents until we find one.
525 if (icalcomponent_isa(event) != ICAL_VEVENT_COMPONENT) {
526 for (c = icalcomponent_get_first_component(event, ICAL_VEVENT_COMPONENT);
528 c = icalcomponent_get_next_component(event, ICAL_VEVENT_COMPONENT) ) {
529 ical_merge_attendee_reply(c, reply);
534 /* Now do the same thing with the reply.
536 if (icalcomponent_isa(reply) != ICAL_VEVENT_COMPONENT) {
537 for (c = icalcomponent_get_first_component(reply, ICAL_VEVENT_COMPONENT);
539 c = icalcomponent_get_next_component(reply, ICAL_VEVENT_COMPONENT) ) {
540 ical_merge_attendee_reply(event, c);
545 /* Clone the reply, because we're going to rip its guts out. */
546 reply = icalcomponent_new_clone(reply);
548 /* At this point we're looking at the correct subcomponents.
549 * Iterate through the attendees looking for a match.
552 for (e_attendee = icalcomponent_get_first_property(event, ICAL_ATTENDEE_PROPERTY);
554 e_attendee = icalcomponent_get_next_property(event, ICAL_ATTENDEE_PROPERTY)) {
556 for (r_attendee = icalcomponent_get_first_property(reply, ICAL_ATTENDEE_PROPERTY);
558 r_attendee = icalcomponent_get_next_property(reply, ICAL_ATTENDEE_PROPERTY)) {
560 /* Check to see if these two attendees match...
563 icalproperty_get_attendee(e_attendee),
564 icalproperty_get_attendee(r_attendee)
566 /* ...and if they do, remove the attendee from the event
567 * and replace it with the attendee from the reply. (The
568 * reply's copy will have the same address, but an updated
572 icalcomponent_remove_property(event, e_attendee);
574 icalproperty_free(e_attendee);
576 icalcomponent_remove_property(reply, r_attendee);
578 icalcomponent_add_property(event, r_attendee);
581 /* Since we diddled both sets of attendees, we have to start
582 * the iteration over again. This will not create an infinite
583 * loop because we removed the attendee from the reply. (That's
584 * why we cloned the reply, and that's what we mean by "ripping
593 /* Free the *clone* of the reply. */
594 icalcomponent_free(reply);
601 * Handle an incoming RSVP (object with method==ICAL_METHOD_REPLY) for a
602 * calendar event. The object has already been deserialized for us; all
603 * we have to do here is hunt for the event in our calendar, merge in the
604 * updated attendee status, and save it again.
606 * This function returns 0 on success, 1 if the event was not found in the
607 * user's calendar, or 2 if an internal error occurred.
609 int ical_update_my_calendar_with_reply(icalcomponent *cal) {
611 char hold_rm[ROOMNAMELEN];
612 long msgnum_being_replaced = 0;
613 struct CtdlMessage *template = NULL;
614 struct CtdlMessage *msg;
615 struct original_event_container oec;
616 icalcomponent *original_event;
617 char *serialized_event = NULL;
618 char roomname[ROOMNAMELEN];
619 char *message_text = NULL;
621 /* Figure out just what event it is we're dealing with */
622 strcpy(uid, "--==<< InVaLiD uId >>==--");
623 ical_learn_uid_of_reply(uid, cal);
624 lprintf(9, "UID of event being replied to is <%s>\n", uid);
626 strcpy(hold_rm, CC->quickroom.QRname); /* save current room */
628 if (getroom(&CC->quickroom, USERCALENDARROOM) != 0) {
629 getroom(&CC->quickroom, hold_rm);
630 lprintf(3, "cannot get user calendar room\n");
635 * Pound through the user's calendar looking for a message with
636 * the Citadel EUID set to the value we're looking for. Since
637 * Citadel always sets the message EUID to the vCalendar UID of
638 * the event, this will work.
640 template = (struct CtdlMessage *)
641 mallok(sizeof(struct CtdlMessage));
642 memset(template, 0, sizeof(struct CtdlMessage));
643 template->cm_fields['E'] = strdoop(uid);
644 CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
645 template, ical_hunt_for_event_to_update, &msgnum_being_replaced);
646 CtdlFreeMessage(template);
647 getroom(&CC->quickroom, hold_rm); /* return to saved room */
649 lprintf(9, "msgnum_being_replaced == %ld\n", msgnum_being_replaced);
650 if (msgnum_being_replaced == 0) {
651 return(1); /* no calendar event found */
654 /* Now we know the ID of the message containing the event being updated.
655 * We don't actually have to delete it; that'll get taken care of by the
656 * server when we save another event with the same UID. This just gives
657 * us the ability to load the event into memory so we can diddle the
660 msg = CtdlFetchMessage(msgnum_being_replaced);
662 return(2); /* internal error */
665 mime_parser(msg->cm_fields['M'],
667 *ical_locate_original_event, /* callback function */
669 &oec, /* user data */
672 CtdlFreeMessage(msg);
674 original_event = oec.c;
675 if (original_event == NULL) {
676 lprintf(3, "ERROR: Original_component is NULL.\n");
680 /* Merge the attendee's updated status into the event */
681 ical_merge_attendee_reply(original_event, cal);
684 serialized_event = strdoop(icalcomponent_as_ical_string(original_event));
685 icalcomponent_free(original_event); /* Don't need this anymore. */
686 if (serialized_event == NULL) return(2);
688 MailboxName(roomname, sizeof roomname, &CC->usersupp, USERCALENDARROOM);
690 message_text = mallok(strlen(serialized_event) + SIZ);
691 if (message_text != NULL) {
692 sprintf(message_text,
693 "Content-type: text/calendar\r\n\r\n%s\r\n",
697 msg = CtdlMakeMessage(&CC->usersupp,
698 "", /* No recipient */
706 CIT_ICAL->avoid_sending_invitations = 1;
707 CtdlSubmitMsg(msg, NULL, roomname);
708 CtdlFreeMessage(msg);
709 CIT_ICAL->avoid_sending_invitations = 0;
712 phree(serialized_event);
718 * Handle an incoming RSVP for an event. (This is the server subcommand part; it
719 * simply extracts the calendar object from the message, deserializes it, and
720 * passes it up to ical_update_my_calendar_with_reply() for processing.
722 void ical_handle_rsvp(long msgnum, char *partnum, char *action) {
723 struct CtdlMessage *msg;
724 struct ical_respond_data ird;
728 (strcasecmp(action, "update"))
729 && (strcasecmp(action, "ignore"))
731 cprintf("%d Action must be 'update' or 'ignore'\n",
732 ERROR + ILLEGAL_VALUE
737 msg = CtdlFetchMessage(msgnum);
739 cprintf("%d Message %ld not found.\n",
746 memset(&ird, 0, sizeof ird);
747 strcpy(ird.desired_partnum, partnum);
748 mime_parser(msg->cm_fields['M'],
750 *ical_locate_part, /* callback function */
752 (void *) &ird, /* user data */
756 /* We're done with the incoming message, because we now have a
757 * calendar object in memory.
759 CtdlFreeMessage(msg);
762 * Here is the real meat of this function. Handle the event.
764 if (ird.cal != NULL) {
765 /* Update the user's calendar if necessary */
766 if (!strcasecmp(action, "update")) {
767 ret = ical_update_my_calendar_with_reply(ird.cal);
769 cprintf("%d Your calendar has been updated with this reply.\n",
773 cprintf("%d This event does not exist in your calendar.\n",
774 ERROR + FILE_NOT_FOUND);
777 cprintf("%d An internal error occurred.\n",
778 ERROR + INTERNAL_ERROR);
782 cprintf("%d This reply has been ignored.\n", CIT_OK);
785 /* Now that we've processed this message, we don't need it
786 * anymore. So delete it. (Maybe make this optional?)
788 CtdlDeleteMessages(CC->quickroom.QRname, msgnum, "");
790 /* Free the memory we allocated and return a response. */
791 icalcomponent_free(ird.cal);
796 cprintf("%d No calendar object found\n", ERROR);
800 /* should never get here */
805 * Search for a property in both the top level and in a VEVENT subcomponent
807 icalproperty *ical_ctdl_get_subprop(
809 icalproperty_kind which_prop
814 p = icalcomponent_get_first_property(cal, which_prop);
816 c = icalcomponent_get_first_component(cal,
817 ICAL_VEVENT_COMPONENT);
819 p = icalcomponent_get_first_property(c, which_prop);
827 * Check to see if two events overlap. Returns nonzero if they do.
829 int ical_ctdl_is_overlap(
830 struct icaltimetype t1start,
831 struct icaltimetype t1end,
832 struct icaltimetype t2start,
833 struct icaltimetype t2end
836 if (icaltime_is_null_time(t1start)) return(0);
837 if (icaltime_is_null_time(t2start)) return(0);
839 /* First, check for all-day events */
840 if (t1start.is_date) {
841 if (!icaltime_compare_date_only(t1start, t2start)) {
844 if (!icaltime_is_null_time(t2end)) {
845 if (!icaltime_compare_date_only(t1start, t2end)) {
851 if (t2start.is_date) {
852 if (!icaltime_compare_date_only(t2start, t1start)) {
855 if (!icaltime_is_null_time(t1end)) {
856 if (!icaltime_compare_date_only(t2start, t1end)) {
862 /* Now check for overlaps using date *and* time. */
864 /* First, bail out if either event 1 or event 2 is missing end time. */
865 if (icaltime_is_null_time(t1end)) return(0);
866 if (icaltime_is_null_time(t2end)) return(0);
868 /* If event 1 ends before event 2 starts, we're in the clear. */
869 if (icaltime_compare(t1end, t2start) <= 0) return(0);
871 /* If event 2 ends before event 1 starts, we're also ok. */
872 if (icaltime_compare(t2end, t1start) <= 0) return(0);
874 /* Otherwise, they overlap. */
881 * Backend for ical_hunt_for_conflicts()
883 void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
885 struct CtdlMessage *msg;
886 struct ical_respond_data ird;
887 struct icaltimetype t1start, t1end, t2start, t2end;
889 char conflict_event_uid[SIZ];
890 char conflict_event_summary[SIZ];
891 char compare_uid[SIZ];
893 cal = (icalcomponent *)data;
894 strcpy(compare_uid, "");
895 strcpy(conflict_event_uid, "");
896 strcpy(conflict_event_summary, "");
898 msg = CtdlFetchMessage(msgnum);
899 if (msg == NULL) return;
900 memset(&ird, 0, sizeof ird);
901 strcpy(ird.desired_partnum, "_HUNT_");
902 mime_parser(msg->cm_fields['M'],
904 *ical_locate_part, /* callback function */
906 (void *) &ird, /* user data */
909 CtdlFreeMessage(msg);
911 if (ird.cal == NULL) return;
913 t1start = icaltime_null_time();
914 t1end = icaltime_null_time();
915 t2start = icaltime_null_time();
916 t1end = icaltime_null_time();
918 /* Now compare cal to ird.cal */
919 p = ical_ctdl_get_subprop(ird.cal, ICAL_DTSTART_PROPERTY);
920 if (p == NULL) return;
921 if (p != NULL) t2start = icalproperty_get_dtstart(p);
923 p = ical_ctdl_get_subprop(ird.cal, ICAL_DTEND_PROPERTY);
924 if (p != NULL) t2end = icalproperty_get_dtend(p);
926 p = ical_ctdl_get_subprop(cal, ICAL_DTSTART_PROPERTY);
927 if (p == NULL) return;
928 if (p != NULL) t1start = icalproperty_get_dtstart(p);
930 p = ical_ctdl_get_subprop(cal, ICAL_DTEND_PROPERTY);
931 if (p != NULL) t1end = icalproperty_get_dtend(p);
933 p = ical_ctdl_get_subprop(cal, ICAL_UID_PROPERTY);
935 strcpy(compare_uid, icalproperty_get_comment(p));
938 p = ical_ctdl_get_subprop(ird.cal, ICAL_UID_PROPERTY);
940 strcpy(conflict_event_uid, icalproperty_get_comment(p));
943 p = ical_ctdl_get_subprop(ird.cal, ICAL_SUMMARY_PROPERTY);
945 strcpy(conflict_event_summary, icalproperty_get_comment(p));
948 icalcomponent_free(ird.cal);
950 if (ical_ctdl_is_overlap(t1start, t1end, t2start, t2end)) {
951 cprintf("%ld||%s|%s|%d|\n",
954 conflict_event_summary,
955 ( ((strlen(compare_uid)>0)
956 &&(!strcasecmp(compare_uid,
957 conflict_event_uid))) ? 1 : 0
966 * Phase 2 of "hunt for conflicts" operation.
967 * At this point we have a calendar object which represents the VEVENT that
968 * we're considering adding to the calendar. Now hunt through the user's
969 * calendar room, and output zero or more existing VEVENTs which conflict
972 void ical_hunt_for_conflicts(icalcomponent *cal) {
973 char hold_rm[ROOMNAMELEN];
975 strcpy(hold_rm, CC->quickroom.QRname); /* save current room */
977 if (getroom(&CC->quickroom, USERCALENDARROOM) != 0) {
978 getroom(&CC->quickroom, hold_rm);
979 cprintf("%d You do not have a calendar.\n", ERROR);
983 cprintf("%d Conflicting events:\n", LISTING_FOLLOWS);
985 CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
987 ical_hunt_for_conflicts_backend,
992 getroom(&CC->quickroom, hold_rm); /* return to saved room */
999 * Hunt for conflicts (Phase 1 -- retrieve the object and call Phase 2)
1001 void ical_conflicts(long msgnum, char *partnum) {
1002 struct CtdlMessage *msg;
1003 struct ical_respond_data ird;
1005 msg = CtdlFetchMessage(msgnum);
1007 cprintf("%d Message %ld not found.\n",
1008 ERROR+ILLEGAL_VALUE,
1014 memset(&ird, 0, sizeof ird);
1015 strcpy(ird.desired_partnum, partnum);
1016 mime_parser(msg->cm_fields['M'],
1018 *ical_locate_part, /* callback function */
1020 (void *) &ird, /* user data */
1024 CtdlFreeMessage(msg);
1026 if (ird.cal != NULL) {
1027 ical_hunt_for_conflicts(ird.cal);
1028 icalcomponent_free(ird.cal);
1032 cprintf("%d No calendar object found\n", ERROR);
1036 /* should never get here */
1042 * Look for busy time in a VEVENT and add it to the supplied VFREEBUSY.
1044 void ical_add_to_freebusy(icalcomponent *fb, icalcomponent *cal) {
1047 struct icalperiodtype my_period;
1049 if (cal == NULL) return;
1050 my_period = icalperiodtype_null_period();
1052 if (icalcomponent_isa(cal) != ICAL_VEVENT_COMPONENT) {
1053 ical_add_to_freebusy(fb,
1054 icalcomponent_get_first_component(
1055 cal, ICAL_VEVENT_COMPONENT
1063 /* If this event is not opaque, the user isn't publishing it as
1064 * busy time, so don't bother doing anything else.
1066 p = icalcomponent_get_first_property(cal, ICAL_TRANSP_PROPERTY);
1068 v = icalproperty_get_value(p);
1070 if (icalvalue_get_transp(v) != ICAL_TRANSP_OPAQUE) {
1076 /* Convert the DTSTART and DTEND properties to an icalperiod. */
1077 p = icalcomponent_get_first_property(cal, ICAL_DTSTART_PROPERTY);
1079 my_period.start = icalproperty_get_dtstart(p);
1082 p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
1084 my_period.end = icalproperty_get_dtstart(p);
1088 icalcomponent_add_property(fb,
1089 icalproperty_new_freebusy(my_period)
1097 * Backend for ical_freebusy()
1099 * This function simply loads the messages in the user's calendar room,
1100 * which contain VEVENTs, then strips them of all non-freebusy data, and
1101 * adds them to the supplied VCALENDAR.
1104 void ical_freebusy_backend(long msgnum, void *data) {
1106 struct CtdlMessage *msg;
1107 struct ical_respond_data ird;
1109 cal = (icalcomponent *)data;
1111 msg = CtdlFetchMessage(msgnum);
1112 if (msg == NULL) return;
1113 memset(&ird, 0, sizeof ird);
1114 strcpy(ird.desired_partnum, "_HUNT_");
1115 mime_parser(msg->cm_fields['M'],
1117 *ical_locate_part, /* callback function */
1119 (void *) &ird, /* user data */
1122 CtdlFreeMessage(msg);
1124 if (ird.cal == NULL) return;
1126 ical_add_to_freebusy(cal, ird.cal);
1128 /* Now free the memory. */
1129 icalcomponent_free(ird.cal);
1135 * Grab another user's free/busy times
1137 void ical_freebusy(char *who) {
1138 struct usersupp usbuf;
1139 char calendar_room_name[ROOMNAMELEN];
1140 char hold_rm[ROOMNAMELEN];
1141 char *serialized_request = NULL;
1142 icalcomponent *encaps = NULL;
1143 icalcomponent *fb = NULL;
1145 if (getuser(&usbuf, who) != 0) {
1146 cprintf("%d No such user.\n", ERROR + NO_SUCH_USER);
1150 MailboxName(calendar_room_name, sizeof calendar_room_name,
1151 &usbuf, USERCALENDARROOM);
1153 strcpy(hold_rm, CC->quickroom.QRname); /* save current room */
1155 if (getroom(&CC->quickroom, USERCALENDARROOM) != 0) {
1156 cprintf("%d Cannot open calendar\n", ERROR+ROOM_NOT_FOUND);
1157 getroom(&CC->quickroom, hold_rm);
1161 /* Create a VFREEBUSY subcomponent */
1162 lprintf(9, "Creating VFREEBUSY component\n");
1163 fb = icalcomponent_new_vfreebusy();
1165 cprintf("%d Internal error: cannot allocate memory.\n",
1166 ERROR+INTERNAL_ERROR);
1167 icalcomponent_free(encaps);
1168 getroom(&CC->quickroom, hold_rm);
1172 lprintf(9, "Adding busy time from events\n");
1173 CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
1174 NULL, ical_freebusy_backend, (void *)fb
1177 /* Set the method to PUBLISH */
1178 icalcomponent_set_method(fb, ICAL_METHOD_PUBLISH);
1180 /* Set the DTSTAMP to right now. */
1181 icalcomponent_set_dtstamp(fb, icaltime_from_timet(time(NULL), 0));
1183 /* FIXME we still need (at least) DTSTART, DTEND, and the user's
1184 * e-mail address as ORGANIZER.
1187 /* Put the freebusy component into the calendar component */
1188 lprintf(9, "Encapsulating\n");
1189 encaps = ical_encapsulate_subcomponent(fb);
1190 if (encaps == NULL) {
1191 icalcomponent_free(fb);
1192 cprintf("%d Internal error: cannot allocate memory.\n",
1193 ERROR+INTERNAL_ERROR);
1194 getroom(&CC->quickroom, hold_rm);
1198 /* Set the method to PUBLISH */
1199 lprintf(9, "Setting method\n");
1200 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
1203 lprintf(9, "Serializing\n");
1204 serialized_request = strdoop(icalcomponent_as_ical_string(encaps));
1205 icalcomponent_free(encaps); /* Don't need this anymore. */
1207 cprintf("%d Here is the free/busy data:\n", LISTING_FOLLOWS);
1208 if (serialized_request != NULL) {
1209 client_write(serialized_request, strlen(serialized_request));
1210 phree(serialized_request);
1214 /* Go back to the room from which we came... */
1215 getroom(&CC->quickroom, hold_rm);
1222 * All Citadel calendar commands from the client come through here.
1224 void cmd_ical(char *argbuf)
1232 extract(subcmd, argbuf, 0);
1234 /* Allow "test" and "freebusy" subcommands without logging in. */
1236 if (!strcmp(subcmd, "test")) {
1237 cprintf("%d This server supports calendaring\n", CIT_OK);
1241 if (!strcmp(subcmd, "freebusy")) {
1242 extract(who, argbuf, 1);
1247 if (CtdlAccessCheck(ac_logged_in)) return;
1249 if (!strcmp(subcmd, "respond")) {
1250 msgnum = extract_long(argbuf, 1);
1251 extract(partnum, argbuf, 2);
1252 extract(action, argbuf, 3);
1253 ical_respond(msgnum, partnum, action);
1257 if (!strcmp(subcmd, "handle_rsvp")) {
1258 msgnum = extract_long(argbuf, 1);
1259 extract(partnum, argbuf, 2);
1260 extract(action, argbuf, 3);
1261 ical_handle_rsvp(msgnum, partnum, action);
1265 if (!strcmp(subcmd, "conflicts")) {
1266 msgnum = extract_long(argbuf, 1);
1267 extract(partnum, argbuf, 2);
1268 ical_conflicts(msgnum, partnum);
1272 cprintf("%d Invalid subcommand\n", ERROR+CMD_NOT_SUPPORTED);
1278 * We don't know if the calendar room exists so we just create it at login
1280 void ical_create_room(void)
1282 struct quickroom qr;
1285 /* Create the calendar room if it doesn't already exist */
1286 create_room(USERCALENDARROOM, 4, "", 0, 1, 0);
1288 /* Set expiration policy to manual; otherwise objects will be lost! */
1289 if (lgetroom(&qr, USERCALENDARROOM)) {
1290 lprintf(3, "Couldn't get the user calendar room!\n");
1293 qr.QRep.expire_mode = EXPIRE_MANUAL;
1294 qr.QRdefaultview = 3; /* 3 = calendar view */
1297 /* Set the view to a calendar view */
1298 CtdlGetRelationship(&vbuf, &CC->usersupp, &qr);
1299 vbuf.v_view = 3; /* 3 = calendar */
1300 CtdlSetRelationship(&vbuf, &CC->usersupp, &qr);
1302 /* Create the tasks list room if it doesn't already exist */
1303 create_room(USERTASKSROOM, 4, "", 0, 1, 0);
1305 /* Set expiration policy to manual; otherwise objects will be lost! */
1306 if (lgetroom(&qr, USERTASKSROOM)) {
1307 lprintf(3, "Couldn't get the user calendar room!\n");
1310 qr.QRep.expire_mode = EXPIRE_MANUAL;
1311 qr.QRdefaultview = 4; /* 4 = tasks view */
1314 /* Set the view to a task list view */
1315 CtdlGetRelationship(&vbuf, &CC->usersupp, &qr);
1316 vbuf.v_view = 4; /* 4 = tasks */
1317 CtdlSetRelationship(&vbuf, &CC->usersupp, &qr);
1324 * ical_send_out_invitations() is called by ical_saving_vevent() when it
1327 void ical_send_out_invitations(icalcomponent *cal) {
1328 icalcomponent *the_request = NULL;
1329 char *serialized_request = NULL;
1330 icalcomponent *encaps = NULL;
1331 char *request_message_text = NULL;
1332 struct CtdlMessage *msg = NULL;
1333 struct recptypes *valid = NULL;
1334 char attendees_string[SIZ];
1335 int num_attendees = 0;
1336 char this_attendee[SIZ];
1337 icalproperty *attendee = NULL;
1338 char summary_string[SIZ];
1339 icalproperty *summary = NULL;
1342 lprintf(3, "ERROR: trying to reply to NULL event?\n");
1347 /* If this is a VCALENDAR component, look for a VEVENT subcomponent. */
1348 if (icalcomponent_isa(cal) == ICAL_VCALENDAR_COMPONENT) {
1349 ical_send_out_invitations(
1350 icalcomponent_get_first_component(
1351 cal, ICAL_VEVENT_COMPONENT
1357 /* Clone the event */
1358 the_request = icalcomponent_new_clone(cal);
1359 if (the_request == NULL) {
1360 lprintf(3, "ERROR: cannot clone calendar object\n");
1364 /* Extract the summary string -- we'll use it as the
1365 * message subject for the request
1367 strcpy(summary_string, "Meeting request");
1368 summary = icalcomponent_get_first_property(the_request, ICAL_SUMMARY_PROPERTY);
1369 if (summary != NULL) {
1370 if (icalproperty_get_summary(summary)) {
1371 strcpy(summary_string,
1372 icalproperty_get_summary(summary) );
1376 /* Determine who the recipients of this message are (the attendees) */
1377 strcpy(attendees_string, "");
1378 for (attendee = icalcomponent_get_first_property(the_request, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(the_request, ICAL_ATTENDEE_PROPERTY)) {
1379 if (icalproperty_get_attendee(attendee)) {
1380 strcpy(this_attendee, icalproperty_get_attendee(attendee) );
1381 if (!strncasecmp(this_attendee, "MAILTO:", 7)) {
1382 strcpy(this_attendee, &this_attendee[7]);
1383 snprintf(&attendees_string[strlen(attendees_string)],
1384 sizeof(attendees_string) - strlen(attendees_string),
1393 lprintf(9, "<%d> attendees: <%s>\n", num_attendees, attendees_string);
1395 /* If there are no attendees, there are no invitations to send, so...
1396 * don't bother putting one together! Punch out, Maverick!
1398 if (num_attendees == 0) {
1399 icalcomponent_free(the_request);
1403 /* Encapsulate the VEVENT component into a complete VCALENDAR */
1404 encaps = icalcomponent_new_vcalendar();
1405 if (encaps == NULL) {
1406 lprintf(3, "Error at %s:%d - could not allocate component!\n",
1407 __FILE__, __LINE__);
1408 icalcomponent_free(the_request);
1412 /* Set the Product ID */
1413 icalcomponent_add_property(encaps, icalproperty_new_prodid(PRODID));
1415 /* Set the Version Number */
1416 icalcomponent_add_property(encaps, icalproperty_new_version("2.0"));
1418 /* Set the method to REQUEST */
1419 icalcomponent_set_method(encaps, ICAL_METHOD_REQUEST);
1421 /* Now make sure all of the DTSTART and DTEND properties are UTC. */
1422 ical_dezonify(the_request);
1424 /* Here we go: put the VEVENT into the VCALENDAR. We now no longer
1425 * are responsible for "the_request"'s memory -- it will be freed
1426 * when we free "encaps".
1428 icalcomponent_add_component(encaps, the_request);
1431 serialized_request = strdoop(icalcomponent_as_ical_string(encaps));
1432 icalcomponent_free(encaps); /* Don't need this anymore. */
1433 if (serialized_request == NULL) return;
1435 request_message_text = mallok(strlen(serialized_request) + SIZ);
1436 if (request_message_text != NULL) {
1437 sprintf(request_message_text,
1438 "Content-type: text/calendar\r\n\r\n%s\r\n",
1442 msg = CtdlMakeMessage(&CC->usersupp,
1443 "", /* No single recipient here */
1444 CC->quickroom.QRname, 0, FMT_RFC822,
1446 summary_string, /* Use summary for subject */
1447 request_message_text);
1450 valid = validate_recipients(attendees_string);
1451 CtdlSubmitMsg(msg, valid, "");
1452 CtdlFreeMessage(msg);
1455 phree(serialized_request);
1460 * When a calendar object is being saved, determine whether it's a VEVENT
1461 * and the user saving it is the organizer. If so, send out invitations
1462 * to any listed attendees.
1465 void ical_saving_vevent(icalcomponent *cal) {
1467 icalproperty *organizer = NULL;
1468 char organizer_string[SIZ];
1470 /* Don't send out invitations if we've been asked not to. */
1471 lprintf(9, "CIT_ICAL->avoid_sending_invitations = %d\n",
1472 CIT_ICAL->avoid_sending_invitations);
1473 if (CIT_ICAL->avoid_sending_invitations > 0) {
1477 strcpy(organizer_string, "");
1479 * The VEVENT subcomponent is the one we're interested in.
1480 * Send out invitations if, and only if, this user is the Organizer.
1482 if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
1483 organizer = icalcomponent_get_first_property(cal,
1484 ICAL_ORGANIZER_PROPERTY);
1485 if (organizer != NULL) {
1486 if (icalproperty_get_organizer(organizer)) {
1487 strcpy(organizer_string,
1488 icalproperty_get_organizer(organizer));
1491 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
1492 strcpy(organizer_string, &organizer_string[7]);
1493 striplt(organizer_string);
1495 * If the user saving the event is listed as the
1496 * organizer, then send out invitations.
1498 if (CtdlIsMe(organizer_string)) {
1499 ical_send_out_invitations(cal);
1504 /* If the component has subcomponents, recurse through them. */
1505 for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
1507 c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
1508 /* Recursively process subcomponent */
1509 ical_saving_vevent(c);
1517 * Back end for ical_obj_beforesave()
1518 * This hunts for the UID of the calendar event (becomes Citadel msg EUID),
1519 * the summary of the event (becomes message subject),
1520 * and the start time (becomes message date/time).
1522 void ical_ctdl_set_extended_msgid(char *name, char *filename, char *partnum,
1523 char *disp, void *content, char *cbtype, size_t length,
1524 char *encoding, void *cbuserdata)
1528 struct icalmessagemod *imm;
1530 imm = (struct icalmessagemod *)cbuserdata;
1532 /* If this is a text/calendar object, hunt for the UID and drop it in
1533 * the "user data" pointer for the MIME parser. When
1534 * ical_obj_beforesave() sees it there, it'll set the Extended msgid
1537 if (!strcasecmp(cbtype, "text/calendar")) {
1538 cal = icalcomponent_new_from_string(content);
1540 if (icalcomponent_isa(cal) == ICAL_VCALENDAR_COMPONENT) {
1541 cal = icalcomponent_get_first_component(
1542 cal, ICAL_VEVENT_COMPONENT
1547 p = ical_ctdl_get_subprop(cal, ICAL_UID_PROPERTY);
1549 strcpy(imm->uid, icalproperty_get_comment(p));
1551 p = ical_ctdl_get_subprop(cal, ICAL_SUMMARY_PROPERTY);
1553 strcpy(imm->subject,
1554 icalproperty_get_comment(p));
1556 p = ical_ctdl_get_subprop(cal, ICAL_DTSTART_PROPERTY);
1558 imm->dtstart = icaltime_as_timet(icalproperty_get_dtstart(p));
1560 icalcomponent_free(cal);
1570 * See if we need to prevent the object from being saved (we don't allow
1571 * MIME types other than text/calendar in the Calendar> room). Also, when
1572 * saving an event to the calendar, set the message's Citadel extended message
1573 * ID to the UID of the object. This causes our replication checker to
1574 * automatically delete any existing instances of the same object. (Isn't
1577 * We also set the message's Subject to the event summary, and the Date/time to
1578 * the event start time.
1580 int ical_obj_beforesave(struct CtdlMessage *msg)
1582 char roomname[ROOMNAMELEN];
1585 struct icalmessagemod imm;
1588 * Only messages with content-type text/calendar
1589 * may be saved to Calendar>. If the message is bound for
1590 * Calendar> but doesn't have this content-type, throw an error
1591 * so that the message may not be posted.
1594 /* First determine if this is our room */
1595 MailboxName(roomname, sizeof roomname, &CC->usersupp, USERCALENDARROOM);
1596 if (strcasecmp(roomname, CC->quickroom.QRname)) {
1597 return 0; /* It's not the Calendar room. */
1600 /* Then determine content-type of the message */
1602 /* It must be an RFC822 message! */
1603 /* FIXME: Not handling MIME multipart messages; implement with IMIP */
1604 if (msg->cm_format_type != 4)
1605 return 1; /* You tried to save a non-RFC822 message! */
1607 /* Find the Content-Type: header */
1608 p = msg->cm_fields['M'];
1611 if (!strncasecmp(p, "Content-Type: ", 14)) { /* Found it */
1612 if (!strncasecmp(p + 14, "text/calendar", 13)) {
1613 memset(&imm, 0, sizeof(struct icalmessagemod));
1614 mime_parser(msg->cm_fields['M'],
1616 *ical_ctdl_set_extended_msgid,
1621 if (strlen(imm.uid) > 0) {
1622 if (msg->cm_fields['E'] != NULL) {
1623 phree(msg->cm_fields['E']);
1625 msg->cm_fields['E'] = strdoop(imm.uid);
1627 if (strlen(imm.subject) > 0) {
1628 if (msg->cm_fields['U'] != NULL) {
1629 phree(msg->cm_fields['U']);
1631 msg->cm_fields['U'] = strdoop(imm.subject);
1633 if (imm.dtstart > 0) {
1634 if (msg->cm_fields['T'] != NULL) {
1635 phree(msg->cm_fields['T']);
1637 msg->cm_fields['T'] = strdoop("000000000000000000");
1638 sprintf(msg->cm_fields['T'], "%ld", imm.dtstart);
1649 /* Oops! No Content-Type in this message! How'd that happen? */
1650 lprintf(7, "RFC822 message with no Content-Type header!\n");
1656 * Things we need to do after saving a calendar event.
1658 void ical_obj_aftersave_backend(char *name, char *filename, char *partnum,
1659 char *disp, void *content, char *cbtype, size_t length,
1660 char *encoding, void *cbuserdata)
1664 /* If this is a text/calendar object, hunt for the UID and drop it in
1665 * the "user data" pointer for the MIME parser. When
1666 * ical_obj_beforesave() sees it there, it'll set the Extended msgid
1669 if (!strcasecmp(cbtype, "text/calendar")) {
1670 cal = icalcomponent_new_from_string(content);
1672 ical_saving_vevent(cal);
1673 icalcomponent_free(cal);
1680 * Things we need to do after saving a calendar event.
1682 int ical_obj_aftersave(struct CtdlMessage *msg)
1684 char roomname[ROOMNAMELEN];
1689 * If this isn't the Calendar> room, no further action is necessary.
1692 /* First determine if this is our room */
1693 MailboxName(roomname, sizeof roomname, &CC->usersupp, USERCALENDARROOM);
1694 if (strcasecmp(roomname, CC->quickroom.QRname)) {
1695 return 0; /* It's not the Calendar room. */
1698 /* Then determine content-type of the message */
1700 /* It must be an RFC822 message! */
1701 /* FIXME: Not handling MIME multipart messages; implement with IMIP */
1702 if (msg->cm_format_type != 4) return(1);
1704 /* Find the Content-Type: header */
1705 p = msg->cm_fields['M'];
1708 if (!strncasecmp(p, "Content-Type: ", 14)) { /* Found it */
1709 if (!strncasecmp(p + 14, "text/calendar", 13)) {
1710 mime_parser(msg->cm_fields['M'],
1712 *ical_obj_aftersave_backend,
1726 /* Oops! No Content-Type in this message! How'd that happen? */
1727 lprintf(7, "RFC822 message with no Content-Type header!\n");
1732 void ical_session_startup(void) {
1733 CtdlAllocUserData(SYM_CIT_ICAL, sizeof(struct cit_ical));
1734 memset(CIT_ICAL, 0, sizeof(struct cit_ical));
1738 #endif /* CITADEL_WITH_CALENDAR_SERVICE */
1741 * Register this module with the Citadel server.
1743 char *serv_calendar_init(void)
1745 #ifdef CITADEL_WITH_CALENDAR_SERVICE
1746 SYM_CIT_ICAL = CtdlGetDynamicSymbol();
1747 CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE);
1748 CtdlRegisterMessageHook(ical_obj_aftersave, EVT_AFTERSAVE);
1749 CtdlRegisterSessionHook(ical_create_room, EVT_LOGIN);
1750 CtdlRegisterProtoHook(cmd_ical, "ICAL", "Citadel iCal commands");
1751 CtdlRegisterSessionHook(ical_session_startup, EVT_START);