NS_IMETHODIMP
calIcalProperty::GetValue(nsACString &str)
{
    icalvalue *value = icalproperty_get_value(mProperty);
    icalvalue_kind valuekind = icalvalue_isa(value);

    const char *icalstr;
    if (valuekind == ICAL_TEXT_VALUE) {
        icalstr = icalvalue_get_text(value);
    } else if (valuekind == ICAL_X_VALUE) {
        icalstr = icalvalue_get_x(value);
    } else if (valuekind == ICAL_ATTACH_VALUE) {
        icalattach *attach = icalvalue_get_attach(value);
        if (icalattach_get_is_url(attach)) {
            icalstr = icalattach_get_url(attach);
        } else {
            icalstr = (const char *)icalattach_get_data(attach);
        }
    } else {
        icalstr = icalproperty_get_value_as_string(mProperty);
    }

    if (!icalstr) {
        if (icalerrno == ICAL_BADARG_ERROR) {
            str.Truncate();
            // Set string to null, because we don't have a value
            // (which is something different then an empty value)
            str.SetIsVoid(true);
            return NS_OK;
        }

#ifdef DEBUG
        fprintf(stderr, "Error getting string value: %d (%s)\n",
                icalerrno, icalerror_strerror(icalerrno));
#endif
        return NS_ERROR_FAILURE;
    }

    str.Assign(icalstr);
    return NS_OK;
}
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);
	}
}