Exemplo n.º 1
0
icalcomponent *
icalcap_component_new_from_string(const char *data) {

	icalcomponent  *ret = NULL;
	char	       *mtype;

	/* FIXME split the check */
	if (strncmp(data, CONTENT_TYPE, strlen(CONTENT_TYPE))) {
		return NULL;
	}

	mtype = (char *)data+strlen(CONTENT_TYPE);

	ret = icalcomponent_new_from_string(mtype);
	if (ret == NULL) {
		return NULL;
	}

#ifdef DEBUG
	g_message("icalcap_component_new_from_string icalcomponent_new_from_string = %p", ret);
#endif

	/* FIXME
	 * Validate here: should check at least the version
	 */
	if (icalcomponent_isa(ret) != ICAL_VCALENDAR_COMPONENT &&
	    icalcomponent_isa(ret) != ICAL_XROOT_COMPONENT) {
		icalcomponent_free(ret);

		return NULL;
	}

	return ret;
}
Exemplo n.º 2
0
icalcomponent *icalparser_parse(icalparser *parser,
                                icalparser_line_gen_func line_gen_func)
{
    char *line;
    icalcomponent *c = 0;
    icalcomponent *root = 0;
    icalerrorstate es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR);
    int cont;

    icalerror_check_arg_rz((parser != 0), "parser");

    icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, ICAL_ERROR_NONFATAL);

    do {
        line = icalparser_get_line(parser, line_gen_func);

        if ((c = icalparser_add_line(parser, line)) != 0) {

            if (icalcomponent_get_parent(c) != 0) {
                /* This is bad news... assert? */
            }

            assert(parser->root_component == 0);
            assert(pvl_count(parser->components) == 0);

            if (root == 0) {
                /* Just one component */
                root = c;
            } else if (icalcomponent_isa(root) != ICAL_XROOT_COMPONENT) {
                /*Got a second component, so move the two components under
                   an XROOT container */
                icalcomponent *tempc = icalcomponent_new(ICAL_XROOT_COMPONENT);

                icalcomponent_add_component(tempc, root);
                icalcomponent_add_component(tempc, c);
                root = tempc;
            } else if (icalcomponent_isa(root) == ICAL_XROOT_COMPONENT) {
                /* Already have an XROOT container, so add the component
                   to it */
                icalcomponent_add_component(root, c);

            } else {
                /* Badness */
                assert(0);
            }

            c = 0;
        }
        cont = 0;
        if (line != 0) {
            icalmemory_free_buffer(line);
            cont = 1;
        }
    } while (cont);

    icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR, es);

    return root;
}
Exemplo n.º 3
0
static gboolean
update_objects (ECal *client, icalcomponent *icalcomp)
{
	icalcomponent_kind kind;
	icalcomponent *vcal;
	gboolean success = TRUE;

	kind = icalcomponent_isa (icalcomp);

	if (kind == ICAL_VTODO_COMPONENT || kind == ICAL_VEVENT_COMPONENT) {
		vcal = e_cal_util_new_top_level ();
		if (icalcomponent_get_method (icalcomp) == ICAL_METHOD_CANCEL)
			icalcomponent_set_method (vcal, ICAL_METHOD_CANCEL);
		else
			icalcomponent_set_method (vcal, ICAL_METHOD_PUBLISH);
		icalcomponent_add_component (vcal, icalcomponent_new_clone (icalcomp));
	} else if (kind == ICAL_VCALENDAR_COMPONENT) {
		vcal = icalcomponent_new_clone (icalcomp);
		if (!icalcomponent_get_first_property (vcal, ICAL_METHOD_PROPERTY))
			icalcomponent_set_method (vcal, ICAL_METHOD_PUBLISH);
	} else
		return FALSE;

	if (!e_cal_receive_objects (client, vcal, NULL))
		success = FALSE;

	icalcomponent_free (vcal);

	return success;
}
Exemplo n.º 4
0
/* This removes all components except VTODOs and VTIMEZONEs from the toplevel
   icalcomponent, and adds the given list of VTODO components. The list is
   freed afterwards. */
