Ejemplo n.º 1
0
/**
 * get parameters from the icalendar property and store them in the internal
 * struct if the parameter describes a hidden or inline attachment.
 */
static void
add_e_attachment_parameters(icalproperty *prop, I_common *i_common, gboolean inln)
{
	gboolean binary = FALSE;
	gchar* mime_type = NULL;
	gchar* label = NULL;

	/* iterate over all parameters of the attachment property */
	int i, pc = icalproperty_count_parameters(prop);
	icalparameter *para;
	for (i = 0; i < pc; i++) {
		icalparameter_kind kind;
		icalparameter_value xvalue;

		para = i == 0 ? icalproperty_get_first_parameter(prop, ICAL_ANY_PARAMETER) :
			icalproperty_get_next_parameter(prop, ICAL_ANY_PARAMETER);

		kind = icalparameter_isa(para);
		xvalue = icalparameter_get_value(para);
		if (kind == ICAL_VALUE_PARAMETER && xvalue == ICAL_VALUE_BINARY)
			binary = TRUE; /* not a link attachment */
		else if (kind == ICAL_FMTTYPE_PARAMETER) /* found mime type */
			mime_type = (gchar*) icalparameter_get_xvalue(para);
		else if (xvalue == ICAL_VALUE_X) { /* found attachment name */
			const char* name = icalparameter_get_xname(para);
			const char* value = icalparameter_get_xvalue(para);
			if (name && strcmp(name, ICONTACT_KOLAB_STORE_ATTACHMENT_NAME) == 0)
				label = (gchar*) value;
		}
	}

	if (binary) { /* if not a linked attachment add data to struct */
		Kolab_conv_mail_part *mpart = g_new0(Kolab_conv_mail_part, 1);
		gchar* pname = NULL;

		if (label != NULL) {
			if (inln)
				i_common->inline_attachment_names = g_list_append(
				                                                  i_common->inline_attachment_names,
				                                                  strdup(label));
			mpart->name = strdup(label);
		}
		if (mime_type != NULL)
			mpart->mime_type = strdup(mime_type);
		/* add data and length */
		pname = (gchar*) icalproperty_get_value_as_string(prop);
		if (pname) {
			gsize outlen;
			mpart->data = (gchar*) g_base64_decode (pname, &outlen);
			mpart->length = outlen;
			/* add created mail part to the attachment list */
			i_common->kolab_attachment_store = g_list_append(i_common->kolab_attachment_store, mpart);
		}
	}
}
static icalparameter*
FindParameter(icalproperty *prop, const nsACString &param, icalparameter_kind kind)
{
    for (icalparameter *icalparam =
             icalproperty_get_first_parameter(prop, kind);
         icalparam;
         icalparam = icalproperty_get_next_parameter(prop, kind)) {
        if (param.Equals(icalparameter_get_xname(icalparam)))
            return icalparam;
    }
    return nullptr;
}
Ejemplo n.º 3
0
/*
 * Add an iCalendar parameter to an existing JSON object.
 */
static void icalparameter_as_json_object_member(icalparameter *param,
                                                json_t *jparams)
{
    icalparameter_kind kind;
    const char *kind_string, *value_string;

    kind = icalparameter_isa(param);

    switch (kind) {
    case ICAL_X_PARAMETER:
        kind_string = icalparameter_get_xname(param);
        break;

#ifdef HAVE_IANA_PARAMS
    case ICAL_IANA_PARAMETER:
        kind_string = icalparameter_get_iana_name(param);
        break;
#endif

    default:
        kind_string = icalparameter_kind_to_string(kind);
        if (kind_string) break;

    case ICAL_NO_PARAMETER:
    case ICAL_ANY_PARAMETER:
            icalerror_set_errno(ICAL_BADARG_ERROR);
            return;
    }

    /* XXX  Need to handle multi-valued parameters */
    value_string = icalparameter_get_xvalue(param);
    if (!value_string) {
        icalparameter_value value = icalparameter_get_value(param);

        if (value) value_string = icalparameter_enum_to_string(value);
    }
    if (!value_string) return;

    json_object_set_new(jparams, lcase(icalmemory_tmp_copy(kind_string)),
                        json_string(value_string));
}
static nsresult
FillParameterName(icalparameter *icalparam, nsACString &name)
{
    const char *propname = nullptr;
    if (icalparam) {
        icalparameter_kind paramkind = icalparameter_isa(icalparam);
        if (paramkind == ICAL_X_PARAMETER)
            propname = icalparameter_get_xname(icalparam);
        else if (paramkind == ICAL_IANA_PARAMETER)
            propname = icalparameter_get_iana_name(icalparam);
        else if (paramkind != ICAL_NO_PARAMETER)
            propname = icalparameter_kind_to_string(paramkind);
    }

    if (propname) {
        name.Assign(propname);
    } else {
        name.Truncate();
        name.SetIsVoid(true);
    }

    return NS_OK;
}
Ejemplo n.º 5
0
/*
 * Construct an XML element for an iCalendar parameter.
 */
