]> code.citadel.org Git - citadel.git/blob - citadel/serv_calendar.c
* More work on reply to meeting invitation
[citadel.git] / citadel / serv_calendar.c
1 /* 
2  * $Id$ 
3  *
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.
7  *
8  */
9
10 #include "sysdep.h"
11 #include <unistd.h>
12 #include <sys/types.h>
13 #include <limits.h>
14 #include <stdio.h>
15 #include <string.h>
16 #ifdef HAVE_STRINGS_H
17 #include <strings.h>
18 #endif
19 #include "serv_calendar.h"
20 #include "citadel.h"
21 #include "server.h"
22 #include "citserver.h"
23 #include "sysdep_decls.h"
24 #include "support.h"
25 #include "config.h"
26 #include "dynloader.h"
27 #include "user_ops.h"
28 #include "room_ops.h"
29 #include "tools.h"
30 #include "msgbase.h"
31 #include "mime_parser.h"
32
33
34 #ifdef HAVE_ICAL_H
35
36 #include <ical.h>
37
38 struct ical_respond_data {
39         char desired_partnum[SIZ];
40         icalcomponent *cal;
41 };
42
43
44 /*
45  * Write a calendar object into the specified user's calendar room.
46  */
47 void ical_write_to_cal(struct usersupp *u, icalcomponent *cal) {
48         char temp[PATH_MAX];
49         FILE *fp;
50         char *ser;
51
52         strcpy(temp, tmpnam(NULL));
53         ser = icalcomponent_as_ical_string(cal);
54         if (ser == NULL) return;
55
56         /* Make a temp file out of it */
57         fp = fopen(temp, "w");
58         if (fp == NULL) return;
59         fwrite(ser, strlen(ser), 1, fp);
60         fclose(fp);
61
62         /* This handy API function does all the work for us.
63          */
64         CtdlWriteObject(USERCALENDARROOM,       /* which room */
65                         "text/calendar",        /* MIME type */
66                         temp,                   /* temp file */
67                         u,                      /* which user */
68                         0,                      /* not binary */
69                         0,              /* don't delete others of this type */
70                         0);                     /* no flags */
71
72         unlink(temp);
73 }
74
75
76 /*
77  * Add a calendar object to the user's calendar
78  */
79 void ical_add(icalcomponent *cal, int recursion_level) {
80         icalcomponent *c;
81
82         /*
83          * The VEVENT subcomponent is the one we're interested in saving.
84          */
85         if (icalcomponent_isa(cal) == ICAL_VEVENT_COMPONENT) {
86         
87                 ical_write_to_cal(&CC->usersupp, cal);
88
89         }
90
91         /* If the component has subcomponents, recurse through them. */
92         for (c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
93             (c != 0);
94             c = icalcomponent_get_next_component(cal, ICAL_ANY_COMPONENT)) {
95                 /* Recursively process subcomponent */
96                 ical_add(c, recursion_level+1);
97         }
98
99 }
100
101
102
103 /*
104  * Send a reply to a meeting invitation.
105  *
106  * 'request' is the invitation to reply to.
107  * 'action' is the string "accept" or "decline".
108  *
109  * (Sorry about this being more than 80 columns ... there was just
110  * no easy way to break it down sensibly.)
111  */
112 void ical_send_a_reply(icalcomponent *request, char *action) {
113         icalcomponent *the_reply = NULL;
114         icalcomponent *vevent = NULL;
115         icalproperty *attendee = NULL;
116         char attendee_string[SIZ];
117         icalproperty *organizer = NULL;
118         char organizer_string[SIZ];
119         icalproperty *me_attend = NULL;
120         struct recptypes *recp = NULL;
121         icalparameter *partstat = NULL;
122         char *serialized_reply = NULL;
123         char *reply_message_text = NULL;
124         struct CtdlMessage *msg = NULL;
125         struct recptypes *valid = NULL;
126
127         strcpy(organizer_string, "");
128
129         if (request == NULL) {
130                 lprintf(3, "ERROR: trying to reply to NULL event?\n");
131                 return;
132         }
133
134         the_reply = icalcomponent_new_clone(request);
135         if (the_reply == NULL) {
136                 lprintf(3, "ERROR: cannot clone request\n");
137                 return;
138         }
139
140         /* Change the method from REQUEST to REPLY */
141         icalcomponent_set_method(the_reply, ICAL_METHOD_REPLY);
142
143         vevent = icalcomponent_get_first_component(the_reply, ICAL_VEVENT_COMPONENT);
144         if (vevent != NULL) {
145                 /* Hunt for attendees, removing ones that aren't us.
146                  * (Actually, remove them all, cloning our own one so we can
147                  * re-insert it later)
148                  */
149                 while (attendee = icalcomponent_get_first_property(vevent,
150                     ICAL_ATTENDEE_PROPERTY), (attendee != NULL)
151                 ) {
152                         if (icalproperty_get_attendee(attendee)) {
153                                 strcpy(attendee_string,
154                                         icalproperty_get_attendee(attendee) );
155                                 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
156                                         strcpy(attendee_string, &attendee_string[7]);
157                                         striplt(attendee_string);
158                                         recp = validate_recipients(attendee_string);
159                                         if (recp != NULL) {
160                                                 if (!strcasecmp(recp->recp_local, CC->usersupp.fullname)) {
161                                                         if (me_attend) icalproperty_free(me_attend);
162                                                         me_attend = icalproperty_new_clone(attendee);
163                                                 }
164                                                 phree(recp);
165                                         }
166                                 }
167                         }
168                         /* Remove it... */
169                         icalcomponent_remove_property(vevent, attendee);
170                 }
171
172                 /* We found our own address in the attendee list. */
173                 if (me_attend) {
174                         /* Change the partstat from NEEDS-ACTION to ACCEPT or DECLINE */
175                         icalproperty_remove_parameter(me_attend, ICAL_PARTSTAT_PARAMETER);
176
177                         if (!strcasecmp(action, "accept")) {
178                                 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_ACCEPTED);
179                         }
180                         else if (!strcasecmp(action, "decline")) {
181                                 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_DECLINED);
182                         }
183                         else if (!strcasecmp(action, "tentative")) {
184                                 partstat = icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE);
185                         }
186
187                         if (partstat) icalproperty_add_parameter(me_attend, partstat);
188
189                         /* Now insert it back into the vevent. */
190                         icalcomponent_add_property(vevent, me_attend);
191                 }
192
193                 /* Figure out who to send this thing to */
194                 organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
195                 if (organizer != NULL) {
196                         if (icalproperty_get_organizer(organizer)) {
197                                 strcpy(organizer_string,
198                                         icalproperty_get_organizer(organizer) );
199                         }
200                 }
201                 if (!strncasecmp(organizer, "MAILTO:", 7)) {
202                         strcpy(organizer_string, &organizer_string[7]);
203                         striplt(organizer_string);
204                 } else {
205                         strcpy(organizer_string, "");
206                 }
207         }
208
209         /* Now generate the reply message and send it out. */
210         serialized_reply = strdoop(icalcomponent_as_ical_string(the_reply));
211         icalcomponent_free(the_reply);  /* don't need this anymore */
212         if (serialized_reply == NULL) return;
213
214         reply_message_text = mallok(strlen(serialized_reply) + SIZ);
215         if (reply_message_text != NULL) {
216                 sprintf(reply_message_text,
217                         "Content-type: text/calendar\r\n\r\n%s\r\n",
218                         serialized_reply
219                 );
220
221                 /* FIXME this still causes crashy crashy badness.  */
222                 msg = CtdlMakeMessage(&CC->usersupp, organizer_string,
223                         CC->quickroom.QRname, 0, FMT_RFC822,
224                         NULL, "FIXME subject", reply_message_text);
225         
226                 if (msg != NULL) {
227                         valid = validate_recipients(organizer_string);
228                         CtdlSubmitMsg(msg, valid, "");
229                         CtdlFreeMessage(msg);
230                 }
231         }
232         phree(serialized_reply);
233 }
234
235
236
237 /*
238  * Callback function for mime parser that hunts for calendar content types
239  * and turns them into calendar objects
240  */
241 void ical_locate_part(char *name, char *filename, char *partnum, char *disp,
242                 void *content, char *cbtype, size_t length, char *encoding,
243                 void *cbuserdata) {
244
245         struct ical_respond_data *ird = NULL;
246
247         ird = (struct ical_respond_data *) cbuserdata;
248         if (ird->cal != NULL) {
249                 icalcomponent_free(ird->cal);
250                 ird->cal = NULL;
251         }
252         if (strcasecmp(partnum, ird->desired_partnum)) return;
253         ird->cal = icalcomponent_new_from_string(content);
254 }
255
256
257 /*
258  * Respond to a meeting request.
259  */
260 void ical_respond(long msgnum, char *partnum, char *action) {
261         struct CtdlMessage *msg;
262         struct ical_respond_data ird;
263
264         if (
265            (strcasecmp(action, "accept"))
266            && (strcasecmp(action, "decline"))
267         ) {
268                 cprintf("%d Action must be 'accept' or 'decline'\n",
269                         ERROR + ILLEGAL_VALUE
270                 );
271                 return;
272         }
273
274         msg = CtdlFetchMessage(msgnum);
275         if (msg == NULL) {
276                 cprintf("%d Message %ld not found.\n",
277                         ERROR+ILLEGAL_VALUE,
278                         (long)msgnum
279                 );
280                 return;
281         }
282
283         memset(&ird, 0, sizeof ird);
284         strcpy(ird.desired_partnum, partnum);
285         mime_parser(msg->cm_fields['M'],
286                 NULL,
287                 *ical_locate_part,              /* callback function */
288                 NULL, NULL,
289                 (void *) &ird,                  /* user data */
290                 0
291         );
292
293         /* We're done with the incoming message, because we now have a
294          * calendar object in memory.
295          */
296         CtdlFreeMessage(msg);
297
298         /*
299          * Here is the real meat of this function.  Handle the event.
300          */
301         if (ird.cal != NULL) {
302                 /* Save this in the user's calendar if necessary */
303                 if (!strcasecmp(action, "accept")) {
304                         ical_add(ird.cal, 0);
305                 }
306
307                 /* Send a reply if necessary */
308                 if (icalcomponent_get_method(ird.cal) == ICAL_METHOD_REQUEST) {
309                         ical_send_a_reply(ird.cal, action);
310                 }
311
312                 /* Delete the message from the inbox */
313                 /* FIXME ... do this */
314
315                 /* Free the memory we allocated and return a response. */
316                 icalcomponent_free(ird.cal);
317                 ird.cal = NULL;
318                 cprintf("%d ok\n", CIT_OK);
319                 return;
320         }
321         else {
322                 cprintf("%d No calendar object found\n", ERROR);
323                 return;
324         }
325
326         /* should never get here */
327 }
328
329
330 /*
331  * Search for a property in both the top level and in a VEVENT subcomponent
332  */
333 icalproperty *ical_ctdl_get_subprop(
334                 icalcomponent *cal,
335                 icalproperty_kind which_prop
336 ) {
337         icalproperty *p;
338         icalcomponent *c;
339
340         p = icalcomponent_get_first_property(cal, which_prop);
341         if (p == NULL) {
342                 c = icalcomponent_get_first_component(cal,
343                                                         ICAL_VEVENT_COMPONENT);
344                 if (c != NULL) {
345                         p = icalcomponent_get_first_property(c, which_prop);
346                 }
347         }
348         return p;
349 }
350
351
352 /*
353  * Check to see if two events overlap.  Returns nonzero if they do.
354  */
355 int ical_ctdl_is_overlap(
356                         struct icaltimetype t1start,
357                         struct icaltimetype t1end,
358                         struct icaltimetype t2start,
359                         struct icaltimetype t2end
360 ) {
361
362         if (icaltime_is_null_time(t1start)) return(0);
363         if (icaltime_is_null_time(t2start)) return(0);
364
365         /* First, check for all-day events */
366         if (t1start.is_date) {
367                 if (!icaltime_compare_date_only(t1start, t2start)) {
368                         return(1);
369                 }
370                 if (!icaltime_is_null_time(t2end)) {
371                         if (!icaltime_compare_date_only(t1start, t2end)) {
372                                 return(1);
373                         }
374                 }
375         }
376
377         if (t2start.is_date) {
378                 if (!icaltime_compare_date_only(t2start, t1start)) {
379                         return(1);
380                 }
381                 if (!icaltime_is_null_time(t1end)) {
382                         if (!icaltime_compare_date_only(t2start, t1end)) {
383                                 return(1);
384                         }
385                 }
386         }
387
388         /* Now check for overlaps using date *and* time. */
389
390         /* First, bail out if either event 1 or event 2 is missing end time. */
391         if (icaltime_is_null_time(t1end)) return(0);
392         if (icaltime_is_null_time(t2end)) return(0);
393
394         /* If event 1 ends before event 2 starts, we're in the clear. */
395         if (icaltime_compare(t1end, t2start) <= 0) return(0);
396
397         /* If event 2 ends before event 1 starts, we're also ok. */
398         if (icaltime_compare(t2end, t1start) <= 0) return(0);
399
400         /* Otherwise, they overlap. */
401         return(1);
402 }
403
404
405
406 /*
407  * Backend for ical_hunt_for_conflicts()
408  */
409 void ical_hunt_for_conflicts_backend(long msgnum, void *data) {
410         icalcomponent *cal;
411         struct CtdlMessage *msg;
412         struct ical_respond_data ird;
413         struct icaltimetype t1start, t1end, t2start, t2end;
414         icalproperty *p;
415         char conflict_event_uid[SIZ];
416         char conflict_event_summary[SIZ];
417         char compare_uid[SIZ];
418
419         cal = (icalcomponent *)data;
420         strcpy(compare_uid, "");
421         strcpy(conflict_event_uid, "");
422         strcpy(conflict_event_summary, "");
423
424         msg = CtdlFetchMessage(msgnum);
425         if (msg == NULL) return;
426         memset(&ird, 0, sizeof ird);
427         strcpy(ird.desired_partnum, "1");       /* hopefully it's always 1 */
428         mime_parser(msg->cm_fields['M'],
429                 NULL,
430                 *ical_locate_part,              /* callback function */
431                 NULL, NULL,
432                 (void *) &ird,                  /* user data */
433                 0
434         );
435         CtdlFreeMessage(msg);
436
437         if (ird.cal == NULL) return;
438
439         t1start = icaltime_null_time();
440         t1end = icaltime_null_time();
441         t2start = icaltime_null_time();
442         t1end = icaltime_null_time();
443
444         /* Now compare cal to ird.cal */
445         p = ical_ctdl_get_subprop(ird.cal, ICAL_DTSTART_PROPERTY);
446         if (p == NULL) return;
447         if (p != NULL) t2start = icalproperty_get_dtstart(p);
448         
449         p = ical_ctdl_get_subprop(ird.cal, ICAL_DTEND_PROPERTY);
450         if (p != NULL) t2end = icalproperty_get_dtend(p);
451
452         p = ical_ctdl_get_subprop(cal, ICAL_DTSTART_PROPERTY);
453         if (p == NULL) return;
454         if (p != NULL) t1start = icalproperty_get_dtstart(p);
455         
456         p = ical_ctdl_get_subprop(cal, ICAL_DTEND_PROPERTY);
457         if (p != NULL) t1end = icalproperty_get_dtend(p);
458         
459         p = ical_ctdl_get_subprop(cal, ICAL_UID_PROPERTY);
460         if (p != NULL) {
461                 strcpy(compare_uid, icalproperty_get_comment(p));
462         }
463
464         p = ical_ctdl_get_subprop(ird.cal, ICAL_UID_PROPERTY);
465         if (p != NULL) {
466                 strcpy(conflict_event_uid, icalproperty_get_comment(p));
467         }
468
469         p = ical_ctdl_get_subprop(ird.cal, ICAL_SUMMARY_PROPERTY);
470         if (p != NULL) {
471                 strcpy(conflict_event_summary, icalproperty_get_comment(p));
472         }
473
474
475         icalcomponent_free(ird.cal);
476
477         if (ical_ctdl_is_overlap(t1start, t1end, t2start, t2end)) {
478                 cprintf("%ld||%s|%s|%d|\n",
479                         msgnum,
480                         conflict_event_uid,
481                         conflict_event_summary,
482                         (       ((strlen(compare_uid)>0)
483                                 &&(!strcasecmp(compare_uid,
484                                 conflict_event_uid))) ? 1 : 0
485                         )
486                 );
487         }
488 }
489
490
491
492 /* 
493  * Phase 2 of "hunt for conflicts" operation.
494  * At this point we have a calendar object which represents the VEVENT that
495  * we're considering adding to the calendar.  Now hunt through the user's
496  * calendar room, and output zero or more existing VEVENTs which conflict
497  * with this one.
498  */
499 void ical_hunt_for_conflicts(icalcomponent *cal) {
500         char hold_rm[ROOMNAMELEN];
501
502         strcpy(hold_rm, CC->quickroom.QRname);  /* save current room */
503
504         if (getroom(&CC->quickroom, USERCALENDARROOM) != 0) {
505                 getroom(&CC->quickroom, hold_rm);
506                 cprintf("%d You do not have a calendar.\n", ERROR);
507                 return;
508         }
509
510         cprintf("%d Conflicting events:\n", LISTING_FOLLOWS);
511
512         CtdlForEachMessage(MSGS_ALL, 0, "text/calendar",
513                 NULL,
514                 ical_hunt_for_conflicts_backend,
515                 (void *) cal
516         );
517
518         cprintf("000\n");
519         getroom(&CC->quickroom, hold_rm);       /* return to saved room */
520
521 }
522
523
524
525 /*
526  * Hunt for conflicts (Phase 1 -- retrieve the object and call Phase 2)
527  */
528 void ical_conflicts(long msgnum, char *partnum) {
529         struct CtdlMessage *msg;
530         struct ical_respond_data ird;
531
532         msg = CtdlFetchMessage(msgnum);
533         if (msg == NULL) {
534                 cprintf("%d Message %ld not found.\n",
535                         ERROR+ILLEGAL_VALUE,
536                         (long)msgnum
537                 );
538                 return;
539         }
540
541         memset(&ird, 0, sizeof ird);
542         strcpy(ird.desired_partnum, partnum);
543         mime_parser(msg->cm_fields['M'],
544                 NULL,
545                 *ical_locate_part,              /* callback function */
546                 NULL, NULL,
547                 (void *) &ird,                  /* user data */
548                 0
549         );
550
551         CtdlFreeMessage(msg);
552
553         if (ird.cal != NULL) {
554                 ical_hunt_for_conflicts(ird.cal);
555                 icalcomponent_free(ird.cal);
556                 return;
557         }
558         else {
559                 cprintf("%d No calendar object found\n", ERROR);
560                 return;
561         }
562
563         /* should never get here */
564 }
565
566
567
568
569 /*
570  * All Citadel calendar commands from the client come through here.
571  */
572 void cmd_ical(char *argbuf)
573 {
574         char subcmd[SIZ];
575         long msgnum;
576         char partnum[SIZ];
577         char action[SIZ];
578
579         if (CtdlAccessCheck(ac_logged_in)) return;
580
581         extract(subcmd, argbuf, 0);
582
583         if (!strcmp(subcmd, "test")) {
584                 cprintf("%d This server supports calendaring\n", CIT_OK);
585                 return;
586         }
587
588         else if (!strcmp(subcmd, "respond")) {
589                 msgnum = extract_long(argbuf, 1);
590                 extract(partnum, argbuf, 2);
591                 extract(action, argbuf, 3);
592                 ical_respond(msgnum, partnum, action);
593         }
594
595         else if (!strcmp(subcmd, "conflicts")) {
596                 msgnum = extract_long(argbuf, 1);
597                 extract(partnum, argbuf, 2);
598                 ical_conflicts(msgnum, partnum);
599         }
600
601         else {
602                 cprintf("%d Invalid subcommand\n", ERROR+CMD_NOT_SUPPORTED);
603                 return;
604         }
605
606         /* should never get here */
607 }
608
609
610
611 /*
612  * We don't know if the calendar room exists so we just create it at login
613  */
614 void ical_create_room(void)
615 {
616         struct quickroom qr;
617         struct visit vbuf;
618
619         /* Create the calendar room if it doesn't already exist */
620         create_room(USERCALENDARROOM, 4, "", 0, 1, 0);
621
622         /* Set expiration policy to manual; otherwise objects will be lost! */
623         if (lgetroom(&qr, USERCALENDARROOM)) {
624                 lprintf(3, "Couldn't get the user calendar room!\n");
625                 return;
626         }
627         qr.QRep.expire_mode = EXPIRE_MANUAL;
628         lputroom(&qr);
629
630         /* Set the view to a calendar view */
631         CtdlGetRelationship(&vbuf, &CC->usersupp, &qr);
632         vbuf.v_view = 3;        /* 3 = calendar */
633         CtdlSetRelationship(&vbuf, &CC->usersupp, &qr);
634
635         /* Create the tasks list room if it doesn't already exist */
636         create_room(USERTASKSROOM, 4, "", 0, 1, 0);
637
638         /* Set expiration policy to manual; otherwise objects will be lost! */
639         if (lgetroom(&qr, USERTASKSROOM)) {
640                 lprintf(3, "Couldn't get the user calendar room!\n");
641                 return;
642         }
643         qr.QRep.expire_mode = EXPIRE_MANUAL;
644         lputroom(&qr);
645
646         /* Set the view to a task list view */
647         CtdlGetRelationship(&vbuf, &CC->usersupp, &qr);
648         vbuf.v_view = 4;        /* 4 = tasks */
649         CtdlSetRelationship(&vbuf, &CC->usersupp, &qr);
650
651         return;
652 }
653
654
655
656 /*
657  * Back end for ical_obj_beforesave()
658  * This hunts for the UID of the calendar event.
659  */
660 void ical_ctdl_set_extended_msgid(char *name, char *filename, char *partnum,
661                 char *disp, void *content, char *cbtype, size_t length,
662                 char *encoding, void *cbuserdata)
663 {
664         icalcomponent *cal;
665         icalproperty *p;
666
667         /* If this is a text/calendar object, hunt for the UID and drop it in
668          * the "user data" pointer for the MIME parser.  When
669          * ical_obj_beforesave() sees it there, it'll set the Extended msgid
670          * to that string.
671          */
672         if (!strcasecmp(cbtype, "text/calendar")) {
673                 cal = icalcomponent_new_from_string(content);
674                 if (cal != NULL) {
675                         p = ical_ctdl_get_subprop(cal, ICAL_UID_PROPERTY);
676                         if (p != NULL) {
677                                 strcpy((char *)cbuserdata,
678                                         icalproperty_get_comment(p)
679                                 );
680                         }
681                         icalcomponent_free(cal);
682                 }
683         }
684 }
685
686
687
688
689
690 /*
691  * See if we need to prevent the object from being saved (we don't allow
692  * MIME types other than text/calendar in the Calendar> room).  Also, when
693  * saving an event to the calendar, set the message's Citadel extended message
694  * ID to the UID of the object.  This causes our replication checker to
695  * automatically delete any existing instances of the same object.  (Isn't
696  * that cool?)
697  */
698 int ical_obj_beforesave(struct CtdlMessage *msg)
699 {
700         char roomname[ROOMNAMELEN];
701         char *p;
702         int a;
703         char eidbuf[SIZ];
704
705         /*
706          * Only messages with content-type text/calendar
707          * may be saved to Calendar>.  If the message is bound for
708          * Calendar> but doesn't have this content-type, throw an error
709          * so that the message may not be posted.
710          */
711
712         /* First determine if this is our room */
713         MailboxName(roomname, sizeof roomname, &CC->usersupp, USERCALENDARROOM);
714         if (strcasecmp(roomname, CC->quickroom.QRname)) {
715                 return 0;       /* It's not the Calendar room. */
716         }
717
718         /* Then determine content-type of the message */
719         
720         /* It must be an RFC822 message! */
721         /* FIXME: Not handling MIME multipart messages; implement with IMIP */
722         if (msg->cm_format_type != 4)
723                 return 1;       /* You tried to save a non-RFC822 message! */
724         
725         /* Find the Content-Type: header */
726         p = msg->cm_fields['M'];
727         a = strlen(p);
728         while (--a > 0) {
729                 if (!strncasecmp(p, "Content-Type: ", 14)) {    /* Found it */
730                         if (!strncasecmp(p + 14, "text/calendar", 13)) {
731                                 strcpy(eidbuf, "");
732                                 mime_parser(msg->cm_fields['M'],
733                                         NULL,
734                                         *ical_ctdl_set_extended_msgid,
735                                         NULL, NULL,
736                                         (void *)eidbuf,
737                                         0
738                                 );
739                                 if (strlen(eidbuf) > 0) {
740                                         if (msg->cm_fields['E'] != NULL) {
741                                                 phree(msg->cm_fields['E']);
742                                         }
743                                         msg->cm_fields['E'] = strdoop(eidbuf);
744                                 }
745                                 return 0;
746                         }
747                         else {
748                                 return 1;
749                         }
750                 }
751                 p++;
752         }
753         
754         /* Oops!  No Content-Type in this message!  How'd that happen? */
755         lprintf(7, "RFC822 message with no Content-Type header!\n");
756         return 1;
757 }
758
759
760 #endif  /* HAVE_ICAL_H */
761
762 /*
763  * Register this module with the Citadel server.
764  */
765 char *Dynamic_Module_Init(void)
766 {
767 #ifdef HAVE_ICAL_H
768         CtdlRegisterMessageHook(ical_obj_beforesave, EVT_BEFORESAVE);
769         CtdlRegisterSessionHook(ical_create_room, EVT_LOGIN);
770         CtdlRegisterProtoHook(cmd_ical, "ICAL", "Citadel iCal commands");
771 #endif
772         return "$Id$";
773 }