static void
prepare_tasks (icalcomponent *icalcomp, GList *vtodos)
{
	icalcomponent *subcomp;
	GList *elem;
	icalcompiter iter;

	iter = icalcomponent_begin_component (icalcomp, ICAL_ANY_COMPONENT);
	while ((subcomp = icalcompiter_deref (&iter)) != NULL) {
		icalcomponent_kind child_kind = icalcomponent_isa (subcomp);
		if (child_kind != ICAL_VTODO_COMPONENT
		    && child_kind != ICAL_VTIMEZONE_COMPONENT) {
			icalcompiter_next (&iter);
			icalcomponent_remove_component (icalcomp, subcomp);
			icalcomponent_free (subcomp);
		} else {
			icalcompiter_next (&iter);
		}
	}

	for (elem = vtodos; elem; elem = elem->next) {
		icalcomponent_add_component (icalcomp, elem->data);
	}
	g_list_free (vtodos);
}
Exemplo n.º 5
0
/* This removes all components except VEVENTs and VTIMEZONEs from the toplevel */
static void
prepare_events (icalcomponent *icalcomp, GList **vtodos)
{
	icalcomponent *subcomp;
	icalcompiter iter;

	if (vtodos)
		*vtodos = NULL;

	iter = icalcomponent_begin_component (icalcomp, ICAL_ANY_COMPONENT);
	while ((subcomp = icalcompiter_deref (&iter)) != NULL) {
		icalcomponent_kind child_kind = icalcomponent_isa (subcomp);
		if (child_kind != ICAL_VEVENT_COMPONENT
		    && child_kind != ICAL_VTIMEZONE_COMPONENT) {

			icalcompiter_next (&iter);

			icalcomponent_remove_component (icalcomp, subcomp);
			if (child_kind == ICAL_VTODO_COMPONENT && vtodos)
				*vtodos = g_list_prepend (*vtodos, subcomp);
			else
                                icalcomponent_free (subcomp);
		} else {
			icalcompiter_next (&iter);
		}
	}
}
Exemplo n.º 6
0
/* Add_timezone handler for the file backend */
static void
e_cal_backend_http_add_timezone (ECalBackendSync *backend,
                                 EDataCal *cal,
                                 GCancellable *cancellable,
                                 const gchar *tzobj,
                                 GError **error)
{
	ETimezoneCache *timezone_cache;
	icalcomponent *tz_comp;
	icaltimezone *zone;

	timezone_cache = E_TIMEZONE_CACHE (backend);

	tz_comp = icalparser_parse_string (tzobj);
	if (!tz_comp) {
		g_propagate_error (error, EDC_ERROR (InvalidObject));
		return;
	}

	if (icalcomponent_isa (tz_comp) != ICAL_VTIMEZONE_COMPONENT) {
		icalcomponent_free (tz_comp);
		g_propagate_error (error, EDC_ERROR (InvalidObject));
		return;
	}

	zone = icaltimezone_new ();
	icaltimezone_set_component (zone, tz_comp);
	e_timezone_cache_add_timezone (timezone_cache, zone);
}
nsresult
calIcalComponent::Serialize(char **icalstr)
{
    NS_ENSURE_ARG_POINTER(icalstr);

    // add the timezone bits
    if (icalcomponent_isa(mComponent) == ICAL_VCALENDAR_COMPONENT && mReferencedTimezones.Count() > 0) {
        for (auto iter = mReferencedTimezones.ConstIter(); !iter.Done(); iter.Next() ) {
            icaltimezone * icaltz = cal::getIcalTimezone(iter.Data());
            if (icaltz) {
                icalcomponent * const tzcomp = icalcomponent_new_clone(icaltimezone_get_component(icaltz));
                icalcomponent_add_component(mComponent, tzcomp);
            }
        }
    }

    *icalstr = icalcomponent_as_ical_string(mComponent);
    if (!*icalstr) {
        // xxx todo: what about NS_ERROR_OUT_OF_MEMORY?
#ifdef DEBUG
        fprintf(stderr, "Error serializing: %d (%s)\n",
                icalerrno, icalerror_strerror(icalerrno));
#endif
        // The return values in calIError match with libical errnos,
        // so no need for a conversion table or anything.
        return static_cast<nsresult>(calIErrors::ICS_ERROR_BASE + icalerrno);
    }

    return NS_OK;
}
Exemplo n.º 8
0
static icalcomponent_kind
get_menu_type (void *data)
{
	CamelMimePart *part;
	char *path;
	icalcomponent *icalcomp, *subcomp;
	icalcomponent_kind kind;
	EPopupTarget *target = (EPopupTarget *) data;

	if (target->type == EM_POPUP_TARGET_ATTACHMENTS)
		part = ((EAttachment *) ((EMPopupTargetAttachments *) target)->attachments->data)->body;
	else
		part = ((EMPopupTargetPart *) target)->part;

	path = em_utils_temp_save_part (NULL, part, FALSE);

	icalcomp = get_icalcomponent_from_file (path);

	subcomp = icalcomponent_get_inner(icalcomp);
	kind = icalcomponent_isa (subcomp);

	if (kind == ICAL_VTODO_COMPONENT ) {
		return ICAL_VTODO_COMPONENT;
	} else if ( kind == ICAL_VEVENT_COMPONENT) {
		return ICAL_VEVENT_COMPONENT;
	}
	return ICAL_NO_COMPONENT;
}
Exemplo n.º 9
0
/* This function is called recursively, since objects may be embedded in a
 * single VCALENDAR component or each in its own. Returns 0 on an empty set,
 * 1 -- otherwise.
 */
