]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_calendar.c
* Replaced all "Citadel/UX" references with "Citadel"
[citadel.git] / citadel / serv_calendar.c
index ce20785944379696b4947aebe090faab12e3c901..e60cba927ba4cd319685e3b937a4d38c64455630 100644 (file)
@@ -2,7 +2,7 @@
  * $Id$ 
  *
  * This module implements iCalendar object processing and the Calendar>
- * room on a Citadel/UX server.  It handles iCalendar objects using the
+ * room on a Citadel server.  It handles iCalendar objects using the
  * iTIP protocol.  See RFCs 2445 and 2446.
  *
  */
@@ -387,7 +387,7 @@ void ical_respond(long msgnum, char *partnum, char *action) {
                return;
        }
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) {
                cprintf("%d Message %ld not found.\n",
                        ERROR + ILLEGAL_VALUE,
@@ -656,7 +656,7 @@ int ical_update_my_calendar_with_reply(icalcomponent *cal) {
         * us the ability to load the event into memory so we can diddle the
         * attendees.
         */
-       msg = CtdlFetchMessage(msgnum_being_replaced);
+       msg = CtdlFetchMessage(msgnum_being_replaced, 1);
        if (msg == NULL) {
                return(2);                      /* internal error */
        }
@@ -733,7 +733,7 @@ void ical_handle_rsvp(long msgnum, char *partnum, char *action) {
                return;
        }
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) {
                cprintf("%d Message %ld not found.\n",
                        ERROR + ILLEGAL_VALUE,
@@ -896,7 +896,7 @@ void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
        strcpy(conflict_event_uid, "");
        strcpy(conflict_event_summary, "");
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;
        memset(&ird, 0, sizeof ird);
        strcpy(ird.desired_partnum, "_HUNT_");
@@ -1003,7 +1003,7 @@ void ical_conflicts(long msgnum, char *partnum) {
        struct CtdlMessage *msg;
        struct ical_respond_data ird;
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) {
                cprintf("%d Message %ld not found.\n",
                        ERROR + ILLEGAL_VALUE,
@@ -1090,6 +1090,42 @@ void ical_add_to_freebusy(icalcomponent *fb, icalcomponent *cal) {
                icalproperty_new_freebusy(my_period)
        );
 
+       /* Make sure the DTSTART property of the freebusy *list* is set to
+        * the DTSTART property of the *earliest event*.
+        */
+       p = icalcomponent_get_first_property(fb, ICAL_DTSTART_PROPERTY);
+       if (p == NULL) {
+               icalcomponent_set_dtstart(fb,
+                       icalcomponent_get_dtstart(cal) );
+       }
+       else {
+               if (icaltime_compare(
+                       icalcomponent_get_dtstart(cal),
+                       icalcomponent_get_dtstart(fb)
+                  ) < 0) {
+                       icalcomponent_set_dtstart(fb,
+                               icalcomponent_get_dtstart(cal) );
+               }
+       }
+
+       /* Make sure the DTEND property of the freebusy *list* is set to
+        * the DTEND property of the *latest event*.
+        */
+       p = icalcomponent_get_first_property(fb, ICAL_DTEND_PROPERTY);
+       if (p == NULL) {
+               icalcomponent_set_dtend(fb,
+                       icalcomponent_get_dtend(cal) );
+       }
+       else {
+               if (icaltime_compare(
+                       icalcomponent_get_dtend(cal),
+                       icalcomponent_get_dtend(fb)
+                  ) > 0) {
+                       icalcomponent_set_dtend(fb,
+                               icalcomponent_get_dtend(cal) );
+               }
+       }
+
 }
 
 
@@ -1109,7 +1145,7 @@ void ical_freebusy_backend(long msgnum, void *data) {
 
        cal = (icalcomponent *)data;
 
-       msg = CtdlFetchMessage(msgnum);
+       msg = CtdlFetchMessage(msgnum, 1);
        if (msg == NULL) return;
        memset(&ird, 0, sizeof ird);
        strcpy(ird.desired_partnum, "_HUNT_");
@@ -1233,20 +1269,38 @@ void ical_freebusy(char *who) {
                return;
        }
 
-       lprintf(CTDL_DEBUG, "Adding busy time from events\n");
-       CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
-               NULL, ical_freebusy_backend, (void *)fb
-       );
-
        /* Set the method to PUBLISH */
        icalcomponent_set_method(fb, ICAL_METHOD_PUBLISH);
 
        /* Set the DTSTAMP to right now. */
        icalcomponent_set_dtstamp(fb, icaltime_from_timet(time(NULL), 0));
 
-       /* FIXME we still need (at least) DTSTART, DTEND, and the user's
-        * e-mail address as ORGANIZER.
+       /* Add the user's email address as ORGANIZER */
+       sprintf(buf, "MAILTO:%s", who);
+       if (strchr(buf, '@') == NULL) {
+               strcat(buf, "@");
+               strcat(buf, config.c_fqdn);
+       }
+       for (i=0; i<strlen(buf); ++i) {
+               if (buf[i]==' ') buf[i] = '_';
+       }
+       icalcomponent_add_property(fb, icalproperty_new_organizer(buf));
+
+       /* Add busy time from events */
+       lprintf(CTDL_DEBUG, "Adding busy time from events\n");
+       CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
+               NULL, ical_freebusy_backend, (void *)fb
+       );
+
+       /* If values for DTSTART and DTEND are still not present, set them
+        * to yesterday and tomorrow as default values.
         */
+       if (icalcomponent_get_first_property(fb, ICAL_DTSTART_PROPERTY) == NULL) {
+               icalcomponent_set_dtstart(fb, icaltime_from_timet(time(NULL)-86400L, 0));
+       }
+       if (icalcomponent_get_first_property(fb, ICAL_DTEND_PROPERTY) == NULL) {
+               icalcomponent_set_dtend(fb, icaltime_from_timet(time(NULL)+86400L, 0));
+       }
 
        /* Put the freebusy component into the calendar component */
        lprintf(CTDL_DEBUG, "Encapsulating\n");