Пример #1
0
/** Set icalcomponent X-* property.
 *
 * @param comp iCal component.
 * @param key Property name (i.e. X-EEE-WHATEVER).
 * @param value Property value.
 */
static void icomp_x_prop_set(icalcomponent *comp, const char *key, const char *value)
{
    icalproperty *iter;

    g_return_if_fail(comp != NULL);
    g_return_if_fail(key != NULL);

again:
    for (iter = icalcomponent_get_first_property(comp, ICAL_X_PROPERTY);
         iter;
         iter = icalcomponent_get_next_property(comp, ICAL_X_PROPERTY))
    {
        const char *str = icalproperty_get_x_name(iter);

        if (str && !g_strcmp0(str, key))
        {
            icalcomponent_remove_property(comp, iter);
            icalproperty_free(iter);
            goto again;
        }
    }

    if (value)
    {
        iter = icalproperty_new_x(value);
        icalproperty_set_x_name(iter, key);
        icalcomponent_add_property(comp, iter);
    }
}
Пример #2
0
icalproperty *icallangbind_get_next_property(icalcomponent *c, const char *prop)
{
    icalproperty_kind kind = icalenum_string_to_property_kind(prop);
    icalproperty *p;

    if (kind == ICAL_NO_PROPERTY) {
        return 0;
    }

    if (kind == ICAL_X_PROPERTY) {
        for (p = icalcomponent_get_next_property(c, kind);
             p != 0; p = icalcomponent_get_next_property(c, kind)) {

            if (strcmp(icalproperty_get_x_name(p), prop) == 0) {
                return p;
            }
        }
    } else {
        p = icalcomponent_get_next_property(c, kind);

        return p;
    }

    return 0;
}
Пример #3
0
/** Gets the LOCATION or X-LIC-LOCATION property from a VTIMEZONE. */
static char*
icaltimezone_get_location_from_vtimezone (icalcomponent *component)
{
    icalproperty *prop;
    const char *location;
    const char *name;

    prop = icalcomponent_get_first_property (component,
					     ICAL_LOCATION_PROPERTY);
    if (prop) {
	location = icalproperty_get_location (prop);
	if (location)
	    return strdup (location);
    }

    prop = icalcomponent_get_first_property (component, ICAL_X_PROPERTY);
    while (prop) {
	name = icalproperty_get_x_name (prop);
	if (name && !strcasecmp (name, "X-LIC-LOCATION")) {
	    location = icalproperty_get_x (prop);
	    if (location)
		return strdup (location);
	}
	prop = icalcomponent_get_next_property (component,
						ICAL_X_PROPERTY);
    }

    return NULL;
}
Пример #4
0
gboolean
scalix_appointment_get (ScalixAppointment * comp, const char *key, char **value)
{
    icalcomponent *icomp;
    icalproperty *icalprop;
    const char *x_val;

    icomp = e_cal_component_get_icalcomponent (E_CAL_COMPONENT (comp));
    icalprop = icalcomponent_get_first_property (icomp, ICAL_X_PROPERTY);

    while (icalprop) {
        const char *x_name;

        x_name = icalproperty_get_x_name (icalprop);
        x_val = icalproperty_get_x (icalprop);

        if (!strcmp (x_name, key)) {
            break;
        }

        icalprop = icalcomponent_get_next_property (icomp, ICAL_X_PROPERTY);
    }

    if (icalprop) {
        *value = g_strdup (x_val);
        return TRUE;
    }

    *value = NULL;

    return FALSE;
}
Пример #5
0
void view_event(icalcomponent* calendar)
{
  //Ask user if they want null fields in addition to filled ones
  bool show_null_fields_too = yes_no_prompt("Do you want to view empty fields? (y/n)");
    
  icalcomponent* event = find_event(calendar);
  
  if (event == NULL)
  {
    append_action_to_closed_log("View event", false);
  }
  
  //Once user selects desired one, displays all needed fields  
  icalproperty* p;
  for(p = icalcomponent_get_first_property(event,ICAL_ANY_PROPERTY); p != 0; p = icalcomponent_get_next_property(event,ICAL_ANY_PROPERTY))
  {
    if ((icalproperty_get_comment(p) != NULL) || (show_null_fields_too))
    {
      cout << icalproperty_get_x_name(p) << ": ";
      cout << icalproperty_get_comment(p) << endl;
    }
  }
  
  append_action_to_closed_log("View event", true);
}
Пример #6
0
void
scalix_appointment_unset (ScalixAppointment * comp, const char *key)
{
    icalcomponent *icomp;
    icalproperty *icalprop;
    const char *x_val;
    GSList *list, *iter;

    list = NULL;
    icomp = e_cal_component_get_icalcomponent (E_CAL_COMPONENT (comp));
    icalprop = icalcomponent_get_first_property (icomp, ICAL_X_PROPERTY);

    while (icalprop) {
        const char *x_name;

        x_name = icalproperty_get_x_name (icalprop);
        x_val = icalproperty_get_x (icalprop);

        if (!strcmp (x_name, key)) {
            list = g_slist_prepend (list, icalprop);
        }

        icalprop = icalcomponent_get_next_property (icomp, ICAL_X_PROPERTY);
    }

    for (iter = list; iter; iter = iter->next) {
        icalprop = iter->data;
        icalcomponent_remove_property (icomp, icalprop);
        icalproperty_free (icalprop);
    }

    return;
}
NS_IMETHODIMP
calIcalComponent::GetNextProperty(const nsACString &kind, calIIcalProperty **prop)
{
    NS_ENSURE_ARG_POINTER(prop);

    icalproperty_kind propkind =
        icalproperty_string_to_kind(PromiseFlatCString(kind).get());

    if (propkind == ICAL_NO_PROPERTY)
        return NS_ERROR_INVALID_ARG;
    icalproperty *icalprop = nullptr;
    if (propkind == ICAL_X_PROPERTY) {
        for (icalprop =
                 icalcomponent_get_next_property(mComponent, ICAL_X_PROPERTY);
             icalprop;
             icalprop = icalcomponent_get_next_property(mComponent,
                                                        ICAL_X_PROPERTY)) {

            if (kind.Equals(icalproperty_get_x_name(icalprop)))
                break;
        }
    } else {
        icalprop = icalcomponent_get_next_property(mComponent, propkind);
    }

    if (!icalprop) {
        *prop = nullptr;
        return NS_OK;
    }

    *prop = new calIcalProperty(icalprop, this);
    CAL_ENSURE_MEMORY(*prop);
    NS_ADDREF(*prop);
    return NS_OK;
}
Пример #8
0
/*
 * Construct an XML element for an iCalendar property.
 */