static xmlNodePtr icalparameter_as_xml_element(icalparameter *param)
{
    icalparameter_kind kind;
    icalparameter_value value;
    const char *kind_string, *type_string, *value_string;
    xmlNodePtr xparam;

    kind = icalparameter_isa(param);

    switch (kind) {
    case ICAL_X_PARAMETER:
        kind_string = icalparameter_get_xname(param);
        break;

#ifdef HAVE_IANA_PARAMS
    case ICAL_IANA_PARAMETER:
        kind_string = icalparameter_get_iana_name(param);
        break;
#endif

    default:
        kind_string = icalparameter_kind_to_string(kind);
        if (kind_string) break;

    case ICAL_NO_PARAMETER:
    case ICAL_ANY_PARAMETER:
        icalerror_set_errno(ICAL_BADARG_ERROR);
        return NULL;
    }

    /* Get value type */
    switch (kind) {
    case ICAL_ALTREP_PARAMETER:
    case ICAL_DIR_PARAMETER:
        type_string = "uri";
        break;

    case ICAL_DELEGATEDFROM_PARAMETER:
    case ICAL_DELEGATEDTO_PARAMETER:
    case ICAL_MEMBER_PARAMETER:
    case ICAL_SENTBY_PARAMETER:
        type_string = "cal-address";
        break;

    case ICAL_RSVP_PARAMETER:
        type_string = "boolean";
        break;

    default:
        type_string = "text";
        break;
    }

    /* XXX  Need to handle multi-valued parameters */
    value = icalparameter_get_value(param);
    if (value == ICAL_VALUE_X) value_string = icalparameter_get_xvalue(param);
    else value_string = icalparameter_enum_to_string(value);
    if (!value_string) return NULL;

    xparam = xmlNewNode(NULL, BAD_CAST lcase(icalmemory_tmp_copy(kind_string)));
    xmlNewTextChild(xparam, NULL, BAD_CAST type_string, BAD_CAST value_string);

    return xparam;
}
Ejemplo n.º 6
0
void ical2exchange_property_ATTACH(struct ical2exchange *ical2exchange)
{
	int 		data;
	char 		*extension = NULL;
	char 		*filename = NULL;
	const char 	*fmttype = NULL;
	icalattach	*icalattach = NULL;
	icalparameter	*fmttypePar = NULL;
	icalparameter	*xfilePar = NULL;
	const char 	*xname = NULL;
	icalproperty	*attachProp = NULL;
	
	/*sanity check*/
	if(!ical2exchange->attachEvent) return;
	
	attachProp=icalcomponent_get_first_property(ical2exchange->attachEvent, ICAL_ATTACH_PROPERTY);
	while(attachProp){
	
		icalattach = icalproperty_get_attach(attachProp);
		data = ldb_base64_decode((char *) icalattach_get_data (icalattach));
		
		/*FMTTYPE*/
		fmttypePar = icalproperty_get_first_parameter(attachProp, ICAL_FMTTYPE_PARAMETER);
		if(fmttypePar){
			fmttype = icalparameter_get_fmttype(fmttypePar);
		}
		
		/*X-FIlename*/
		xfilePar = icalproperty_get_first_parameter(attachProp, ICAL_X_PARAMETER);
		if(xfilePar){
			xname = icalparameter_get_xname(xfilePar);
			if(!strcmp(xname,"X-FILENAME")){
				filename = (char *) icalparameter_get_x(xfilePar);
		
			}
		}
		
		/*Extension*/
		if(filename){
			char buff[256]; 
			char *temp;
			strncpy(buff,filename, 255);
			buff[255] = '\0';
			extension = strtok(buff, ".");
			while((temp = strtok(NULL, "."))) extension = temp;
		}
		
		printf("Create a new attachment object with\n");
		printf("	set PidTagAttachDataBinary to %d\n", data);
		printf("	set PidTagAttachExtension to %s\n", extension);
		printf("	set PidTagAttachFilename to %s\n", filename);
		printf("	set PidTagAttachLongFilename to %s\n", filename);
		printf("	set PidTagAttachMimeTag to %s\n", fmttype);
		printf("	set PidTagAttachFlags to 0x00000000\n");
		printf("	set PidTagAttachMethod to 0x00000001\n");
		printf("	set PidTagAttachmentContactPhoto to FALSE\n");
		printf("	set PidTagAttachmentFlags to 0x00000000\n");
		printf("	set PidTagAttachEncoding to empty SBinary");
		printf("	set PidTagAttachmentHidden to FALSE\n");
		printf("	set PidTagAttachmentLinkId to 0x00000000\n");
		printf("	set PidTagDisplayName to  %s\n", filename);
		printf("	set PidTagExceptionEndTime to 0x0CB34557A3DD4000\n");
		printf("	set PidTagExceptionStartTime to 0x0CB34557A3DD4000\n");
		printf("	set PidTagRenderingPosition to 0xFFFFFFFF\n");
		
		attachProp=icalcomponent_get_next_property(ical2exchange->attachEvent, ICAL_ATTACH_PROPERTY);
	}
}