MSGS command can now do full text search on the room
[citadel.git] / citadel / serv_calendar.c
index cb8adcb1a5c0683d72180a7f57e64c00f64ed14b..a847f20002b6296bb2eb012b09bc5e61c85d3cd8 100644 (file)
@@ -430,7 +430,7 @@ void ical_respond(long msgnum, char *partnum, char *action) {
                /* Now that we've processed this message, we don't need it
                 * anymore.  So delete it.
                 */
-               CtdlDeleteMessages(CC->room.QRname, msgnum, "", 1);
+               CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "", 1);
 
                /* Free the memory we allocated and return a response. */
                icalcomponent_free(ird.cal);
@@ -777,7 +777,7 @@ void ical_handle_rsvp(long msgnum, char *partnum, char *action) {
                /* Now that we've processed this message, we don't need it
                 * anymore.  So delete it.  (Maybe make this optional?)
                 */
-               CtdlDeleteMessages(CC->room.QRname, msgnum, "", 1);
+               CtdlDeleteMessages(CC->room.QRname, &msgnum, 1, "", 1);
 
                /* Free the memory we allocated and return a response. */
                icalcomponent_free(ird.cal);
@@ -976,7 +976,7 @@ void ical_hunt_for_conflicts(icalcomponent *cal) {
 
        cprintf("%d Conflicting events:\n", LISTING_FOLLOWS);
 
-       CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/calendar",
                NULL,
                ical_hunt_for_conflicts_backend,
                (void *) cal
@@ -1281,7 +1281,7 @@ void ical_freebusy(char *who) {
 
        /* Add busy time from events */
        lprintf(CTDL_DEBUG, "Adding busy time from events\n");
-       CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL, "text/calendar",
                NULL, ical_freebusy_backend, (void *)fb
        );
 
@@ -1421,7 +1421,8 @@ void ical_getics(void)
        icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
 
        /* Now go through the room encapsulating all calendar items. */
-       CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
+       CtdlForEachMessage(MSGS_ALL, 0, NULL,
+               "text/calendar",
                NULL,
                ical_getics_backend,
                (void *) encaps
@@ -1444,6 +1445,7 @@ void ical_putics(void)
 {
        char *calstream = NULL;
        icalcomponent *cal;
+       icalcomponent *c;
 
        if ( (CC->room.QRdefaultview != VIEW_CALENDAR)
           &&(CC->room.QRdefaultview != VIEW_TASKS) ) {
@@ -1466,7 +1468,31 @@ void ical_putics(void)
        free(calstream);
        ical_dezonify(cal);
 
-       /* FIXME -- WRITE THE CODE TO TAKE APART THE CALENDAR AND POST ITS ITEMS */
+       /* We got our data stream -- now do something with it. */
+
+       /* Delete the existing messages in the room, because we are replacing
+        * the entire calendar with an entire new (or updated) calendar.
+        * (Careful: this opens an S_ROOMS critical section!)
+        */
+       CtdlDeleteMessages(CC->room.QRname, NULL, 0, "", 0);
+
+       /* If the top-level component is *not* a VCALENDAR, we can drop it right
+        * in.  This will almost never happen.
+        */
+       if (icalcomponent_isa(cal) != ICAL_VCALENDAR_COMPONENT) {
+               ical_write_to_cal(&CC->user, cal);
+       }
+       /*
+        * In the more likely event that we're looking at a VCALENDAR with the VEVENT
+        * and other components encapsulated inside, we have to extract them.
+        */
+       else {
+               for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
+                   (c != NULL);
+                   c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
+                       ical_write_to_cal(&CC->user, c);
+               }
+       }
 
        icalcomponent_free(cal);
 }
@@ -2001,7 +2027,6 @@ int ical_obj_aftersave(struct CtdlMessage *msg)
        /* Then determine content-type of the message */
        
        /* It must be an RFC822 message! */
-       /* FIXME: Not handling MIME multipart messages; implement with IMIP */
        if (msg->cm_format_type != 4) return(1);
        
        /* Find the Content-Type: header */
@@ -2049,87 +2074,26 @@ void ical_fixed_output_backend(icalcomponent *cal,
                        int recursion_level
 ) {
        icalcomponent *c;
-       icalproperty *method = NULL;
-       icalproperty_method the_method = ICAL_METHOD_NONE;
        icalproperty *p;
-       struct icaltimetype t;
-       time_t tt;
        char buf[256];
 
-       /* Look for a method */
-       method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
-
-       /* See what we need to do with this */
-       if (method != NULL) {
-               the_method = icalproperty_get_method(method);
-               switch(the_method) {
-                   case ICAL_METHOD_REQUEST:
-                       cprintf("Meeting invitation\n");
-                       break;
-                   case ICAL_METHOD_REPLY:
-                       cprintf("Attendee's reply to your invitation\n");
-                       break;
-                   case ICAL_METHOD_PUBLISH:
-                       cprintf("Published event\n");
-                       break;
-                   default:
-                       cprintf("This is an unknown type of calendar item.\n");
-                       break;
-               }
-       }
-
        p = icalcomponent_get_first_property(cal, ICAL_SUMMARY_PROPERTY);
        if (p != NULL) {
-               cprintf("Summary: %s\n", (const char *)icalproperty_get_comment(p));
+               cprintf("%s\n", (const char *)icalproperty_get_comment(p));
        }
 
        p = icalcomponent_get_first_property(cal, ICAL_LOCATION_PROPERTY);
        if (p != NULL) {
-               cprintf("Location: %s\n", (const char *)icalproperty_get_comment(p));
-       }
-
-       /*
-        * Only show start/end times if we're actually looking at the VEVENT
-        * component.  Otherwise it shows bogus dates for things like timezone.
-        */
-       if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
-
-               p = icalcomponent_get_first_property(cal,
-                                               ICAL_DTSTART_PROPERTY);
-               if (p != NULL) {
-                       t = icalproperty_get_dtstart(p);
-
-                       if (t.is_date) {
-                               cprintf("Date: %s %d, %d\n",
-                                       ascmonths[t.month - 1],
-                                       t.day, t.year
-                               );
-                       }
-                       else {
-                               tt = icaltime_as_timet(t);
-                               fmt_date(buf, sizeof buf, tt, 0);
-                               cprintf("Starting date/time: %s\n", buf);
-                       }
-               }
-       
-               p = icalcomponent_get_first_property(cal, ICAL_DTEND_PROPERTY);
-               if (p != NULL) {
-                       t = icalproperty_get_dtend(p);
-                       tt = icaltime_as_timet(t);
-                       fmt_date(buf, sizeof buf, tt, 0);
-                       cprintf("Ending date/time: %s\n", buf);
-               }
-
+               cprintf("%s\n", (const char *)icalproperty_get_comment(p));
        }
 
        p = icalcomponent_get_first_property(cal, ICAL_DESCRIPTION_PROPERTY);
        if (p != NULL) {
-               cprintf("Description: %s\n", (const char *)icalproperty_get_comment(p));
+               cprintf("%s\n", (const char *)icalproperty_get_comment(p));
        }
 
        /* If the component has attendees, iterate through them. */
        for (p = icalcomponent_get_first_property(cal, ICAL_ATTENDEE_PROPERTY); (p != NULL); p = icalcomponent_get_next_property(cal, ICAL_ATTENDEE_PROPERTY)) {
-               cprintf("Attendee: ");
                safestrncpy(buf, icalproperty_get_attendee(p), sizeof buf);
                if (!strncasecmp(buf, "MAILTO:", 7)) {
 
@@ -2153,7 +2117,7 @@ void ical_fixed_output_backend(icalcomponent *cal,
 
 
 /*
- * Function to output a calendar item  as plain text.  Nobody uses MSG0
+ * Function to output vcalendar data as plain text.  Nobody uses MSG0
  * anymore, so really this is just so we expose the vCard data to the full
  * text indexer.
  */
@@ -2167,7 +2131,6 @@ void ical_fixed_output(char *ptr, int len) {
        free(stringy_cal);
 
        if (cal == NULL) {
-               cprintf("There was an error parsing this calendar item.\n");
                return;
        }