static xmlNodePtr icalproperty_as_xml_element(icalproperty *prop)
{
    icalproperty_kind prop_kind;
    const char *x_name, *property_name = NULL;
    icalparameter *param;
    xmlNodePtr xprop, xparams = NULL;

    if (!prop) return NULL;

    prop_kind = icalproperty_isa(prop);
    x_name = icalproperty_get_x_name(prop);

    if (prop_kind == ICAL_X_PROPERTY && x_name)
        property_name = x_name;
    else
        property_name = icalproperty_kind_to_string(prop_kind);

    if (!property_name) {
        icalerror_warn("Got a property of an unknown kind.");
        return NULL;
    }

    /* Create property */
    xprop = xmlNewNode(NULL,
                       BAD_CAST lcase(icalmemory_tmp_copy(property_name)));


    /* Add parameters */
    for (param = icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER);
            param != 0;
            param = icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER)) {

        if (icalparameter_isa(param) == ICAL_VALUE_PARAMETER) continue;

        if (!xparams)
            xparams = xmlNewChild(xprop, NULL, BAD_CAST "parameters", NULL);

        xmlAddChild(xparams, icalparameter_as_xml_element(param));
    }


    /* Add value */
    icalproperty_add_value_as_xml_element(xprop, prop);

    return xprop;
}
Пример #9
0
/* Fills the procedure alarm data with the values from the widgets */
static void
palarm_widgets_to_alarm (Dialog *dialog,
                         ECalComponentAlarm *alarm)
{
	gchar *program;
	icalattach *attach;
	gchar *str;
	ECalComponentText description;
	icalcomponent *icalcomp;
	icalproperty *icalprop;

	program = e_dialog_editable_get (dialog->palarm_program);
	attach = icalattach_new_from_url (program ? program : "");
	g_free (program);

	e_cal_component_alarm_set_attach (alarm, attach);
	icalattach_unref (attach);

	str = e_dialog_editable_get (dialog->palarm_args);

		description.value = str;
		description.altrep = NULL;

		e_cal_component_alarm_set_description (alarm, &description);

	g_free (str);

	/* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that
	 * we don't re-set the alarm's description */
	icalcomp = e_cal_component_alarm_get_icalcomponent (alarm);
	icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);
	while (icalprop) {
		const gchar *x_name;

		x_name = icalproperty_get_x_name (icalprop);
		if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
			icalcomponent_remove_property (icalcomp, icalprop);
			break;
		}

		icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
	}
}
Пример #10
0
static const char *get_expect(icalcomponent *c)
{
    icalproperty *p;
    const char *note = 0;

    if (c != 0) {
        for (p = icalcomponent_get_first_property(c, ICAL_X_PROPERTY);
             p != 0; p = icalcomponent_get_next_property(c, ICAL_X_PROPERTY)) {
            if (strcmp(icalproperty_get_x_name(p), "X-LIC-EXPECT") == 0) {
                note = icalproperty_get_x(p);
            }
        }
    }

    if (note == 0) {
        note = "None";
    }

    return note;
}
Пример #11
0
/* Fills the display alarm data with the values from the widgets */
static void
dalarm_widgets_to_alarm (Dialog *dialog,
                         ECalComponentAlarm *alarm)
{
	gchar *str;
	ECalComponentText description;
	GtkTextBuffer *text_buffer;
	GtkTextIter text_iter_start, text_iter_end;
	icalcomponent *icalcomp;
	icalproperty *icalprop;

	if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->dalarm_message)))
		return;

	text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->dalarm_description));
	gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start);
	gtk_text_buffer_get_end_iter   (text_buffer, &text_iter_end);
	str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE);

	description.value = str;
	description.altrep = NULL;

	e_cal_component_alarm_set_description (alarm, &description);
	g_free (str);

	/* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that
	 * we don't re-set the alarm's description */
	icalcomp = e_cal_component_alarm_get_icalcomponent (alarm);
	icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);
	while (icalprop) {
		const gchar *x_name;

		x_name = icalproperty_get_x_name (icalprop);
		if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
			icalcomponent_remove_property (icalcomp, icalprop);
			break;
		}

		icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
	}
}
Пример #12
0
/** Get X-* property value from icalcomponent object.
 *
 * @param comp iCal component.
 * @param key Property name (i.e. X-EEE-WHATEVER).
 *
 * @return Property value or NULL.
 */