static int iterate_cal(icalcomponent *parent, int depth, int *count, icalcomponent **result, icalcomponent_kind kind)
{
	icalcomponent *comp = NULL;
	icalcompiter compiter;

	if (!parent)
		return 0;

	/* we need to use iterators because we're calling iterate_cal recursively */
	compiter = icalcomponent_begin_component(parent, ICAL_ANY_COMPONENT);
	comp = icalcompiter_deref(&compiter);
	for (; comp && *count; comp = icalcompiter_next(&compiter)) {
		if (icalcomponent_isa(comp) == kind) {
			/* FIXME: should we only consider items with category GNOKII? */
			(*count)--;
		}
		if (!*count) {
			*result = comp;
			dprintf("Found component at depth %d\n", depth);
			break;
		}
		iterate_cal(comp, depth+1, count, result, kind);
	}

	return 1;
}
Exemplo n.º 10
0
void MainWindow::loadFromIcsFile()
{
    char* line;
    icalcomponent *c;
    icalparser *parser = icalparser_new();

    FILE* stream = fopen("/home/quentin/Public/test.ics", "r");

    icalparser_set_gen_data(parser, stream);

    do
    {
        line = icalparser_get_line(parser, read_stream);
        c = icalparser_add_line(parser, line);

        if (c != 0)
        {
            icalcomponent *inner = icalcomponent_get_first_component(c, ICAL_ANY_COMPONENT);
            while (inner != NULL)
            {
                if (icalcomponent_isa(inner) == ICAL_VTODO_COMPONENT)
                {
                    const char* name   = icalcomponent_get_summary(inner);
                    const char* uid    = icalcomponent_get_uid(inner);
                    icalproperty *p    = icalcomponent_get_first_property(inner, ICAL_RELATEDTO_PROPERTY);
                    const char* parent = icalproperty_get_relatedto(p);
                    addTask(name, uid, parent);
                }
                if (icalcomponent_isa(inner) == ICAL_VEVENT_COMPONENT)
                {
                    const char* name   = icalcomponent_get_summary(inner);
                    const char* uid    = icalcomponent_get_uid(inner);
                    icalproperty *p    = icalcomponent_get_first_property(inner, ICAL_RELATEDTO_PROPERTY);
                    const char* parent = icalproperty_get_relatedto(p);
                    p                  = icalcomponent_get_first_property(inner, ICAL_DTSTART_PROPERTY);
                    icaltimetype start = icalproperty_get_dtstart(p);
                    p                  = icalcomponent_get_first_property(inner, ICAL_DTEND_PROPERTY);
                    icaltimetype end   = icalproperty_get_dtend(p);
                    Task* task         = findTask(parent);
                    addEvent(task, uid, name, start, end);
                }
                inner = icalcomponent_get_next_component(c, ICAL_ANY_COMPONENT);
            }
        }

    } while (line != 0);
}
Exemplo n.º 11
0
calIcalComponent::GetLibicalTimezone()
{
    NS_ASSERTION(icalcomponent_isa(mComponent) == ICAL_VTIMEZONE_COMPONENT, "no VTIMEZONE -- unexpected!");
    if (!mTimezone && (icalcomponent_isa(mComponent) == ICAL_VTIMEZONE_COMPONENT)) {
        // xxx todo: libical needs a parent VCALENDAR to retrieve a icaltimezone
        NS_ASSERTION(mParent, "VTIMEZONE has no parent!");
        if (mParent) {
            icalproperty * const tzidProp = icalcomponent_get_first_property(mComponent, ICAL_TZID_PROPERTY);
            NS_ASSERTION(tzidProp, "no TZID property in VTIMEZONE!?");
            if (tzidProp) {
                mTimezone = icalcomponent_get_timezone(mParent->GetLibicalComponent(),
                                                       icalvalue_get_string(icalproperty_get_value(tzidProp)));
            }
        }
    }
    return mTimezone;
}
Exemplo n.º 12
0
static icalcomponent *icalmessage_get_inner(icalcomponent *comp)
{
    if (icalcomponent_isa(comp) == ICAL_VCALENDAR_COMPONENT) {
        return icalcomponent_get_first_real_component(comp);
    } else {
        return comp;
    }
}
Exemplo n.º 13
0
/*
 * Construct a JSON array for an iCalendar component.
 */
