+ ++sequence;
+ lprintf(9, "New sequence is %d. Adding...\n", sequence);
+ icalcomponent_add_property(vevent,
+ icalproperty_new_sequence(sequence)
+ );
+
+ /* Set the organizer, only if one does not already exist *and*
+ * the form is supplying one
+ */
+ lprintf(9, "Setting the organizer...\n");
+ strcpy(buf, bstr("organizer"));
+ if ( (icalcomponent_get_first_property(vevent,
+ ICAL_ORGANIZER_PROPERTY) == NULL)
+ && (strlen(buf) > 0) ) {
+
+ /* set new organizer */
+ sprintf(organizer_string, "MAILTO:%s", buf);
+ icalcomponent_add_property(vevent,
+ icalproperty_new_organizer(organizer_string)
+ );
+
+ }
+
+ /*
+ * Add any new attendees listed in the web form
+ */
+ lprintf(9, "Add any new attendees\n");
+
+ /* First, strip out the parenthesized partstats. */
+ strcpy(form_attendees, bstr("attendees"));
+ stripout(form_attendees, '(', ')');
+
+ /* Now iterate! */
+ for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
+ extract_token(buf, form_attendees, i, '\n', sizeof buf);
+ striplt(buf);
+ if (strlen(buf) > 0) {
+ lprintf(9, "Attendee: <%s>\n", buf);
+ sprintf(attendee_string, "MAILTO:%s", buf);
+ foundit = 0;
+
+ for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
+ if (!strcasecmp(attendee_string,
+ icalproperty_get_attendee(attendee)))
+ ++foundit;
+ }
+
+
+ if (foundit == 0) {
+ icalcomponent_add_property(vevent,
+ icalproperty_new_attendee(attendee_string)
+ );
+ }
+ }
+ }
+
+ /*
+ * Remove any attendees *not* listed in the web form
+ */
+STARTOVER: lprintf(9, "Remove unlisted attendees\n");
+ for (attendee = icalcomponent_get_first_property(vevent, ICAL_ATTENDEE_PROPERTY); attendee != NULL; attendee = icalcomponent_get_next_property(vevent, ICAL_ATTENDEE_PROPERTY)) {
+ strcpy(attendee_string, icalproperty_get_attendee(attendee));
+ if (!strncasecmp(attendee_string, "MAILTO:", 7)) {
+ strcpy(attendee_string, &attendee_string[7]);
+ striplt(attendee_string);
+ foundit = 0;
+ for (i=0; i<num_tokens(form_attendees, '\n'); ++i) {
+ extract_token(buf, form_attendees, i, '\n', sizeof buf);
+ striplt(buf);
+ if (!strcasecmp(buf, attendee_string)) ++foundit;
+ }
+ if (foundit == 0) {
+ icalcomponent_remove_property(vevent, attendee);
+ icalproperty_free(attendee);
+ goto STARTOVER;
+ }
+ }
+ }
+
+ /*
+ * Encapsulate event into full VCALENDAR component. Clone it first,
+ * for two reasons: one, it's easier to just free the whole thing
+ * when we're done instead of unbundling, but more importantly, we
+ * can't encapsulate something that may already be encapsulated
+ * somewhere else.
+ */
+ lprintf(9, "Encapsulating into full VCALENDAR component\n");
+ encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vevent));
+
+ /* If the user clicked 'Save' then save it to the server. */
+ lprintf(9, "Serializing it for saving\n");
+ if ( (encaps != NULL) && (strlen(bstr("save_button")) > 0) ) {
+ serv_puts("ENT0 1|||4|||1|");
+ serv_getln(buf, sizeof buf);
+ if (buf[0] == '8') {
+ serv_puts("Content-type: text/calendar");
+ serv_puts("");
+ serv_puts(icalcomponent_as_ical_string(encaps));
+ serv_puts("000");
+ }
+ while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+ lprintf(9, "ENT0 REPLY: %s\n", buf);
+ }
+ icalcomponent_free(encaps);
+ }
+
+ /* Or, check attendee availability if the user asked for that. */
+ if ( (encaps != NULL) && (strlen(bstr("check_button")) > 0) ) {
+
+ /* Call this function, which does the real work */
+ check_attendee_availability(encaps);
+
+ /* This displays the form again, with our annotations */
+ display_edit_individual_event(encaps, msgnum);
+
+ icalcomponent_free(encaps);
+ }
+