* event.c: fixed a misspelling
[citadel.git] / webcit / event.c
1 /*
2  * $Id$
3  *
4  * Editing calendar events.
5  *
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <sys/socket.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include <time.h>
27 #include "webcit.h"
28 #include "webserver.h"
29
30
31 #ifdef WEBCIT_WITH_CALENDAR_SERVICE
32
33 /*
34  * Display an event by itself (for editing)
35  */
36 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum) {
37         icalcomponent *vevent;
38         icalproperty *p;
39         icalvalue *v;
40         struct icaltimetype t_start, t_end;
41         time_t now;
42         struct tm tm_now;
43         int created_new_vevent = 0;
44         icalproperty *organizer = NULL;
45         char organizer_string[SIZ];
46         icalproperty *attendee = NULL;
47         char attendee_string[SIZ];
48         char buf[SIZ];
49         int i;
50         int organizer_is_me = 0;
51         int sequence = 0;
52
53         now = time(NULL) % 60;  /* mod 60 to force :00 seconds */
54         strcpy(organizer_string, "");
55         strcpy(attendee_string, "");
56
57         if (supplied_vevent != NULL) {
58                 vevent = supplied_vevent;
59         }
60         else {
61                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
62                 created_new_vevent = 1;
63         }
64
65         /* Learn the sequence */
66         p = icalcomponent_get_first_property(vevent, ICAL_SEQUENCE_PROPERTY);
67         if (p != NULL) {
68                 sequence = icalproperty_get_sequence(p);
69         }
70
71         /* Begin output */
72         output_headers(3);
73         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>"
74                 "<IMG ALIGN=CENTER SRC=\"/static/vcalendar.gif\">"
75                 "<FONT SIZE=+1 COLOR=\"FFFFFF\""
76                 "<B>Edit event</B>"
77                 "</FONT></TD></TR></TABLE><BR>\n"
78         );
79
80         /************************************************************
81          * Uncomment this to see the UID in calendar events for debugging
82         wprintf("UID == ");
83         p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
84         if (p != NULL) {
85                 escputs((char *)icalproperty_get_comment(p));
86         }
87         wprintf("<BR>\n");
88         wprintf("SEQUENCE == %d<BR>\n", sequence);
89         *************************************************************/
90
91         wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" ACTION=\"/save_event\">\n");
92
93         wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
94                 msgnum);
95         wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
96                 bstr("calview"));
97         wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
98                 bstr("year"));
99         wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
100                 bstr("month"));
101         wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
102                 bstr("day"));
103
104         /* Put it in a borderless table so it lines up nicely */
105         wprintf("<TABLE border=0 width=100%%>\n");
106
107         wprintf("<TR><TD><B>Summary</B></TD><TD>\n"
108                 "<INPUT TYPE=\"text\" NAME=\"summary\" "
109                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
110         p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
111         if (p != NULL) {
112                 escputs((char *)icalproperty_get_comment(p));
113         }
114         wprintf("\"></TD></TR>\n");
115
116         wprintf("<TR><TD><B>Location</B></TD><TD>\n"
117                 "<INPUT TYPE=\"text\" NAME=\"location\" "
118                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
119         p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
120         if (p != NULL) {
121                 escputs((char *)icalproperty_get_comment(p));
122         }
123         wprintf("\"></TD></TR>\n");
124
125         wprintf("<TR><TD><B>Start</B></TD><TD>\n");
126         p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
127         if (p != NULL) {
128                 t_start = icalproperty_get_dtstart(p);
129                 if (t_start.is_date) {
130                         t_start.hour = 0;
131                         t_start.minute = 0;
132                         t_start.second = 0;
133                 }
134         }
135         else {
136                 memcpy(&tm_now, localtime(&now), sizeof(struct tm));
137                 tm_now.tm_year = atoi(bstr("year")) - 1900;
138                 tm_now.tm_mon = atoi(bstr("month")) - 1;
139                 tm_now.tm_mday = atoi(bstr("day"));
140                 if (strlen(bstr("hour")) > 0) {
141                         tm_now.tm_hour = atoi(bstr("hour"));
142                         tm_now.tm_min = atoi(bstr("minute"));
143                         tm_now.tm_sec = 0;
144                 }
145                 else {
146                         tm_now.tm_hour = 9;
147                         tm_now.tm_min = 0;
148                         tm_now.tm_sec = 0;
149                 }
150
151                 t_start = icaltime_from_timet_with_zone(
152                         mktime(&tm_now),
153                         ((!strcasecmp(bstr("alldayevent"), "yes")) ? 1 : 0),
154                         icaltimezone_get_utc_timezone
155                 );
156                 t_start.is_utc = 1;
157
158         }
159         display_icaltimetype_as_webform(&t_start, "dtstart");
160
161         wprintf("<INPUT TYPE=\"checkbox\" NAME=\"alldayevent\" "
162                 "VALUE=\"yes\" onClick=\"
163
164                         if (this.checked) {
165                                 this.form.dtstart_hour.value='0';
166                                 this.form.dtstart_hour.disabled = true;
167                                 this.form.dtstart_minute.value='0';
168                                 this.form.dtstart_minute.disabled = true;
169                                 this.form.dtend_hour.value='0';
170                                 this.form.dtend_hour.disabled = true;
171                                 this.form.dtend_minute.value='0';
172                                 this.form.dtend_minute.disabled = true;
173                                 this.form.dtend_month.disabled = true;
174                                 this.form.dtend_day.disabled = true;
175                                 this.form.dtend_year.disabled = true;
176                         }
177                         else {
178                                 this.form.dtstart_hour.disabled = false;
179                                 this.form.dtstart_minute.disabled = false;
180                                 this.form.dtend_hour.disabled = false;
181                                 this.form.dtend_minute.disabled = false;
182                                 this.form.dtend_month.disabled = false;
183                                 this.form.dtend_day.disabled = false;
184                                 this.form.dtend_year.disabled = false;
185                         }
186
187
188                 \" %s >All day event",
189                 (t_start.is_date ? "CHECKED" : "" )
190         );
191
192         wprintf("</TD></TR>\n");
193
194         /* If this is an all-day-event, set the end time to be identical to
195          * the start time (the hour/minute/second will be set to midnight).
196          * Otherwise extract or create it.
197          */
198         wprintf("<TR><TD><B>End</B></TD><TD>\n");
199         if (t_start.is_date) {
200                 t_end = t_start;
201         }
202         else {
203                 p = icalcomponent_get_first_property(vevent,
204                                                         ICAL_DTEND_PROPERTY);
205                 if (p != NULL) {
206                         t_end = icalproperty_get_dtend(p);
207                 }
208                 else {
209                         /* If this is not an all-day event and there is no
210                          * end time specified, make the default one hour
211                          * from the start time.
212                          */
213                         t_end = t_start;
214                         t_end.hour += 1;
215                         t_end.second = 0;
216                         t_end = icaltime_normalize(t_end);
217                         /* t_end = icaltime_from_timet(now, 0); */
218                 }
219         }
220         display_icaltimetype_as_webform(&t_end, "dtend");
221         wprintf("</TD></TR>\n");
222
223         wprintf("<TR><TD><B>Notes</B></TD><TD>\n"
224                 "<TEXTAREA NAME=\"description\" wrap=soft "
225                 "ROWS=10 COLS=80 WIDTH=80>\n"
226         );
227         p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
228         if (p != NULL) {
229                 escputs((char *)icalproperty_get_comment(p));
230         }
231         wprintf("</TEXTAREA></TD></TR>");
232
233         /* For a new event, the user creating the event should be the
234          * organizer.  Set this field accordingly.
235          */
236         if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
237            == NULL) {
238                 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
239                 icalcomponent_add_property(vevent,
240                         icalproperty_new_organizer(organizer_string)
241                 );
242         }
243
244         /* Determine who is the organizer of this event.
245          * We need to determine "me" or "not me."
246          */
247         organizer = icalcomponent_get_first_property(vevent,
248                                                 ICAL_ORGANIZER_PROPERTY);
249         if (organizer != NULL) {
250                 strcpy(organizer_string, icalproperty_get_organizer(organizer));
251                 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
252                         strcpy(organizer_string, &organizer_string[7]);
253                         striplt(organizer_string);
254                         lprintf(9, "ISME %s\n", organizer_string);
255                         serv_printf("ISME %s", organizer_string);
256                         serv_gets(buf);
257                         lprintf(9, "%s\n", buf);
258                         if (buf[0] == '2') {
259                                 organizer_is_me = 1;
260                         }
261                 }
262         }
263
264         wprintf("<TR><TD><B>Organizer</B></TD><TD>");
265         escputs(organizer_string);
266         if (organizer_is_me) {
267                 wprintf(" <FONT SIZE=-1><I>"
268                         "(you are the organizer)</I></FONT>\n");
269         }
270
271         /*
272          * Transmit the organizer as a hidden field.   We don't want the user
273          * to be able to change it, but we do want it fed back to the server,
274          * especially if this is a new event and there is no organizer already
275          * in the calendar object.
276          */
277         wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
278         escputs(organizer_string);
279         wprintf("\">");
280
281         wprintf("</TD></TR>\n");
282
283         /* Transparency */
284         wprintf("<TR><TD><B>Show time as:</B></TD><TD>");
285
286         p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
287         if (p == NULL) {
288                 /* No transparency found.  Default to opaque (busy). */
289                 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
290                 if (p != NULL) {
291                         icalcomponent_add_property(vevent, p);
292                 }
293         }
294         if (p != NULL) {
295                 v = icalproperty_get_value(p);
296         }
297         else {
298                 v = NULL;
299         }
300
301         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
302         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
303                 wprintf(" CHECKED");
304         wprintf(">Free&nbsp;&nbsp;");
305
306         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
307         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
308                 wprintf(" CHECKED");
309         wprintf(">Busy");
310
311         wprintf("</TD></TR>\n");
312
313         /* Attendees */
314         wprintf("<TR><TD><B>Attendees</B><BR>"
315                 "<FONT SIZE=-2>(Separate multiple attendees with commas)"
316                 "</FONT></TD><TD>"
317                 "<TEXTAREA %s NAME=\"attendees\" wrap=soft "
318                 "ROWS=3 COLS=80 WIDTH=80>\n",
319                 (organizer_is_me ? "" : "DISABLED ")
320         );
321         i = 0;
322         for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
323                 strcpy(attendee_string, icalproperty_get_attendee(attendee));
324                 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
325
326                         /* screen name or email address */
327                         strcpy(attendee_string, &attendee_string[7]);
328                         striplt(attendee_string);
329                         if (i++) wprintf(", ");
330                         escputs(attendee_string);
331                         wprintf(" ");
332
333                         /* participant status */
334                         partstat_as_string(buf, attendee);
335                         escputs(buf);
336                 }
337         }
338         wprintf("</TEXTAREA></TD></TR>\n");
339
340         /* Done with properties. */
341         wprintf("</TABLE>\n<CENTER>"
342                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save\">"
343                 "&nbsp;&nbsp;"
344                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Delete\">\n"
345                 "&nbsp;&nbsp;"
346                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">\n"
347                 "</CENTER>\n"
348         );
349
350         wprintf("</FORM>\n");
351         
352         wprintf("<SCRIPT language=\"javascript\">
353                 <!--
354
355                         if (document.EventForm.alldayevent.checked) {
356                                 document.EventForm.dtstart_hour.value='0';
357                                 document.EventForm.dtstart_hour.disabled = true;
358                                 document.EventForm.dtstart_minute.value='0';
359                                 document.EventForm.dtstart_minute.disabled = true;
360                                 document.EventForm.dtend_hour.value='0';
361                                 document.EventForm.dtend_hour.disabled = true;
362                                 document.EventForm.dtend_minute.value='0';
363                                 document.EventForm.dtend_minute.disabled = true;
364                                 document.EventForm.dtend_month.disabled = true;
365                                 document.EventForm.dtend_day.disabled = true;
366                                 document.EventForm.dtend_year.disabled = true;
367                         }
368                         else {
369                                 document.EventForm.dtstart_hour.disabled = false;
370                                 document.EventForm.dtstart_minute.disabled = false;
371                                 document.EventForm.dtend_hour.disabled = false;
372                                 document.EventForm.dtend_minute.disabled = false;
373                                 document.EventForm.dtend_month.disabled = false;
374                                 document.EventForm.dtend_day.disabled = false;
375                                 document.EventForm.dtend_year.disabled = false;
376                         }
377                 //-->
378                 </SCRIPT>
379         ");
380
381         wDumpContent(1);
382
383         if (created_new_vevent) {
384                 icalcomponent_free(vevent);
385         }
386 }
387
388 /*
389  * Save an edited event
390  */
391 void save_individual_event(icalcomponent *supplied_vevent, long msgnum) {
392         char buf[SIZ];
393         icalproperty *prop;
394         icalcomponent *vevent;
395         int created_new_vevent = 0;
396         int all_day_event = 0;
397         struct icaltimetype event_start;
398         icalproperty *attendee = NULL;
399         char attendee_string[SIZ];
400         int i;
401         int foundit;
402         char form_attendees[SIZ];
403         char organizer_string[SIZ];
404         int sequence = 0;
405         enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
406
407         if (supplied_vevent != NULL) {
408                 vevent = supplied_vevent;
409         }
410         else {
411                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
412                 created_new_vevent = 1;
413         }
414
415         if (!strcasecmp(bstr("sc"), "Save")) {
416
417                 /* Replace values in the component with ones from the form */
418
419                 while (prop = icalcomponent_get_first_property(vevent,
420                       ICAL_SUMMARY_PROPERTY), prop != NULL) {
421                         icalcomponent_remove_property(vevent, prop);
422                         icalproperty_free(prop);
423                 }
424                 icalcomponent_add_property(vevent,
425                         icalproperty_new_summary(bstr("summary")));
426
427                 while (prop = icalcomponent_get_first_property(vevent,
428                       ICAL_LOCATION_PROPERTY), prop != NULL) {
429                         icalcomponent_remove_property(vevent, prop);
430                         icalproperty_free(prop);
431                 }
432                 icalcomponent_add_property(vevent,
433                         icalproperty_new_location(bstr("location")));
434                 
435                 while (prop = icalcomponent_get_first_property(vevent,
436                       ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
437                         icalcomponent_remove_property(vevent, prop);
438                         icalproperty_free(prop);
439                 }
440                 icalcomponent_add_property(vevent,
441                         icalproperty_new_description(bstr("description")));
442         
443                 while (prop = icalcomponent_get_first_property(vevent,
444                       ICAL_DTSTART_PROPERTY), prop != NULL) {
445                         icalcomponent_remove_property(vevent, prop);
446                         icalproperty_free(prop);
447                 }
448
449                 if (!strcmp(bstr("alldayevent"), "yes")) {
450                         all_day_event = 1;
451                 }
452                 else {
453                         all_day_event = 0;
454                 }
455
456                 event_start = icaltime_from_webform("dtstart");
457                 if (all_day_event) {
458                         event_start.is_date = 1;
459                         event_start.hour = 0;
460                         event_start.minute = 0;
461                         event_start.second = 0;
462                 }
463
464
465                 /* The following odd-looking snippet of code looks like it
466                  * takes some unnecessary steps.  It is done this way because
467                  * libical incorrectly turns an "all day event" into a normal
468                  * event starting at midnight (i.e. it serializes as date/time
469                  * instead of just date) unless icalvalue_new_date() is used.
470                  * So we force it, if this is an all day event.
471                  */
472                 prop = icalproperty_new_dtstart(event_start);
473                 if (all_day_event) {
474                         icalproperty_set_value(prop,
475                                 icalvalue_new_date(event_start)
476                         );
477                 }
478
479                 if (prop) icalcomponent_add_property(vevent, prop);
480                 else icalproperty_free(prop);
481
482                 while (prop = icalcomponent_get_first_property(vevent,
483                       ICAL_DTEND_PROPERTY), prop != NULL) {
484                         icalcomponent_remove_property(vevent, prop);
485                         icalproperty_free(prop);
486                 }
487                 while (prop = icalcomponent_get_first_property(vevent,
488                       ICAL_DURATION_PROPERTY), prop != NULL) {
489                         icalcomponent_remove_property(vevent, prop);
490                         icalproperty_free(prop);
491                 }
492
493                 if (all_day_event == 0) {
494                         icalcomponent_add_property(vevent,
495                                 icalproperty_new_dtend(icaltime_normalize(
496                                         icaltime_from_webform("dtend"))
497                                 )
498                         );
499                 }
500
501                 /* See if transparency is indicated */
502                 if (strlen(bstr("transp")) > 0) {
503                         lprintf(9, "FORM VALUE: <%s>\n", bstr("transp"));
504                         if (!strcasecmp(bstr("transp"), "opaque")) {
505                                 formtransp = ICAL_TRANSP_OPAQUE;
506                                 lprintf(9, "setting to opaque\n");
507                         }
508                         else if (!strcasecmp(bstr("transp"), "transparent")) {
509                                 formtransp = ICAL_TRANSP_TRANSPARENT;
510                                 lprintf(9, "setting to transparent\n");
511                         }
512
513                         while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
514                               (prop != NULL)) {
515                                 lprintf(9, "removing existing property\n");
516                                 icalcomponent_remove_property(vevent, prop);
517                                 icalproperty_free(prop);
518                         }
519
520                         lprintf(9, "adding new property\n");
521                         icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
522                 }
523
524                 /* Give this event a UID if it doesn't have one. */
525                 if (icalcomponent_get_first_property(vevent,
526                    ICAL_UID_PROPERTY) == NULL) {
527                         generate_new_uid(buf);
528                         icalcomponent_add_property(vevent,
529                                 icalproperty_new_uid(buf)
530                         );
531                 }
532
533                 /* Increment the sequence ID */
534                 while (prop = icalcomponent_get_first_property(vevent,
535                       ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
536                         i = icalproperty_get_sequence(prop);
537                         if (i > sequence) sequence = i;
538                         icalcomponent_remove_property(vevent, prop);
539                         icalproperty_free(prop);
540                 }
541                 ++sequence;
542                 icalcomponent_add_property(vevent,
543                         icalproperty_new_sequence(sequence)
544                 );
545                 
546                 /* Set the organizer, only if one does not already exist *and*
547                  * the form is supplying one
548                  */
549                 strcpy(buf, bstr("organizer"));
550                 if ( (icalcomponent_get_first_property(vevent,
551                    ICAL_ORGANIZER_PROPERTY) == NULL) 
552                    && (strlen(buf) > 0) ) {
553
554                         /* set new organizer */
555                         sprintf(organizer_string, "MAILTO:%s", buf);
556                         icalcomponent_add_property(vevent,
557                                 icalproperty_new_organizer(organizer_string)
558                         );
559
560                 }
561
562                 /*
563                  * Add any new attendees listed in the web form
564                  */
565
566                 /* First, strip out the parenthesized partstats.  */
567                 strcpy(form_attendees, bstr("attendees"));
568                 stripout(form_attendees, '(', ')');
569
570                 /* Now iterate! */
571                 for (i=0; i<num_tokens(form_attendees, ','); ++i) {
572                         extract_token(buf, form_attendees, i, ',');
573                         striplt(buf);
574                         if (strlen(buf) > 0) {
575                                 lprintf(9, "Attendee: <%s>\n", buf);
576                                 sprintf(attendee_string, "MAILTO:%s", buf);
577                                 foundit = 0;
578
579                                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
580                                         if (!strcasecmp(attendee_string,
581                                            icalproperty_get_attendee(attendee)))
582                                                 ++foundit;
583                                 }
584
585
586                                 if (foundit == 0) {
587                                         icalcomponent_add_property(vevent,
588                                                 icalproperty_new_attendee(attendee_string)
589                                         );
590                                 }
591                         }
592                 }
593
594                 /*
595                  * Remove any attendees *not* listed in the web form
596                  */
597 STARTOVER:
598                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
599                         strcpy(attendee_string, icalproperty_get_attendee(attendee));
600                         if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
601                                 strcpy(attendee_string, &attendee_string[7]);
602                                 striplt(attendee_string);
603                                 foundit = 0;
604                                 for (i=0; i<num_tokens(form_attendees, ','); ++i) {
605                                         extract_token(buf, form_attendees, i, ',');
606                                         striplt(buf);
607                                         if (!strcasecmp(buf, attendee_string)) ++foundit;
608                                 }
609                                 if (foundit == 0) {
610                                         icalcomponent_remove_property(vevent, attendee);
611                                         icalproperty_free(attendee);
612                                         goto STARTOVER;
613                                 }
614                         }
615                 }
616
617                 /*
618                  * Serialize it and save it to the message base
619                  */
620                 serv_puts("ENT0 1|||4");
621                 serv_gets(buf);
622                 if (buf[0] == '4') {
623                         serv_puts("Content-type: text/calendar");
624                         serv_puts("");
625                         serv_puts(icalcomponent_as_ical_string(vevent));
626                         serv_puts("000");
627                 }
628         }
629
630         /*
631          * If the user clicked 'Delete' then delete it.
632          */
633         if ( (!strcasecmp(bstr("sc"), "Delete")) && (msgnum > 0L) ) {
634                 serv_printf("DELE %ld", atol(bstr("msgnum")));
635                 serv_gets(buf);
636         }
637
638         if (created_new_vevent) {
639                 icalcomponent_free(vevent);
640         }
641
642         /* Go back to the event list */
643         readloop("readfwd");
644 }
645
646
647 #endif /* WEBCIT_WITH_CALENDAR_SERVICE */