static json_t *icalcomponent_as_json_array(icalcomponent *comp)
{
    icalcomponent *c;
    icalproperty *p;
    icalcomponent_kind kind;
    const char* kind_string;
    json_t *jcomp, *jprops, *jsubs;

    if (!comp) return NULL;

    kind = icalcomponent_isa(comp);
    switch (kind) {
    case ICAL_NO_COMPONENT:
        return NULL;
        break;

    case ICAL_X_COMPONENT:
        kind_string = ""; //comp->x_name;
        break;

    default:
        kind_string = icalcomponent_kind_to_string(kind);
    }


    /* Create component array */
    jcomp = json_array();


    /* Add component name */
    json_array_append_new(jcomp,
        json_string(lcase(icalmemory_tmp_copy(kind_string))));


    /* Add properties */
    jprops = json_array();
    for (p = icalcomponent_get_first_property(comp, ICAL_ANY_PROPERTY);
         p;
         p = icalcomponent_get_next_property(comp, ICAL_ANY_PROPERTY)) {

        json_array_append_new(jprops, icalproperty_as_json_array(p));
    }
    json_array_append_new(jcomp, jprops);


    /* Add sub-components */
    jsubs = json_array();
    for (c = icalcomponent_get_first_component(comp, ICAL_ANY_COMPONENT);
         c;
         c = icalcomponent_get_next_component(comp, ICAL_ANY_COMPONENT)) {

        json_array_append_new(jsubs, icalcomponent_as_json_array(c));
    }
    json_array_append_new(jcomp, jsubs);

    return jcomp;
}
Exemplo n.º 14
0
/*
 * Construct a XML element for an iCalendar component.
 */
static xmlNodePtr icalcomponent_as_xml_element(icalcomponent *comp)
{
    icalcomponent *c;
    icalproperty *p;
    icalcomponent_kind kind;
    const char* kind_string;
    xmlNodePtr xcomp, xprops = NULL, xsubs = NULL;

    if (!comp) return NULL;

    kind = icalcomponent_isa(comp);
    switch (kind) {
    case ICAL_NO_COMPONENT:
        return NULL;
        break;

    case ICAL_X_COMPONENT:
        kind_string = ""; //comp->x_name;
        break;

    default:
        kind_string = icalcomponent_kind_to_string(kind);
    }


    /* Create component */
    xcomp = xmlNewNode(NULL,
                       BAD_CAST lcase(icalmemory_tmp_copy(kind_string)));


    /* Add properties */
    for (p = icalcomponent_get_first_property(comp, ICAL_ANY_PROPERTY);
            p;
            p = icalcomponent_get_next_property(comp, ICAL_ANY_PROPERTY)) {

        if (!xprops)
            xprops = xmlNewChild(xcomp, NULL, BAD_CAST "properties", NULL);

        xmlAddChild(xprops, icalproperty_as_xml_element(p));
    }


    /* Add sub-components */
    for (c = icalcomponent_get_first_component(comp, ICAL_ANY_COMPONENT);
            c;
            c = icalcomponent_get_next_component(comp, ICAL_ANY_COMPONENT)) {

        if (!xsubs)
            xsubs = xmlNewChild(xcomp, NULL, BAD_CAST "components", NULL);

        xmlAddChild(xsubs, icalcomponent_as_xml_element(c));
    }

    return xcomp;
}
Exemplo n.º 15
0
/** Get VEVENT from the iTip.
 *
 * VCALENDAR
 *   VTIMEZONE+
 *   VEVENT    <--- will return this
 *
 * @param comp iCal component.
 *
 * @return VEVENT icalcomponent object or NULL.
 */
