]> code.citadel.org Git - citadel.git/blobdiff - citadel/serv_calendar.c
* Do calendar support only if libical header *and* library are present
[citadel.git] / citadel / serv_calendar.c
index 4e87415402e5ce2034f19803dc45c420cc56061a..60d6db9471414d114ccef06fed662e84cbf53298 100644 (file)
@@ -18,7 +18,6 @@
 #ifdef HAVE_STRINGS_H
 #include <strings.h>
 #endif
-#include "serv_calendar.h"
 #include "citadel.h"
 #include "server.h"
 #include "citserver.h"
 #include "tools.h"
 #include "msgbase.h"
 #include "mime_parser.h"
+#include "serv_calendar.h"
 
-#ifdef HAVE_ICAL_H
+#ifdef CITADEL_WITH_CALENDAR_SERVICE
 
 #include <ical.h>
+#include "ical_dezonify.h"
 
 struct ical_respond_data {
        char desired_partnum[SIZ];
@@ -271,6 +272,9 @@ void ical_locate_part(char *name, char *filename, char *partnum, char *disp,
        }
        if (strcasecmp(partnum, ird->desired_partnum)) return;
        ird->cal = icalcomponent_new_from_string(content);
+       if (ird->cal != NULL) {
+               ical_dezonify(ird->cal);
+       }
 }
 
 
@@ -1038,7 +1042,7 @@ void ical_create_room(void)
 
 /*
  * ical_send_out_invitations() is called by ical_saving_vevent() when it
- * finds a VEVENT.   FIXME ... finish implementing.
+ * finds a VEVENT.
  */
 void ical_send_out_invitations(icalcomponent *cal) {
        icalcomponent *the_request = NULL;
@@ -1047,6 +1051,7 @@ void ical_send_out_invitations(icalcomponent *cal) {
        struct CtdlMessage *msg = NULL;
        struct recptypes *valid = NULL;
        char attendees_string[SIZ];
+       int num_attendees = 0;
        char this_attendee[SIZ];
        icalproperty *attendee = NULL;
        char summary_string[SIZ];
@@ -1089,11 +1094,20 @@ void ical_send_out_invitations(icalcomponent *cal) {
                                        "%s, ",
                                        this_attendee
                                );
+                               ++num_attendees;
                        }
                }
        }
 
-       lprintf(9, "attendees_string: <%s>\n", attendees_string);
+       lprintf(9, "<%d> attendees: <%s>\n", num_attendees, attendees_string);
+
+       /* If there are no attendees, there are no invitations to send, so...
+        * don't bother putting one together!  Punch out, Maverick!
+        */
+       if (num_attendees == 0) {
+               icalcomponent_free(the_request);
+               return;
+       }
 
        /* Encapsulate the VEVENT component into a complete VCALENDAR */
        encaps = icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