static const char *icomp_x_prop_get(icalcomponent *comp, const char *key)
{
    icalproperty *iter;

    g_return_val_if_fail(comp != NULL, NULL);
    g_return_val_if_fail(key != NULL, NULL);

    for (iter = icalcomponent_get_first_property(comp, ICAL_X_PROPERTY);
         iter;
         iter = icalcomponent_get_next_property(comp, ICAL_X_PROPERTY))
    {
        const char *str = icalproperty_get_x_name(iter);

        if (str && !g_strcmp0(str, key))
        {
            return icalproperty_get_value_as_string(iter);
        }
    }

    return NULL;
}
Пример #13
0
static int get_expected_numevents(icalcomponent *c)
{
    icalproperty *p;
    const char* note = 0;
    int num_events = 0;

    if(c != 0){
        for(p = icalcomponent_get_first_property(c,ICAL_X_PROPERTY);
            p!= 0;
            p = icalcomponent_get_next_property(c,ICAL_X_PROPERTY)){
            if(strcmp(icalproperty_get_x_name(p),"X-EXPECT-NUMEVENTS")==0){
	      note = icalproperty_get_x(p);
            }
        }
    } 
    
    if(note != 0){
      num_events = atoi(note);
    }
    
    
    return num_events;
}
Пример #14
0
/* Fills the mail alarm data with the values from the widgets */
static void
malarm_widgets_to_alarm (Dialog *dialog,
                         ECalComponentAlarm *alarm)
{
	gchar *str;
	ECalComponentText description;
	GSList *attendee_list = NULL;
	GtkTextBuffer *text_buffer;
	GtkTextIter text_iter_start, text_iter_end;
	ENameSelectorModel *name_selector_model;
	EDestinationStore *destination_store;
	GList *destinations;
	icalcomponent *icalcomp;
	icalproperty *icalprop;
	GList *l;

	/* Attendees */
	name_selector_model = e_name_selector_peek_model (dialog->name_selector);
	e_name_selector_model_peek_section (name_selector_model, section_name, NULL, &destination_store);
	destinations = e_destination_store_list_destinations (destination_store);

	for (l = destinations; l; l = g_list_next (l)) {
		EDestination *dest;
		ECalComponentAttendee *a;

		dest = l->data;

		a = g_new0 (ECalComponentAttendee, 1);
		a->value = e_destination_get_email (dest);
		a->cn = e_destination_get_name (dest);
		a->cutype = ICAL_CUTYPE_INDIVIDUAL;
		a->status = ICAL_PARTSTAT_NEEDSACTION;
		a->role = ICAL_ROLE_REQPARTICIPANT;

		attendee_list = g_slist_append (attendee_list, a);
	}

	e_cal_component_alarm_set_attendee_list (alarm, attendee_list);

	e_cal_component_free_attendee_list (attendee_list);
	g_list_free (destinations);

	if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->malarm_message)))
		return;

	/* Description */
	text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (dialog->malarm_description));
	gtk_text_buffer_get_start_iter (text_buffer, &text_iter_start);
	gtk_text_buffer_get_end_iter   (text_buffer, &text_iter_end);
	str = gtk_text_buffer_get_text (text_buffer, &text_iter_start, &text_iter_end, FALSE);

	description.value = str;
	description.altrep = NULL;

	e_cal_component_alarm_set_description (alarm, &description);
	g_free (str);

	/* remove the X-EVOLUTION-NEEDS-DESCRIPTION property, so that
	 * we don't re-set the alarm's description */
	icalcomp = e_cal_component_alarm_get_icalcomponent (alarm);
	icalprop = icalcomponent_get_first_property (icalcomp, ICAL_X_PROPERTY);
	while (icalprop) {
		const gchar *x_name;

		x_name = icalproperty_get_x_name (icalprop);
		if (!strcmp (x_name, "X-EVOLUTION-NEEDS-DESCRIPTION")) {
			icalcomponent_remove_property (icalcomp, icalprop);
			break;
		}

		icalprop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY);
	}
}
Пример #15
0
static void ical2exchange_get_properties(struct ical2exchange *ical2exchange, icalcomponent *vevent){
	icalproperty *icalProp = NULL;
	icalproperty *prop = NULL;
	const char *xname;
	enum icalproperty_kind propType;

	icalProp=icalcomponent_get_first_property(vevent, ICAL_ANY_PROPERTY);
	
	while(icalProp!=0){
		propType=icalproperty_isa(icalProp);
		switch (propType){
			case ICAL_ATTACH_PROPERTY:
				if(!ical2exchange->attachEvent){
					ical2exchange->attachEvent=icalcomponent_new_vevent();
				}
				prop = icalproperty_new_clone(icalProp);
				icalcomponent_add_property(ical2exchange->attachEvent, prop);
				break;
			case ICAL_ATTENDEE_PROPERTY:
				if(!ical2exchange->attendeeEvent){
					ical2exchange->attendeeEvent=icalcomponent_new_vevent();
				}
				prop = icalproperty_new_clone(icalProp);
				icalcomponent_add_property(ical2exchange->attendeeEvent, prop);
				break;
			case ICAL_CATEGORIES_PROPERTY:
				if(!ical2exchange->categoriesEvent){
					ical2exchange->categoriesEvent=icalcomponent_new_vevent();
				}
				prop = icalproperty_new_clone(icalProp);
				icalcomponent_add_property(ical2exchange->categoriesEvent, prop);
				break;
			case ICAL_CLASS_PROPERTY:
				ical2exchange->classProp=icalProp;
				break;
			case ICAL_COMMENT_PROPERTY:
				ical2exchange->commentProp=icalProp;
				break;
			case ICAL_CONTACT_PROPERTY:
				if(!ical2exchange->contactEvent){
					ical2exchange->contactEvent=icalcomponent_new_vevent();
				}
				prop = icalproperty_new_clone(icalProp);
				icalcomponent_add_property(ical2exchange->contactEvent, prop);
				break;
			case ICAL_CREATED_PROPERTY:
				break;
			case ICAL_DESCRIPTION_PROPERTY:
				ical2exchange->descriptionProp=icalProp;
				break;
			case ICAL_DTEND_PROPERTY:
				ical2exchange->dtendProp=icalProp;
				break;
			case ICAL_DTSTAMP_PROPERTY:
				ical2exchange->dtstampProp=icalProp;
				break;
			case ICAL_DTSTART_PROPERTY:
				ical2exchange->dtstartProp=icalProp;
				break;
			case ICAL_DURATION_PROPERTY:
				ical2exchange->durationProp=icalProp;
				break;
			case ICAL_EXDATE_PROPERTY:
				if(!ical2exchange->exdateEvent){
					ical2exchange->exdateEvent=icalcomponent_new_vevent();
				}
				prop = icalproperty_new_clone(icalProp);
				ical2exchange->exdateCount ++;
				icalcomponent_add_property(ical2exchange->exdateEvent, prop);
				break;
			case ICAL_LASTMODIFIED_PROPERTY:
				break;
			case ICAL_LOCATION_PROPERTY:
				ical2exchange->locationProp=icalProp;
				break;
			case ICAL_ORGANIZER_PROPERTY:
				//TODO: figure out how to MS-OXOABK
				ical2exchange->organizerProp=icalProp;
				break;
			case ICAL_PRIORITY_PROPERTY:
				ical2exchange->priorityProp=icalProp;
				break;
			case ICAL_RDATE_PROPERTY:
				if(!ical2exchange->rdateEvent){
					ical2exchange->rdateEvent=icalcomponent_new_vevent();
				}
				prop = icalproperty_new_clone(icalProp);
				ical2exchange->rdateCount ++;
				icalcomponent_add_property(ical2exchange->rdateEvent, prop);
				break;
			case ICAL_RECURRENCEID_PROPERTY:
				ical2exchange->recurrenceidProp=icalProp;
				break;
			case ICAL_RESOURCES_PROPERTY:
				if(!ical2exchange->resourcesEvent){
					ical2exchange->resourcesEvent=icalcomponent_new_vevent();
				}
				prop = icalproperty_new_clone(icalProp);
				icalcomponent_add_property(ical2exchange->resourcesEvent, prop);
				break;
			case ICAL_RRULE_PROPERTY:
				ical2exchange->rruleProp=icalProp;
				break;
			case ICAL_SEQUENCE_PROPERTY:
				ical2exchange->sequenceProp=icalProp;
				break;
			case ICAL_STATUS_PROPERTY:
				ical2exchange->statusProp=icalProp;
				break;
			case ICAL_SUMMARY_PROPERTY:
				ical2exchange->summaryProp=icalProp;
				break;
			case ICAL_TRANSP_PROPERTY:
				ical2exchange->transpProp=icalProp;
				break;
			case ICAL_UID_PROPERTY:
				//TODO
				ical2exchange->uidProp=icalProp;
				break;
		 	case ICAL_X_PROPERTY: 
				xname=icalproperty_get_x_name(icalProp);
				if(!strcmp(xname,"X-MICROSOFT-CDO-BUSYSTATUS")){
					ical2exchange->x_busystatusProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-MSNCALENDAR-BUSYSTATUS")){
					ical2exchange->x_busystatusProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-CDO-APPT-SEQUENCE")){
					ical2exchange->x_sequenceProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-CDO-IMPORTANCE")){
					ical2exchange->x_importanceProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-MSNCALENDAR-IMPORTANCE")){
					ical2exchange->x_importanceProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-CDO-INTENDEDSTATUS")){
					ical2exchange->x_intendedProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-MSNCALENDAR-INTENDEDSTATUS")){
					ical2exchange->x_intendedProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-CDO-OWNERAPPTID")){
					ical2exchange->x_ownerapptidProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE")){
					ical2exchange->x_attendeecriticalchangeProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE")){
					ical2exchange->x_ownercriticalchangeProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-CDO-REPLYTIME")){
					ical2exchange->x_replytimeProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-DISALLOW-COUNTER")){
					ical2exchange->x_disallowcounterProp=icalProp;
				} else if(!strcmp(xname,"X-MICROSOFT-ISDRAFT")){
					ical2exchange->x_isdraftProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-ALLOWEXTERNCHECK")){
					ical2exchange->x_allowexterncheckProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-APPTLASTSEQUENCE")){
					ical2exchange->x_apptlastsequenceProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-APPTSEQTIME")){
					ical2exchange->x_apptseqtimeProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-AUTOFILLLOCATION")){
					ical2exchange->x_autofilllocationProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-AUTOSTARTCHECK")){
					ical2exchange->x_autostartcheckProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-CONFCHECK")){
					ical2exchange->x_confcheckProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-COLLABORATEDDOC")){
					ical2exchange->x_collaborateddocProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-CONFTYPE")){
					ical2exchange->x_conftypeProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-MWSURL")){
					ical2exchange->x_mwsurlProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-NETSHOWURL")){
					ical2exchange->x_netshowurlProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-ONLINEPASSWORD")){
					ical2exchange->x_onlinepasswordProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-ORGALIAS")){
					ical2exchange->x_orgaliasProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-ORIGINALEND")){
					ical2exchange->x_originalendProp=icalProp;
				} else if(!strcmp(xname,"X-MS-OLK-ORIGINALSTART")){
					ical2exchange->x_originalstartProp=icalProp;
				}
				
				break;
			default:
				break;
		}
		icalProp=icalcomponent_get_next_property(vevent, ICAL_ANY_PROPERTY);
	}
	
	ical2exchange->valarmEvent = icalcomponent_get_first_component(vevent,ICAL_VALARM_COMPONENT);
	
}
Пример #16
0
/*
 * Construct a JSON array for an iCalendar property.
 */