icalcomponent *icalcomponent_get_itip_payload(icalcomponent *comp)
{
    icalcomponent *ret = NULL;

    g_return_val_if_fail(comp != NULL, NULL);

    if (icalcomponent_isa(comp) == ICAL_VCALENDAR_COMPONENT)
    {
        icalcomponent *vevent = icalcomponent_get_first_component(comp, ICAL_VEVENT_COMPONENT);
        if (vevent)
        {
            ret = vevent;
        }
    }
    else if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT)
    {
        ret = comp;
    }

    return ret;
}
Exemplo n.º 16
0
icalcomponent *icalcluster_get_component(icalcluster *impl) {

	icalerror_check_arg_rz((impl!=0),"cluster");

	if (icalcomponent_isa(impl->data) != ICAL_XROOT_COMPONENT) {
		icalerror_warn("The top component is not an XROOT");
		fprintf(stderr, "%s\n", icalcomponent_as_ical_string(impl->data));
		abort();
	}

	return impl->data;
}
Exemplo n.º 17
0
void icalcomponent_remove_invitee(icalcomponent *comp, icalproperty *prop)
{
    if (icalcomponent_isa(comp) == ICAL_VPOLL_COMPONENT) {
        icalcomponent *vvoter = icalproperty_get_parent(prop);

        icalcomponent_remove_component(comp, vvoter);
        icalcomponent_free(vvoter);
    }
    else {
        icalcomponent_remove_property(comp, prop);
        icalproperty_free(prop);
    }
}
Exemplo n.º 18
0
void
dates_ical_drop_cb (DatesView *view, const gchar *ical, DatesData *d)
{
    icalcomponent *icalcomp, *icalcomp2;
    gint events;

    if (!d->cal_loaded) {
	/* TODO: Toggle the default calendar here maybe? */
	g_warning ("No calendars selected to add new event to");
	return;
    }
	
    icalcomp = icalcomponent_new_from_string (g_strdup (ical));
    if (!icalcomp)
	g_warning ("Error creating icalcomponent from string");

    switch (icalcomponent_isa (icalcomp)) {
	case ICAL_VEVENT_COMPONENT :
	    icalcomponent_set_uid (icalcomp, "");
	    dates_new (d, icalcomponent_new_clone (icalcomp), TRUE);
	    return;
	case ICAL_VCALENDAR_COMPONENT :
	    /* Iterate through events */
	    /* TODO: A confirmation dialog when calendar has
	     * multiple events?
	     */
	    events = icalcomponent_count_components (icalcomp,
						     ICAL_VEVENT_COMPONENT);
	    if (events == 0) {
		g_warning ("Dragged ical contains no supported "
			   "kinds.");
		break;
	    }
			
	    icalcomp2 = icalcomponent_get_first_component (icalcomp,
							   ICAL_VEVENT_COMPONENT);
	    do {
		icalcomponent_set_uid (icalcomp2, "");
		dates_new (d, icalcomponent_new_clone (
			       icalcomp2), (events == 1) ?
			   TRUE : FALSE);
	    } while ((icalcomp2 = icalcomponent_get_next_component (
			  icalcomp2, ICAL_VEVENT_COMPONENT))); 
	    break;
	default :
	    g_warning ("Dragged ical not a supported kind.");
	    break;
    }

    icalcomponent_free (icalcomp);
}
Exemplo n.º 19
0
static gboolean
deserialize (ScalixObject * object, const char *string)
{
    ScalixAppointmentPrivate *priv;
    icalcomponent *icomp, *subcomp;
    icalcomponent_kind kind;
    icaltimezone *zone;

    priv = SCALIX_APPOINTMENT_GET_PRIVATE (SCALIX_APPOINTMENT (object));

    icomp = icalparser_parse_string (string);

    if (icalcomponent_isa (icomp) != ICAL_VCALENDAR_COMPONENT) {
        g_warning ("No VCALENAR while deserializing! (%s)\n", string);
        icalcomponent_free (icomp);
        return FALSE;
    }

    /* Grab the timezone if any */
    subcomp = icalcomponent_get_first_component (icomp,
                                                 ICAL_VTIMEZONE_COMPONENT);
    if (subcomp != NULL) {
        zone = icaltimezone_new ();
        icalcomponent_remove_component (icomp, subcomp);
        if (icaltimezone_set_component (zone, subcomp))
            priv->timezone = zone;
    }

    kind = ICAL_VEVENT_COMPONENT;
    /* Grab the main VEVENT */
    subcomp = icalcomponent_get_first_component (icomp, kind);

    if (subcomp == NULL) {
        icalcomponent_free (icomp);
        return FALSE;
    }

    icalcomponent_remove_component (icomp, subcomp);
    e_cal_component_set_icalcomponent (E_CAL_COMPONENT (object), subcomp);
    e_cal_component_commit_sequence (E_CAL_COMPONENT (object));

    priv->exceptions = NULL;
    while ((subcomp = icalcomponent_get_next_component (icomp, kind))) {
        icalcomponent_remove_component (icomp, subcomp);
        priv->exceptions = g_slist_prepend (priv->exceptions, subcomp);
    }

    icalcomponent_free (icomp);

    return TRUE;
}
Exemplo n.º 20
0
/**
 * e_cal_util_parse_ics_string:
 * @string: iCalendar string to be parsed.
 *
 * Parses an iCalendar string and returns a new #icalcomponent representing
 * that string. Note that this function deals with multiple VCALENDAR's in the
 * string, something that Mozilla used to do and which libical does not
 * support.
 *
 * Returns: a newly created #icalcomponent or NULL if the string isn't a
 * valid iCalendar string.
 */