@@ -1113,7 +1127,8 @@ void ical_send_out_invitations(icalcomponent *cal) {
        /* Set the method to REQUEST */
        icalcomponent_set_method(encaps, ICAL_METHOD_REQUEST);
 
-       /* FIXME: here we need to insert a VTIMEZONE object. */
+       /* Now make sure all of the DTSTART and DTEND properties are UTC. */
+       ical_dezonify(the_request);
 
        /* Here we go: put the VEVENT into the VCALENDAR.  We now no longer
         * are responsible for "the_request"'s memory -- it will be freed
@@ -1162,7 +1177,9 @@ void ical_saving_vevent(icalcomponent *cal) {
        char organizer_string[SIZ];
 
        /* Don't send out invitations if we've been asked not to. */
-       if (CIT_ICAL->avoid_sending_invitations) {
+       lprintf(9, "CIT_ICAL->avoid_sending_invitations = %d\n",
+               CIT_ICAL->avoid_sending_invitations);
+       if (CIT_ICAL->avoid_sending_invitations > 0) {
                return;
        }
 
@@ -1207,7 +1224,9 @@ void ical_saving_vevent(icalcomponent *cal) {
 
 /*
  * Back end for ical_obj_beforesave()
- * This hunts for the UID of the calendar event.
+ * This hunts for the UID of the calendar event (becomes Citadel msg EUID),
+ * the summary of the event (becomes message subject),
+ * and the start time (becomes message date/time).
  */
 void ical_ctdl_set_extended_msgid(char *name, char *filename, char *partnum,
                char *disp, void *content, char *cbtype, size_t length,
@@ -1215,6 +1234,9 @@ void ical_ctdl_set_extended_msgid(char *name, char *filename, char *partnum,
 {
        icalcomponent *cal;
        icalproperty *p;
+       struct icalmessagemod *imm;
+
+       imm = (struct icalmessagemod *)cbuserdata;
 
        /* If this is a text/calendar object, hunt for the UID and drop it in
         * the "user data" pointer for the MIME parser.  When
@@ -1226,9 +1248,16 @@ void ical_ctdl_set_extended_msgid(char *name, char *filename, char *partnum,
                if (cal != NULL) {
                        p = ical_ctdl_get_subprop(cal, ICAL_UID_PROPERTY);
                        if (p != NULL) {
-                               strcpy((char *)cbuserdata,
-                                       icalproperty_get_comment(p)
-                               );
+                               strcpy(imm->uid, icalproperty_get_comment(p));
+                       }
+                       p = ical_ctdl_get_subprop(cal, ICAL_SUMMARY_PROPERTY);
+                       if (p != NULL) {
+                               strcpy(imm->subject,
+                                               icalproperty_get_comment(p));
+                       }
+                       p = ical_ctdl_get_subprop(cal, ICAL_DTSTART_PROPERTY);
+                       if (p != NULL) {
+                               imm->dtstart = icaltime_as_timet(icalproperty_get_dtstart(p));
                        }
                        icalcomponent_free(cal);
                }
@@ -1246,13 +1275,16 @@ void ical_ctdl_set_extended_msgid(char *name, char *filename, char *partnum,
  * ID to the UID of the object.  This causes our replication checker to
  * automatically delete any existing instances of the same object.  (Isn't
  * that cool?)
+ *
+ * We also set the message's Subject to the event summary, and the Date/time to
+ * the event start time.
  */
 int ical_obj_beforesave(struct CtdlMessage *msg)
 {
        char roomname[ROOMNAMELEN];
        char *p;
        int a;
-       char eidbuf[SIZ];
+       struct icalmessagemod imm;
 
        /*
         * Only messages with content-type text/calendar
@@ -1280,19 +1312,32 @@ int ical_obj_beforesave(struct CtdlMessage *msg)
        while (--a > 0) {
                if (!strncasecmp(p, "Content-Type: ", 14)) {    /* Found it */
                        if (!strncasecmp(p + 14, "text/calendar", 13)) {
-                               strcpy(eidbuf, "");
+                               memset(&imm, 0, sizeof(struct icalmessagemod));
                                mime_parser(msg->cm_fields['M'],
                                        NULL,
                                        *ical_ctdl_set_extended_msgid,
                                        NULL, NULL,
-                                       (void *)eidbuf,
+                                       (void *)&imm,
                                        0
                                );
-                               if (strlen(eidbuf) > 0) {
+                               if (strlen(imm.uid) > 0) {
                                        if (msg->cm_fields['E'] != NULL) {
                                                phree(msg->cm_fields['E']);
                                        }
-                                       msg->cm_fields['E'] = strdoop(eidbuf);
+                                       msg->cm_fields['E'] = strdoop(imm.uid);
+                               }
+                               if (strlen(imm.subject) > 0) {
+                                       if (msg->cm_fields['U'] != NULL) {
+                                               phree(msg->cm_fields['U']);
+                                       }
+                                       msg->cm_fields['U'] = strdoop(imm.subject);
+                               }
+                               if (imm.dtstart > 0) {
+                                       if (msg->cm_fields['T'] != NULL) {
+                                               phree(msg->cm_fields['T']);
+                                       }
+                                       msg->cm_fields['T'] = strdoop("000000000000000000");
+                                       sprintf(msg->cm_fields['T'], "%ld", imm.dtstart);
                                }
                                return 0;
                        }
@@ -1387,18 +1432,21 @@ int ical_obj_aftersave(struct CtdlMessage *msg)
 
 
 void ical_session_startup(void) {
+       SYM_CIT_ICAL = CtdlGetDynamicSymbol();
        CtdlAllocUserData(SYM_CIT_ICAL, sizeof(struct cit_ical));
+       memset(CIT_ICAL, 0, sizeof(struct cit_ical));
+       
 }
 
 
-#endif /* HAVE_ICAL_H */
+#endif /* CITADEL_WITH_CALENDAR_SERVICE */
 
 /*
  * Register this module with the Citadel server.
  */
 char *Dynamic_Module_Init(void)
 {
-#ifdef HAVE_ICAL_H
+#ifdef CITADEL_WITH_CALENDAR_SERVICE
        CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE);
        CtdlRegisterMessageHook(ical_obj_aftersave, EVT_AFTERSAVE);
        CtdlRegisterSessionHook(ical_create_room, EVT_LOGIN);