static json_t *icalproperty_as_json_array(icalproperty *prop)
{
    icalproperty_kind prop_kind;
    const char *x_name, *property_name = NULL;
    icalparameter *param;
    const char *type = NULL;
    const icalvalue *value;
    json_t *jprop, *jparams;

    if (!prop) return NULL;

    prop_kind = icalproperty_isa(prop);
    x_name = icalproperty_get_x_name(prop);

    if (prop_kind == ICAL_X_PROPERTY && x_name)
        property_name = x_name;
    else
        property_name = icalproperty_kind_to_string(prop_kind);

    if (!property_name) {
        icalerror_warn("Got a property of an unknown kind.");
        return NULL;
    }

    /* Create property array */
    jprop = json_array();


    /* Add property name */
    json_array_append_new(jprop,
                          json_string(lcase(icalmemory_tmp_copy(property_name))));


    /* Add parameters */
    jparams = json_object();
    for (param = icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER);
         param != 0;
         param = icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER)) {

        if (icalparameter_isa(param) == ICAL_VALUE_PARAMETER) continue;

        icalparameter_as_json_object_member(param, jparams);
    }
    json_array_append_new(jprop, jparams);


    /* Add type */
    type = icalproperty_value_kind_as_string(prop);
    json_array_append_new(jprop, json_string(lcase(icalmemory_tmp_copy(type))));


    /* Add value */
    value = icalproperty_get_value(prop);
    if (value) {
        switch (icalproperty_isa(prop)) {
        case ICAL_CATEGORIES_PROPERTY:
        case ICAL_RESOURCES_PROPERTY:
        case ICAL_POLLPROPERTIES_PROPERTY:
            if (icalvalue_isa(value) == ICAL_TEXT_VALUE) {
                /* Handle multi-valued properties */
                const char *str = icalvalue_as_ical_string(value);
                tok_t tok;

                tok_init(&tok, str, ",", TOK_TRIMLEFT|TOK_TRIMRIGHT|TOK_EMPTY);
                while ((str = tok_next(&tok))) {
                    if (*str) json_array_append_new(jprop, json_string(str));
                }
                tok_fini(&tok);
                break;
            }

        default:
            json_array_append_new(jprop, icalvalue_as_json_object(value));
            break;
        }
    }

    return jprop;
}
Пример #17
0
int main(int argc, char *argv[])
{
    icalcomponent *c, *next_c = NULL;
    int i = 0;
    int dont_remove;
    icalfileset_options options = { O_RDONLY, 0644, 0, NULL };

    icalset *f = icalset_new(ICAL_FILE_SET, TEST_DATADIR "/process-incoming.ics", &options);
    icalset *trash = icalset_new_file("trash.ics");
    icalset *cal = icalset_new(ICAL_FILE_SET, TEST_DATADIR "/process-calendar.ics", &options);
    icalset *out = icalset_new_file("outgoing.ics");

    const char *this_user = "******";

    _unused(argc);
    _unused(argv);

    assert(f != 0);
    assert(cal != 0);
    assert(trash != 0);
    assert(out != 0);

    /* Foreach incoming message */
    for (c = icalset_get_first_component(f); c != 0; c = next_c) {

        icalproperty_xlicclass class;
        icalcomponent *match;
        icalcomponent *inner;
        icalcomponent *reply = 0;

        assert(c != 0);

        inner = icalcomponent_get_first_real_component(c);

        i++;
        reply = 0;
        dont_remove = 0;

        if (inner == 0) {
            printf("Bad component, no inner\n %s\n", icalcomponent_as_ical_string(c));
            continue;
        }

        /* Find a booked component that is matched to the incoming
           message, based on the incoming component's UID, SEQUENCE
           and RECURRENCE-ID */

        match = icalset_fetch_match(cal, c);

        class = icalclassify(c, match, this_user);

        /* Print out the notes associated with the incoming component
           and the matched component in the */
        {
            const char *inc_note = 0;
            const char *match_note = 0;
            icalproperty *p;

            for (p = icalcomponent_get_first_property(c, ICAL_X_PROPERTY);
                 p != 0; p = icalcomponent_get_next_property(c, ICAL_X_PROPERTY)) {

                if (strcmp(icalproperty_get_x_name(p), "X-LIC-NOTE") == 0) {
                    inc_note = icalproperty_get_x(p);
                }
            }

            if (match != 0) {
                for (p = icalcomponent_get_first_property(match, ICAL_X_PROPERTY);
                     p != 0;
                     p = icalcomponent_get_next_property(match, ICAL_X_PROPERTY)) {
                    if (strcmp(icalproperty_get_x_name(p), "X-LIC-NOTE") == 0) {
                        match_note = icalproperty_get_x(p);
                    }
                }
            }

            if (inc_note != 0) {
                printf("Incoming: %s\n", inc_note);
            }
            if (match_note != 0) {
                printf("Match   : %s\n", match_note);
            }
        }

        /* Main processing structure */

        switch (class) {
        case ICAL_XLICCLASS_NONE:{
                char temp[1024];

                /* Huh? Return an error to sender */
                icalrestriction_check(c);
                icalcomponent_convert_errors(c);

                snprintf(temp, 1024,
                         "I can't understand the component you sent.\n"
                         "Here is the component you sent, possibly with error messages:\n"
                         "%s",
                         icalcomponent_as_ical_string(c));

                reply = icalmessage_new_error_reply(c, this_user, temp, "", ICAL_UNKNOWN_STATUS);

                break;
            }
        case ICAL_XLICCLASS_PUBLISHNEW:{

                /* Don't accept published events from anyone but
                   self. If self, fall through to ICAL_XLICCLASS_REQUESTNEW */
            }
        case ICAL_XLICCLASS_REQUESTNEW:{

                /* Book the new component if it does not overlap
                   anything. If the time is busy and the start time is
                   an even modulo 4, delegate to
                   [email protected]. If the time is busy and
                   is 1 modulo 4, counterpropose for the first
                   available free time. Otherwise, deline the meeting */

                icalcomponent *overlaps = icalclassify_find_overlaps(cal, c);

                if (overlaps == 0) {
                    /* No overlaps, book the meeting */
/*                  icalset_add_component(cal,icalcomponent_new_clone(c));*/

                    /* Return a reply */
                    reply =
                        icalmessage_new_accept_reply(
                            c, this_user, "I can make it to this meeting");

                    (void)icalset_add_component(out, reply);

                } else {
                    /* There was a conflict, so delegate, counterpropose
                       or decline it */
                    struct icaltimetype dtstart = icalcomponent_get_dtstart(c);

                    if (dtstart.hour % 4 == 0) {
                        /* Delegate the meeting */
                        reply =
                            icalmessage_new_delegate_reply(
                                c,
                                this_user,
                                "*****@*****.**",
                                "Unfortunately, I have another commitment that conflicts "
                                "with this meeting. I am delegating my attendance to Bob.");
                        (void)icalset_add_component(out, reply);

                    } else if (dtstart.hour % 4 == 1) {
                        /* Counter propose to next available time */
                        icalcomponent *newc;
                        struct icalperiodtype next_time;

                        icalspanlist *spanl = icalspanlist_new(cal, dtstart,
                                                               icaltime_null_time());

                        next_time =
                            icalspanlist_next_free_time(spanl, icalcomponent_get_dtstart(c));

                        newc = icalcomponent_new_clone(c);

                        icalcomponent_set_dtstart(newc, next_time.start);

                        /* Hack, the duration of the counterproposed
                           meeting may be longer than the free time
                           available */
                        icalcomponent_set_duration(newc, icalcomponent_get_duration(c));

                        reply =
                            icalmessage_new_counterpropose_reply(
                                c,
                                newc,
                                this_user,
                                "Unfortunately, I have another commitment that conflicts with "
                                "this meeting. I am proposing a time that works better for me.");

                        (void)icalset_add_component(out, reply);
                        icalspanlist_free(spanl);
                        icalcomponent_free(newc);

                    } else {
                        /* Decline the meeting */

                        reply =
                            icalmessage_new_decline_reply(
                                c,
                                this_user,
                                "I can't make it to this meeting");

                        (void)icalset_add_component(out, reply);
                    }
                }
                icalcomponent_free(overlaps);
                break;
            }
        case ICAL_XLICCLASS_PUBLISHFREEBUSY:{
                /* Store the busy time information in a file named after
                   the sender */
                break;
            }

        case ICAL_XLICCLASS_PUBLISHUPDATE:{
                /* Only accept publish updates from self. If self, fall
                   through to ICAL_XLICCLASS_REQUESTUPDATE */
            }

        case ICAL_XLICCLASS_REQUESTUPDATE:{
                /* always accept the changes */
                break;
            }

        case ICAL_XLICCLASS_REQUESTRESCHEDULE:{
                /* Use same rules as REQUEST_NEW */
                (void)icalclassify_find_overlaps(cal, c);
                break;
            }
        case ICAL_XLICCLASS_REQUESTDELEGATE:{

                break;
            }
        case ICAL_XLICCLASS_REQUESTNEWORGANIZER:{
                break;
            }
        case ICAL_XLICCLASS_REQUESTFORWARD:{
                break;
            }
        case ICAL_XLICCLASS_REQUESTSTATUS:{
                break;
            }

        case ICAL_XLICCLASS_REQUESTFREEBUSY:{
                break;
            }
        case ICAL_XLICCLASS_REPLYACCEPT:{
                /* Change the PARTSTAT of the sender */
                break;
            }
        case ICAL_XLICCLASS_REPLYDECLINE:{
                /* Change the PARTSTAT of the sender */
                break;
            }
        case ICAL_XLICCLASS_REPLYCRASHERACCEPT:{
                /* Add the crasher to the ATTENDEE list with the
                   appropriate PARTSTAT */
                break;
            }
        case ICAL_XLICCLASS_REPLYCRASHERDECLINE:{
                /* Add the crasher to the ATTENDEE list with the
                   appropriate PARTSTAT */
                break;
            }
        case ICAL_XLICCLASS_ADDINSTANCE:{
                break;
            }
        case ICAL_XLICCLASS_CANCELEVENT:{
                /* Remove the component */
                break;
            }
        case ICAL_XLICCLASS_CANCELINSTANCE:{
                break;
            }
        case ICAL_XLICCLASS_CANCELALL:{
                /* Remove the component */
                break;
            }
        case ICAL_XLICCLASS_REFRESH:{
                /* Resend the latest copy of the request */
                break;
            }
        case ICAL_XLICCLASS_COUNTER:{
                break;
            }
        case ICAL_XLICCLASS_DECLINECOUNTER:{
                break;
            }
        case ICAL_XLICCLASS_MALFORMED:{
                /* Send back an error */
                break;
            }
        case ICAL_XLICCLASS_OBSOLETE:{
                printf(" ** Got an obsolete component:\n%s", icalcomponent_as_ical_string(c));
                /* Send back an error */
                break;
            }
        case ICAL_XLICCLASS_MISSEQUENCED:{
                printf(" ** Got a missequenced component:\n%s", icalcomponent_as_ical_string(c));
                /* Send back an error */
                break;
            }
        case ICAL_XLICCLASS_UNKNOWN:{
                printf(" ** Don't know what to do with this component:\n%s",
                       icalcomponent_as_ical_string(c));
                /* Send back an error */
                break;
            }
        case ICAL_XLICCLASS_X:
        case ICAL_XLICCLASS_REPLYDELEGATE:
        default:{
            }
        }

#if 0
        if (reply != 0) {

            /* Don't send the reply if the RSVP parameter indicates not to */
            icalcomponent *reply_inner;
            icalproperty *attendee;
            icalparameter *rsvp;

            reply_inner = icalcomponent_get_first_real_component(reply);
            attendee = icalcomponent_get_first_property(reply_inner, ICAL_ATTENDEE_PROPERTY);
            rsvp = icalproperty_get_first_parameter(attendee, ICAL_RSVP_PARAMETER);

            if (rsvp == 0 || icalparameter_get_rsvp(rsvp) == 1) {
                icalrestriction_check(reply);
                send_message(reply, this_user);
            }

            icalcomponent_free(reply);
        }
#endif

        if (reply != 0) {
            printf("%s\n", icalcomponent_as_ical_string(reply));
        }

        next_c = icalset_get_next_component(f);

        if (dont_remove == 0) {
            /*icalset_remove_component(f,c);
               icalset_add_component(trash,c); */
        }
    }

#if 0

    for (c = icalset_get_first_component(out); c != 0; c = icalset_get_next_component(out)) {

        printf("%s", icalcomponent_as_ical_string(c));
    }
#endif

    icalset_free(f);
    icalset_free(trash);
    icalset_free(cal);
    icalset_free(out);

    return 0;
}
Пример #18
0
/**
 * Get common fields from ECalComponentWithTZ and set them in I_common
 */