icalcomponent *
e_cal_util_parse_ics_string (const gchar *string)
{
	GString *comp_str = NULL;
	gchar *s;
	icalcomponent *icalcomp = NULL;

	g_return_val_if_fail (string != NULL, NULL);

	/* Split string into separated VCALENDAR's, if more than one */
	s = g_strstr_len (string, strlen (string), "BEGIN:VCALENDAR");

	if (s == NULL)
		return icalparser_parse_string (string);

	while (*s != '\0') {
		gchar *line = read_line (s);

		if (!comp_str)
			comp_str = g_string_new (line);
		else
			comp_str = g_string_append (comp_str, line);

		if (strncmp (line, "END:VCALENDAR", 13) == 0) {
			icalcomponent *tmp;

			tmp = icalparser_parse_string (comp_str->str);
			if (tmp && icalcomponent_isa (tmp) == ICAL_VCALENDAR_COMPONENT) {
				if (icalcomp)
					icalcomponent_merge_component (icalcomp, tmp);
				else
					icalcomp = tmp;
			} else {
				g_warning (
					"Could not merge the components, "
					"the component is either invalid "
					"or not a toplevel component \n");
			}

			g_string_free (comp_str, TRUE);
			comp_str = NULL;
		}

		s += strlen (line);

		g_free (line);
	}

	return icalcomp;
}
Exemplo n.º 21
0
/** Get iTIP method.
 *
 * @param comp iCal component.
 *
 * @return Method.
 */
