- /** Replace values in the component with ones from the form */
-
- while (prop = icalcomponent_get_first_property(vtodo,
- ICAL_SUMMARY_PROPERTY), prop != NULL) {
- icalcomponent_remove_property(vtodo, prop);
- icalproperty_free(prop);
- }
- if (havebstr("summary")) {
-
- icalcomponent_add_property(vtodo,
- icalproperty_new_summary(bstr("summary")));
- } else {
- icalcomponent_add_property(vtodo,
- icalproperty_new_summary(_("Untitled Task")));
- }
-
- while (prop = icalcomponent_get_first_property(vtodo,
- ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
- icalcomponent_remove_property(vtodo, prop);
- icalproperty_free(prop);
- }
- if (havebstr("description")) {
- icalcomponent_add_property(vtodo,
- icalproperty_new_description(bstr("description")));
- }
-
- while (prop = icalcomponent_get_first_property(vtodo,
- ICAL_DTSTART_PROPERTY), prop != NULL) {
- icalcomponent_remove_property(vtodo, prop);
- icalproperty_free(prop);
- }
- if (IsEmptyStr(bstr("nodtstart"))) {
- if (yesbstr("dtstart_time")) {
- icaltime_from_webform(&t, "dtstart");
- }
- else {
- icaltime_from_webform_dateonly(&t, "dtstart");
- }
- icalcomponent_add_property(vtodo,
- icalproperty_new_dtstart(t)
- );
- }
- while(prop = icalcomponent_get_first_property(vtodo,
- ICAL_STATUS_PROPERTY), prop != NULL) {
- icalcomponent_remove_property(vtodo,prop);
- icalproperty_free(prop);
- }
- while(prop = icalcomponent_get_first_property(vtodo,
- ICAL_PERCENTCOMPLETE_PROPERTY), prop != NULL) {
- icalcomponent_remove_property(vtodo,prop);
- icalproperty_free(prop);
- }
-
- if (havebstr("status")) {
- icalproperty_status taskStatus = icalproperty_string_to_status(bstr("status"));
- icalcomponent_set_status(vtodo, taskStatus);
- icalcomponent_add_property(vtodo,
- icalproperty_new_percentcomplete(
- (strcasecmp(bstr("status"), "completed") ? 0 : 100)
- )
- );
- }
- else {
- icalcomponent_add_property(vtodo, icalproperty_new_percentcomplete(0));
- }
- while (prop = icalcomponent_get_first_property(vtodo,
- ICAL_CATEGORIES_PROPERTY), prop != NULL) {
- icalcomponent_remove_property(vtodo,prop);
- icalproperty_free(prop);
- }
- if (!IsEmptyStr(bstr("category"))) {
- prop = icalproperty_new_categories(bstr("category"));
- icalcomponent_add_property(vtodo,prop);
- }
- while (prop = icalcomponent_get_first_property(vtodo,
- ICAL_DUE_PROPERTY), prop != NULL) {
- icalcomponent_remove_property(vtodo, prop);
- icalproperty_free(prop);
- }
- if (IsEmptyStr(bstr("nodue"))) {
- if (yesbstr("due_time")) {
- icaltime_from_webform(&t, "due");
- }
- else {
- icaltime_from_webform_dateonly(&t, "due");
- }
- icalcomponent_add_property(vtodo,
- icalproperty_new_due(t)
- );
- }
- /** Give this task a UID if it doesn't have one. */
- lprintf(9, "Give this task a UID if it doesn't have one.\n");
- if (icalcomponent_get_first_property(vtodo,
- ICAL_UID_PROPERTY) == NULL) {
- generate_uuid(buf);
- icalcomponent_add_property(vtodo,
- icalproperty_new_uid(buf)
- );
- }
-
- /* Increment the sequence ID */
- lprintf(9, "Increment the sequence ID\n");
- while (prop = icalcomponent_get_first_property(vtodo,
- ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
- i = icalproperty_get_sequence(prop);
- lprintf(9, "Sequence was %d\n", i);
- if (i > sequence) sequence = i;
- icalcomponent_remove_property(vtodo, prop);
- icalproperty_free(prop);
- }
- ++sequence;
- lprintf(9, "New sequence is %d. Adding...\n", sequence);
- icalcomponent_add_property(vtodo,
- icalproperty_new_sequence(sequence)
- );
-
- /*
- * 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 a full VCALENDAR component\n");
- encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo));
-
- /* Serialize it and save it to the message base */
- serv_puts("ENT0 1|||4");
- serv_getln(buf, sizeof buf);
- if (buf[0] == '4') {
- serv_puts("Content-type: text/calendar");
- serv_puts("");
- serv_puts(icalcomponent_as_ical_string(encaps));
- serv_puts("000");
-
- /*
- * Probably not necessary; the server will see the UID
- * of the object and delete the old one anyway, but
- * just in case...
- */
- delete_existing = 1;
- }
- icalcomponent_free(encaps);
- }
-
- /**
- * If the user clicked 'Delete' then explicitly delete the message.
- */
- if (havebstr("delete_button")) {
- delete_existing = 1;
- }
-
- if ( (delete_existing) && (msgnum > 0L) ) {
- serv_printf("DELE %ld", lbstr("msgnum"));
- serv_getln(buf, sizeof buf);
- }
-
- if (created_new_vtodo) {
- icalcomponent_free(vtodo);
- }
-
- /* Go back to wherever we came from */
- if (ibstr("return_to_summary") == 1) {
- summary();
- }
- else {
- readloop(readfwd);
- }
-}