void
conv_common_e_to_i (const ECalComponentWithTZ *ectz, I_common *i_common)
{
	GSList *descr_list = NULL;
	const gchar *uid = NULL;
	const gchar *categories = NULL;
	struct icaltimetype *lastModifiedDate;
	struct icaltimetype *createdDate;
	icalcomponent *icomp = NULL;
	icalproperty *prop = NULL;

	i_common->vtimezone = get_vtimezone(ectz);
	sensitivity_e_to_i(ectz->maincomp, i_common);
	link_attachments_e_to_i(ectz->maincomp, i_common);

	/* handle description/body */
	e_cal_component_get_description_list ((ECalComponent*) ectz->maincomp, &descr_list);

	if (descr_list != NULL) {
		ECalComponentText *text = (ECalComponentText*) descr_list->data;
		i_common->body = g_string_new (text->value);
		e_cal_component_free_text_list(descr_list);
	}

	/* ******************************************SET UID************************************ */
	e_cal_component_get_uid (ectz->maincomp, &uid);

	if (uid)
		i_common->uid = g_string_new (uid);

	/* ******************************************SET CATEGORIES************************************ */
	e_cal_component_get_categories (ectz->maincomp, &categories);

	if (categories)
		i_common->categories = g_string_new (categories);

	/* ******************************************SET DATES (CREATION, LASTMODIFICATION, START, END etc.)************************************ */

	e_cal_component_get_last_modified (ectz->maincomp, &lastModifiedDate);
	i_common->last_modified_datetime = new_date_or_datetime();

	if (lastModifiedDate)
		/* log_debug("ICalDate %d-%d-%d-%d-%d-%d", lastModifiedDate->year, lastModifiedDate->month, lastModifiedDate->day, lastModifiedDate->hour, lastModifiedDate->minute, lastModifiedDate->second); */
		date_or_datetime_e_to_i (lastModifiedDate, i_common->last_modified_datetime);
	else {
		/* Set lastModifiedDate to current system time */
		i_common->last_modified_datetime->date_time = g_new0(time_t, 1);
		*(i_common->last_modified_datetime->date_time) = time(NULL);
	}
	g_free(lastModifiedDate);

	i_common->creation_datetime = new_date_or_datetime();
	e_cal_component_get_created (ectz->maincomp, &createdDate);

	if (createdDate)
		date_or_datetime_e_to_i (createdDate, i_common->creation_datetime);
	else {
		/* Set createdDate to current system time */
		i_common->creation_datetime->date_time = g_new0(time_t, 1);
		*(i_common->creation_datetime->date_time) = time(NULL);
	}
	g_free(createdDate);


	/* ******************************************SET ATTACHMENT LIST******************************************************************************* */

	/* iterate over all ical properties */
	icomp = e_cal_component_get_icalcomponent (ectz->maincomp);
	prop = icalcomponent_get_first_property(icomp, ICAL_ANY_PROPERTY);
	while (prop != NULL) {
		icalproperty_kind kind = icalproperty_isa(prop);
		gchar *pname = (gchar*) icalproperty_get_x_name(prop);
		if (ICAL_ATTACH_PROPERTY == kind) /* found kolab inline or link attachment */
			add_e_attachment_parameters(prop, i_common, TRUE);
		else if (pname && strcmp(pname, ICONTACT_KOLAB_STORE_ATTACHMENT) == 0) /* found hidden kolab attachment */
			add_e_attachment_parameters(prop, i_common, FALSE);
		prop = icalcomponent_get_next_property(icomp, ICAL_ANY_PROPERTY);
	}

	i_common->is_html_richtext = FALSE;
}