* added gcc printf format checking to wprintf
[citadel.git] / webcit / event.c
1 /*
2  * $Id$
3  *
4  * Editing calendar events.
5  */
6
7 #include "webcit.h"
8 #include "webserver.h"
9
10
11 /*
12  * \brief Display an event by itself (for editing)
13  * \param supplied_vevent the event to edit
14  * \param msgnum reference on the citserver
15  */
16 void display_edit_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from, int unread) {
17         icalcomponent *vevent;
18         icalproperty *p;
19         icalvalue *v;
20         struct icaltimetype t_start, t_end;
21         time_t now;
22         struct tm tm_now;
23         int created_new_vevent = 0;
24         icalproperty *organizer = NULL;
25         char organizer_string[SIZ];
26         icalproperty *attendee = NULL;
27         char attendee_string[SIZ];
28         char buf[SIZ];
29         int organizer_is_me = 0;
30         int i;
31         int sequence = 0;
32
33         lprintf(9, "display_edit_individual_event(%ld) calview=%s year=%s month=%s day=%s\n",
34                 msgnum, bstr("calview"), bstr("year"), bstr("month"), bstr("day")
35         );
36
37         now = time(NULL);
38         strcpy(organizer_string, "");
39         strcpy(attendee_string, "");
40
41         if (supplied_vevent != NULL) {
42                 vevent = supplied_vevent;
43                 /**
44                  * If we're looking at a fully encapsulated VCALENDAR
45                  * rather than a VEVENT component, attempt to use the first
46                  * relevant VEVENT subcomponent.  If there is none, the
47                  * NULL returned by icalcomponent_get_first_component() will
48                  * tell the next iteration of this function to create a
49                  * new one.
50                  */
51                 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
52                         display_edit_individual_event(
53                                 icalcomponent_get_first_component(
54                                         vevent, ICAL_VEVENT_COMPONENT), 
55                                 msgnum, from, unread
56                         );
57                         return;
58                 }
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(1, 1, 2, 0, 0, 0);
73         wprintf("<div id=\"banner\">\n");
74         wprintf("<h1>");
75         wprintf(_("Add or edit an event"));
76         wprintf("</h1>");
77         wprintf("</div>\n");
78
79         wprintf("<div id=\"content\" class=\"service\">\n");
80
81         wprintf("<div class=\"fix_scrollbar_bug\">"
82                 "<table  class=\"event_background\"><tr><td>\n");
83
84         /************************************************************
85          * Uncomment this to see the UID in calendar events for debugging
86         wprintf("UID == ");
87         p = icalcomponent_get_first_property(vevent, ICAL_UID_PROPERTY);
88         if (p != NULL) {
89                 escputs((char *)icalproperty_get_comment(p));
90         }
91         wprintf("<br />\n");
92         wprintf("SEQUENCE == %d<br />\n", sequence);
93         *************************************************************/
94
95         wprintf("<FORM NAME=\"EventForm\" METHOD=\"POST\" action=\"save_event\">\n");
96         wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
97
98         wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n",
99                 msgnum);
100         wprintf("<INPUT TYPE=\"hidden\" NAME=\"calview\" VALUE=\"%s\">\n",
101                 bstr("calview"));
102         wprintf("<INPUT TYPE=\"hidden\" NAME=\"year\" VALUE=\"%s\">\n",
103                 bstr("year"));
104         wprintf("<INPUT TYPE=\"hidden\" NAME=\"month\" VALUE=\"%s\">\n",
105                 bstr("month"));
106         wprintf("<INPUT TYPE=\"hidden\" NAME=\"day\" VALUE=\"%s\">\n",
107                 bstr("day"));
108
109         /** Put it in a borderless table so it lines up nicely */
110         wprintf("<TABLE border=0 width=100%%>\n");
111
112         wprintf("<TR><TD><B>");
113         wprintf(_("Summary"));
114         wprintf("</B></TD><TD>\n"
115                 "<INPUT TYPE=\"text\" NAME=\"summary\" "
116                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
117         p = icalcomponent_get_first_property(vevent, ICAL_SUMMARY_PROPERTY);
118         if (p != NULL) {
119                 escputs((char *)icalproperty_get_comment(p));
120         }
121         wprintf("\"></TD></TR>\n");
122
123         wprintf("<TR><TD><B>");
124         wprintf(_("Location"));
125         wprintf("</B></TD><TD>\n"
126                 "<INPUT TYPE=\"text\" NAME=\"location\" "
127                 "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
128         p = icalcomponent_get_first_property(vevent, ICAL_LOCATION_PROPERTY);
129         if (p != NULL) {
130                 escputs((char *)icalproperty_get_comment(p));
131         }
132         wprintf("\"></TD></TR>\n");
133
134         wprintf("<TR><TD><B>");
135         wprintf(_("Start"));
136         wprintf("</B></TD><TD>\n");
137         p = icalcomponent_get_first_property(vevent, ICAL_DTSTART_PROPERTY);
138         if (p != NULL) {
139                 t_start = icalproperty_get_dtstart(p);
140                 if (t_start.is_date) {
141                         t_start.hour = 0;
142                         t_start.minute = 0;
143                         t_start.second = 0;
144                 }
145         }
146         else {
147                 localtime_r(&now, &tm_now);
148                 if (havebstr("year")) {
149                         tm_now.tm_year = ibstr("year") - 1900;
150                         tm_now.tm_mon = ibstr("month") - 1;
151                         tm_now.tm_mday = ibstr("day");
152                 }
153                 if (havebstr("hour")) {
154                         tm_now.tm_hour = ibstr("hour");
155                         tm_now.tm_min = ibstr("minute");
156                         tm_now.tm_sec = 0;
157                 }
158                 else {
159                         tm_now.tm_hour = 0;
160                         tm_now.tm_min = 0;
161                         tm_now.tm_sec = 0;
162                 }
163
164                 t_start = icaltime_from_timet_with_zone(
165                         mktime(&tm_now),
166                         ((yesbstr("alldayevent")) ? 1 : 0),
167                         icaltimezone_get_utc_timezone()
168                 );
169                 t_start.is_utc = 1;
170
171         }
172         display_icaltimetype_as_webform(&t_start, "dtstart");
173
174         wprintf("<INPUT TYPE=\"checkbox\" id=\"alldayevent\" NAME=\"alldayevent\" "
175                 "VALUE=\"yes\" onclick=\"eventEditAllDay();\""
176                 " %s >%s",
177                 (t_start.is_date ? "CHECKED=\"CHECKED\"" : "" ),
178                 _("All day event")
179         );
180
181         wprintf("</TD></TR>\n");
182
183         /**
184          * If this is an all-day-event, set the end time to be identical to
185          * the start time (the hour/minute/second will be set to midnight).
186          * Otherwise extract or create it.
187          */
188         wprintf("<TR><TD><B>");
189         wprintf(_("End"));
190         wprintf("</B></TD><TD id=\"dtendcell\">\n");
191         if (t_start.is_date) {
192                 t_end = t_start;
193         }
194         else {
195                 p = icalcomponent_get_first_property(vevent,
196                                                         ICAL_DTEND_PROPERTY);
197                 if (p != NULL) {
198                         t_end = icalproperty_get_dtend(p);
199                 }
200                 else {
201                         /**
202                          * If this is not an all-day event and there is no
203                          * end time specified, make the default one hour
204                          * from the start time.
205                          */
206                         t_end = t_start;
207                         t_end.hour += 1;
208                         t_end.second = 0;
209                         t_end = icaltime_normalize(t_end);
210                         /* t_end = icaltime_from_timet(now, 0); */
211                 }
212         }
213         display_icaltimetype_as_webform(&t_end, "dtend");
214         wprintf("</TD></TR>\n");
215
216         wprintf("<TR><TD><B>");
217         wprintf(_("Notes"));
218         wprintf("</B></TD><TD>\n"
219                 "<TEXTAREA NAME=\"description\" wrap=soft "
220                 "ROWS=5 COLS=80 WIDTH=80>\n"
221         );
222         p = icalcomponent_get_first_property(vevent, ICAL_DESCRIPTION_PROPERTY);
223         if (p != NULL) {
224                 escputs((char *)icalproperty_get_comment(p));
225         }
226         wprintf("</TEXTAREA></TD></TR>");
227
228         /**
229          * For a new event, the user creating the event should be the
230          * organizer.  Set this field accordingly.
231          */
232         if (icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY)
233            == NULL) {
234                 sprintf(organizer_string, "MAILTO:%s", WC->cs_inet_email);
235                 icalcomponent_add_property(vevent,
236                         icalproperty_new_organizer(organizer_string)
237                 );
238         }
239
240         /**
241          * Determine who is the organizer of this event.
242          * We need to determine "me" or "not me."
243          */
244         organizer = icalcomponent_get_first_property(vevent, ICAL_ORGANIZER_PROPERTY);
245         if (organizer != NULL) {
246                 strcpy(organizer_string, icalproperty_get_organizer(organizer));
247                 if (!strncasecmp(organizer_string, "MAILTO:", 7)) {
248                         strcpy(organizer_string, &organizer_string[7]);
249                         striplt(organizer_string);
250                         serv_printf("ISME %s", organizer_string);
251                         serv_getln(buf, sizeof buf);
252                         if (buf[0] == '2') {
253                                 organizer_is_me = 1;
254                         }
255                 }
256         }
257
258         wprintf("<TR><TD><B>");
259         wprintf(_("Organizer"));
260         wprintf("</B></TD><TD>");
261         escputs(organizer_string);
262         if (organizer_is_me) {
263                 wprintf(" <FONT SIZE=-1><I>");
264                 wprintf(_("(you are the organizer)"));
265                 wprintf("</I></FONT>\n");
266         }
267
268         /**
269          * Transmit the organizer as a hidden field.   We don't want the user
270          * to be able to change it, but we do want it fed back to the server,
271          * especially if this is a new event and there is no organizer already
272          * in the calendar object.
273          */
274         wprintf("<INPUT TYPE=\"hidden\" NAME=\"organizer\" VALUE=\"");
275         escputs(organizer_string);
276         wprintf("\">");
277
278         wprintf("</TD></TR>\n");
279
280         /** Transparency */
281         wprintf("<TR><TD><B>");
282         wprintf(_("Show time as:"));
283         wprintf("</B></TD><TD>");
284
285         p = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY);
286         if (p == NULL) {
287                 /** No transparency found.  Default to opaque (busy). */
288                 p = icalproperty_new_transp(ICAL_TRANSP_OPAQUE);
289                 if (p != NULL) {
290                         icalcomponent_add_property(vevent, p);
291                 }
292         }
293         if (p != NULL) {
294                 v = icalproperty_get_value(p);
295         }
296         else {
297                 v = NULL;
298         }
299
300         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"transparent\"");
301         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_TRANSPARENT)
302                 wprintf(" CHECKED");
303         wprintf(">");
304         wprintf(_("Free"));
305         wprintf("&nbsp;&nbsp;");
306
307         wprintf("<INPUT TYPE=\"radio\" NAME=\"transp\" VALUE=\"opaque\"");
308         if (v != NULL) if (icalvalue_get_transp(v) == ICAL_TRANSP_OPAQUE)
309                 wprintf(" CHECKED");
310         wprintf(">");
311         wprintf(_("Busy"));
312
313         wprintf("</TD></TR>\n");
314
315         /** Attendees */
316         wprintf("<TR><TD><B>");
317         wprintf(_("Attendees"));
318         wprintf("</B><br />"
319                 "<font size=-2>");
320         wprintf(_("(One per line)"));
321         wprintf("</font>\n");
322
323         /** Pop open an address book -- begin **/
324         wprintf(
325                 "&nbsp;<a href=\"javascript:PopOpenAddressBook('attendees_box|%s');\" "
326                 "title=\"%s\">"
327                 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
328                 "</a>",
329                 _("Attendees"),
330                 _("Contacts")
331         );
332         /** Pop open an address book -- end **/
333
334         wprintf("</TD><TD>"
335                 "<TEXTAREA %s NAME=\"attendees\" id=\"attendees_box\" wrap=soft "
336                 "ROWS=3 COLS=80 WIDTH=80>\n",
337                 (organizer_is_me ? "" : "DISABLED ")
338         );
339         i = 0;
340         for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY);
341             attendee != NULL;
342             attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
343                 strcpy(attendee_string, icalproperty_get_attendee(attendee));
344                 if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
345
346                         /** screen name or email address */
347                         strcpy(attendee_string, &attendee_string[7]);
348                         striplt(attendee_string);
349                         if (i++) wprintf("\n");
350                         escputs(attendee_string);
351                         wprintf(" ");
352
353                         /** participant status */
354                         partstat_as_string(buf, attendee);
355                         escputs(buf);
356                 }
357         }
358         wprintf("</TEXTAREA></TD></TR>\n");
359
360         /** Done with properties. */
361         wprintf("</TABLE>\n<CENTER>"
362                 "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
363                 "&nbsp;&nbsp;"
364                 "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
365                 "&nbsp;&nbsp;"
366                 "<INPUT TYPE=\"submit\" NAME=\"check_button\" "
367                                 "VALUE=\"%s\">\n"
368                 "&nbsp;&nbsp;"
369                 "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
370                 "</CENTER>\n",
371                 _("Save"),
372                 _("Delete"),
373                 _("Check attendee availability"),
374                 _("Cancel")
375         );
376
377         wprintf("</FORM>\n");
378         
379         wprintf("</td></tr></table></div>\n");
380         wprintf("<script type=\"text/javascript\">"
381                 "eventEditAllDay();"
382                 "</script>\n"
383         );
384         
385         address_book_popup();
386         wDumpContent(1);
387
388         if (created_new_vevent) {
389                 icalcomponent_free(vevent);
390         }
391 }
392
393 /**
394  * \brief Save an edited event
395  * \param supplied_vevent the event to save
396  * \param msgnum the index on the citserver
397  */
398 void save_individual_event(icalcomponent *supplied_vevent, long msgnum, char *from, int unread) {
399         char buf[SIZ];
400         icalproperty *prop;
401         icalcomponent *vevent, *encaps;
402         int created_new_vevent = 0;
403         int all_day_event = 0;
404         struct icaltimetype event_start, t;
405         icalproperty *attendee = NULL;
406         char attendee_string[SIZ];
407         int i, j;
408         int foundit;
409         char form_attendees[SIZ];
410         char organizer_string[SIZ];
411         int sequence = 0;
412         enum icalproperty_transp formtransp = ICAL_TRANSP_NONE;
413
414         if (supplied_vevent != NULL) {
415                 vevent = supplied_vevent;
416                 /**
417                  * If we're looking at a fully encapsulated VCALENDAR
418                  * rather than a VEVENT component, attempt to use the first
419                  * relevant VEVENT subcomponent.  If there is none, the
420                  * NULL returned by icalcomponent_get_first_component() will
421                  * tell the next iteration of this function to create a
422                  * new one.
423                  */
424                 if (icalcomponent_isa(vevent) == ICAL_VCALENDAR_COMPONENT) {
425                         save_individual_event(
426                                 icalcomponent_get_first_component(
427                                         vevent, ICAL_VEVENT_COMPONENT), 
428                                 msgnum, from, unread
429                         );
430                         return;
431                 }
432         }
433         else {
434                 vevent = icalcomponent_new(ICAL_VEVENT_COMPONENT);
435                 created_new_vevent = 1;
436         }
437
438         if ( (havebstr("save_button"))
439            || (havebstr("check_button")) ) {
440
441                 /** Replace values in the component with ones from the form */
442
443                 while (prop = icalcomponent_get_first_property(vevent,
444                       ICAL_SUMMARY_PROPERTY), prop != NULL) {
445                         icalcomponent_remove_property(vevent, prop);
446                         icalproperty_free(prop);
447                 }
448
449                 if (havebstr("summary")) {
450         
451                         icalcomponent_add_property(vevent,
452                                         icalproperty_new_summary(bstr("summary")));
453                 } else {
454                         icalcomponent_add_property(vevent,
455                                         icalproperty_new_summary("Untitled Event"));
456                 }
457         
458                 while (prop = icalcomponent_get_first_property(vevent,
459                                         ICAL_LOCATION_PROPERTY), prop != NULL) {
460                         icalcomponent_remove_property(vevent, prop);
461                         icalproperty_free(prop);
462                 }
463                 if (havebstr("location")) {
464                         icalcomponent_add_property(vevent,
465                                         icalproperty_new_location(bstr("location")));
466                 }
467                 while (prop = icalcomponent_get_first_property(vevent,
468                                   ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
469                         icalcomponent_remove_property(vevent, prop);
470                         icalproperty_free(prop);
471                 }
472                 if (havebstr("description")) {
473                         icalcomponent_add_property(vevent,
474                                 icalproperty_new_description(bstr("description")));
475                 }
476
477                 while (prop = icalcomponent_get_first_property(vevent,
478                       ICAL_DTSTART_PROPERTY), prop != NULL) {
479                         icalcomponent_remove_property(vevent, prop);
480                         icalproperty_free(prop);
481                 }
482
483                 if (yesbstr("alldayevent")) {
484                         all_day_event = 1;
485                 }
486                 else {
487                         all_day_event = 0;
488                 }
489
490                 if (all_day_event) {
491                         icaltime_from_webform_dateonly(&event_start, "dtstart");
492                 }
493                 else {
494                         icaltime_from_webform(&event_start, "dtstart");
495                 }
496
497                 /**
498                  * The following odd-looking snippet of code looks like it
499                  * takes some unnecessary steps.  It is done this way because
500                  * libical incorrectly turns an "all day event" into a normal
501                  * event starting at midnight (i.e. it serializes as date/time
502                  * instead of just date) unless icalvalue_new_date() is used.
503                  * So we force it, if this is an all day event.
504                  */
505                 prop = icalproperty_new_dtstart(event_start);
506                 if (all_day_event) {
507                         icalproperty_set_value(prop, icalvalue_new_date(event_start));
508                 }
509
510                 if (prop) icalcomponent_add_property(vevent, prop);
511                 else icalproperty_free(prop);
512
513                 while (prop = icalcomponent_get_first_property(vevent,
514                       ICAL_DTEND_PROPERTY), prop != NULL) {
515                         icalcomponent_remove_property(vevent, prop);
516                         icalproperty_free(prop);
517                 }
518                 while (prop = icalcomponent_get_first_property(vevent,
519                       ICAL_DURATION_PROPERTY), prop != NULL) {
520                         icalcomponent_remove_property(vevent, prop);
521                         icalproperty_free(prop);
522                 }
523
524                 if (all_day_event == 0) {
525                         icaltime_from_webform(&t, "dtend");     
526                         icalcomponent_add_property(vevent,
527                                 icalproperty_new_dtend(icaltime_normalize(t)
528                                 )
529                         );
530                 }
531
532                 /** See if transparency is indicated */
533                 if (havebstr("transp")) {
534                         if (!strcasecmp(bstr("transp"), "opaque")) {
535                                 formtransp = ICAL_TRANSP_OPAQUE;
536                         }
537                         else if (!strcasecmp(bstr("transp"), "transparent")) {
538                                 formtransp = ICAL_TRANSP_TRANSPARENT;
539                         }
540
541                         while (prop = icalcomponent_get_first_property(vevent, ICAL_TRANSP_PROPERTY),
542                               (prop != NULL)) {
543                                 icalcomponent_remove_property(vevent, prop);
544                                 icalproperty_free(prop);
545                         }
546
547                         icalcomponent_add_property(vevent, icalproperty_new_transp(formtransp));
548                 }
549
550                 /** Give this event a UID if it doesn't have one. */
551                 if (icalcomponent_get_first_property(vevent,
552                    ICAL_UID_PROPERTY) == NULL) {
553                         generate_uuid(buf);
554                         icalcomponent_add_property(vevent, icalproperty_new_uid(buf));
555                 }
556
557                 /** Increment the sequence ID */
558                 while (prop = icalcomponent_get_first_property(vevent,
559                       ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
560                         i = icalproperty_get_sequence(prop);
561                         if (i > sequence) sequence = i;
562                         icalcomponent_remove_property(vevent, prop);
563                         icalproperty_free(prop);
564                 }
565                 ++sequence;
566                 icalcomponent_add_property(vevent,
567                         icalproperty_new_sequence(sequence)
568                 );
569                 
570                 /**
571                  * Set the organizer, only if one does not already exist *and*
572                  * the form is supplying one
573                  */
574                 strcpy(buf, bstr("organizer"));
575                 if ( (icalcomponent_get_first_property(vevent,
576                    ICAL_ORGANIZER_PROPERTY) == NULL) 
577                    && (!IsEmptyStr(buf)) ) {
578
579                         /** set new organizer */
580                         sprintf(organizer_string, "MAILTO:%s", buf);
581                         icalcomponent_add_property(vevent,
582                                 icalproperty_new_organizer(organizer_string)
583                         );
584
585                 }
586
587                 /**
588                  * Add any new attendees listed in the web form
589                  */
590
591                 /* First, strip out the parenthesized partstats.  */
592                 strcpy(form_attendees, bstr("attendees"));
593                 stripout(form_attendees, '(', ')');
594
595                 /* Next, change any commas to newlines, because we want newline-separated attendees. */
596                 j = strlen(form_attendees);
597                 for (i=0; i<j; ++i) {
598                         if (form_attendees[i] == ',') {
599                                 form_attendees[i] = '\n';
600                                 while (isspace(form_attendees[i+1])) {
601                                         strcpy(&form_attendees[i+1], &form_attendees[i+2]);
602                                 }
603                         }
604                 }
605
606                 /** Now iterate! */
607                 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
608                         extract_token(buf, form_attendees, i, '\n', sizeof buf);
609                         striplt(buf);
610                         if (!IsEmptyStr(buf)) {
611                                 sprintf(attendee_string, "MAILTO:%s", buf);
612                                 foundit = 0;
613
614                                 for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
615                                         if (!strcasecmp(attendee_string,
616                                            icalproperty_get_attendee(attendee)))
617                                                 ++foundit;
618                                 }
619
620
621                                 if (foundit == 0) {
622                                         icalcomponent_add_property(vevent,
623                                                 icalproperty_new_attendee(attendee_string)
624                                         );
625                                 }
626                         }
627                 }
628
629                 /**
630                  * Remove any attendees *not* listed in the web form
631                  */
632 STARTOVER:      for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
633                         strcpy(attendee_string, icalproperty_get_attendee(attendee));
634                         if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
635                                 strcpy(attendee_string, &attendee_string[7]);
636                                 striplt(attendee_string);
637                                 foundit = 0;
638                                 for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
639                                         extract_token(buf, form_attendees, i, '\n', sizeof buf);
640                                         striplt(buf);
641                                         if (!strcasecmp(buf, attendee_string)) ++foundit;
642                                 }
643                                 if (foundit == 0) {
644                                         icalcomponent_remove_property(vevent, attendee);
645                                         icalproperty_free(attendee);
646                                         goto STARTOVER;
647                                 }
648                         }
649                 }
650
651                 /**
652                  * Encapsulate event into full VCALENDAR component.  Clone it first,
653                  * for two reasons: one, it's easier to just free the whole thing
654                  * when we're done instead of unbundling, but more importantly, we
655                  * can't encapsulate something that may already be encapsulated
656                  * somewhere else.
657                  */
658                 encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
659
660                 /* Set the method to PUBLISH */
661                 icalcomponent_set_method(encaps, ICAL_METHOD_PUBLISH);
662
663                 /** If the user clicked 'Save' then save it to the server. */
664                 if ( (encaps != NULL) && (havebstr("save_button")) ) {
665                         serv_puts("ENT0 1|||4|||1|");
666                         serv_getln(buf, sizeof buf);
667                         if (buf[0] == '8') {
668                                 serv_puts("Content-type: text/calendar");
669                                 serv_puts("");
670                                 serv_puts(icalcomponent_as_ical_string(encaps));
671                                 serv_puts("000");
672                         }
673                         if ( (buf[0] == '8') || (buf[0] == '4') ) {
674                                 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
675                                 }
676                         }
677                         if (buf[0] == '2') {
678                                 strcpy(WC->ImportantMessage, &buf[4]);
679                         }
680                         icalmemory_free_ring ();
681                         icalcomponent_free(encaps);
682                 }
683
684                 /** Or, check attendee availability if the user asked for that. */
685                 if ( (encaps != NULL) && (havebstr("check_button")) ) {
686
687                         /** Call this function, which does the real work */
688                         check_attendee_availability(encaps);
689
690                         /** This displays the form again, with our annotations */
691                         display_edit_individual_event(encaps, msgnum, from, unread);
692
693                         icalcomponent_free(encaps);
694                 }
695
696         }
697
698         /**
699          * If the user clicked 'Delete' then delete it.
700          */
701         if ( (havebstr("delete_button")) && (msgnum > 0L) ) {
702                 serv_printf("DELE %ld", lbstr("msgnum"));
703                 serv_getln(buf, sizeof buf);
704         }
705
706         if (created_new_vevent) {
707                 icalcomponent_free(vevent);
708         }
709
710         /** If this was a save or delete, go back to the calendar view. */
711         if (!havebstr("check_button")) {
712                 readloop("readfwd");
713         }
714 }
715
716