icalproperty_method icalcomponent_get_itip_method(icalcomponent *comp)
{
    icalproperty_method method = ICAL_METHOD_NONE;

    if (icalcomponent_isa(comp) == ICAL_VCALENDAR_COMPONENT)
    {
        icalcomponent *vevent = icalcomponent_get_first_component(comp, ICAL_VEVENT_COMPONENT);

        if (vevent && icalcomponent_get_first_property(vevent, ICAL_METHOD_PROPERTY))
        {
            method = icalcomponent_get_method(vevent);
        }
        else
        {
            method = icalcomponent_get_method(comp);
        }
    }
    else if (icalcomponent_isa(comp) == ICAL_VEVENT_COMPONENT)
    {
        method = icalcomponent_get_method(comp);
    }

    return method;
}
Exemplo n.º 22
0
static gboolean
set_ical_from_mime_part (CamelMimePart * part, ScalixObject * object)
{
    CamelDataWrapper *content;
    CamelStream *stream;
    GByteArray *data;
    icalcomponent *icomp = NULL;
    icalcomponent *subcomp = NULL;
    ScalixAppointmentPrivate *priv;

    priv = SCALIX_APPOINTMENT_GET_PRIVATE (SCALIX_APPOINTMENT (object));

    content = camel_medium_get_content_object (CAMEL_MEDIUM (part));

    data = g_byte_array_new ();
    stream = camel_stream_mem_new_with_byte_array (data);
    camel_data_wrapper_decode_to_stream (content, stream);

    if (data == NULL || data->data == NULL) {
        g_print ("Found corrupt ical data\n");
        return FALSE;
    }

    icomp = icalparser_parse_string ((const char *) data->data);

    if (icalcomponent_isa (icomp) != ICAL_VCALENDAR_COMPONENT) {
        icalcomponent_free (icomp);
        return FALSE;
    }

    /* Grab the timezone if any */
    subcomp = icalcomponent_get_first_component (icomp,
                                                 ICAL_VTIMEZONE_COMPONENT);
    if (subcomp != NULL) {
        icaltimezone *zone;

        zone = icaltimezone_new ();
        icaltimezone_set_component (zone, subcomp);
        priv->timezone = zone;
    }

    /* Grab the main VEVENT */
    subcomp = icalcomponent_get_first_component (icomp, ICAL_VEVENT_COMPONENT);

    e_cal_component_set_icalcomponent (E_CAL_COMPONENT (object), subcomp);

    return TRUE;
}
Exemplo n.º 23
0
icalproperty *icalcomponent_get_next_invitee(icalcomponent *comp)
{
    icalproperty *prop;

    if (icalcomponent_isa(comp) == ICAL_VPOLL_COMPONENT) {
        icalcomponent *vvoter =
            icalcomponent_get_next_component(comp, ICAL_VVOTER_COMPONENT);

        prop = icalcomponent_get_first_property(vvoter, ICAL_VOTER_PROPERTY);
    }
    else {
        prop = icalcomponent_get_next_property(comp, ICAL_ATTENDEE_PROPERTY);
    }

    return prop;
}
Exemplo n.º 24
0
void Todo::updateDataFromIcal() {
    assert(_ptrIcal);
    assert(icalcomponent_isa(_ptrIcal) == ICAL_VTODO_COMPONENT);

    for (icalproperty * ptrProperty = icalcomponent_get_first_property(_ptrIcal, ICAL_ANY_PROPERTY);
            ptrProperty != 0;
            ptrProperty = icalcomponent_get_next_property(_ptrIcal, ICAL_ANY_PROPERTY)) {

        icalproperty_kind propertyKind = icalproperty_isa(ptrProperty);

        switch (propertyKind) {
            case ICAL_SUMMARY_PROPERTY:     convertIcalToString(_summary, ptrProperty);         break;
            case ICAL_LOCATION_PROPERTY:    convertIcalToString(_location, ptrProperty);        break;
            case ICAL_DESCRIPTION_PROPERTY: convertIcalToString(_description, ptrProperty);     break;
            default: break;
        }
    }
}
Exemplo n.º 25
0
static gboolean
scalix_appointment_from_string (ScalixObject * object, const char *string)
{
    icalcomponent *icomp, *subcomp;

    icomp = icalparser_parse_string (string);
    if (icalcomponent_isa (icomp) == ICAL_VCALENDAR_COMPONENT) {
        subcomp = icalcomponent_get_first_component (icomp,
                                                     ICAL_VEVENT_COMPONENT);
        icalcomponent_remove_component (icomp, subcomp);
        icalcomponent_free (icomp);
        icomp = subcomp;

    }

    e_cal_component_set_icalcomponent (E_CAL_COMPONENT (object), icomp);

    return TRUE;
}
Exemplo n.º 26
0
void _IcalEvent2Exchange(mapi_object_t *obj_folder, icalcomponent *vevent)
{
	struct ical2exchange ical2exchange;
	TALLOC_CTX	*mem_ctx;
	enum MAPISTATUS			retval;
	mapi_object_t		obj_message;
	ical2exchange.obj_message = &obj_message;

	ical2exchange.method=ICAL_METHOD_PUBLISH;
	mapi_object_init(&obj_message);
	
	/*sanity check*/
	if(icalcomponent_isa(vevent) != ICAL_VEVENT_COMPONENT) return;
	
	mem_ctx = talloc_named(mapi_object_get_session(obj_folder), 0, "ical2exchange");
	ical2exchange.lpProps = talloc_array(mem_ctx, struct SPropValue, 2);

	ical2exchange_init(&ical2exchange, mem_ctx);
	ical2exchange_get_properties(&ical2exchange, vevent);
	ical2exchange_convert_event(&ical2exchange);
	
	retval = CreateMessage(obj_folder, &obj_message);
	
	if (retval != MAPI_E_SUCCESS){
		mapi_errstr("CreateMessage", GetLastError());
	} else {
		retval = SetProps(&obj_message, 0, ical2exchange.lpProps, ical2exchange.cValues);
		if (retval != MAPI_E_SUCCESS){
			mapi_errstr("SetProps", GetLastError());
		} else {
			retval = SaveChangesMessage(obj_folder, &obj_message, KeepOpenReadOnly);
			if (retval != MAPI_E_SUCCESS){
				mapi_errstr("SaveChangesMessage", GetLastError());
			}
		}
	}
	

	MAPIFreeBuffer(ical2exchange.lpProps);
	ical2exchange_reset(&ical2exchange);
	talloc_free(mem_ctx);

}
void update_attendees(icalcomponent* event)
{
    icalproperty* p;
    icalparameter* parameter;

    assert(event != 0);
        assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT);

    for(
        p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
        p != 0;
        p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
        ) {

        parameter = icalproperty_get_first_parameter(p,ICAL_PARTSTAT_PARAMETER);

        if (parameter == 0) {

            /* There was no PARTSTAT parameter, so add one.  */
            icalproperty_add_parameter(
                p,
                icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
                );

        } else if (icalparameter_get_partstat(parameter) == ICAL_PARTSTAT_NEEDSACTION) {
            /* Remove the NEEDSACTION parameter and replace it with
               TENTATIVE */

            icalproperty_remove_parameter_by_kind(p,ICAL_PARTSTAT_PARAMETER);

            /* Don't forget to free it */
            icalparameter_free(parameter);

            /* Add a new one */
            icalproperty_add_parameter(
                p,
                icalparameter_new_partstat(ICAL_PARTSTAT_TENTATIVE)
                );
        }

    }
}
void get_required_attendees(icalcomponent* event)
{
    icalproperty* p;
    icalparameter* parameter;

    assert(event != 0);
    assert(icalcomponent_isa(event) == ICAL_VEVENT_COMPONENT);

    /* This loop iterates over all of the ATTENDEE properties in the
       event */

    /* The iteration routines save their state in the event
       struct, so the are not thread safe unless you lock the whole
       component. */

    for(
        p = icalcomponent_get_first_property(event,ICAL_ATTENDEE_PROPERTY);
        p != 0;
        p = icalcomponent_get_next_property(event,ICAL_ATTENDEE_PROPERTY)
        ) {

        /* Get the first ROLE parameter in the property. There should
           only be one, so we won't bother to iterate over them. But,
           you can iterate over parameters just like with properties */

        parameter = icalproperty_get_first_parameter(p,ICAL_ROLE_PARAMETER);

        /* If the parameter indicates the participant is required, get
           the attendees name and stick a copy of it into the output
           array */

        if ( icalparameter_get_role(parameter) == ICAL_ROLE_REQPARTICIPANT)
        {
            /* Remember, the caller does not own this string, so you
               should strdup it if you want to change it. */
            const char *attendee = icalproperty_get_attendee(p);
            printf("%s",attendee);
        }
    }

}
Exemplo n.º 29
0
icalcluster * icalcluster_new(const char* key, icalcomponent *data) {
	struct icalcluster_impl *impl = icalcluster_new_impl();
	assert(impl->data == 0);

	impl->key	= strdup(key);
	impl->changed	= 0;
	impl->data	= 0;

	if (data != NULL) {
		if (icalcomponent_isa(data) != ICAL_XROOT_COMPONENT) {
			impl->data = icalcomponent_new(ICAL_XROOT_COMPONENT);
			icalcomponent_add_component(impl->data, data);
		} else {
			impl->data = icalcomponent_new_clone(data);
		}
	} else {
		impl->data = icalcomponent_new(ICAL_XROOT_COMPONENT);
	}

	return impl;
}
static void
patch_tzids (icalcomponent *subcomp,
             GHashTable *mapping)
{
	gchar *tzid = NULL;

	if (icalcomponent_isa (subcomp) != ICAL_VTIMEZONE_COMPONENT) {
		icalproperty *prop = icalcomponent_get_first_property (
			subcomp, ICAL_ANY_PROPERTY);
		while (prop) {
			icalparameter *param = icalproperty_get_first_parameter (
				prop, ICAL_TZID_PARAMETER);
			while (param) {
				const gchar *oldtzid;
				const gchar *newtzid;

				g_free (tzid);
				tzid = g_strdup (icalparameter_get_tzid (param));

				if (!g_hash_table_lookup_extended (
					mapping, tzid,
					(gpointer *) &oldtzid,
					(gpointer *) &newtzid)) {
					/* Corresponding VTIMEZONE not seen before! */
					newtzid = e_cal_match_tzid (tzid);
				}
				if (newtzid) {
					icalparameter_set_tzid (param, newtzid);
				}
				param = icalproperty_get_next_parameter (
					prop, ICAL_TZID_PARAMETER);
			}
			prop = icalcomponent_get_next_property (
				subcomp, ICAL_ANY_PROPERTY);
		}
	}

	g_free (tzid);
}