Fix bug 637064 - reference libical - Update to libical 0.46. r=pmartinak
authorPhilipp Kewisch <mozilla@kewis.ch>
Tue, 24 May 2011 17:13:45 +0200
changeset 7813 c68b4de81618d8208a2f3d2cbeee8fd44547b13b
parent 7812 212a62f8c1ffca0d530bec530ec1bcecbf2623aa
child 7814 8b7cdb6dd35786138888fe69645d88dd4cd81dc3
push id5
push userbugzilla@standard8.plus.com
push dateTue, 24 May 2011 21:37:58 +0000
treeherdercomm-aurora@f314c7f8580f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspmartinak
bugs637064
Fix bug 637064 - reference libical - Update to libical 0.46. r=pmartinak
calendar/libical/design-data/parameters.csv
calendar/libical/design-data/value-types.csv
calendar/libical/scripts/mkderivedparameters.pl
calendar/libical/scripts/mkderivedproperties.pl
calendar/libical/scripts/mkderivedvalues.pl
calendar/libical/scripts/readvaluesfile.pl
calendar/libical/src/libical/Makefile.in
calendar/libical/src/libical/caldate.c
calendar/libical/src/libical/icalarray.c
calendar/libical/src/libical/icalarray.h
calendar/libical/src/libical/icalattach.c
calendar/libical/src/libical/icalattach.h
calendar/libical/src/libical/icalattachimpl.h
calendar/libical/src/libical/icalcomponent.c
calendar/libical/src/libical/icalcomponent.h
calendar/libical/src/libical/icalderivedparameter.c.in
calendar/libical/src/libical/icalderivedproperty.c.in
calendar/libical/src/libical/icalderivedproperty.h.in
calendar/libical/src/libical/icalderivedvalue.c.in
calendar/libical/src/libical/icalderivedvalue.h.in
calendar/libical/src/libical/icalduration.c
calendar/libical/src/libical/icalenums.c
calendar/libical/src/libical/icalerror.c
calendar/libical/src/libical/icalerror.h
calendar/libical/src/libical/icallangbind.c
calendar/libical/src/libical/icalmime.c
calendar/libical/src/libical/icalparameter.c
calendar/libical/src/libical/icalparameter.h
calendar/libical/src/libical/icalparser.c
calendar/libical/src/libical/icalperiod.c
calendar/libical/src/libical/icalproperty.c
calendar/libical/src/libical/icalrecur.c
calendar/libical/src/libical/icalrestriction.c.in
calendar/libical/src/libical/icaltime.c
calendar/libical/src/libical/icaltimezone.c
calendar/libical/src/libical/icaltimezone.h
calendar/libical/src/libical/icaltypes.c
calendar/libical/src/libical/icaltypes.h
calendar/libical/src/libical/icalvalue.c
calendar/libical/src/libical/icalvalue.h
calendar/libical/src/libical/libicals_w32_vsnprintf_replacement.c
calendar/libical/src/libical/pvl.c
calendar/libical/src/libical/pvl.h
calendar/libical/src/libical/sspm.c
calendar/libical/src/libical/sspm.h
calendar/libical/src/libical/vsnprintf.h
--- a/calendar/libical/design-data/parameters.csv
+++ b/calendar/libical/design-data/parameters.csv
@@ -1,39 +1,39 @@
-"#Name ","C Type","Enumeration Values"
-"ALTREP","const char*",
-"CHARSET","const char*",
-"CN","const char*",
-"CUTYPE","icalparameter_cutype","INDIVIDUAL;GROUP;RESOURCE;ROOM;UNKNOWN"
-"DELEGATED-FROM","const char*",
-"DELEGATED-TO","const char*",
-"DIR","const char*",
-"ENCODING","icalparameter_encoding","8BIT;BASE64"
-"FBTYPE","icalparameter_fbtype","FREE;BUSY;BUSY-UNAVAILABLE;BUSY-TENTATIVE"
-"FMTTYPE","const char*",
-"LANGUAGE","const char*",
-"MEMBER","const char*",
-"PARTSTAT","icalparameter_partstat","NEEDS-ACTION;ACCEPTED;DECLINED;TENTATIVE;DELEGATED;COMPLETED;INPROCESS"
-"RANGE","icalparameter_range","THISANDPRIOR;THISANDFUTURE"
-"RELATED","icalparameter_related","START;END"
-"RELTYPE","icalparameter_reltype","PARENT;CHILD;SIBLING"
-"ROLE","icalparameter_role","CHAIR;REQ-PARTICIPANT;OPT-PARTICIPANT;NON-PARTICIPANT"
-"RSVP","icalparameter_rsvp","TRUE;FALSE"
-"SENT-BY","const char*",
-"RECEIVED-SEQUENCE","const char*",
-"RECEIVED-DTSTAMP","const char*",
-"TZID","const char*",
-"VALUE","icalparameter_value","BINARY;BOOLEAN;DATE;DURATION;FLOAT;INTEGER;PERIOD;RECUR;TEXT;URI;ERROR;DATE-TIME;UTC-OFFSET;CAL-ADDRESS"
-"X","const char*",
-"X-LIC-ERRORTYPE","icalparameter_xlicerrortype","COMPONENT-PARSE-ERROR;PROPERTY-PARSE-ERROR;PARAMETER-NAME-PARSE-ERROR;PARAMETER-VALUE-PARSE-ERROR;VALUE-PARSE-ERROR;INVALID-ITIP;UNKNOWN-VCAL-PROP-ERROR;MIME-PARSE-ERROR;VCAL-PROP-PARSE-ERROR"
-"X-LIC-COMPARETYPE","icalparameter_xliccomparetype","EQUAL;NOTEQUAL;LESS;GREATER;LESSEQUAL;GREATEREQUAL;REGEX;ISNULL;ISNOTNULL"
+"#Name ","C icalparameter_kind Enum","C Type","Enumeration Values"
+"ALTREP","2","const char*",
+"CHARSET","3","const char*",
+"CN","4","const char*",
+"CUTYPE","5","icalparameter_cutype","INDIVIDUAL;GROUP;RESOURCE;ROOM;UNKNOWN"
+"DELEGATED-FROM","6","const char*",
+"DELEGATED-TO","7","const char*",
+"DIR","8","const char*",
+"ENCODING","10","icalparameter_encoding","8BIT;BASE64"
+"FBTYPE","11","icalparameter_fbtype","FREE;BUSY;BUSY-UNAVAILABLE;BUSY-TENTATIVE"
+"FMTTYPE","12","const char*",
+"LANGUAGE","14","const char*",
+"MEMBER","18","const char*",
+"PARTSTAT","20","icalparameter_partstat","NEEDS-ACTION;ACCEPTED;DECLINED;TENTATIVE;DELEGATED;COMPLETED;INPROCESS"
+"RANGE","21","icalparameter_range","THISANDPRIOR;THISANDFUTURE"
+"RELATED","22","icalparameter_related","START;END"
+"RELTYPE","23","icalparameter_reltype","PARENT;CHILD;SIBLING"
+"ROLE","24","icalparameter_role","CHAIR;REQ-PARTICIPANT;OPT-PARTICIPANT;NON-PARTICIPANT"
+"RSVP","25","icalparameter_rsvp","TRUE;FALSE"
+"SENT-BY","26","const char*",
+"TZID","27","const char*",
+"VALUE","28","icalparameter_value","BINARY;BOOLEAN;DATE;DURATION;FLOAT;INTEGER;PERIOD;RECUR;TEXT;URI;ERROR;DATE-TIME;UTC-OFFSET;CAL-ADDRESS"
+"X","29","const char*",
+"X-LIC-ERRORTYPE","31","icalparameter_xlicerrortype","COMPONENT-PARSE-ERROR;PROPERTY-PARSE-ERROR;PARAMETER-NAME-PARSE-ERROR;PARAMETER-VALUE-PARSE-ERROR;VALUE-PARSE-ERROR;INVALID-ITIP;UNKNOWN-VCAL-PROP-ERROR;MIME-PARSE-ERROR;VCAL-PROP-PARSE-ERROR"
+"X-LIC-COMPARETYPE","30","icalparameter_xliccomparetype","EQUAL;NOTEQUAL;LESS;GREATER;LESSEQUAL;GREATEREQUAL;REGEX;ISNULL;ISNOTNULL"
 "#CAP Parameters","Draft 8",
 "#this parameter should really be called ACTION, but this conflicts with the ACTION property"
-"ACTIONPARAM","icalparameter_action","ASK;ABORT"
-"ID","const char*",
-"ENABLE","icalparameter_enable","TRUE;FALSE"
-"LATENCY","const char*",
-"LOCAL","icalparameter_local","TRUE;FALSE"
-"LOCALIZE","const char*",
-"OPTIONS","const char*",
-"SCHEDULE-AGENT","const char*",
-"SCHEDULE-STATUS","const char*",
-"SCHEDULE-FORCE-SEND","const char*",
+"ACTIONPARAM","1","icalparameter_action","ASK;ABORT"
+"ID","13","const char*",
+"ENABLE","9","icalparameter_enable","TRUE;FALSE"
+"LATENCY","15","const char*",
+"LOCAL","16","icalparameter_local","TRUE;FALSE"
+"LOCALIZE","17","const char*",
+"OPTIONS","19","const char*",
+"NO","32",,
+"#In practice any unknown paramater that is not an xparam is treated as an ianaparam"
+"IANA","33","const char*",
+"ANY","0",,
+"#NOTE for updaters.  Preserve the icalparameter_kind Enum values to aid forward compatibility"
--- a/calendar/libical/design-data/value-types.csv
+++ b/calendar/libical/design-data/value-types.csv
@@ -1,14 +1,14 @@
 "#Name","C type& gen flag","Python","Component Values","Enum Values"
 "BINARY","(a)const char*","file","unitary",
 "BOOLEAN","(a)int","integer","unitary",
 "CAL-ADDRESS","(a)const char*","string","unitary",
 "DATE","(a)struct icaltimetype","Time","unitary",
-"DATE-TIME","(a)struct icaltimetype","Time","unitary",
+"DATE-TIME","(m)struct icaltimetype","Time","unitary",
 "DURATION","(a)struct icaldurationtype","Duration","unitary",
 "FLOAT","(a)float","float","unitary",
 "INTEGER","(a)int","integer","unitary",
 "PERIOD","(a)struct icalperiodtype","Period","unitary",
 "RECUR","(m)struct icalrecurrencetype","RecurrenceSet","unitary",
 "TEXT","(a)const char*","string","unitary",
 "URI","(a)const char*","string","unitary",
 "UTC-OFFSET","(a)int","integer","unitary",
@@ -18,18 +18,18 @@
 "DATE-TIME-PERIOD","(m)struct icaldatetimeperiodtype","none","DATE-TIME;PERIOD",
 "TRIGGER","(m)struct icaltriggertype","string","DURATION;DATE-TIME",
 "#Non-standard property enumeration types",,,,
 "METHOD","(a)enum icalproperty_method","string","unitary","PUBLISH;REQUEST;REPLY;ADD;CANCEL;REFRESH;COUNTER;DECLINECOUNTER;CREATE;READ;RESPONSE;MOVE;MODIFY;GENERATEUID;DELETE"
 "X-LIC-CLASS","(a)enum icalproperty_xlicclass","string","unitary","PUBLISH-NEW;PUBLISH-UPDATE;PUBLISH-FREEBUSY;REQUEST-NEW;REQUEST-UPDATE;REQUEST-RESCHEDULE;REQUEST-DELEGATE;REQUEST-NEW-ORGANIZER;REQUEST-FORWARD;REQUEST-STATUS;REQUEST-FREEBUSY;REPLY-ACCEPT;REPLY-DECLINE;REPLY-DELEGATE;REPLY-CRASHER-ACCEPT;REPLY-CRASHER-DECLINE;ADD-INSTANCE;CANCEL-EVENT;CANCEL-INSTANCE;CANCEL-ALL;REFRESH;COUNTER;DECLINECOUNTER;MALFORMED;OBSOLETE;MISSEQUENCED;UNKNOWN"
 "ACTION","(a)enum icalproperty_action","string","unitary","AUDIO;DISPLAY;EMAIL;PROCEDURE"
 "STATUS","(a)enum icalproperty_status","string","unitary","TENTATIVE;CONFIRMED;COMPLETED;NEEDS-ACTION;CANCELLED;IN-PROCESS;DRAFT;FINAL"
 "TRANSP","(a)enum icalproperty_transp","string","unitary","OPAQUE;OPAQUE-NOCONFLICT;TRANSPARENT;TRANSPARENT-NOCONFLICT"
-"CLASS","(a)enum icalproperty_class","string","unitary","PUBLIC;PRIVATE;CONFIDENTIAL"
+"CLASS","(m)enum icalproperty_class","string","unitary","PUBLIC;PRIVATE;CONFIDENTIAL"
 "#Other non-standard",,,,
 "REQUEST-STATUS","(a)struct icalreqstattype","string","unitary"
-"GEO","(a)struct icalgeotype","tuple","unitary",
+"GEO","(m)struct icalgeotype","tuple","unitary",
 "STRING","(a)const char*","string","unitary",
 "X","(m)const char*","string","unitary",
 "#CAP enumeration types",,,,
 "CMD","(a)enum icalproperty_cmd","string","unitary","ABORT;CONTINUE;CREATE;DELETE;GENERATE-UID;GET-CAPABILITY;IDENTIFY;MODIFY;MOVE;REPLY;SEARCH;SET-LOCALE"
 "QUERY-LEVEL","(a)enum icalproperty_querylevel","string","unitary","CAL-QL-1;CAL-QL-NONE"
 "CAR-LEVEL","(a)enum icalproperty_carlevel","string","unitary","CAR-NONE;CAR-MIN;CAR-FULL-1"
--- a/calendar/libical/scripts/mkderivedparameters.pl
+++ b/calendar/libical/scripts/mkderivedparameters.pl
@@ -14,63 +14,72 @@ getopts('chspi:');
 # line, and putting the generated data after the demarcation
 
 if ($opt_i) {
 
   open(IN,$opt_i) || die "Can't open input file $opt_i";
 
   while(<IN>){
     if (/<insert_code_here>/){
+      $autogenMsg = "of section of machine generated code (mkderivedparameters.pl). Do not edit.";
+      if($opt_p){
+          $startComment = "#";
+          $endComment = "";
+      } else {
+          $startComment = "/*";
+          $endComment = " */";
+      }
+      print $startComment." START ".$autogenMsg.$endComment."\n\n";
+
       insert_code();
+
+      print $startComment." END   ".$autogenMsg.$endComment."\n\n";
     } else {
       print;
    }
 
   }    
 
-  if($opt_p){
-     print "# Everything below this line is machine generated. Do not edit. \n";
-  } else {
-    print "/* Everything below this line is machine generated. Do not edit. */\n";
-  }
-
 }
 
 sub insert_code
 {
 
 # Write parameter enumerations and datatypes
 
 if($opt_h){
-  print "typedef enum icalparameter_kind {\n    ICAL_ANY_PARAMETER = 0,\n";
+  my $enumConst = $params{'ANY'}->{"kindEnum"};
+  print "typedef enum icalparameter_kind {\n    ICAL_ANY_PARAMETER = ".$enumConst.",\n";
+  $enumVal = 1;
   foreach $param (sort keys %params) {
     
     next if !$param;
     
     next if $param eq 'NO' or $param eq 'ANY';
 
     my $uc = join("",map {uc($_);}  split(/-/,$param));
 
-    my @enums = @{$params{$param}->{'enums'}};
+    $enumConst = $params{$param}->{"kindEnum"};
         
-    print "    ICAL_${uc}_PARAMETER, \n";
+    print "    ICAL_${uc}_PARAMETER = ".$enumConst.", \n";
     
   }  
-  print "    ICAL_NO_PARAMETER\n} icalparameter_kind;\n\n";
+  $enumConst = $params{'NO'}->{"kindEnum"};
+  print "    ICAL_NO_PARAMETER = ".$enumConst."\n} icalparameter_kind;\n\n";
 
   # Now create enumerations for parameter values
   $idx = 20000;
   
   print "#define ICALPARAMETER_FIRST_ENUM $idx\n\n";
   
   foreach $param (sort keys %params) {
     
     next if !$param;
     
-    next if $param eq 'NO' or $prop eq 'ANY';
+    next if $param eq 'NO' or $param eq 'ANY';
 
     my $type = $params{$param}->{"C"};
     my $ucv = join("",map {uc(lc($_));}  split(/-/,$param));    
     my @enums = @{$params{$param}->{'enums'}};
 
     if(@enums){
 
       print "typedef enum $type {\n";
@@ -126,17 +135,17 @@ if ($opt_c){
   #Create the parameter Name map
 
   $out="";
   $count=0;
   foreach $param (sort keys %params) {
     
     next if !$param;
     
-    next if $param eq 'NO' or $prop eq 'ANY';
+    next if $param eq 'NO' or $param eq 'ANY';
 
     my $lc = join("",map {lc($_);}  split(/-/,$param));    
     my $uc = join("",map {uc(lc($_));}  split(/-/,$param));    
 
     $count++;
     $out.="    {ICAL_${uc}_PARAMETER,\"$param\"},\n";
 
   }
@@ -147,17 +156,17 @@ if ($opt_c){
   
   # Create the parameter value map
   $out ="";
   $count=0;
   foreach $param (sort keys %params) {
     
     next if !$param;
     
-    next if $param eq 'NO' or $prop eq 'ANY';
+    next if $param eq 'NO' or $param eq 'ANY';
 
     my $type = $params{$param}->{"C"};
     my $uc = join("",map {uc(lc($_));}  split(/-/,$param));    
     my @enums = @{$params{$param}->{'enums'}};
 
     if(@enums){
 
       foreach $e (@enums){
@@ -173,17 +182,19 @@ if ($opt_c){
   $count+=3;
   print "static const struct icalparameter_map icalparameter_map[] = {\n";
   print "{ICAL_ANY_PARAMETER,0,\"\"},\n";
   print $out;
   print "    {ICAL_NO_PARAMETER,0,\"\"}};\n\n";
 
 }
 
-foreach $param  (keys %params){
+foreach $param  (sort keys %params){
+
+  next if $param eq 'NO' or $param eq 'ANY';
 
   my $type = $params{$param}->{'C'};
 
   my $ucf = join("",map {ucfirst(lc($_));}  split(/-/,$param));
   
   my $lc = lc($ucf);
   my $uc = uc($lc);
  
--- a/calendar/libical/scripts/mkderivedproperties.pl
+++ b/calendar/libical/scripts/mkderivedproperties.pl
@@ -174,30 +174,34 @@ foreach $prop (sort keys %propmap) {
   my $set_pointer_check = "icalerror_check_arg_rv( (v!=0),\"v\");\n" if $type =~ /\*/;
 
   if($opt_c) { # Generate C source
 
    if ($include_vanew) {
      print<<EOM;
 icalproperty* icalproperty_vanew_${lc}($type v, ...){
    va_list args;
-   struct icalproperty_impl *impl = icalproperty_new_impl(ICAL_${uc}_PROPERTY);   $pointer_check
+   struct icalproperty_impl *impl;
+   $pointer_check
+   impl= icalproperty_new_impl(ICAL_${uc}_PROPERTY);
    icalproperty_set_${lc}((icalproperty*)impl,v);
    va_start(args,v);
    icalproperty_add_parameters(impl, args);
    va_end(args);
    return (icalproperty*)impl;
 }
 EOM
 }
 	print<<EOM;
 
 /* $prop */
 icalproperty* icalproperty_new_${lc}($type v) {
-   struct icalproperty_impl *impl = icalproperty_new_impl(ICAL_${uc}_PROPERTY);   $pointer_check
+   struct icalproperty_impl *impl;
+   $pointer_check
+   impl = icalproperty_new_impl(ICAL_${uc}_PROPERTY);
    icalproperty_set_${lc}((icalproperty*)impl,v);
    return (icalproperty*)impl;
 }
 
 EOM
     # Allow DTSTART, DTEND, DUE, EXDATE and RECURRENCE-ID to take DATE values.
     if ($lc eq "dtstart" || $lc eq "dtend" || $lc eq "due" || $lc eq "exdate"
 	|| $lc eq "recurrenceid") {
--- a/calendar/libical/scripts/mkderivedvalues.pl
+++ b/calendar/libical/scripts/mkderivedvalues.pl
@@ -179,18 +179,19 @@ foreach $value  (keys %h) {
   } else {
     $union_data = $lc;
   }
   
   if ($opt_c && $autogen) {
     
     print "\n\n\
 icalvalue* icalvalue_new_${lc} ($type v){\
-   struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_${uc}_VALUE);\
+   struct icalvalue_impl* impl;\
    $pointer_check\
+   impl = icalvalue_new_impl(ICAL_${uc}_VALUE);\
    icalvalue_set_${lc}((icalvalue*)impl,v);\
    return (icalvalue*)impl;\
 }\
 void icalvalue_set_${lc}(icalvalue* value, $type v) {\
     struct icalvalue_impl* impl; \
     icalerror_check_arg_rv( (value!=0),\"value\");\
     $pointer_check_rv\
     icalerror_check_value_type(value, ICAL_${uc}_VALUE);\
--- a/calendar/libical/scripts/readvaluesfile.pl
+++ b/calendar/libical/scripts/readvaluesfile.pl
@@ -105,25 +105,27 @@ sub read_parameters_file {
     s/\r//g;
    
     next if ! $_;
 
     @column = split(/\,/,$_);
   
     my $parameter_name = $column[0];
 
-    my $data_type = $column[1];
-    my $enum_string = $column[2];
+    my $enumConst = $column[1];
+    my $data_type = $column[2];
+    my $enum_string = $column[3];
 
     my @enums;
     if($enum_string){
       @enums =  split(/;/,$enum_string);
     }
     
     $h{$parameter_name} = { C => $data_type,
+			   kindEnum => $enumConst,
 			   enums => [@enums]
 			 };
   }
 
   close(F);
 
   return %h;
 }
--- a/calendar/libical/src/libical/Makefile.in
+++ b/calendar/libical/src/libical/Makefile.in
@@ -103,41 +103,42 @@ include $(topsrcdir)/config/rules.mk
 
 DESIGNDATA = $(srcdir)/../../design-data
 ICALSCRIPTS = $(srcdir)/../../scripts
 
 # ORDERING OF HEADERS IS SIGNIFICANT. Don't change this ordering. It
 # is required to make the combined header ical.h properly
 COMBINEDHEADERS =                        \
         $(srcdir)/../../config.h         \
-	$(srcdir)/icalversion.h          \
-	$(srcdir)/icaltime.h             \
-	$(srcdir)/icalduration.h         \
-	$(srcdir)/icalperiod.h           \
-	$(srcdir)/icalenums.h            \
-	$(srcdir)/icaltypes.h            \
-	$(srcdir)/icalrecur.h            \
-	$(srcdir)/icalattach.h           \
-	icalderivedvalue.h               \
-	icalderivedparameter.h           \
-	$(srcdir)/icalvalue.h            \
-	$(srcdir)/icalparameter.h        \
-	icalderivedproperty.h            \
-	$(srcdir)/icalproperty.h         \
-	$(srcdir)/pvl.h                  \
-	$(srcdir)/icalarray.h            \
-	$(srcdir)/icalcomponent.h        \
-	$(srcdir)/icaltimezone.h         \
-	$(srcdir)/icalparser.h           \
-	$(srcdir)/icalmemory.h           \
-	$(srcdir)/icalerror.h            \
-	$(srcdir)/icalrestriction.h      \
-	$(srcdir)/sspm.h                 \
-	$(srcdir)/icalmime.h             \
-	$(srcdir)/icallangbind.h        
+   $(srcdir)/icalversion.h               \
+   $(srcdir)/icaltime.h                  \
+   $(srcdir)/icalduration.h              \
+   $(srcdir)/icalperiod.h                \
+   $(srcdir)/icalenums.h                 \
+   $(srcdir)/icaltypes.h                 \
+   $(srcdir)/icalrecur.h                 \
+   $(srcdir)/icalattach.h                \
+   icalderivedvalue.h                    \
+   icalderivedparameter.h                \
+   $(srcdir)/icalvalue.h                 \
+   $(srcdir)/icalparameter.h             \
+   icalderivedproperty.h                 \
+   $(srcdir)/icalproperty.h              \
+   $(srcdir)/pvl.h                       \
+   $(srcdir)/icalarray.h                 \
+   $(srcdir)/icalcomponent.h             \
+   $(srcdir)/icaltimezone.h              \
+   $(srcdir)/icalparser.h                \
+   $(srcdir)/icalmemory.h                \
+   $(srcdir)/icalerror.h                 \
+   $(srcdir)/icalrestriction.h           \
+   $(srcdir)/sspm.h                      \
+   $(srcdir)/icalmime.h                  \
+   $(srcdir)/icallangbind.h              \
+   $(NULL)
 
 BUILT_COMBINEDHEADERS = 	\
 	icalderivedparameter.h	\
 	icalderivedproperty.h	\
 	icalderivedvalue.h
 
 BUILT_SOURCES =			\
 	$(BUILT_COMBINEDHEADERS)\
--- a/calendar/libical/src/libical/caldate.c
+++ b/calendar/libical/src/libical/caldate.c
@@ -67,40 +67,40 @@ struct ut_instant * date;
 	long ke;
 	long ialp;
 
 	jd = (long) (date->j_date + 0.5);	/* integer julian date */
 	frac = date->j_date + 0.5 - (double) jd + 1.0e-10; /* day fraction */
 	ka = (long) jd;
 	if ( jd >= 2299161L )
 	{
-		ialp = ( (double) jd - 1867216.25 ) / ( 36524.25 );
+		ialp = (long) (((double) jd) - 1867216.25 ) / 36524.25;
 		ka = jd + 1L + ialp - ( ialp >> 2 );
 	}
 	kb = ka + 1524L;
-	kc =  ( (double) kb - 122.1 ) / 365.25;
-	kd = (double) kc * 365.25;
-	ke = (double) ( kb - kd ) / 30.6001;
+	kc = (long) ((double) kb - 122.1 ) / 365.25;
+	kd = (long) (double) kc * 365.25;
+	ke = (long) (double) ( kb - kd ) / 30.6001;
 	date->day = kb - kd - ((long) ( (double) ke * 30.6001 ));
 	if ( ke > 13L )
 		date->month = ke - 13L;
 	else
 		date->month = ke - 1L;
 	if ( (date->month == 2) && (date->day > 28) )
 		date->day = 29;
 	if ( (date->month == 2) && (date->day == 29) && (ke == 3L) )
 		date->year = kc - 4716L;
 	else if ( date->month > 2 )
 		date->year = kc - 4716L;
 	else
 		date->year = kc - 4715L;
 	date->i_hour = date->d_hour = frac * 24.0;	/* hour */
-	date->i_minute = date->d_minute =
+	date->i_minute = date->d_minute = (long)
 		( date->d_hour - (double) date->i_hour ) * 60.0; /* minute */
-	date->i_second = date->d_second =
+	date->i_second = date->d_second = (long)
 		( date->d_minute - (double) date->i_minute ) * 60.0;/* second */
 	date->weekday = (jd + 1L) % 7L;	/* day of week */
 	if ( date->year == ((date->year >> 2) << 2) )
 		date->day_of_year =
 			( ( 275 * date->month ) / 9)
 			- ((date->month + 9) / 12)
 			+ date->day - 30;
 	else
--- a/calendar/libical/src/libical/icalarray.c
+++ b/calendar/libical/src/libical/icalarray.c
@@ -61,25 +61,52 @@ icalarray_new			(int		 element_size,
     array->increment_size = increment_size;
     array->num_elements = 0;
     array->space_allocated = 0;
     array->data = NULL;
 
     return array;
 }
 
+
+icalarray *icalarray_copy	(icalarray	*originalarray)
+{
+    icalarray *array = icalarray_new(originalarray->element_size, originalarray->increment_size);
+
+    if (!array)
+        return NULL;
+
+    array->num_elements = originalarray->num_elements;
+    array->space_allocated = originalarray->space_allocated;
+    
+    array->data = malloc(array->space_allocated * array->element_size);
+
+    if (array->data) {
+	memcpy(array->data, originalarray->data,
+               array->element_size*array->space_allocated);
+    } else {
+	icalerror_set_errno(ICAL_ALLOCATION_ERROR);
+    }
+
+    return array;
+}
+
+
 /** @brief Destructor
  */
 
 void
 icalarray_free			(icalarray	*array)
 {
-    if (array->data)
+    if (array->data) {
 	free (array->data);
+	array->data = 0;
+    }
     free (array);
+    array = 0;
 }
 
 
 void
 icalarray_append		(icalarray	*array,
 				 const void		*element)
 {
     if (array->num_elements >= array->space_allocated)
@@ -147,17 +174,20 @@ icalarray_expand		(icalarray	*array,
 	/*
     new_data = realloc (array->data,
 			new_space_allocated * array->element_size);
 	*/
 	new_data = malloc(new_space_allocated * array->element_size);
 
     if (new_data) {
 	memcpy(new_data,array->data,array->element_size*array->space_allocated);
-	free(array->data);
+	if (array->data) {
+	    free(array->data);
+	    array->data = 0;
+	}
 	array->data = new_data;
 	array->space_allocated = new_space_allocated;
     } else {
 	icalerror_set_errno(ICAL_ALLOCATION_ERROR);
     }
 }
 
 
--- a/calendar/libical/src/libical/icalarray.h
+++ b/calendar/libical/src/libical/icalarray.h
@@ -41,16 +41,17 @@ struct _icalarray {
     unsigned int	 space_allocated;
     void		*data;
 };
 
 
 
 icalarray *icalarray_new		(int		 element_size,
 					 int		 increment_size);
+icalarray *icalarray_copy		(icalarray	*array);
 void	   icalarray_free		(icalarray	*array);
 
 void	   icalarray_append		(icalarray	*array,
 					 const void		*element);
 void	   icalarray_remove_element_at	(icalarray	*array,
 					 int		 position);
 
 void	  *icalarray_element_at		(icalarray	*array,
--- a/calendar/libical/src/libical/icalattach.c
+++ b/calendar/libical/src/libical/icalattach.c
@@ -58,31 +58,38 @@ icalattach_new_from_url (const char *url
     attach->refcount = 1;
     attach->is_url = 1;
     attach->u.url.url = url_copy;
 
     return attach;
 }
 
 icalattach *
-icalattach_new_from_data (unsigned char *data, icalattach_free_fn_t free_fn,
+icalattach_new_from_data (const char *data, icalattach_free_fn_t free_fn,
 			  void *free_fn_data)
 {
     icalattach *attach;
+    char *data_copy;
 
     icalerror_check_arg_rz ((data != NULL), "data");
 
     if ((attach = malloc (sizeof (icalattach))) == NULL) {
 	errno = ENOMEM;
 	return NULL;
     }
 
+    if ((data_copy = strdup (data)) == NULL) {
+	free (attach);
+	errno = ENOMEM;
+	return NULL;
+    }
+
     attach->refcount = 1;
     attach->is_url = 0;
-    attach->u.data.data = data;
+    attach->u.data.data = data_copy;
     attach->u.data.free_fn = free_fn;
     attach->u.data.free_fn_data = free_fn_data;
 
     return attach;
 }
 
 void
 icalattach_ref (icalattach *attach)
@@ -99,20 +106,25 @@ icalattach_unref (icalattach *attach)
     icalerror_check_arg_rv ((attach != NULL), "attach");
     icalerror_check_arg_rv ((attach->refcount > 0), "attach->refcount > 0");
 
     attach->refcount--;
 
     if (attach->refcount != 0)
 	return;
 
-    if (attach->is_url)
+    if (attach->is_url) {
 	free (attach->u.url.url);
-    else if (attach->u.data.free_fn)
-	(* attach->u.data.free_fn) (attach->u.data.data, attach->u.data.free_fn_data);
+    } else {
+	free (attach->u.data.data);
+/* unused for now
+	if (attach->u.data.free_fn)
+	   (* attach->u.data.free_fn) (attach->u.data.data, attach->u.data.free_fn_data);
+*/
+    }
 
     free (attach);
 }
 
 int
 icalattach_get_is_url (icalattach *attach)
 {
     icalerror_check_arg_rz ((attach != NULL), "attach");
--- a/calendar/libical/src/libical/icalattach.h
+++ b/calendar/libical/src/libical/icalattach.h
@@ -25,17 +25,17 @@
 #define ICALATTACH_H
 
 
 typedef struct icalattach_impl icalattach;
 
 typedef void (* icalattach_free_fn_t) (unsigned char *data, void *user_data);
 
 icalattach *icalattach_new_from_url (const char *url);
-icalattach *icalattach_new_from_data (unsigned char *data,
+icalattach *icalattach_new_from_data (const char *data,
 	icalattach_free_fn_t free_fn, void *free_fn_data);
 
 void icalattach_ref (icalattach *attach);
 void icalattach_unref (icalattach *attach);
 
 int icalattach_get_is_url (icalattach *attach);
 const char *icalattach_get_url (icalattach *attach);
 unsigned char *icalattach_get_data (icalattach *attach);
--- a/calendar/libical/src/libical/icalattachimpl.h
+++ b/calendar/libical/src/libical/icalattachimpl.h
@@ -41,17 +41,17 @@ struct icalattach_impl {
 	union {
 		/* URL attachment data */
 		struct {
 			char *url;
 		} url;
 
 		/* Inline data */
 		struct {
-			unsigned char *data;
+			char *data;
 			icalattach_free_fn_t free_fn;
 			void *free_fn_data;
 		} data;
 	} u;
 
 	/* TRUE if URL, FALSE if inline data */
 	unsigned int is_url : 1;
 };
--- a/calendar/libical/src/libical/icalcomponent.c
+++ b/calendar/libical/src/libical/icalcomponent.c
@@ -41,19 +41,22 @@
 
 #include <stdlib.h>  /* for malloc */
 #include <stdarg.h> /* for va_list, etc */
 #include <errno.h>
 #include <assert.h>
 #include <stdio.h> /* for fprintf */
 #include <string.h> /* for strdup */
 #include <limits.h> /* for INT_MAX */
+
 #ifdef WIN32
-#define snprintf _snprintf
-#define strncasecmp strnicmp
+#define strncasecmp      strnicmp
+#ifndef HAVE_SNPRINTF
+#include "vsnprintf.h"
+#endif
 #endif
 
 struct icalcomponent_impl 
 {
 	char id[5];
 	icalcomponent_kind kind;
 	char* x_name;
 	pvl_list properties;
@@ -89,16 +92,18 @@ static unsigned int icalcomponent_get_tz
 static void icalcomponent_rename_tzids(icalcomponent* comp,
 				       icalarray* rename_table);
 static void icalcomponent_rename_tzids_callback(icalparameter *param,
 						void *data);
 static int icalcomponent_compare_vtimezones (icalcomponent	*vtimezone1,
 					     icalcomponent	*vtimezone2);
 static int icalcomponent_compare_timezone_fn	(const void	*elem1,
 						 const void	*elem2);
+static struct icaltimetype
+icalcomponent_get_datetime(icalcomponent *comp, icalproperty *prop);
 
 
 void icalcomponent_add_children(icalcomponent *impl, va_list args)
 {
     void* vp;
     
     while((vp = va_arg(args, void*)) != 0) {
 
@@ -311,30 +316,30 @@ icalcomponent_as_ical_string_r (icalcomp
    const char newline[] = "\r\n";
    
    icalcomponent *c;
    icalproperty *p;
    icalcomponent_kind kind = icalcomponent_isa(impl);
 
    const char* kind_string;
 
-   buf = icalmemory_new_buffer(buf_size);
-   buf_ptr = buf; 
-
    icalerror_check_arg_rz( (impl!=0), "component");
    icalerror_check_arg_rz( (kind!=ICAL_NO_COMPONENT), "component kind is ICAL_NO_COMPONENT");
    
    if (kind != ICAL_X_COMPONENT) {
        kind_string  = icalcomponent_kind_to_string(kind);
    } else {
        kind_string = impl->x_name;
    }
 
    icalerror_check_arg_rz( (kind_string!=0),"Unknown kind of component");
 
+   buf = icalmemory_new_buffer(buf_size);
+   buf_ptr = buf; 
+
    icalmemory_append_string(&buf, &buf_ptr, &buf_size, "BEGIN:");
    icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string);
    icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline);
    
 
 
    for( itr = pvl_head(impl->properties);
 	 itr != 0;
@@ -389,17 +394,16 @@ icalcomponent_kind
 icalcomponent_isa (const icalcomponent* component)
 {
    icalerror_check_arg_rx( (component!=0), "component", ICAL_NO_COMPONENT);
 
    if(component != 0)
    {
        return component->kind;
    }
-
    return ICAL_NO_COMPONENT;
 }
 
 
 int
 icalcomponent_isa_component (void* component)
 {
     icalcomponent *impl = component;
@@ -846,31 +850,33 @@ icaltime_span icalcomponent_get_span(ica
  * In this case though you don't need to worry how you call this
  * function.  It will always return the correct result.
  */
 
 int icalproperty_recurrence_is_excluded(icalcomponent *comp,
 				       struct icaltimetype *dtstart,
 				       struct icaltimetype *recurtime) {
   icalproperty *exdate, *exrule;
-  pvl_elem property_iterator = comp->property_iterator;
+  pvl_elem property_iterator;
 
   if (comp == NULL || 
       dtstart == NULL || 
       recurtime == NULL ||
       icaltime_is_null_time(*recurtime))
     /* BAD DATA */
-    return 1;	
+    return 1;
+    
+  property_iterator = comp->property_iterator;
 
   /** first test against the exdate values **/
   for (exdate = icalcomponent_get_first_property(comp,ICAL_EXDATE_PROPERTY);
        exdate != NULL;
        exdate = icalcomponent_get_next_property(comp,ICAL_EXDATE_PROPERTY)) {
 	 
-    struct icaltimetype exdatetime = icalproperty_get_exdate(exdate);
+    struct icaltimetype exdatetime = icalcomponent_get_datetime(comp, exdate);
 
     if (icaltime_compare(*recurtime, exdatetime) == 0) {
       /** MATCHED **/
         
       comp->property_iterator = property_iterator;
       return 1;
     }
   }
@@ -879,17 +885,17 @@ int icalproperty_recurrence_is_excluded(
   for (exrule = icalcomponent_get_first_property(comp,ICAL_EXRULE_PROPERTY);
        exrule != NULL;
        exrule = icalcomponent_get_next_property(comp,ICAL_EXRULE_PROPERTY)) {
 	 
     struct icalrecurrencetype recur = icalproperty_get_exrule(exrule);
     icalrecur_iterator *exrule_itr  = icalrecur_iterator_new(recur, *dtstart);
     struct icaltimetype exrule_time;
 
-    while (1) {
+    while (exrule_itr) {
       int result;
       exrule_time = icalrecur_iterator_next(exrule_itr);
 
       if (icaltime_is_null_time(exrule_time))
 	break;
 
       result = icaltime_compare(*recurtime, exrule_time);
       if (result == 0) {
@@ -1041,21 +1047,23 @@ void icalcomponent_foreach_recurrence(ic
   
   /* Now cycle through the rrule entries */
   for (rrule = icalcomponent_get_first_property(comp,ICAL_RRULE_PROPERTY);
        rrule != NULL;
        rrule = icalcomponent_get_next_property(comp,ICAL_RRULE_PROPERTY)) {
 
     struct icalrecurrencetype recur = icalproperty_get_rrule(rrule);
     icalrecur_iterator *rrule_itr  = icalrecur_iterator_new(recur, dtstart);
-    struct icaltimetype rrule_time = icalrecur_iterator_next(rrule_itr);
+    struct icaltimetype rrule_time;
+    if(rrule_itr)  
+        rrule_time = icalrecur_iterator_next(rrule_itr);
     /** note that icalrecur_iterator_next always returns dtstart
 	the first time.. **/
 
-    while (1) {
+    while (rrule_itr) {
       rrule_time = icalrecur_iterator_next(rrule_itr);
 
       if (icaltime_is_null_time(rrule_time)) 
 	break;
 
       dur = icaltime_subtract(rrule_time, dtstart);
 
       recurspan.start = basespan.start + icaldurationtype_as_int(dur);
@@ -2026,61 +2034,61 @@ enum icalproperty_status icalcomponent_g
 
     if (prop == 0){
         return 0;
     }
 
     return icalproperty_get_status(prop);
 }
 
-icalcomponent* icalcomponent_new_vcalendar()
+icalcomponent* icalcomponent_new_vcalendar(void)
 {
     return icalcomponent_new(ICAL_VCALENDAR_COMPONENT);
 }
-icalcomponent* icalcomponent_new_vevent()
+icalcomponent* icalcomponent_new_vevent(void)
 {
     return icalcomponent_new(ICAL_VEVENT_COMPONENT);
 }
-icalcomponent* icalcomponent_new_vtodo()
+icalcomponent* icalcomponent_new_vtodo(void)
 {
     return icalcomponent_new(ICAL_VTODO_COMPONENT);
 }
-icalcomponent* icalcomponent_new_vjournal()
+icalcomponent* icalcomponent_new_vjournal(void)
 {
     return icalcomponent_new(ICAL_VJOURNAL_COMPONENT);
 }
-icalcomponent* icalcomponent_new_valarm()
+icalcomponent* icalcomponent_new_valarm(void)
 {
     return icalcomponent_new(ICAL_VALARM_COMPONENT);
 }
-icalcomponent* icalcomponent_new_vfreebusy()
+icalcomponent* icalcomponent_new_vfreebusy(void)
 {
     return icalcomponent_new(ICAL_VFREEBUSY_COMPONENT);
 }
-icalcomponent* icalcomponent_new_vtimezone()
+icalcomponent* icalcomponent_new_vtimezone(void)
 {
     return icalcomponent_new(ICAL_VTIMEZONE_COMPONENT);
 }
-icalcomponent* icalcomponent_new_xstandard()
+icalcomponent* icalcomponent_new_xstandard(void)
 {
     return icalcomponent_new(ICAL_XSTANDARD_COMPONENT);
 }
-icalcomponent* icalcomponent_new_xdaylight()
+icalcomponent* icalcomponent_new_xdaylight(void)
 {
     return icalcomponent_new(ICAL_XDAYLIGHT_COMPONENT);
 }
-icalcomponent* icalcomponent_new_vagenda()
+icalcomponent* icalcomponent_new_vagenda(void)
 {
     return icalcomponent_new(ICAL_VAGENDA_COMPONENT);
 }
-icalcomponent* icalcomponent_new_vquery()
+icalcomponent* icalcomponent_new_vquery(void)
 {
     return icalcomponent_new(ICAL_VQUERY_COMPONENT);
 }
-icalcomponent* icalcomponent_new_vreply()
+icalcomponent* icalcomponent_new_vreply(void)
 {
     return icalcomponent_new(ICAL_VREPLY_COMPONENT);
 }
 
 /*
  * Timezone stuff.
  */
 
@@ -2121,19 +2129,18 @@ void icalcomponent_merge_component(icalc
   /* If we need to do any renaming of TZIDs, do it now. */
   if (tzids_to_rename->num_elements != 0) {
     icalcomponent_rename_tzids (comp_to_merge, tzids_to_rename);
       
     /* Now free the tzids_to_rename array. */
     for (i = 0; i < tzids_to_rename->num_elements; i++) {
       free (icalarray_element_at (tzids_to_rename, i));
     }
-    icalarray_free (tzids_to_rename);
   }
-
+  icalarray_free (tzids_to_rename);
   /* Now move all the components from comp_to_merge to comp, excluding
      VTIMEZONE components. */
   subcomp = icalcomponent_get_first_component (comp_to_merge,
 					       ICAL_ANY_COMPONENT);
   while (subcomp) {
     next_subcomp = icalcomponent_get_next_component (comp_to_merge,
 						     ICAL_ANY_COMPONENT);
     if (icalcomponent_isa(subcomp) != ICAL_VTIMEZONE_COMPONENT) {
@@ -2244,21 +2251,27 @@ icalcomponent_handle_conflicting_vtimezo
     if (tzid_len == existing_tzid_len
 	&& !strncmp (tzid, existing_tzid, tzid_len)) {
       /* Compare the VTIMEZONEs. */
       if (icalcomponent_compare_vtimezones (icaltimezone_get_component (zone),
 					    vtimezone)) {
 	/* The VTIMEZONEs match, so we can use the existing VTIMEZONE. But
 	   we have to rename TZIDs to this TZID. */
 	tzid_copy = strdup (tzid);
+        if(!tzid_copy) {
+          icalerror_set_errno(ICAL_NEWFAILED_ERROR);
+          return;
+        }
 	existing_tzid_copy = strdup (existing_tzid);
-	if (!tzid_copy || !existing_tzid_copy) {
+        if (!existing_tzid_copy) {
 	  icalerror_set_errno(ICAL_NEWFAILED_ERROR);
+          free(tzid_copy);
 	} else {
 	  icalarray_append (tzids_to_rename, tzid_copy);
+	  free(tzid_copy);
 	  icalarray_append (tzids_to_rename, existing_tzid_copy);
 	}
 	return;
       } else {
 	/* FIXME: Handle possible NEWFAILED error. */
 
 	/* Convert the suffix to an integer and remember the maximum numeric
 	   suffix found. */
@@ -2267,27 +2280,35 @@ icalcomponent_handle_conflicting_vtimezo
 	  max_suffix = suffix;
       }
     }
   }
 
   /* We didn't find a VTIMEZONE that matched, so we have to rename the TZID,
      using the maximum numerical suffix found + 1. */
   tzid_copy = strdup (tzid);
+  if(!tzid_copy) {
+    icalerror_set_errno(ICAL_NEWFAILED_ERROR);
+    return;
+  }
+
   snprintf (suffix_buf, sizeof(suffix_buf), "%i", max_suffix + 1);
   new_tzid = malloc (tzid_len + strlen (suffix_buf) + 1);
-  if (!new_tzid || !tzid_copy) {
+  if (!new_tzid) {
     icalerror_set_errno(ICAL_NEWFAILED_ERROR);
+    free(tzid_copy);
     return;
   }
 
   strncpy (new_tzid, tzid, tzid_len);
   strcpy (new_tzid + tzid_len, suffix_buf);
   icalarray_append (tzids_to_rename, tzid_copy);
   icalarray_append (tzids_to_rename, new_tzid);
+  free(tzid_copy);
+  free(new_tzid);
 }
 
 
 /* Returns the length of the TZID, without any trailing digits. */
 static unsigned int icalcomponent_get_tzid_prefix_len (const char *tzid)
 {
   int len;
   const char *p;
@@ -2399,23 +2420,25 @@ icaltimezone* icalcomponent_get_timezone
     /* Do a simple binary search. */
     lower = middle = 0;
     upper = comp->timezones->num_elements;
 
     while (lower < upper) {
 	middle = (lower + upper) >> 1;
 	zone = icalarray_element_at (comp->timezones, middle);
 	zone_tzid = icaltimezone_get_tzid (zone);
-	cmp = strcmp (tzid, zone_tzid);
-	if (cmp == 0)
-	    return zone;
-	else if (cmp < 0)
-	    upper = middle;
-	else
-	    lower = middle + 1;
+	if (zone_tzid != NULL) {
+		cmp = strcmp (tzid, zone_tzid);
+		if (cmp == 0)
+			return zone;
+		else if (cmp < 0)
+			upper = middle;
+		else
+			lower = middle + 1;
+	}
     }
 
     return NULL;
 }
 
 
 /**
  * A function to compare 2 icaltimezone elements, used for qsort().
@@ -2568,38 +2591,31 @@ struct icaltimetype icalcomponent_get_du
     icalcomponent *inner = icalcomponent_get_inner(comp);
 
     icalproperty *due_prop
         = icalcomponent_get_first_property(inner,ICAL_DUE_PROPERTY);
 
     icalproperty *dur_prop
         = icalcomponent_get_first_property(inner, ICAL_DURATION_PROPERTY);
 
-    if( due_prop == 0 && dur_prop == 0){
-        return icaltime_null_time();
-    } else if ( due_prop != 0) {
+    if ( due_prop != 0) {
         return icalproperty_get_due(due_prop);
     } else if ( dur_prop != 0) {
 
         struct icaltimetype start =
             icalcomponent_get_dtstart(inner);
         struct icaldurationtype duration =
             icalproperty_get_duration(dur_prop);
 
         struct icaltimetype due = icaltime_add(start,duration);
 
         return due;
 
-    } else {
-        /* Error, both duration and due have been specified */
-        icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-        return icaltime_null_time();
-
     }
-
+    return icaltime_null_time();
 }
 
 /** @brief Set the due date of a VTODO task.
  *
  *  @param comp Valid VTODO component.
  *  @param v    Valid due date time.
  *
  *  - If no duration or due properties then set the DUE property.
@@ -2631,13 +2647,10 @@ void icalcomponent_set_due(icalcomponent
         struct icaltimetype due =
             icalcomponent_get_due(inner);
 
         struct icaldurationtype dur
             = icaltime_subtract(due,start);
 
         icalproperty_set_duration(dur_prop,dur);
 
-    } else {
-        /* Error, both duration and due have been specified */
-        icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
     }
 }
--- a/calendar/libical/src/libical/icalcomponent.h
+++ b/calendar/libical/src/libical/icalcomponent.h
@@ -265,21 +265,21 @@ void icalcomponent_foreach_recurrence(ic
 			void (*callback)(icalcomponent *comp, 
                                          struct icaltime_span *span, 
                                          void *data),
 			      void *callback_data);
 
 
 /*************** Type Specific routines ***************/
 
-icalcomponent* icalcomponent_new_vcalendar();
-icalcomponent* icalcomponent_new_vevent();
-icalcomponent* icalcomponent_new_vtodo();
-icalcomponent* icalcomponent_new_vjournal();
-icalcomponent* icalcomponent_new_valarm();
-icalcomponent* icalcomponent_new_vfreebusy();
-icalcomponent* icalcomponent_new_vtimezone();
-icalcomponent* icalcomponent_new_xstandard();
-icalcomponent* icalcomponent_new_xdaylight();
-icalcomponent* icalcomponent_new_vagenda();
-icalcomponent* icalcomponent_new_vquery();
+icalcomponent* icalcomponent_new_vcalendar(void);
+icalcomponent* icalcomponent_new_vevent(void);
+icalcomponent* icalcomponent_new_vtodo(void);
+icalcomponent* icalcomponent_new_vjournal(void);
+icalcomponent* icalcomponent_new_valarm(void);
+icalcomponent* icalcomponent_new_vfreebusy(void);
+icalcomponent* icalcomponent_new_vtimezone(void);
+icalcomponent* icalcomponent_new_xstandard(void);
+icalcomponent* icalcomponent_new_xdaylight(void);
+icalcomponent* icalcomponent_new_vagenda(void);
+icalcomponent* icalcomponent_new_vquery(void);
 
 #endif /* !ICALCOMPONENT_H */
--- a/calendar/libical/src/libical/icalderivedparameter.c.in
+++ b/calendar/libical/src/libical/icalderivedparameter.c.in
@@ -33,16 +33,17 @@
 
 
 #include "icalparameter.h"
 #include "icalparameterimpl.h"
 
 #include "icalproperty.h"
 #include "icalerror.h"
 #include "icalmemory.h"
+#include "icaltypes.h"
 
 #include <stdlib.h> /* for malloc() */
 #include <errno.h>
 #include <string.h> /* for memset() */
 
 #ifdef WIN32
 #define strcasecmp      stricmp
 #endif
@@ -93,31 +94,35 @@ const char* icalparameter_kind_to_string
 
 }
 
 icalparameter_kind icalparameter_string_to_kind(const char* string)
 {
     int i;
 
     if (string ==0 ) { 
-	return ICAL_NO_PARAMETER;
+        return ICAL_NO_PARAMETER;
     }
 
     for (i=0; parameter_map[i].kind  != ICAL_NO_PARAMETER; i++) {
 
-	if (strcasecmp(parameter_map[i].name, string) == 0) {
-	    return parameter_map[i].kind;
-	}
+        if (strcasecmp(parameter_map[i].name, string) == 0) {
+            return parameter_map[i].kind;
+        }
     }
 
     if(strncmp(string,"X-",2)==0){
-	return ICAL_X_PARAMETER;
+        return ICAL_X_PARAMETER;
     }
 
-    return ICAL_NO_PARAMETER;
+    if (ical_get_unknown_token_handling_setting() == ICAL_TREAT_AS_ERROR) {
+        return ICAL_NO_PARAMETER;
+    } else {
+        return ICAL_IANA_PARAMETER;
+    }
 }
 
 
 icalvalue_kind icalparameter_value_to_value_kind(icalparameter_value value)
 {
     int i;
 
     for (i=0; value_kind_map[i].kind  != ICAL_NO_VALUE; i++) {
--- a/calendar/libical/src/libical/icalderivedproperty.c.in
+++ b/calendar/libical/src/libical/icalderivedproperty.c.in
@@ -187,17 +187,18 @@ int icalproperty_kind_and_string_to_enum
     for (i=ICALPROPERTY_FIRST_ENUM; i != ICALPROPERTY_LAST_ENUM; i++) {
 	if (enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == pkind)
 	    break;
     }
     if (i == ICALPROPERTY_LAST_ENUM)
 	    return 0;
 
     for (; i != ICALPROPERTY_LAST_ENUM; i++) {
-	if ( strcasecmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
+	if(enum_map[i-ICALPROPERTY_FIRST_ENUM].prop == pkind &&
+           strcasecmp(enum_map[i-ICALPROPERTY_FIRST_ENUM].str, str) == 0) {
 	    return enum_map[i-ICALPROPERTY_FIRST_ENUM].prop_enum;
 	}
     }
 
     return 0;
 }
 
 /** @deprecated please use icalproperty_kind_and_string_to_enum instead */
--- a/calendar/libical/src/libical/icalderivedproperty.h.in
+++ b/calendar/libical/src/libical/icalderivedproperty.h.in
@@ -1,15 +1,26 @@
 /* -*- Mode: C -*-
   ======================================================================
   FILE: icalderivedproperties.{c,h}
   CREATOR: eric 09 May 1999
   
   $Id: icalderivedproperty.h.in,v 1.7 2007-04-30 13:57:48 artcancro Exp $
-    
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of either:
+
+    The LGPL as published by the Free Software Foundation, version
+    2.1, available at: http://www.fsf.org/copyleft/lesser.html
+
+  Or:
+
+    The Mozilla Public License Version 1.0. You may obtain a copy of
+    the License at http://www.mozilla.org/MPL/
+
  (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
  ======================================================================*/
 
 
 #ifndef ICALDERIVEDPROPERTY_H
 #define ICALDERIVEDPROPERTY_H
 
 #include <time.h>
--- a/calendar/libical/src/libical/icalderivedvalue.c.in
+++ b/calendar/libical/src/libical/icalderivedvalue.c.in
@@ -97,19 +97,21 @@ icalvalue_kind icalvalue_string_to_kind(
 	}
     }
 
     return  value_map[i].kind;
 
 }
 
 icalvalue* icalvalue_new_x (const char* v){
-   struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_X_VALUE);
+   struct icalvalue_impl* impl;
    icalerror_check_arg_rz( (v!=0),"v");
 
+   impl = icalvalue_new_impl(ICAL_X_VALUE);
+
    icalvalue_set_x((icalvalue*)impl,v);
    return (icalvalue*)impl;
 }
 void icalvalue_set_x(icalvalue* impl, const char* v) {
     icalerror_check_arg_rv( (impl!=0),"value");
     icalerror_check_arg_rv( (v!=0),"v");
 
     if(impl->x_value!=0) {free((void*)impl->x_value);}
@@ -118,17 +120,17 @@ void icalvalue_set_x(icalvalue* impl, co
 
     if (impl->x_value == 0){
       errno = ENOMEM;
     }
  
  }
 const char* icalvalue_get_x(const icalvalue* value) {
 
-    icalerror_check_arg( (value!=0),"value");
+    icalerror_check_arg_rz( (value!=0),"value");
     icalerror_check_value_type(value, ICAL_X_VALUE);
     return value->x_value;
 }
 
 /* Recur is a special case, so it is not auto generated. */
 icalvalue*
 icalvalue_new_recur (struct icalrecurrencetype v)
 {
@@ -159,17 +161,20 @@ icalvalue_set_recur(icalvalue* impl, str
 	memcpy(impl->data.v_recur, &v, sizeof(struct icalrecurrencetype));
     }
 	       
 }
 
 struct icalrecurrencetype
 icalvalue_get_recur(const icalvalue* value)
 {
-    icalerror_check_arg( (value!=0),"value");
+    struct icalrecurrencetype rt;
+    icalrecurrencetype_clear(&rt);
+
+    icalerror_check_arg_rx( (value!=0),"value", rt);
     icalerror_check_value_type(value, ICAL_RECUR_VALUE);
   
     return *(value->data.v_recur);
 }
 
 
 
 
@@ -197,32 +202,72 @@ icalvalue_set_trigger(icalvalue* value, 
    }
 }
 
 struct icaltriggertype
 icalvalue_get_trigger(const icalvalue* impl)
 {
     struct icaltriggertype tr;
 
-    icalerror_check_arg( (impl!=0),"value");
-    icalerror_check_arg( (impl!=0),"value");
+    tr.duration = icaldurationtype_from_int(0);
+    tr.time = icaltime_null_time();
+
+    icalerror_check_arg_rx( (impl!=0),"value", tr);
 
-    if(impl->kind == ICAL_DATETIME_VALUE){
-	 tr.duration = icaldurationtype_from_int(0);
-	 tr.time = impl->data.v_time;
-    } else if(impl->kind == ICAL_DURATION_VALUE){
+    if(impl) {
+      if(impl->kind == ICAL_DATETIME_VALUE){
+	tr.duration = icaldurationtype_from_int(0);
+	tr.time = impl->data.v_time;
+      } else if(impl->kind == ICAL_DURATION_VALUE){
 	tr.time = icaltime_null_time();
 	tr.duration = impl->data.v_duration;
-    } else {
+      } else {
 	tr.duration = icaldurationtype_from_int(0);
 	tr.time = icaltime_null_time();
 	icalerror_set_errno(ICAL_BADARG_ERROR);
+      }
+    } else {
+      tr.duration = icaldurationtype_from_int(0);
+      tr.time = icaltime_null_time();
+      icalerror_set_errno(ICAL_BADARG_ERROR);
     }
+    
+    return tr;
+}
+
+icalvalue*
+icalvalue_new_datetime (struct icaltimetype v){
+
+   struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_DATETIME_VALUE);
+   icalvalue_set_datetime((icalvalue*)impl,v);
+   return (icalvalue*)impl;
+}
 
-    return tr;
+void
+icalvalue_set_datetime(icalvalue* value, struct icaltimetype v) {
+    struct icalvalue_impl* impl;
+    icalerror_check_arg_rv( (value!=0),"value");
+
+    icalerror_check_value_type(value, ICAL_DATETIME_VALUE);
+    impl = (struct icalvalue_impl*)value;
+
+
+    impl->data.v_time = v;
+
+    icalvalue_reset_kind(impl);
+}
+
+struct icaltimetype
+icalvalue_get_datetime (const icalvalue* value) {
+  struct icaltimetype dt;
+  dt = icaltime_null_time();
+
+  icalerror_check_arg_rx((value!=0),"value", dt);
+  icalerror_check_value_type (value, ICAL_DATETIME_VALUE);
+  return ((struct icalvalue_impl*)value)->data.v_time;
 }
 
 /* DATE-TIME-PERIOD is a special case, and is not auto generated */
 
 icalvalue*
 icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v)
 {
    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_DATETIMEPERIOD_VALUE);
@@ -257,35 +302,108 @@ icalvalue_set_datetimeperiod(icalvalue* 
 	icalerror_set_errno(ICAL_BADARG_ERROR);
     }
 }
 
 struct icaldatetimeperiodtype
 icalvalue_get_datetimeperiod(const icalvalue* impl)
 {
   struct icaldatetimeperiodtype dtp;
-  
-  icalerror_check_arg( (impl!=0),"value");
+
+  dtp.period = icalperiodtype_null_period();
+  dtp.time = icaltime_null_time();
+
+  icalerror_check_arg_rx( (impl!=0),"value", dtp);
   icalerror_check_value_type(value, ICAL_DATETIMEPERIOD_VALUE);
-  
-  if( impl->kind == ICAL_DATETIME_VALUE || impl->kind == ICAL_DATE_VALUE ){
+
+  if(impl) {
+    if( impl->kind == ICAL_DATETIME_VALUE || impl->kind == ICAL_DATE_VALUE ){
       dtp.period = icalperiodtype_null_period();
       dtp.time = impl->data.v_time;
-  } else if(impl->kind == ICAL_PERIOD_VALUE) {
+    } else if(impl->kind == ICAL_PERIOD_VALUE) {
       dtp.period = impl->data.v_period;
       dtp.time = icaltime_null_time();
-  } else {
+    } else {
       dtp.period = icalperiodtype_null_period();
       dtp.time = icaltime_null_time();
       icalerror_set_errno(ICAL_BADARG_ERROR);
+    }	
+  } else {
+    dtp.period = icalperiodtype_null_period();
+    dtp.time = icaltime_null_time();
+    icalerror_set_errno(ICAL_BADARG_ERROR);
   }	
 
   return dtp;
 }
 
+icalvalue*
+icalvalue_new_class (enum icalproperty_class v){
+
+    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_CLASS_VALUE);
+    icalvalue_set_class((icalvalue*)impl,v);
+    return (icalvalue*)impl;
+}
+
+void
+icalvalue_set_class(icalvalue* value, enum icalproperty_class v) {
+    struct icalvalue_impl* impl;
+    icalerror_check_arg_rv( (value!=0),"value");
+
+    icalerror_check_value_type(value, ICAL_CLASS_VALUE);
+    impl = (struct icalvalue_impl*)value;
+
+    impl->data.v_enum = v;
+
+    icalvalue_reset_kind(impl);
+}
+
+enum icalproperty_class
+icalvalue_get_class (const icalvalue* value) {
+
+    icalproperty_class pr;
+    pr = ICAL_CLASS_NONE;
+
+    icalerror_check_arg_rx ((value!=NULL),"value", pr);
+    icalerror_check_arg ((value!=0),"value");
+    icalerror_check_value_type (value, ICAL_CLASS_VALUE);
+    return ((struct icalvalue_impl*)value)->data.v_enum;
+}
+
+icalvalue*
+icalvalue_new_geo (struct icalgeotype v){
+
+    struct icalvalue_impl* impl = icalvalue_new_impl(ICAL_GEO_VALUE);
+    icalvalue_set_geo((icalvalue*)impl,v);
+    return (icalvalue*)impl;
+}
+
+void
+icalvalue_set_geo(icalvalue* value, struct icalgeotype v) {
+    struct icalvalue_impl* impl;
+    icalerror_check_arg_rv( (value!=0),"value");
+
+    icalerror_check_value_type(value, ICAL_GEO_VALUE);
+    impl = (struct icalvalue_impl*)value;
+
+    impl->data.v_geo = v;
+
+    icalvalue_reset_kind(impl);
+}
+
+struct icalgeotype
+icalvalue_get_geo (const icalvalue* value) {
+    struct icalgeotype gt;
+    gt.lat = 255.0;
+    gt.lon = 255.0;
+
+    icalerror_check_arg_rx((value!=0),"value", gt);
+    icalerror_check_value_type (value, ICAL_GEO_VALUE);
+    return ((struct icalvalue_impl*)value)->data.v_geo;
+}
 
 
 icalvalue *
 icalvalue_new_attach (icalattach *attach)
 {
     struct icalvalue_impl *impl;
 
     icalerror_check_arg_rz ((attach != NULL), "attach");
--- a/calendar/libical/src/libical/icalderivedvalue.h.in
+++ b/calendar/libical/src/libical/icalderivedvalue.h.in
@@ -33,33 +33,45 @@
 #include "icalrecur.h"
 #include "icaltime.h"
 #include "icalduration.h"
 #include "icalperiod.h"
 #include "icalattach.h"
      
 typedef struct icalvalue_impl icalvalue;
 
-
-
 void icalvalue_set_x(icalvalue* value, const char* v);
 icalvalue* icalvalue_new_x(const char* v);
 const char* icalvalue_get_x(const icalvalue* value);
 
 icalvalue* icalvalue_new_recur (struct icalrecurrencetype v);
 void icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v);
 struct icalrecurrencetype icalvalue_get_recur(const icalvalue* value);
 
 icalvalue* icalvalue_new_trigger (struct icaltriggertype v);
 void icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v);
 struct icaltriggertype icalvalue_get_trigger(const icalvalue* value);
 
+icalvalue* icalvalue_new_datetime(struct icaltimetype v);
+struct icaltimetype icalvalue_get_datetime(const icalvalue* value);
+void icalvalue_set_datetime(icalvalue* value, struct icaltimetype v);
+
 icalvalue* icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v);
 void icalvalue_set_datetimeperiod(icalvalue* value, struct icaldatetimeperiodtype v);
 struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(const icalvalue* value);
 
+/* GEO */
+icalvalue* icalvalue_new_geo(struct icalgeotype v);
+struct icalgeotype icalvalue_get_geo(const icalvalue* value);
+void icalvalue_set_geo(icalvalue* value, struct icalgeotype v);
+
 icalvalue *icalvalue_new_attach (icalattach *attach);
 void icalvalue_set_attach (icalvalue *value, icalattach *attach);
 icalattach *icalvalue_get_attach (const icalvalue *value);
 
 void icalvalue_reset_kind(icalvalue* value);
 
 <insert_code_here>
+
+
+icalvalue* icalvalue_new_class(enum icalproperty_class v);
+enum icalproperty_class icalvalue_get_class(const icalvalue* value);
+void icalvalue_set_class(icalvalue* value, enum icalproperty_class v);
--- a/calendar/libical/src/libical/icalduration.c
+++ b/calendar/libical/src/libical/icalduration.c
@@ -30,24 +30,26 @@
 #endif
 
 #include "icalduration.h"
 
 #include <assert.h>
 #include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
-#ifdef WIN32
-#define snprintf _snprintf
-#endif
 
 #include "icalerror.h"
 #include "icalmemory.h"
 #include "icalvalue.h"
 
+#ifdef WIN32
+#ifndef HAVE_SNPRINTF
+#include "vsnprintf.h"
+#endif
+#endif
 
 
 
 /* From Seth Alves,  <alves@hungry.com>   */
 struct icaldurationtype icaldurationtype_from_int(int t)
 {
     struct icaldurationtype dur;
     int used = 0;
--- a/calendar/libical/src/libical/icalenums.c
+++ b/calendar/libical/src/libical/icalenums.c
@@ -30,20 +30,24 @@
 #endif
 
 #include "icalenums.h"
 
 #include <stdio.h> /* For fprintf */
 #include <stdio.h> /* For stderr */
 #include <string.h> /* For strncmp */
 #include <assert.h>
+#include "icalmemory.h"
+
 #ifdef WIN32
-#define snprintf _snprintf
+#ifndef HAVE_SNPRINTF
+#include "vsnprintf.h"
 #endif
-#include "icalmemory.h"
+#endif
+
 
 /*** @brief Allowed request status values
  */
 static const struct {
 	 enum icalrequeststatus kind;
 	int major;
 	int minor;
 	const char* str;
--- a/calendar/libical/src/libical/icalerror.c
+++ b/calendar/libical/src/libical/icalerror.c
@@ -184,17 +184,17 @@ icalerrorstate icalerror_supress(const c
 
 
     es = icalerror_get_error_state(e);
     icalerror_set_error_state(e,ICAL_ERROR_NONFATAL);
 
     return es;
 }
 
-const char* icalerror_perror()
+const char* icalerror_perror(void)
 {
     return icalerror_strerror(icalerrno);
 }
 
 void icalerror_restore(const char* error, icalerrorstate es){
 
 
     icalerrorenum e = icalerror_error_from_string(error);
--- a/calendar/libical/src/libical/icalerror.h
+++ b/calendar/libical/src/libical/icalerror.h
@@ -64,17 +64,27 @@ typedef enum icalerrorenum {
 icalerrorenum * icalerrno_return(void);
 #define icalerrno (*(icalerrno_return()))
 
 /** If true, libicl aborts after a call to icalerror_set_error
  *
  *  @warning NOT THREAD SAFE -- recommended that you do not change
  *           this in a multithreaded program.
  */
-extern int icalerror_errors_are_fatal;
+#ifdef _MSC_VER
+  #ifdef BUILD_LIBICALDLL
+    #define LIBICAL_EXPORT __declspec(dllexport)
+  #else
+    #define LIBICAL_EXPORT __declspec(dllimport)
+  #endif
+#else
+  #define LIBICAL_EXPORT extern
+#endif
+
+LIBICAL_EXPORT int icalerror_errors_are_fatal;
 
 /* Warning messages */
 
 #ifdef __GNUC__ca
 #define icalerror_warn(message) {fprintf(stderr,"%s(), %s:%d: %s\n",__FUNCTION__,__FILE__,__LINE__,message);}
 #else /* __GNU_C__ */
 #define icalerror_warn(message) {fprintf(stderr,"%s:%d: %s\n",__FILE__,__LINE__,message);}
 #endif /* __GNU_C__ */
@@ -87,17 +97,17 @@ void _icalerror_set_errno(icalerrorenum)
 typedef enum icalerrorstate { 
     ICAL_ERROR_FATAL,     /* Not fata */
     ICAL_ERROR_NONFATAL,  /* Fatal */
     ICAL_ERROR_DEFAULT,   /* Use the value of icalerror_errors_are_fatal*/
     ICAL_ERROR_UNKNOWN    /* Asked state for an unknown error type */
 } icalerrorstate ;
 
 const char* icalerror_strerror(icalerrorenum e);
-const char* icalerror_perror();
+const char* icalerror_perror(void);
 void ical_bt(void);
 void icalerror_set_error_state( icalerrorenum error, icalerrorstate);
 icalerrorstate icalerror_get_error_state( icalerrorenum error);
 
 #ifndef ICAL_SETERROR_ISFUNC
 #define icalerror_set_errno(x) \
 icalerrno = x; \
 if(icalerror_get_error_state(x)==ICAL_ERROR_FATAL || \
--- a/calendar/libical/src/libical/icallangbind.c
+++ b/calendar/libical/src/libical/icallangbind.c
@@ -155,25 +155,28 @@ icalcomponent* icallangbind_get_next_com
 #define APPENDS(x) icalmemory_append_string(&buf, &buf_ptr, &buf_size, x);
 
 #define APPENDC(x) icalmemory_append_char(&buf, &buf_ptr, &buf_size, x);
 
 char* icallangbind_property_eval_string_r(icalproperty* prop, char* sep)
 {
     char tmp[25];
     size_t buf_size = 1024;
-    char* buf = icalmemory_new_buffer(buf_size);
-    char* buf_ptr = buf;
+    char* buf; 
+    char* buf_ptr; 
     icalparameter *param;
     
     icalvalue* value;
 
     if( prop == 0){
 	return 0;
     }
+  
+    buf = icalmemory_new_buffer(buf_size);
+    buf_ptr = buf;
 
     APPENDS("{ ");
 
     value = icalproperty_get_value(prop);
 
     APPENDS(" 'name' ");
     APPENDS(sep);
     APPENDC('\'');
--- a/calendar/libical/src/libical/icalmime.c
+++ b/calendar/libical/src/libical/icalmime.c
@@ -48,17 +48,17 @@
 
 struct text_part
 {
 	char* buf;
 	char* buf_pos;
 	size_t buf_size;
 };
 
-void* icalmime_text_new_part()
+void* icalmime_text_new_part(void)
 {
 
 #define BUF_SIZE 2048
 
     struct text_part* impl;
 
     if ( ( impl = (struct text_part*)
 	   malloc(sizeof(struct text_part))) == 0) {
@@ -120,17 +120,17 @@ void* icalmime_text_end_part(void* part)
 void icalmime_text_free_part(void *part)
 {
     part = part;
 }
 
 
 /* Ignore Attachments for now */
 
-void* icalmime_attachment_new_part()
+void* icalmime_attachment_new_part(void)
 {
     return 0;
 }
 void icalmime_attachment_add_line(void *part, struct sspm_header *header, 
 				  const char* line, size_t size)
 {
     (void)part;
     (void)header;
@@ -340,17 +340,18 @@ line between the header and the previous
 
 	    parent = last;
 	    icalcomponent_add_component(parent,comp);
 
 	    last_level = parts[i].level;
 
 	} else if (parts[i].level < last_level){
 
-	    parent = icalcomponent_get_parent(parent);
+	    if (parent) 
+	        parent = icalcomponent_get_parent(parent);
 	    icalcomponent_add_component(parent,comp);
 
 	    last_level = parts[i].level;
 	} else { 
 	    assert(0);
 	}
 
 	last = comp;
@@ -394,14 +395,15 @@ int icalmime_test(char* (*get_string)(ch
 	   parts[i].data =
 	       icalcomponent_as_ical_string_r((icalcomponent*)parts[i].data);
        }
    }
 
     sspm_write_mime(parts,NUM_PARTS,&out,"To: bob@bob.org");
 
     printf("%s\n",out);
+    free(out);
 
     return 0;
 
 }
 
 
--- a/calendar/libical/src/libical/icalparameter.c
+++ b/calendar/libical/src/libical/icalparameter.c
@@ -22,32 +22,39 @@
     the License at http://www.mozilla.org/MPL/
 
   The original code is icalderivedparameters.{c,h}
 
   Contributions from:
      Graham Davison <g.m.davison@computer.org>
 
  ======================================================================*/
-/*#line 29 "icalparameter.c.in"*/
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
 
 #include "icalparameter.h"
 #include "icalproperty.h"
 #include "icalerror.h"
 #include "icalmemory.h"
 #include "icalparameterimpl.h"
 
 #include <stdlib.h> /* for malloc() */
 #include <errno.h>
 #include <string.h> /* for memset() */
 
+
+#ifdef WIN32
+#ifndef HAVE_SNPRINTF
+#include "vsnprintf.h"
+#endif
+#define strcasecmp      stricmp
+#endif
+
 /* In icalderivedparameter */
 icalparameter* icalparameter_new_from_value_string(icalparameter_kind kind,const  char* val);
 
 
 struct icalparameter_impl* icalparameter_new_impl(icalparameter_kind kind)
 {
     struct icalparameter_impl* v;
 
@@ -162,34 +169,38 @@ icalparameter* icalparameter_new_from_st
         icalerror_set_errno(ICAL_NEWFAILED_ERROR);
         return 0;
     }
 
     eq = strchr(cpy,'=');
 
     if(eq == 0){
         icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+	free(cpy);
         return 0;
     }
 
     *eq = '\0';
 
     eq++;
 
     kind = icalparameter_string_to_kind(cpy);
 
     if(kind == ICAL_NO_PARAMETER){
         icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+	free(cpy);
         return 0;
     }
 
     param = icalparameter_new_from_value_string(kind,eq);
 
     if(kind == ICAL_X_PARAMETER){
         icalparameter_set_xname(param,cpy);
+    } else if(kind == ICAL_IANA_PARAMETER) {
+        icalparameter_set_iana_name(param, cpy);
     }
 
     free(cpy);
 
     return param;
     
 }
 
@@ -215,42 +226,43 @@ icalparameter_as_ical_string(icalparamet
  * SAFE-CHAR	= any character except CTLs, DQUOTE. ";", ":", ","
  */
 char*
 icalparameter_as_ical_string_r(icalparameter* param)
 {
     size_t buf_size = 1024;
     char* buf; 
     char* buf_ptr;
-    char *out_buf;
     const char *kind_string;
 
     icalerror_check_arg_rz( (param!=0), "parameter");
 
     /* Create new buffer that we can append names, parameters and a
      * value to, and reallocate as needed.
      */
 
     buf = icalmemory_new_buffer(buf_size);
     buf_ptr = buf;
 
     if(param->kind == ICAL_X_PARAMETER) {
-
-	icalmemory_append_string(&buf, &buf_ptr, &buf_size, 
-				 icalparameter_get_xname(param));
-
+        icalmemory_append_string(&buf, &buf_ptr, &buf_size, 
+                     icalparameter_get_xname(param));
+    } else if (param->kind == ICAL_IANA_PARAMETER) {
+        icalmemory_append_string(&buf, &buf_ptr, &buf_size, 
+                     icalparameter_get_iana_name(param));
     } else {
 
 	kind_string = icalparameter_kind_to_string(param->kind);
 	
 	if (param->kind == ICAL_NO_PARAMETER || 
 	    param->kind == ICAL_ANY_PARAMETER || 
 	    kind_string == 0)
 	{
 	    icalerror_set_errno(ICAL_BADARG_ERROR);
+	    free(buf);
 	    return 0;
 	}
 	
 	
 	/* Put the parameter name into the string */
 	icalmemory_append_string(&buf, &buf_ptr, &buf_size, kind_string);
 
     }
@@ -269,16 +281,17 @@ icalparameter_as_ical_string_r(icalparam
 	if (qm == 1) {
 		icalmemory_append_char (&buf, &buf_ptr, &buf_size, '"');
 	}
     } else if (param->data != 0){
         const char* str = icalparameter_enum_to_string(param->data);
         icalmemory_append_string(&buf, &buf_ptr, &buf_size, str); 
     } else {
         icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+	free(buf);
         return 0;
     }
 
     return buf;
 }
 
 
 int
@@ -360,26 +373,76 @@ icalparameter_set_xvalue (icalparameter*
 const char*
 icalparameter_get_xvalue (icalparameter* param)
 {
     icalerror_check_arg_rz( (param!=0),"param");
 
     return param->string;
 }
 
+void icalparameter_set_iana_value (icalparameter* param, const char* v)
+{
+    icalparameter_set_xvalue(param, v);
+}
+
+const char* icalparameter_get_iana_value(icalparameter* param)
+{
+    return icalparameter_get_xvalue(param);
+}
+
+void icalparameter_set_iana_name (icalparameter* param, const char* v)
+{
+    icalparameter_set_xname(param, v);
+}
+
+const char* icalparameter_get_iana_name (icalparameter* param)
+{
+    return icalparameter_get_xname(param);
+}
+
 void icalparameter_set_parent(icalparameter* param,
 			     icalproperty* property)
 {
     icalerror_check_arg_rv( (param!=0),"param");
 
     param->parent = property;
 }
 
 icalproperty* icalparameter_get_parent(icalparameter* param)
 {
     icalerror_check_arg_rz( (param!=0),"param");
 
     return param->parent;
 }
 
+/* returns 1 if parameters have same name in ICAL, otherwise 0 */
+int icalparameter_has_same_name(icalparameter* param1, icalparameter* param2)
+{
+    icalparameter_kind kind1;
+    icalparameter_kind kind2;
+    const char *name1;
+    const char *name2;
+
+    icalerror_check_arg_rz( (param1!=0),"param1");
+    icalerror_check_arg_rz( (param2!=0),"param2");
+
+    kind1 = icalparameter_isa(param1);
+    kind2 = icalparameter_isa(param2);
+
+    if (kind1 != kind2)
+        return 0;
+
+    if  (kind1 == ICAL_X_PARAMETER) {
+        name1 = icalparameter_get_xname(param1);
+        name2 = icalparameter_get_xname(param2);
+        if (strcasecmp(name1, name2) != 0)
+            return 0;
+    } else if  (kind1 == ICAL_IANA_PARAMETER) {
+        name1 = icalparameter_get_iana_name(param1);
+        name2 = icalparameter_get_iana_name(param2);
+        if (strcasecmp(name1, name2) != 0)
+            return 0;
+    }
+	return 1;
+}
 
 /* Everything below this line is machine generated. Do not edit. */
 /* ALTREP */
--- a/calendar/libical/src/libical/icalparameter.h
+++ b/calendar/libical/src/libical/icalparameter.h
@@ -50,22 +50,31 @@ char* icalparameter_as_ical_string(icalp
 char* icalparameter_as_ical_string_r(icalparameter* parameter);
 
 int icalparameter_is_valid(icalparameter* parameter);
 
 icalparameter_kind icalparameter_isa(icalparameter* parameter);
 
 int icalparameter_isa_parameter(void* param);
 
-/* Access the name of an X parameer */
+/* Access the name of an X parameter */
 void icalparameter_set_xname (icalparameter* param, const char* v);
 const char* icalparameter_get_xname(icalparameter* param);
 void icalparameter_set_xvalue (icalparameter* param, const char* v);
 const char* icalparameter_get_xvalue(icalparameter* param);
 
+/* Access the name of an IANA parameter */
+void icalparameter_set_iana_name (icalparameter* param, const char* v);
+const char* icalparameter_get_iana_name(icalparameter* param);
+void icalparameter_set_iana_value (icalparameter* param, const char* v);
+const char* icalparameter_get_iana_value(icalparameter* param);
+
+/* returns 1 if parameters have same name in ICAL, otherwise 0 */
+int icalparameter_has_same_name(icalparameter* param1, icalparameter* param2);
+
 /* Convert enumerations */
 
 const char* icalparameter_kind_to_string(icalparameter_kind kind);
 icalparameter_kind icalparameter_string_to_kind(const char* string);
 
 
 
 #endif 
--- a/calendar/libical/src/libical/icalparser.c
+++ b/calendar/libical/src/libical/icalparser.c
@@ -50,21 +50,16 @@
 #include <string.h> /* For strncpy & size_t */
 #include <stdio.h> /* For FILE and fgets and snprintf */
 #include <stdlib.h> /* for free */
 #include <ctype.h>
 
 #include "icalmemory.h"
 #include "icalparser.h"
 
-#ifdef WIN32
-#define HAVE_CTYPE_H
-#define HAVE_ISWSPACE
-#endif
-
 #ifdef HAVE_WCTYPE_H
 # include <wctype.h>
 /* Some systems have an imcomplete implementation on wctype (FreeBSD,
  * Darwin). Cope with that. */
 # ifndef HAVE_ISWSPACE
 #  define iswspace        isspace
 # endif
 #else
@@ -279,16 +274,17 @@ char* parser_get_param_name(char* line, 
     }
 
     str = make_segment(line,next);
     *end = next+1;
     if (**end == '"') {
         *end = *end+1;
 	    next = parser_get_next_char('"',*end,0);
 	    if (next == 0) {
+			free(str);
 		    return 0;
 	    }
 
 	    *buf = *end = make_segment(*end,next);
     }
 
     return str;
 }
@@ -741,21 +737,17 @@ icalcomponent* icalparser_add_line(icalp
         if (comp_kind == ICAL_NO_COMPONENT){
 
 
 	    c = icalcomponent_new(ICAL_XLICINVALID_COMPONENT);
 	    insert_error(c,str,"Parse error in component name",
 			 ICAL_XLICERRORTYPE_COMPONENTPARSEERROR);
         }
 
-	if (comp_kind != ICAL_X_COMPONENT) {
-	    c  =  icalcomponent_new(comp_kind);
-	} else {
-	    c  =  icalcomponent_new_x(str);
-	}
+	c  =  icalcomponent_new(comp_kind);
 
 	if (c == 0){
 	    c = icalcomponent_new(ICAL_XLICINVALID_COMPONENT);
 	    insert_error(c,str,"Parse error in component name",
 			 ICAL_XLICERRORTYPE_COMPONENTPARSEERROR);
 	}
 	    
 	pvl_push(parser->components,c);
@@ -901,23 +893,35 @@ icalcomponent* icalparser_add_line(icalp
 		tail = 0;
 		break;
 	    }
 
 	    kind = icalparameter_string_to_kind(name);
 
 	    if(kind == ICAL_X_PARAMETER){
 		param = icalparameter_new(ICAL_X_PARAMETER);
-		
-		if(param != 0){
-		    icalparameter_set_xname(param,name);
-		    icalparameter_set_xvalue(param,pvalue);
-		}
-		icalmemory_free_buffer(buf_value);
-		buf_value = NULL;
+            if(param != 0){
+                icalparameter_set_xname(param,name);
+                icalparameter_set_xvalue(param,pvalue);
+            }
+            icalmemory_free_buffer(buf_value);
+            buf_value = NULL;
+	    } else if (kind == ICAL_IANA_PARAMETER){
+            ical_unknown_token_handling tokHandlingSetting = 
+                ical_get_unknown_token_handling_setting();
+            if (tokHandlingSetting == ICAL_DISCARD_TOKEN)
+                continue;
+            param = icalparameter_new(ICAL_IANA_PARAMETER);
+            
+            if(param != 0){
+                icalparameter_set_xname(param,name);
+                icalparameter_set_xvalue(param,pvalue);
+            }
+            icalmemory_free_buffer(buf_value);
+            buf_value = NULL;
 
 	    } else if (kind != ICAL_NO_PARAMETER){
 		param = icalparameter_new_from_value_string(kind,pvalue);
 
 		icalmemory_free_buffer(buf_value);
 		buf_value = NULL;
 
 	    } else {
@@ -985,17 +989,16 @@ icalcomponent* icalparser_add_line(icalp
 		    /* Ooops, could not parse the value of the
 		       parameter ( it was not one of the defined
 		       values ), so reset the value_kind */
 			
 		    insert_error(
 			tail, str, 
 			"Got a VALUE parameter with an unknown type",
 			ICAL_XLICERRORTYPE_PARAMETERVALUEPARSEERROR);
-		    icalparameter_free(param);
 			
 		    value_kind = 
 			icalproperty_kind_to_value_kind(
 			    icalproperty_isa(prop));
 			
 		    icalparameter_free(param);
 		    tail = 0;
 		    parser->state = ICALPARSER_ERROR;
@@ -1107,31 +1110,39 @@ icalcomponent* icalparser_add_line(icalp
 	    } else {
 		vcount++;
 		icalproperty_set_value(prop, value);
 	    }
  	    icalmemory_free_buffer(str);
 	    str = NULL;
 
 	} else {
-		if (str != NULL) {
-			icalmemory_free_buffer(str);
-			str = NULL;
-		}
-			
 	    if (vcount == 0){
+		char temp[200]; /* HACK */
+		
+		icalproperty_kind prop_kind = icalproperty_isa(prop);
 		icalcomponent *tail = pvl_data(pvl_tail(parser->components));
 		
-		/* Remove the empty property */
+		snprintf(temp,sizeof(temp),"No value for %s property. Removing entire property",
+			icalproperty_kind_to_string(prop_kind));
+
+		insert_error(tail, str, temp,
+			     ICAL_XLICERRORTYPE_VALUEPARSEERROR);
+
+		/* Remove the troublesome property */
 		icalcomponent_remove_property(tail,prop);
 		icalproperty_free(prop);
-		prop = NULL;
+		prop = 0;
+		tail = 0;
+		parser->state = ICALPARSER_ERROR;
+		return 0;
+	    } else {
+
+		break;
 	    }
-
-        break;
 	}
     }
 	
     /****************************************************************
      * End of component parsing. 
      *****************************************************************/
 
     if (pvl_data(pvl_tail(parser->components)) == 0 &&
--- a/calendar/libical/src/libical/icalperiod.c
+++ b/calendar/libical/src/libical/icalperiod.c
@@ -112,18 +112,18 @@ const char* icalperiodtype_as_ical_strin
 	icalmemory_add_tmp_buffer(buf);
 	return buf;
 }
 
 
 char* icalperiodtype_as_ical_string_r(struct icalperiodtype p)
 {
 
-    const char* start;
-    const char* end;
+    char* start;
+    char* end;
 
     char *buf;
     size_t buf_size = 40;
     char* buf_ptr = 0;
 
     buf = (char*)icalmemory_new_buffer(buf_size);
     buf_ptr = buf;
     
--- a/calendar/libical/src/libical/icalproperty.c
+++ b/calendar/libical/src/libical/icalproperty.c
@@ -169,35 +169,39 @@ icalproperty_new_clone(icalproperty* old
     return new;
 
 }
 
 icalproperty* icalproperty_new_from_string(const char* str)
 {
 
     size_t buf_size = 1024;
-    char* buf = icalmemory_new_buffer(buf_size);
-    char* buf_ptr = buf;  
+    char* buf;
+    char* buf_ptr;
     icalproperty *prop;
     icalcomponent *comp;
     int errors  = 0;
 
     icalerror_check_arg_rz( (str!=0),"str");
 
+    buf = icalmemory_new_buffer(buf_size);
+    buf_ptr = buf;
+
     /* Is this a HACK or a crafty reuse of code? */
 
     icalmemory_append_string(&buf, &buf_ptr, &buf_size, "BEGIN:VCALENDAR\r\n");
     icalmemory_append_string(&buf, &buf_ptr, &buf_size, str);
     icalmemory_append_string(&buf, &buf_ptr, &buf_size, "\r\n");    
     icalmemory_append_string(&buf, &buf_ptr, &buf_size, "END:VCALENDAR\r\n");
 
     comp = icalparser_parse_string(buf);
 
     if(comp == 0){
         icalerror_set_errno(ICAL_PARSE_ERROR);
+        free(buf);
         return 0;
     }
 
     errors = icalcomponent_count_errors(comp);
 
     prop = icalcomponent_get_first_property(comp,ICAL_ANY_PROPERTY);
 
     icalcomponent_remove_property(comp,prop);
@@ -268,16 +272,26 @@ get_next_line_start (char *line_start, i
     char *pos;
 
     /* If we have 74 chars or less left, we can output all of them. 
        we return a pointer to the '\0' at the end of the string. */
     if (chars_left < MAX_LINE_LEN) {
         return line_start + chars_left;
     } 
 
+    /* Now we jump to the last possible character of the line, and step back
+       trying to find a ';' ':' or ' '. If we find one, we return the character
+       after it. */
+    pos = line_start + MAX_LINE_LEN - 2;
+    while (pos > line_start) {
+        if (*pos == ';' || *pos == ':' || *pos == ' ') {
+	    return pos + 1;
+	}
+	pos--;
+    }
     /* Now try to split on a UTF-8 boundary defined as a 7-bit
        value or as a byte with the two high-most bits set:
        11xxxxxx.  See http://czyborra.com/utf/ */
 
     pos = line_start + MAX_LINE_LEN - 1;
     while (pos > line_start) {
         /* plain ascii */
         if ((*pos & 128) == 0)
@@ -302,17 +316,17 @@ get_next_line_start (char *line_start, i
  *  It returns a tmp buffer.  NOTE: I'm not sure if it matters if we
  *  split a line in the middle of a UTF-8 character. It probably won't
  *  look nice in a text editor. 
  */
 static char*
 fold_property_line (char *text)
 {
     size_t buf_size;
-    char *buf, *buf_ptr, *line_start, *next_line_start, *out_buf;
+    char *buf, *buf_ptr, *line_start, *next_line_start;
     int len, chars_left, first_line;
     char ch;
 
     /* Start with a buffer twice the size of our property line, so we almost
        certainly won't overflow it. */
     len = strlen (text);
     buf_size = len * 2;
     buf = icalmemory_new_buffer (buf_size);
@@ -417,26 +431,28 @@ icalproperty_as_ical_string_r(icalproper
     icalparameter *param;
 
     /* Create new buffer that we can append names, parameters and a
      * value to, and reallocate as needed.
      */
 
     const char* property_name = 0; 
     size_t buf_size = 1024;
-    char* buf = icalmemory_new_buffer(buf_size);
-    char* buf_ptr = buf;
+    char* buf;
+    char* buf_ptr;
     icalvalue* value;
     char *out_buf;
     const char* kind_string = 0;
     const char newline[] = "\r\n";
 
     
     icalerror_check_arg_rz( (prop!=0),"prop");
 
+    buf = icalmemory_new_buffer(buf_size);
+    buf_ptr = buf;
 
     /* Append property name */
 
     if (prop->kind == ICAL_X_PROPERTY && prop->x_name != 0){
 	property_name = prop->x_name;
     } else {
 	property_name = icalproperty_kind_to_string(prop->kind);
     }
@@ -484,18 +500,20 @@ icalproperty_as_ical_string_r(icalproper
     /* Append value */
 
     icalmemory_append_string(&buf, &buf_ptr, &buf_size, ":");
 
     value = icalproperty_get_value(prop);
 
     if (value != 0){
 	char *str = icalvalue_as_ical_string_r(value);
-	icalerror_assert((str !=0),"Could not get string representation of a value");
-	icalmemory_append_string(&buf, &buf_ptr, &buf_size, str);
+	if (str != 0)
+	    icalmemory_append_string(&buf, &buf_ptr, &buf_size, str);
+	else
+	    icalmemory_append_string(&buf, &buf_ptr, &buf_size,"ERROR: No Value"); 
 	free(str);
     } else {
 	icalmemory_append_string(&buf, &buf_ptr, &buf_size,"ERROR: No Value"); 
 	
     }
     
     icalmemory_append_string(&buf, &buf_ptr, &buf_size, newline);
 
@@ -548,21 +566,25 @@ void
 icalproperty_set_parameter (icalproperty* prop,icalparameter* parameter)
 {
     icalparameter_kind kind;
     
     icalerror_check_arg_rv( (prop!=0),"prop");
     icalerror_check_arg_rv( (parameter!=0),"parameter");
 
     kind = icalparameter_isa(parameter);
-    if (kind != ICAL_X_PARAMETER)
-      icalproperty_remove_parameter_by_kind(prop,kind);
-    else
+    if (kind == ICAL_X_PARAMETER) {
       icalproperty_remove_parameter_by_name(prop, 
 					    icalparameter_get_xname(parameter));
+    } else if (kind == ICAL_IANA_PARAMETER) {
+      icalproperty_remove_parameter_by_name(prop, 
+					    icalparameter_get_iana_name(parameter));
+    }
+    else
+      icalproperty_remove_parameter_by_kind(prop,kind);
 
     icalproperty_add_parameter(prop,parameter);
 }
 
 void icalproperty_set_parameter_from_string(icalproperty* prop,
                                             const char* name, const char* value)
 {
 
@@ -582,18 +604,20 @@ void icalproperty_set_parameter_from_str
     
     param  = icalparameter_new_from_value_string(kind,value);
 
     if (param == 0){
         icalerror_set_errno(ICAL_BADARG_ERROR);
         return;
     }
 
-    if(kind == ICAL_X_PARAMETER){
-	icalparameter_set_xname(param, name);
+    if (kind == ICAL_X_PARAMETER) {
+        icalparameter_set_xname(param, name);
+    } else if (kind == ICAL_IANA_PARAMETER) {
+        icalparameter_set_iana_name(param, name);
     }
 
     icalproperty_set_parameter(prop,param);
 
 }
 
 const char* icalproperty_get_parameter_as_string(icalproperty* prop,
                                                  const char* name)
@@ -623,23 +647,29 @@ char* icalproperty_get_parameter_as_stri
     if(kind == ICAL_NO_PARAMETER){
         /* icalenum_string_to_parameter_kind will set icalerrno */
         return 0;
     }
     
     for(param = icalproperty_get_first_parameter(prop,kind); 
 	    param != 0; 
 	    param = icalproperty_get_next_parameter(prop,kind)) {
-	    if (kind != ICAL_X_PARAMETER) {
-		    break;
-	    }
 
-	    if (strcmp(icalparameter_get_xname(param),name)==0) {
+	    if (kind == ICAL_X_PARAMETER) {
+            if (strcmp(icalparameter_get_xname(param),name)==0) {
+                break;
+            }		
+        } else if (kind == ICAL_IANA_PARAMETER) {
+            if (strcmp(icalparameter_get_iana_name(param),name)==0) {
+                break;
+            }		
+	    } else {
 		    break;
-	    }		
+        }
+
     }
 
     if (param == 0){
         return 0;
     }
 
 
     str = icalparameter_as_ical_string_r(param);
@@ -742,16 +772,18 @@ icalproperty_remove_parameter_by_name(ic
     icalerror_check_arg_rv((prop!=0),"prop");
     
     for(p=pvl_head(prop->parameters);p != 0; p = pvl_next(p)){
 	icalparameter* param = (icalparameter *)pvl_data (p);
 	const char * kind_string;
 
 	if (icalparameter_isa(param) == ICAL_X_PARAMETER)
 	  kind_string = icalparameter_get_xname(param);
+    else if (icalparameter_isa(param) == ICAL_IANA_PARAMETER)
+	  kind_string = icalparameter_get_iana_name(param);
 	else
 	  kind_string = icalparameter_kind_to_string(icalparameter_isa(param));
 
 	if (!kind_string)
 	  continue;
 
         if (0 == strcmp(kind_string, name)) {
             pvl_remove (prop->parameters, p);
@@ -776,31 +808,25 @@ icalproperty_remove_parameter_by_ref(ica
     pvl_elem p;
     icalparameter_kind kind;
     const char *name;
 
     icalerror_check_arg_rv((prop!=0),"prop");
     icalerror_check_arg_rv((parameter!=0),"parameter");
 
     kind = icalparameter_isa(parameter);
-    name = icalparameter_get_xname(parameter);
 
-    /*
-     * FIXME If it's an X- parameter, also compare the names. It would be nice
-     * to have a better abstraction like icalparameter_equals()
-     */
-    for(p=pvl_head(prop->parameters);p != 0; p = pvl_next(p)){
-	icalparameter* p_param = (icalparameter *)pvl_data (p);
-	if (icalparameter_isa(p_param) == kind &&
-	    (kind != ICAL_X_PARAMETER ||
-	    !strcmp(icalparameter_get_xname(p_param), name))) {
+    for (p=pvl_head(prop->parameters);p != 0; p = pvl_next(p)) {
+        icalparameter* p_param = (icalparameter *)pvl_data (p);
+
+        if (icalparameter_has_same_name(parameter, p_param)) {
             pvl_remove (prop->parameters, p);
             icalparameter_free(p_param);
             break;
-	} 
+        }
     }   
 }
 
 
 int
 icalproperty_count_parameters (const icalproperty* prop)
 {
     if(prop != 0){
@@ -905,16 +931,17 @@ void icalproperty_set_value_from_string(
         kind = icalvalue_string_to_kind(type);
     }
 
     if(kind == ICAL_NO_VALUE){
         icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
         return;
     }
 
+    icalerror_clear_errno();
     nval = icalvalue_new_from_string(kind, str);
 
     if(nval == 0){
         /* icalvalue_new_from_string sets errno */
         assert(icalerrno != ICAL_NO_ERROR);
         return;
     }
 
@@ -984,29 +1011,33 @@ const char* icalproperty_get_property_na
 }
 
 
 char* icalproperty_get_property_name_r(const icalproperty* prop)
 {
 
     const char* property_name = 0;
     size_t buf_size = 256;
-    char* buf = icalmemory_new_buffer(buf_size);
-    char* buf_ptr = buf;  
+    char* buf;
+    char* buf_ptr;
 
     icalerror_check_arg_rz( (prop!=0),"prop");
+
+    buf = icalmemory_new_buffer(buf_size);
+    buf_ptr = buf;
  
     if (prop->kind == ICAL_X_PROPERTY && prop->x_name != 0){
         property_name = prop->x_name;
     } else {
         property_name = icalproperty_kind_to_string(prop->kind);
     }
  
     if (property_name == 0 ) {
         icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+	icalmemory_free_buffer(buf);
         return 0;
 
     } else {
         /* _append_string will automatically grow the buffer if
            property_name is longer than the initial buffer size */
         icalmemory_append_string(&buf, &buf_ptr, &buf_size, property_name);
     }
  
--- a/calendar/libical/src/libical/icalrecur.c
+++ b/calendar/libical/src/libical/icalrecur.c
@@ -134,27 +134,33 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #ifdef HAVE_STDINT_H
 #include <stdint.h>
 #endif
 
+#ifdef WIN32
+#ifndef HAVE_SNPRINTF
+#include "vsnprintf.h"
+#endif
+#endif
+
+
 #include <limits.h>
 
 #ifndef HAVE_INTPTR_T
-#if defined (WIN32) || defined (XP_BEOS)
+#if (defined (WIN32) && !defined (__MINGW32__)) || defined (XP_BEOS)
 typedef long intptr_t;
 #endif
 #endif
 
 #ifdef WIN32
-#define snprintf _snprintf
-#define strcasecmp stricmp
+#define strcasecmp      stricmp
 #endif
 
 #include "icalrecur.h"
 
 #include "icalerror.h"
 #include "icalmemory.h"
 
 #include <stdlib.h> /* for malloc */
@@ -318,19 +324,23 @@ void icalrecur_add_byrules(struct icalre
 }
 
 /*
  * Days in the BYDAY rule are expected by the code to be sorted, and while
  * this may be the common case, the RFC doesn't actually mandate it. This
  * function sorts the days taking into account the first day of week.
  */
 static void
-sort_bydayrules(short * array, int week_start)
+sort_bydayrules(struct icalrecur_parser *parser)
 {
-    int one, two, i, j;
+    short *array;
+    int week_start, one, two, i, j;
+
+    array = parser->rt.by_day;
+    week_start = parser->rt.week_start;
 
     for (i=0;
 	 i<ICAL_BY_DAY_SIZE && array[i] != ICAL_RECURRENCE_ARRAY_MAX;
 	 i++) {
 	for (j=0; j<i; j++) {
 	    one = icalrecurrencetype_day_day_of_week(array[j]) - week_start;
 	    if (one < 0) one += 7;
 	    two = icalrecurrencetype_day_day_of_week(array[i]) - week_start;
@@ -357,18 +367,16 @@ void icalrecur_add_bydayrules(struct ica
     char* end;
     char* vals_copy;
 
     vals_copy = icalmemory_strdup(vals);
 
     end = (char*)vals_copy+strlen(vals_copy);
     n = vals_copy;
 
-    array[0] = ICAL_RECURRENCE_ARRAY_MAX;
-
     while(n != 0){
 	
 
 	t = n;
 
 	n = strchr(t,',');
 
 	if(n != 0){
@@ -393,25 +401,24 @@ void icalrecur_add_bydayrules(struct ica
 	/* Outlook/Exchange generate "BYDAY=MO, FR" and "BYDAY=2 TH".
 	 * Cope with that.
 	 */
 	if (*t == ' ')
 	    t++;
 
 	wd = icalrecur_string_to_weekday(t);
 
-        if (wd != ICAL_NO_WEEKDAY) {
-            array[i++] = (short) (sign * (wd + 8 * weekno));
-            array[i] = ICAL_RECURRENCE_ARRAY_MAX;
-        }
+	array[i++] = (short)(sign* (wd + 8*weekno));
+	array[i] =  ICAL_RECURRENCE_ARRAY_MAX;
+
     }
 
     free(vals_copy);
 
-    sort_bydayrules(parser->rt.by_day, parser->rt.week_start);
+    sort_bydayrules(parser);
 }
 
 
 struct icalrecurrencetype icalrecurrencetype_from_string(const char* str)
 {
     struct icalrecur_parser parser;
 
     memset(&parser,0,sizeof(parser));
@@ -443,30 +450,24 @@ struct icalrecurrencetype icalrecurrence
 	    icalrecurrencetype_clear(&parser.rt);
 		free(parser.copy);
 	    return parser.rt;
 	}
 
 	if (strcasecmp(name,"FREQ") == 0){
 	    parser.rt.freq = icalrecur_string_to_freq(value);
 	} else if (strcasecmp(name,"COUNT") == 0){
-	    int v = atoi(value);
-	    if (v >= 0) {
-	    parser.rt.count = v;
-	    }
+	    parser.rt.count = atoi(value);
 	} else if (strcasecmp(name,"UNTIL") == 0){
 	    parser.rt.until = icaltime_from_string(value);
 	} else if (strcasecmp(name,"INTERVAL") == 0){
-	    int v = atoi(value);
-	    if (v > 0 && v <= SHRT_MAX) {
-	    parser.rt.interval = (short) v;
-	    }
+	    parser.rt.interval = (short)atoi(value);
 	} else if (strcasecmp(name,"WKST") == 0){
 	    parser.rt.week_start = icalrecur_string_to_weekday(value);
-        sort_bydayrules(parser.rt.by_day, parser.rt.week_start);
+	    sort_bydayrules(&parser);
 	} else if (strcasecmp(name,"BYSECOND") == 0){
 	    icalrecur_add_byrules(&parser,parser.rt.by_second,
 				  ICAL_BY_SECOND_SIZE,value);
 	} else if (strcasecmp(name,"BYMINUTE") == 0){
 	    icalrecur_add_byrules(&parser,parser.rt.by_minute,
 				  ICAL_BY_MINUTE_SIZE,value);
 	} else if (strcasecmp(name,"BYHOUR") == 0){
 	    icalrecur_add_byrules(&parser,parser.rt.by_hour,
@@ -811,16 +812,18 @@ static int expand_year_days(icalrecur_it
 
 
 icalrecur_iterator* icalrecur_iterator_new(struct icalrecurrencetype rule, 
 					   struct icaltimetype dtstart)
 {
     icalrecur_iterator* impl;
     icalrecurrencetype_frequency freq;
 
+    icalerror_clear_errno();
+
     if ( ( impl = (icalrecur_iterator*)
 	   malloc(sizeof(icalrecur_iterator))) == 0) {
 	icalerror_set_errno(ICAL_NEWFAILED_ERROR);
 	return 0;
     }
 
     memset(impl,0,sizeof(icalrecur_iterator));
 
@@ -876,62 +879,57 @@ icalrecur_iterator* icalrecur_iterator_n
     /* If the BYYEARDAY appears, no other date rule part may appear.   */
 
     if(icalrecur_two_byrule(impl,BY_YEAR_DAY,BY_MONTH) ||
        icalrecur_two_byrule(impl,BY_YEAR_DAY,BY_WEEK_NO) ||
        icalrecur_two_byrule(impl,BY_YEAR_DAY,BY_MONTH_DAY) ||
        icalrecur_two_byrule(impl,BY_YEAR_DAY,BY_DAY) ){
 
 	icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-
+        free(impl);
 	return 0;
     }
 
-    /* BYWEEKNO and BYMONTH rule parts may not both appear.*/
-
-    if(icalrecur_two_byrule(impl,BY_WEEK_NO,BY_MONTH)){
-	icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-
-	icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-	return 0;
-    }
+    
 
     /* BYWEEKNO and BYMONTHDAY rule parts may not both appear.*/
 
     if(icalrecur_two_byrule(impl,BY_WEEK_NO,BY_MONTH_DAY)){
 	icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-
-	icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-	return 0;
+        free(impl);
+        return 0;
     }
 
 
     /*For MONTHLY recurrences (FREQ=MONTHLY) neither BYYEARDAY nor
       BYWEEKNO may appear. */
 
     if(freq == ICAL_MONTHLY_RECURRENCE && 
        icalrecur_one_byrule(impl,BY_WEEK_NO)){
 	icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-	return 0;
+        free(impl);
+        return 0;
     }
 
 
     /*For WEEKLY recurrences (FREQ=WEEKLY) neither BYMONTHDAY nor
       BYYEARDAY may appear. */
 
     if(freq == ICAL_WEEKLY_RECURRENCE && 
        icalrecur_one_byrule(impl,BY_MONTH_DAY )) {
 	icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-	return 0;
+	free(impl);
+        return 0;
     }
 
     /* BYYEARDAY may only appear in YEARLY rules */
     if(freq != ICAL_YEARLY_RECURRENCE && 
        icalrecur_one_byrule(impl,BY_YEAR_DAY )) {
 	icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+        free(impl);
 	return 0;
     }
 
     /* Rewrite some of the rules and set up defaults to make later
        processing easier. Primarily, t involves copying an element
        from the start time into the corresponding BY_* array when the
        BY_* array is empty */
 
@@ -991,19 +989,25 @@ icalrecur_iterator* icalrecur_iterator_n
 
     }
 
     /* For YEARLY rule, begin by setting up the year days array . The
        YEARLY rules work by expanding one year at a time. */
 
     if(impl->rule.freq == ICAL_YEARLY_RECURRENCE){
         struct icaltimetype next;
+	icalerror_clear_errno();
 
 	for (;;) {
             expand_year_days(impl, impl->last.year);
+        if( icalerrno != ICAL_NO_ERROR) {
+            icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
+            free(impl);
+            return 0;
+        }
 	    if (impl->days[0] != ICAL_RECURRENCE_ARRAY_MAX)
 	        break; /* break when no days are expanded */
 	    increment_year(impl,impl->rule.interval);
 	}
 
         /* Copy the first day into last. */
 	next = icaltime_from_day_of_year(impl->days[0], impl->last.year);
     
@@ -1055,17 +1059,18 @@ icalrecur_iterator* icalrecur_iterator_n
                     }
                 }
             }
         }
 
 
 	if(impl->last.day > days_in_month || impl->last.day == 0){
 	    icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
-	    return 0;
+            free(impl);
+            return 0;
 	}
 	
     } else if (has_by_data(impl,BY_MONTH_DAY)) {
 	impl->last = icaltime_normalize(impl->last);
     }
 
 
 
@@ -1159,17 +1164,17 @@ static void increment_hour(icalrecur_ite
 {
     int days;
 
     impl->last.hour+=inc;
 
     days = impl->last.hour / 24;
     impl->last.hour = impl->last.hour % 24;
 
-    if (impl->days != 0){
+    if (days != 0){
 	increment_monthday(impl,days);
     }
 }
 
 static void increment_minute(icalrecur_iterator* impl, int inc)
 {
     int hours;
 
@@ -1495,16 +1500,30 @@ static int is_day_in_byday(icalrecur_ite
             (nth_weekday(dow,pos,tt) == tt.day)){ /*pos+wod: "3FR" or -1TU" */
             return 1;
         }
     }
 
     return 0;
 }
 
+int check_set_position(icalrecur_iterator* impl, int set_pos)
+{
+    int i;
+    int found = 0;
+    for (i = 0; impl->rule.by_set_pos[i] != ICAL_RECURRENCE_ARRAY_MAX && 
+              i != ICAL_BY_SETPOS_SIZE; i++){
+        if (impl->rule.by_set_pos[i] == set_pos) {
+              found = 1;
+              break;
+        }
+    }
+    return found;
+}
+
 static int next_month(icalrecur_iterator* impl)
 {
     int data_valid = 1;
     
     int this_frequency = (impl->rule.freq == ICAL_MONTHLY_RECURRENCE);
     
     assert( has_by_data(impl,BY_MONTH) || this_frequency);
   
@@ -1554,17 +1573,16 @@ static int next_month(icalrecur_iterator
           }
       }
 
   MDEND:
 
       if ( day > days_in_month){
           impl->last.day = 1;
           increment_month(impl);
-          impl->last.day--; /* Go back one day, so searches next month start at day 1 */
           data_valid = 0; /* signal that impl->last is invalid */
       }
 
     
    /* 
     * Case 2: 
     * Rules Like: FREQ=MONTHLY;INTERVAL=1;BYDAY=FR 
     */
@@ -1577,36 +1595,66 @@ static int next_month(icalrecur_iterator
          and checks if each day is listed in the BY_DAY array. This
          seems very inneficient, but I think it is the simplest way to
          account for both BYDAY=1FR (First friday in month) and
          BYDAY=FR ( every friday in month ) */
 
       int day;
       int days_in_month = icaltime_days_in_month(impl->last.month,
                                                    impl->last.year);
+      int set_pos_counter = 0;
+      int set_pos_total = 0;
+      int found = 0;
+      
       assert( BYDAYPTR[0]!=ICAL_RECURRENCE_ARRAY_MAX);
 
+      /* Count the past positions for the BYSETPOS calculation */
+      if(has_by_data(impl,BY_SET_POS)){
+          int last_day = impl->last.day;
+	  for(day = 1; day <= days_in_month; day++){
+    	      impl->last.day = day;
+	  
+              if(is_day_in_byday(impl,impl->last)){
+		  set_pos_total++;
+		  if(day <= last_day)
+        	      set_pos_counter++;
+	      }
+	  }
+          impl->last.day = last_day;
+      }
+      
       for(day = impl->last.day+1; day <= days_in_month; day++){
           impl->last.day = day;
+	  
           if(is_day_in_byday(impl,impl->last)){
-              data_valid = 1;
-              break;
-          }
+          /* If there is no BYSETPOS rule, calculate only by BYDAY
+             If there is BYSETPOS rule, take into account the occurence
+             matches with BYDAY */
+              if(!has_by_data(impl,BY_SET_POS) || check_set_position(impl, ++set_pos_counter)
+                  	|| check_set_position(impl, set_pos_counter-set_pos_total-1)) {
+                  found = 1;
+                  break;
+              }
+           }
       }
+      
+      data_valid = found;
 
       if ( day > days_in_month){
           impl->last.day = 1;
           increment_month(impl);
 
           /* Did moving to the next month put us on a valid date? if
              so, note that the new data is valid, if, not, mark it
              invalid */
 
           if(is_day_in_byday(impl,impl->last)){
-              data_valid = 1;
+          /* If there is no BYSETPOS rule or BYSETPOS=1, new data is valid */
+              if(!has_by_data(impl,BY_SET_POS) || check_set_position(impl,1))
+                  data_valid = 1;
           } else {
               data_valid = 0; /* signal that impl->last is invalid */
           }
       }
 
      /* 
        * Case 3
        * Rules Like: FREQ=MONTHLY;COUNT=10;BYMONTHDAY=-3  
@@ -1649,22 +1697,25 @@ static int next_month(icalrecur_iterator
           }
       }
 
       impl->last.day = day;
 
   } else {
       int days_in_month;
 
+      assert( BYMDPTR[0]!=ICAL_RECURRENCE_ARRAY_MAX);
+      impl->last.day = BYMDPTR[0];
+
       increment_month(impl);
 
       days_in_month = icaltime_days_in_month(impl->last.month,
                                                    impl->last.year);
       if (impl->last.day > days_in_month){
-          data_valid = 0; /* signal that impl->last is invalid */
+          impl->last.day = days_in_month;
       }
   }
 
   return data_valid;
 
 }
 
 static int next_weekday_by_week(icalrecur_iterator* impl)
@@ -1677,20 +1728,16 @@ static int next_weekday_by_week(icalrecu
   if (next_hour(impl) == 0){
       return 0;
   }
 
   if(!has_by_data(impl,BY_DAY)){
       return 1;
   }
 
-  /* this call to 'sort_bydayrules' assures that the occurrences for
-     weekly recurrences will be generated in a strict linear order. */
-  sort_bydayrules(BYDAYPTR, impl->rule.week_start);
-
   /* If we get here, we need to step to tne next day */
 
   for (;;) {
       struct icaltimetype tt = icaltime_null_time();
       BYDAYIDX++; /* Look at next elem in BYDAY array */
       
       /* Are we at the end of the BYDAY array? */
       if (BYDAYPTR[BYDAYIDX]==ICAL_RECURRENCE_ARRAY_MAX){
@@ -1856,17 +1903,17 @@ static pvl_list expand_by_day(icalrecur_
 
 
 /* For INTERVAL=YEARLY, set up the days[] array in the iterator to
    list all of the days of the current year that are specified in this
    rule. */
 
 static int expand_year_days(icalrecur_iterator* impl, int year)
 {
-    int j,k;
+    int i,j,k;
     int days_index=0;
     struct icaltimetype t;
     int flags;
 
     t = icaltime_null_date();
 
 #define HBD(x) has_by_data(impl,x)
 
@@ -1878,16 +1925,56 @@ static int expand_year_days(icalrecur_it
 
     flags = (HBD(BY_DAY) ? 1<<BY_DAY : 0) + 
         (HBD(BY_WEEK_NO) ? 1<<BY_WEEK_NO : 0) + 
         (HBD(BY_MONTH_DAY) ? 1<<BY_MONTH_DAY : 0) + 
         (HBD(BY_MONTH) ? 1<<BY_MONTH : 0) + 
         (HBD(BY_YEAR_DAY) ? 1<<BY_YEAR_DAY : 0);
 
     
+    /* BY_WEEK_NO together with BY_MONTH - may conflict, in this case BY_MONTH wins */
+    if( (flags & 1<<BY_MONTH) && (flags & 1<<BY_WEEK_NO) ){
+        int valid_weeks[ICAL_BY_WEEKNO_SIZE];
+        int valid = 1;    
+        memset(valid_weeks, 0, sizeof(valid_weeks));
+        t.year = year;
+        t.is_date = 1;
+
+        /* calculate valid week numbers */
+        for(j=0; impl->by_ptrs[BY_MONTH][j]!=ICAL_RECURRENCE_ARRAY_MAX; j++){
+            int month = impl->by_ptrs[BY_MONTH][j];
+            int first_week, last_week;
+            t.month = month;
+            t.day = 1;
+            first_week =  icaltime_week_number(t);
+            t.day = icaltime_days_in_month(month,year);
+            last_week =  icaltime_week_number(t);
+            for(j=first_week; j<last_week; j++) {
+                valid_weeks[j] = 1;        
+            }
+        }
+
+        /* check valid weeks */
+        for(i = 0; BYWEEKPTR[i] != ICAL_RECURRENCE_ARRAY_MAX && valid; i++){
+                int weekno = BYWEEKPTR[i];
+                if(weekno < ICAL_BY_WEEKNO_SIZE)
+			valid &= valid_weeks[i]; /* check if the week number is valid */
+                else
+			valid = 0;  /* invalid week number */
+        }
+
+        /* let us make the decision which rule to keep */
+        if(valid) { /* BYWEEKNO wins */
+            flags -= 1<<BY_MONTH;
+        }
+        else { /* BYMONTH vins */
+            flags -= 1<<BY_WEEK_NO;
+        }
+    }
+
     switch(flags) {
         
     case 0: {
         /* FREQ=YEARLY; */
         t = impl->dtstart;
         t.year = impl->last.year;
         
         impl->days[days_index++] = (short)icaltime_day_of_year(t);
@@ -2017,17 +2104,34 @@ static int expand_year_days(icalrecur_it
 
 	    /* This holds the day offset used to calculate the day of the year
 	       from the month day. Just add the month day to this. */
 	    doy_offset = icaltime_day_of_year(t) - 1;
 
 	    t.day = days_in_month;
 	    last_dow = icaltime_day_of_week(t);
 
-	    for(k=0;impl->by_ptrs[BY_DAY][k]!=ICAL_RECURRENCE_ARRAY_MAX;k++){
+	    if(has_by_data(impl,BY_SET_POS)) {
+	        /*FREQ=YEARLY; BYDAY=TH,20MO,-10FR; BYMONTH = 12; BYSETPOS=1*/
+	        int day;
+	        int set_pos_counter = 0;
+	        int set_pos_total = 0;
+	        int by_month_day[ICAL_BY_MONTHDAY_SIZE];
+	        for(day = 1; day <= days_in_month; day++){
+	            t.day = day;
+	            if(is_day_in_byday(impl,t))
+	                by_month_day[set_pos_total++] = day;
+	        }
+	        for(set_pos_counter = 0; set_pos_counter < set_pos_total; set_pos_counter++){
+	            if(check_set_position(impl, set_pos_counter+1) ||
+	                	check_set_position(impl, set_pos_counter-set_pos_total))
+	                impl->days[days_index++] = doy_offset + by_month_day[set_pos_counter];
+	        }
+	    }
+	    else for(k=0;impl->by_ptrs[BY_DAY][k]!=ICAL_RECURRENCE_ARRAY_MAX;k++){
 	        short day_coded = impl->by_ptrs[BY_DAY][k];
 		enum icalrecurrencetype_weekday dow =
 		  icalrecurrencetype_day_day_of_week(day_coded);
 		int pos = icalrecurrencetype_day_position(day_coded);  
 		int first_matching_day, last_matching_day, day, month_day;
 
 		/* Calculate the first day in the month with the given weekday,
 		   and the last day. */
@@ -2258,18 +2362,18 @@ static int check_contracting_rules(icalr
     } else {
 	return 0;
     }
 }
 
 struct icaltimetype icalrecur_iterator_next(icalrecur_iterator *impl)
 {
     int valid = 1;
-    
-    if( (impl->rule.count!=0 &&impl->occurrence_no >= impl->rule.count) ||
+
+    if( !impl ||  (impl->rule.count!=0 &&impl->occurrence_no >= impl->rule.count) ||
        (!icaltime_is_null_time(impl->rule.until) && 
 	icaltime_compare(impl->last,impl->rule.until) > 0)) {
 	return icaltime_null_time();
     }
 
     if(impl->occurrence_no == 0 
        &&  icaltime_compare(impl->last,impl->dtstart) >= 0){
 
@@ -2310,16 +2414,21 @@ struct icaltimetype icalrecur_iterator_n
 		break;
 	    }
 	    default:{
 		icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
                 return icaltime_null_time();
 	    }
 	}    
 	
+	if(impl->last.year >= 2038 ){
+	    /* HACK */
+	    return icaltime_null_time();
+	}
+	
     } while(!check_contracting_rules(impl) 
 	    || icaltime_compare(impl->last,impl->dtstart) < 0
             || valid == 0);
     
     
 /* Ignore null times and times that are after the until time */
     if( !icaltime_is_null_time(impl->rule.until) && 
 	icaltime_compare(impl->last,impl->rule.until) > 0 ) {
@@ -2471,26 +2580,26 @@ int icalrecur_expand_recurrence(char* ru
     struct icaltimetype icstart, next;
     int i = 0;
 
     memset(array, 0, count*sizeof(time_t));
 
     icstart = icaltime_from_timet_with_zone(start,0,0);
 
     recur = icalrecurrencetype_from_string(rule);
-
-    for(ritr = icalrecur_iterator_new(recur,icstart),
-	next = icalrecur_iterator_next(ritr);
-	!icaltime_is_null_time(next) && i < count;
-	next = icalrecur_iterator_next(ritr)){
-
-	tt = icaltime_as_timet(next);
+    ritr = icalrecur_iterator_new(recur,icstart);
+    if(ritr) {
+        for(next = icalrecur_iterator_next(ritr);
+	        !icaltime_is_null_time(next) && i < count;
+	        next = icalrecur_iterator_next(ritr)){
+
+	            tt = icaltime_as_timet(next);
 	
-	if (tt >= start ){
-	    array[i++] = tt;
-	}
-
+                if (tt >= start ){
+	                   array[i++] = tt;
+	            }
+        }
+    icalrecur_iterator_free(ritr);
     }
 
-    icalrecur_iterator_free(ritr);
 
     return 1;
 }
--- a/calendar/libical/src/libical/icalrestriction.c.in
+++ b/calendar/libical/src/libical/icalrestriction.c.in
@@ -1,29 +1,44 @@
 /*  -*- Mode: C -*- */
 /*  ======================================================================
   File: icalrestriction.c
-    
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of either:
+
+    The LGPL as published by the Free Software Foundation, version
+    2.1, available at: http://www.fsf.org/copyleft/lesser.html
+
+  Or:
+
+    The Mozilla Public License Version 1.0. You may obtain a copy of
+    the License at http://www.mozilla.org/MPL/
+
  (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
  ======================================================================*/
 /*#line 7 "icalrestriction.c.in"*/
 
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
 
 #include "icalrestriction.h"
 #include "icalenums.h"
 #include "icalerror.h"
 
 #include <assert.h>
 #include <stdio.h> /* For snprintf */   
+
 #ifdef WIN32
-#define snprintf _snprintf
+#ifndef HAVE_SNPRINTF
+#include "vsnprintf.h"
 #endif
+#endif
+
 
 #define TMP_BUF_SIZE 1024
 
 /* Define the structs for the restrictions. these data are filled out
 in machine generated code below */
 
 struct icalrestriction_property_record;
 
@@ -279,17 +294,17 @@ const char* icalrestriction_must_if_tz_r
 const char* icalrestriction_no_dtend(
 		const icalrestriction_property_record *rec,
 		icalcomponent* comp,
 		icalproperty* prop)
 {
 
     (void)rec;
     (void)prop;
-    if( !icalcomponent_get_first_property(comp,ICAL_DTEND_PROPERTY)){
+    if(icalcomponent_get_first_property(comp,ICAL_DTEND_PROPERTY)){
 
 	return "Failed iTIP restrictions for DTEND property. The component must not have both DURATION and DTEND";
 
     }
 
     return 0;    
 }
 
--- a/calendar/libical/src/libical/icaltime.c
+++ b/calendar/libical/src/libical/icaltime.c
@@ -324,16 +324,17 @@ char* set_tz(const char* tzid)
 	strcpy (old_tz_copy + 3, old_tz);
     }
 
     /* Create the new TZ string. */
     new_tz = (char*)malloc(strlen (tzid) + 4);
 
     if(new_tz == 0){
 	icalerror_set_errno(ICAL_NEWFAILED_ERROR);
+	free(old_tz_copy);
 	return 0;
     }
 
     strcpy (new_tz, "TZ=");
     strcpy (new_tz + 3, tzid);
 
     /* Add the new TZ to the environment. */
     putenv(new_tz); 
--- a/calendar/libical/src/libical/icaltimezone.c
+++ b/calendar/libical/src/libical/icaltimezone.c
@@ -35,104 +35,63 @@
 #include <stdlib.h>
 #include <string.h>
 
 #include "icalproperty.h"
 #include "icalarray.h"
 #include "icalerror.h"
 #include "icalparser.h"
 #include "icaltimezone.h"
-#ifndef NO_ZONES_TAB
+#include "icaltimezoneimpl.h"
 #include "icaltz-util.h"
-#endif
 
 #include <sys/stat.h>
 
 #ifdef WIN32
 #include <mbstring.h>
 #include <windows.h>
 /* Undef the similar macro from pthread.h, it doesn't check if
  * gmtime() returns NULL.
  */
 #undef gmtime_r
 
 /* The gmtime() in Microsoft's C library is MT-safe */
 #define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0)
 
-#define snprintf _snprintf
-#define strcasecmp stricmp
+// MSVC lacks the POSIX macro S_ISDIR, however it's a trivial one:
+#ifndef S_ISDIR
+#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
+#ifndef HAVE_SNPRINTF
+#include "vsnprintf.h"
+#endif
+#endif
+
+#define strcasecmp      stricmp
 #endif
 
 /** This is the toplevel directory where the timezone data is installed in. */
 #define ZONEINFO_DIRECTORY	PACKAGE_DATA_DIR "/zoneinfo"
 
-/** The prefix we use to uniquely identify TZIDs. */
-#define TZID_PREFIX		"/citadel.org/"
-#define TZID_PREFIX_LEN		13
+/** The prefix we use to uniquely identify TZIDs.
+    It must begin and end with forward slashes.
+ */
+const char *ical_tzid_prefix =	"/freeassociation.sourceforge.net/";
 
 /** This is the filename of the file containing the city names and
     coordinates of all the builtin timezones. */
 #define ZONES_TAB_FILENAME	"zones.tab"
 
 /** This is the number of years of extra coverage we do when expanding
     the timezone changes. */
 #define ICALTIMEZONE_EXTRA_COVERAGE	5
 
 /** This is the maximum year we will expand to. time_t values only go up to
     somewhere around 2037. */
 #define ICALTIMEZONE_MAX_YEAR		2035
 
-struct _icaltimezone {
-    char		*tzid;
-    /**< The unique ID of this timezone,
-       e.g. "/citadel.org/Olson_20010601_1/Africa/Banjul".
-       This should only be used to identify a VTIMEZONE. It is not
-       meant to be displayed to the user in any form. */
-
-    char		*location;
-    /**< The location for the timezone, e.g. "Africa/Accra" for the
-       Olson database. We look for this in the "LOCATION" or
-       "X-LIC-LOCATION" properties of the VTIMEZONE component. It
-       isn't a standard property yet. This will be NULL if no location
-       is found in the VTIMEZONE. */
-
-    char		*tznames;
-    /**< This will be set to a combination of the TZNAME properties
-       from the last STANDARD and DAYLIGHT components in the
-       VTIMEZONE, e.g. "EST/EDT".  If they both use the same TZNAME,
-       or only one type of component is found, then only one TZNAME
-       will appear, e.g. "AZOT". If no TZNAME is found this will be
-       NULL. */
-
-    double		 latitude;
-    double		 longitude;
-    /**< The coordinates of the city, in degrees. */
-
-    icalcomponent	*component;
-    /**< The toplevel VTIMEZONE component loaded from the .ics file for this
-         timezone. If we need to regenerate the changes data we need this. */
-
-    icaltimezone	*builtin_timezone;
-    /**< If this is not NULL it points to the builtin icaltimezone
-       that the above TZID refers to. This icaltimezone should be used
-       instead when accessing the timezone changes data, so that the
-       expanded timezone changes data is shared between calendar
-       components. */
-
-    int			 end_year;
-    /**< This is the last year for which we have expanded the data to.
-       If we need to calculate a date past this we need to expand the
-       timezone component data from scratch. */
-
-    icalarray		*changes;
-    /**< A dynamically-allocated array of time zone changes, sorted by the
-       time of the change in local time. So we can do fast binary-searches
-       to convert from local time to UTC. */
-};
-
 typedef struct _icaltimezonechange	icaltimezonechange;
 
 struct _icaltimezonechange {
     int		 utc_offset;
     /**< The offset to add to UTC to get local time, in seconds. */
 
     int		 prev_utc_offset;
     /**< The offset to add to UTC, before this change, in seconds. */
@@ -148,20 +107,20 @@ struct _icaltimezonechange {
        since we haven't changed to the new offset yet. */
 
     int		 is_daylight;
     /**< Whether this is STANDARD or DAYLIGHT time. */
 };
 
 
 /** An array of icaltimezones for the builtin timezones. */
-static icalarray *s_builtin_timezones = NULL;
+static icalarray *builtin_timezones = NULL;
 
-/** This is the special UTC timezone, which isn't in s_builtin_timezones. */
-static icaltimezone utc_timezone = { (char *) "UTC", NULL, NULL, 0.0, 0.0, NULL, NULL, 0, NULL };
+/** This is the special UTC timezone, which isn't in builtin_timezones. */
+static icaltimezone utc_timezone = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 
 static char* zone_files_directory = NULL;
 
 static void  icaltimezone_reset			(icaltimezone *zone);
 static char* icaltimezone_get_location_from_vtimezone (icalcomponent *component);
 static char* icaltimezone_get_tznames_from_vtimezone (icalcomponent *component);
 static void  icaltimezone_expand_changes	(icaltimezone	*zone,
 						 int		 end_year);
@@ -190,16 +149,18 @@ static int   icaltimezone_get_vtimezone_
 
 
 static void  icaltimezone_load_builtin_timezone	(icaltimezone *zone);
 
 static void  icaltimezone_ensure_coverage	(icaltimezone *zone,
 						 int		 end_year);
 
 
+static void  icaltimezone_init_builtin_timezones(void);
+
 static void  icaltimezone_parse_zone_tab	(void);
 
 #ifdef USE_BUILTIN_TZDATA
 static char* icaltimezone_load_get_line_fn	(char		*s,
 						 size_t		 size,
 						 void		*data);
 #endif
 
@@ -231,20 +192,28 @@ icaltimezone_copy			(icaltimezone *origi
 
     zone = (icaltimezone*) malloc (sizeof (icaltimezone));
     if (!zone) {
 	icalerror_set_errno (ICAL_NEWFAILED_ERROR);
 	return NULL;
     }
 
     memcpy (zone, originalzone, sizeof (icaltimezone));
+    if (zone->tzid != NULL) 
+	zone->tzid = strdup (zone->tzid);
     if (zone->location != NULL) 
 	zone->location = strdup (zone->location);
     if (zone->tznames != NULL)
 	zone->tznames = strdup (zone->tznames);
+    if (zone->changes != NULL)
+        zone->changes = icalarray_copy(zone->changes);
+    
+    /* Let the caller set the component because then they will
+       know to be careful not to free this reference twice. */
+    zone->component = NULL;
 
     return zone;
 }
 
 /** Frees all memory used for the icaltimezone. */
 void
 icaltimezone_free			(icaltimezone *zone,
 					 int	       free_struct)
@@ -686,17 +655,17 @@ icaltimezone_expand_vtimezone		(icalcomp
 		   since that is the offset from UTC that will be in effect
 		   when each of the RRULE occurrences happens. */
 		icaltime_adjust (&rrule.until, 0, 0, 0,
 				 change.prev_utc_offset);
 		rrule.until.is_utc = 0;
 	    }
 
 	    rrule_iterator = icalrecur_iterator_new (rrule, dtstart);
-	    for (;;) {
+	    for (;rrule_iterator;) {
 		occ = icalrecur_iterator_next (rrule_iterator);
 		if (occ.year > end_year || icaltime_is_null_time (occ))
 		    break;
 
 		change.year   = occ.year;
 		change.month  = occ.month;
 		change.day    = occ.day;
 		change.hour   = occ.hour;
@@ -1274,34 +1243,33 @@ icaltimezone_get_display_name		(icaltime
 		display_name = icaltimezone_get_tznames (zone);
 	if (!display_name) {
 		display_name = icaltimezone_get_tzid (zone);
 		/* Outlook will strip out X-LIC-LOCATION property and so all
 		   we get back in the iTIP replies is the TZID. So we see if
 		   this is one of our TZIDs and if so we jump to the city name
 		   at the end of it. */
 		if (display_name
-		    && !strncmp (display_name, TZID_PREFIX, TZID_PREFIX_LEN)) {
+		    && !strncmp (display_name, ical_tzid_prefix, strlen(ical_tzid_prefix))) {
 		    /* Get the location, which is after the 3rd '/' char. */
 		    const char *p;
 		    int num_slashes = 0;
 		    for (p = display_name; *p; p++) {
 			if (*p == '/') {
 			    num_slashes++;
 			    if (num_slashes == 3)
 				return p + 1;
 			}
 		    }
 		}
 	}
 
 	return display_name;
 }
 
-
 icalarray*
 icaltimezone_array_new			(void)
 {
     return icalarray_new (sizeof (icaltimezone), 16);
 }
 
 
 void
@@ -1341,52 +1309,49 @@ icaltimezone_array_free			(icalarray	*ti
 
 /** Returns an icalarray of icaltimezone structs, one for each builtin
    timezone.  This will load and parse the zones.tab file to get the
    timezone names and their coordinates. It will not load the
    VTIMEZONE data for any timezones. */
 icalarray*
 icaltimezone_get_builtin_timezones	(void)
 {
-#ifndef NO_ZONES_TAB
-    if (!s_builtin_timezones) {
-	icaltimezone_parse_zone_tab ();
-    }
-#endif
-    return s_builtin_timezones;
+    if (!builtin_timezones)
+	icaltimezone_init_builtin_timezones ();
+
+    return builtin_timezones;
 }
 
 /** Release builtin timezone memory */
 void
 icaltimezone_free_builtin_timezones(void)
 {
-	icaltimezone_array_free(s_builtin_timezones);
+	icaltimezone_array_free(builtin_timezones);
+	builtin_timezones = 0;
 }
 
 
 /** Returns a single builtin timezone, given its Olson city name. */
 icaltimezone*
 icaltimezone_get_builtin_timezone	(const char *location)
 {
+    icalcomponent *comp;
     icaltimezone *zone;
-    unsigned int lower;
+    int lower;
     const char *zone_location;
-    icalarray * builtin_timezones;
 
     if (!location || !location[0])
 	return NULL;
 
+    if (!builtin_timezones)
+	icaltimezone_init_builtin_timezones ();
+
     if (!strcmp (location, "UTC"))
 	return &utc_timezone;
     
-    builtin_timezones = icaltimezone_get_builtin_timezones();
-    if (!builtin_timezones) {
-	return NULL;
-    }
-
 #if 0
     /* Do a simple binary search. */
     lower = middle = 0;
     upper = builtin_timezones->num_elements;
 
     while (lower < upper) {
 	middle = (lower + upper) / 2;
 	zone = icalarray_element_at (builtin_timezones, middle);
@@ -1405,16 +1370,30 @@ icaltimezone_get_builtin_timezone	(const
        so we just do a sequential search */
     for (lower = 0; lower < builtin_timezones->num_elements; lower++) {
 	zone = icalarray_element_at (builtin_timezones, lower);
 	zone_location = icaltimezone_get_location (zone);
 	if (strcmp (location, zone_location) == 0)
 		return zone;
     }
 
+    /* Check whether file exists, but is not mentioned in zone.tab.
+       It means it's a deprecated timezone, but still available. */
+    comp = icaltzutil_fetch_timezone (location);
+    if (comp) {
+	icaltimezone tz;
+	icaltimezone_init (&tz);
+	if (icaltimezone_set_component (&tz, comp)) {
+	    icalarray_append (builtin_timezones, &tz);
+	    return icalarray_element_at (builtin_timezones, builtin_timezones->num_elements - 1);
+	} else {
+	    icalcomponent_free (comp);
+	}
+    }
+
     return NULL;
 }
 
 static struct icaltimetype
 tm_to_icaltimetype (struct tm *tm)
 {
 	struct icaltimetype itt;
 
@@ -1450,29 +1429,26 @@ get_offset (icaltimezone *zone)
 }
 
 /** Returns a single builtin timezone, given its offset from UTC */
 icaltimezone*
 icaltimezone_get_builtin_timezone_from_offset	(int offset, const char *tzname)
 {
     icaltimezone *zone=NULL;
     int count, i;
-    icalarray * builtin_timezones;
+    
+    if (!builtin_timezones)
+	icaltimezone_init_builtin_timezones ();
 
     if (offset==0)
 	return &utc_timezone;
 
     if (!tzname)
 	return NULL;
 
-    builtin_timezones = icaltimezone_get_builtin_timezones();
-    if (!builtin_timezones) {
-	return NULL;
-    }
-
     count = builtin_timezones->num_elements;
 
     for (i=0; i<count; i++) {
 	int z_offset;
 	zone = icalarray_element_at (builtin_timezones, i);
 	if (!zone->component)
 	    icaltimezone_load_builtin_timezone (zone);
 	
@@ -1492,17 +1468,17 @@ icaltimezone_get_builtin_timezone_from_t
     int num_slashes = 0;
     const char *p, *zone_tzid;
     icaltimezone *zone;
 
     if (!tzid || !tzid[0])
 	return NULL;
 
     /* Check that the TZID starts with our unique prefix. */
-    if (strncmp (tzid, TZID_PREFIX, TZID_PREFIX_LEN))
+    if (strncmp (tzid, ical_tzid_prefix, strlen(ical_tzid_prefix)))
 	return NULL;
 
     /* Get the location, which is after the 3rd '/' character. */
     p = tzid;
     for (p = tzid; *p; p++) {
 	if (*p == '/') {
 	    num_slashes++;
 	    if (num_slashes == 3)
@@ -1530,21 +1506,36 @@ icaltimezone_get_builtin_timezone_from_t
 	return NULL;
 }
 
 
 /** Returns the special UTC timezone. */
 icaltimezone*
 icaltimezone_get_utc_timezone		(void)
 {
+    if (!builtin_timezones)
+	icaltimezone_init_builtin_timezones ();
+
     return &utc_timezone;
 }
 
 
 
+/** This initializes the builtin timezone data, i.e. the
+   builtin_timezones array and the special UTC timezone. It should be
+   called before any code that uses the timezone functions. */
+static void
+icaltimezone_init_builtin_timezones	(void)
+{
+    /* Initialize the special UTC timezone. */
+    utc_timezone.tzid = (char *)"UTC";
+
+    icaltimezone_parse_zone_tab ();
+}
+
 static int
 parse_coord			(char		*coord,
 				 int		 len,
 				 int		*degrees, 
 				 int 		*minutes,
 				 int 		*seconds)
 {
 	if (len == 5)
@@ -1586,55 +1577,70 @@ fetch_lat_long_from_string  (const char 
 		sptr++;
 	
 	loc = ++sptr;
 	while (!isspace (*sptr))
 		sptr++;
 	len = sptr - loc;
 	location = strncpy (location, loc, len);
 	location [len] = '\0';
-	
+
+#if defined(sun) && defined(__SVR4)
+    /* Handle EET, MET and WET in zone_sun.tab. */
+    if (!strcmp (location, "Europe/")) {
+        while (*sptr != '\t')
+            sptr++;
+        loc = ++sptr;
+        while (!isspace (*sptr))
+            sptr++;
+        len = sptr - loc;
+        location = strncpy (location, loc, len);
+        location [len] = '\0';
+    }
+#endif
+
 	lon = lat + 1;
 	while (*lon != '+' && *lon != '-')
 		lon++;
 
 	if (parse_coord (lat, lon - lat, latitude_degrees, latitude_minutes, latitude_seconds) == 1 ||
 		       	parse_coord (lon, strlen (lon), longitude_degrees, longitude_minutes, longitude_seconds) 
-			== 1)
-			return 1;
+			== 1) {
+				free(lat);
+				return 1;
+			}
 	
 	free (lat);
 
 	return 0;
 }
 
 /** This parses the zones.tab file containing the names and locations
    of the builtin timezones. It creates the builtin_timezones array
    which is an icalarray of icaltimezone structs. It only fills in the
    location, latitude and longtude fields; the rest are left
    blank. The VTIMEZONE component is loaded later if it is needed. The
    timezones in the zones.tab file are sorted by their name, which is
    useful for binary searches. */
 static void
 icaltimezone_parse_zone_tab		(void)
 {
-#ifndef NO_ZONES_TAB
     char *filename;
     FILE *fp;
     char buf[1024];  /* Used to store each line of zones.tab as it is read. */
     char location[1024]; /* Stores the city name when parsing buf. */
     unsigned int filename_len;
     int latitude_degrees = 0, latitude_minutes = 0, latitude_seconds = 0;
     int longitude_degrees = 0, longitude_minutes = 0, longitude_seconds = 0;
     icaltimezone zone;
 
-    icalerror_assert (s_builtin_timezones == NULL,
+    icalerror_assert (builtin_timezones == NULL,
 		      "Parsing zones.tab file multiple times");
 
-    s_builtin_timezones = icalarray_new (sizeof (icaltimezone), 32);
+    builtin_timezones = icalarray_new (sizeof (icaltimezone), 32);
 
 #ifndef USE_BUILTIN_TZDATA
     filename_len = strlen ((char *) icaltzutil_get_zone_directory()) + strlen (ZONES_TAB_SYSTEM_FILENAME)
 	+ 2;
 #else    
     filename_len = strlen (get_zone_directory()) + strlen (ZONES_TAB_FILENAME)
 	+ 2;
 #endif    
@@ -1699,46 +1705,45 @@ icaltimezone_parse_zone_tab		(void)
 	    zone.longitude = (double) longitude_degrees
 		+ (double) longitude_minutes / 60
 		+ (double) longitude_seconds / 3600;
 	else
 	    zone.longitude = (double) longitude_degrees
 		- (double) longitude_minutes / 60
 		- (double) longitude_seconds / 3600;
 
-	icalarray_append (s_builtin_timezones, &zone);
+	icalarray_append (builtin_timezones, &zone);
 
 #if 0
 	printf ("Found zone: %s %f %f\n",
 		location, zone.latitude, zone.longitude);
 #endif
     }
 
     fclose (fp);
-#endif /* NO_ZONES_TAB */
 }
 
 void
 icaltimezone_release_zone_tab		(void)
 {
-    unsigned int i;
-    icalarray *mybuiltin_timezones = s_builtin_timezones;
-    if (s_builtin_timezones == NULL)
+    int i;
+    icalarray *mybuiltin_timezones = builtin_timezones;
+
+    if (builtin_timezones == NULL)
 	return;
-    s_builtin_timezones = NULL;
+    builtin_timezones = NULL;
     for (i = 0; i < mybuiltin_timezones->num_elements; i++)
 	free ( ((icaltimezone*)icalarray_element_at(mybuiltin_timezones, i))->location);
     icalarray_free (mybuiltin_timezones);
 }
 
 /** Loads the builtin VTIMEZONE data for the given timezone. */
 static void
 icaltimezone_load_builtin_timezone	(icaltimezone *zone)
 {
-#ifndef NO_ZONES_TAB
     icalcomponent *subcomp;
 
 	    /* If the location isn't set, it isn't a builtin timezone. */
     if (!zone->location || !zone->location[0])
 	return;
 
 #ifdef USE_BUILTIN_TZDATA
     {
@@ -1792,17 +1797,17 @@ icaltimezone_load_builtin_timezone	(ical
 
     icaltimezone_get_vtimezone_properties (zone, subcomp);
 
 #ifdef USE_BUILTIN_TZDATA
     icalcomponent_remove_component(comp,subcomp);
     icalcomponent_free(comp);
     }
 #endif    
-#endif /* NO_ZONES_TAB */
+
 }
 
 
 #ifdef USE_BUILTIN_TZDATA
 /** Callback used from icalparser_parse() */
 static char *
 icaltimezone_load_get_line_fn		(char		*s,
 					 size_t		 size,
@@ -1998,22 +2003,32 @@ static const char* get_zone_directory(vo
 	    }
 	}
 	return ZONEINFO_DIRECTORY;
 #endif
 }
 
 void set_zone_directory(char *path)
 {
+	if (zone_files_directory)
+		free_zone_directory();
 	zone_files_directory = malloc(strlen(path)+1);
 	if ( zone_files_directory != NULL )
 	{
 		strcpy(zone_files_directory,path);
 	}
 }
 
 void free_zone_directory(void)
 {
 	if ( zone_files_directory != NULL )
 	{
 		free(zone_files_directory);
+		zone_files_directory = NULL;
 	}
 }
+
+void icaltimezone_set_tzid_prefix(const char *new_prefix)
+{
+	if (new_prefix) {
+		ical_tzid_prefix = new_prefix;
+	}
+}
--- a/calendar/libical/src/libical/icaltimezone.h
+++ b/calendar/libical/src/libical/icaltimezone.h
@@ -52,16 +52,22 @@ typedef struct _icaltimezone		icaltimezo
 icaltimezone *icaltimezone_new			(void);
 icaltimezone *icaltimezone_copy			(icaltimezone *originalzone);
 
 /** Frees all memory used for the icaltimezone. Set free_struct to free the
    icaltimezone struct as well. */
 void icaltimezone_free				(icaltimezone *zone,
 						 int free_struct);
 
+/** Sets the prefix to be used for tzid's generated from system tzdata.
+    Must be globally unique (such as a domain name owned by the developer
+    of the calling application), and begin and end with forward slashes.
+    Do not change or de-allocate the string buffer after calling this.
+ */
+void icaltimezone_set_tzid_prefix(const char *new_prefix);
 
 /**
  * @par Accessing timezones.
  */
 
 /** Free any builtin timezone information **/
 void icaltimezone_free_builtin_timezones(void);
 
--- a/calendar/libical/src/libical/icaltypes.c
+++ b/calendar/libical/src/libical/icaltypes.c
@@ -38,16 +38,22 @@
 
 #ifdef WIN32
 #define snprintf      _snprintf
 #define strcasecmp    stricmp
 #endif
 
 #define TEMP_MAX 1024
 
+#ifdef HAVE_PTHREAD
+ #include <pthread.h>    
+    static pthread_mutex_t unk_token_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
+static ical_unknown_token_handling unknownTokenHandling = ICAL_TREAT_AS_ERROR;
 
 int icaltriggertype_is_null_trigger(struct icaltriggertype tr)
 {
     if(icaltime_is_null_time(tr.time) && 
        icaldurationtype_is_null_duration(tr.duration)){
         return 1;
     }
 
@@ -173,19 +179,19 @@ const char* icalreqstattype_as_string(st
 	return buf;
 }
 
 
 char* icalreqstattype_as_string_r(struct icalreqstattype stat)
 {
   char *temp;
 
-  temp = (char*)icalmemory_new_buffer(TEMP_MAX);
+  icalerror_check_arg_rz((stat.code != ICAL_UNKNOWN_STATUS),"Status");
 
-  icalerror_check_arg_rz((stat.code != ICAL_UNKNOWN_STATUS),"Status");
+  temp = (char*)icalmemory_new_buffer(TEMP_MAX);
   
   if (stat.desc == 0){
     stat.desc = icalenum_reqstat_desc(stat.code);
   }
   
   if(stat.debug != 0){
     snprintf(temp,TEMP_MAX,"%d.%d;%s;%s", icalenum_reqstat_major(stat.code),
              icalenum_reqstat_minor(stat.code),
@@ -194,8 +200,40 @@ char* icalreqstattype_as_string_r(struct
   } else {
     snprintf(temp,TEMP_MAX,"%d.%d;%s", icalenum_reqstat_major(stat.code),
              icalenum_reqstat_minor(stat.code),
              stat.desc);
   }
 
   return temp;
 }
+
+ical_unknown_token_handling ical_get_unknown_token_handling_setting(void)
+{
+    ical_unknown_token_handling myHandling;
+
+#ifdef HAVE_PTHREAD
+    pthread_mutex_lock (&unk_token_mutex);
+#endif
+
+    myHandling = unknownTokenHandling;
+
+#ifdef HAVE_PTHREAD
+    pthread_mutex_unlock (&unk_token_mutex);
+#endif
+
+    return myHandling;
+}
+
+void ical_set_unknown_token_handling_setting(ical_unknown_token_handling newSetting)
+{
+
+#ifdef HAVE_PTHREAD
+    pthread_mutex_lock (&unk_token_mutex);
+#endif
+
+    unknownTokenHandling = newSetting;
+
+#ifdef HAVE_PTHREAD
+    pthread_mutex_unlock (&unk_token_mutex);
+#endif
+
+}
--- a/calendar/libical/src/libical/icaltypes.h
+++ b/calendar/libical/src/libical/icaltypes.h
@@ -29,18 +29,18 @@
 #include "icalenums.h"
 #include "icaltime.h"
 #include "icalduration.h"
 #include "icalperiod.h"
 
 
 struct icalgeotype 
 {
-	float lat;
-	float lon;
+	double lat;
+	double lon;
 };
 
 
 struct icaldatetimeperiodtype 
 {
 	struct icaltimetype time;
 	struct icalperiodtype period;
 };
@@ -100,10 +100,23 @@ struct icaltimezonetype {
     const char* tzurl;
     
     /* Array of phases. The end of the array is a phase with tzname == 0 */
     struct icaltimezonephase *phases;
 };
 
 void icaltimezonetype_free(struct icaltimezonetype tzt);
 
+/* ical_unknown_token_handling :
+ *    How should the ICAL library handle components, properties and parameters with
+ *    unknown names?
+ *    FIXME:  Currently only affects parameters.  Extend to components and properties.
+ */
+typedef enum ical_unknown_token_handling {
+    ICAL_ASSUME_IANA_TOKEN = 1, 
+    ICAL_DISCARD_TOKEN = 2,
+    ICAL_TREAT_AS_ERROR = 3 
+} ical_unknown_token_handling;
+
+ical_unknown_token_handling ical_get_unknown_token_handling_setting(void);
+void ical_set_unknown_token_handling_setting(ical_unknown_token_handling newSetting);
 
 #endif /* !ICALTYPES_H */
--- a/calendar/libical/src/libical/icalvalue.c
+++ b/calendar/libical/src/libical/icalvalue.c
@@ -131,43 +131,46 @@ icalvalue* icalvalue_new_clone(const ica
 	case ICAL_TEXT_VALUE:
 	case ICAL_CALADDRESS_VALUE:
 	case ICAL_URI_VALUE:
 	{
 	    if (old->data.v_string != 0) { 
 		new->data.v_string=icalmemory_strdup(old->data.v_string);
 
 		if ( new->data.v_string == 0 ) {
+                    icalvalue_free(new);
 		    return 0;
 		}		    
 
 	    }
 	    break;
 	}
 	case ICAL_RECUR_VALUE:
 	{
 	    if(old->data.v_recur != 0){
 		new->data.v_recur = malloc(sizeof(struct icalrecurrencetype));
 
 		if(new->data.v_recur == 0){
+                    icalvalue_free(new);
 		    return 0;
 		}
 
 		memcpy(	new->data.v_recur, old->data.v_recur,
 			sizeof(struct icalrecurrencetype));	
 	    }
 	    break;
 	}
 
 	case ICAL_X_VALUE: 
 	{
 	    if (old->x_value != 0) {
 		new->x_value=icalmemory_strdup(old->x_value);
 
 		if (new->x_value == 0) {
+                    icalvalue_free(new);
 		    return 0;
 		}
 	    }
 
 	    break;
 	}
 
 	default:
@@ -257,82 +260,16 @@ static char* icalmemory_strdup_and_dequo
 	
     }
 
     *pout = '\0';
 
     return out;
 }
 
- /* 
-  * Returns a quoted copy of a string
- */
-
-static char* icalmemory_strdup_and_quote(const char* unquoted_str)
-{
-    char *str;
-    char *str_p;
-    const char *p;
-    size_t buf_sz;
-
-    buf_sz = strlen(unquoted_str)+1;
-
-    str_p = str = (char*)icalmemory_new_buffer(buf_sz);
-
-    if (str_p == 0){
-      return 0;
-    }
-
-    for(p=unquoted_str; *p!=0; p++){
-
-	switch(*p){
-	    case '\n': {
-		icalmemory_append_string(&str,&str_p,&buf_sz,"\\n");
-		break;
-	    }
-
-	    case '\t': {
-		icalmemory_append_string(&str,&str_p,&buf_sz,"\\t");
-		break;
-	    }
-	    case '\r': {
-		icalmemory_append_string(&str,&str_p,&buf_sz,"\\r");
-		break;
-	    }
-	    case '\b': {
-		icalmemory_append_string(&str,&str_p,&buf_sz,"\\b");
-		break;
-	    }
-	    case '\f': {
-		icalmemory_append_string(&str,&str_p,&buf_sz,"\\f");
-		break;
-	    }
-
-	    case ';':
-	    case ',':
-	    case '"':
-	    case '\\':{
-		icalmemory_append_char(&str,&str_p,&buf_sz,'\\');
-		icalmemory_append_char(&str,&str_p,&buf_sz,*p);
-		break;
-	    }
-
-	    default: {
-		icalmemory_append_char(&str,&str_p,&buf_sz,*p);
-	    }
-	}
-    }
-    /* Assume the last character is not a '\0' and add one. We could
-       check *str_p != 0, but that would be an uninitialized memory
-       read. */
-
-
-    icalmemory_append_char(&str,&str_p,&buf_sz,'\0');
-    return str;
-}    
 /*
  * FIXME
  *
  * This is a bad API, as it forces callers to specify their own X type.
  * This function should take care of this by itself.
  */
 static
 icalvalue* icalvalue_new_enum(icalvalue_kind kind, int x_type, const char* str)
@@ -358,19 +295,19 @@ icalvalue* icalvalue_new_enum(icalvalue_
 /**
  * Transforms a simple float number string into a double.
  * The decimal separator (if any) of the double has to be '.'
  * The code is locale *independant* and does *not* change the locale.
  * It should be thread safe.
  * If you want a code that that does the same job with a decimal separator
  * dependant on the current locale, then use strtof() from libc.
  */
-int simple_str_to_float(const char* from,
-                        float *result,
-                        char** to)
+int simple_str_to_double(const char* from,
+                         double *result,
+                         char** to)
 {
 #define TMP_NUM_SIZE 100
     char *start=NULL, *end=NULL, *cur=(char*)from ;
     char tmp_buf[TMP_NUM_SIZE+1] ; /*hack*/
     struct lconv *loc_data = localeconv () ;
     int i=0 ;
 
     /*sanity checks*/
@@ -449,17 +386,17 @@ icalvalue* icalvalue_new_from_string_wit
 	    value = icalvalue_new_attach (attach);
 	    icalattach_unref (attach);
 	    break;
 	}
 
     case ICAL_BINARY_VALUE:
     {
         icalattach *attach;
-        attach = icalattach_new_from_data ((unsigned char*)str, 0, 0);
+        attach = icalattach_new_from_data (str, 0, 0);
         if ( !attach )
           break;
         value = icalvalue_new_attach (attach);
         icalattach_unref (attach);
         break;
     }
     case ICAL_BOOLEAN_VALUE:
         {
@@ -556,17 +493,17 @@ icalvalue* icalvalue_new_from_string_wit
 	    value = icalvalue_new_uri(str);
 	    break;
         
     case ICAL_GEO_VALUE:
     {
         char *cur=NULL ;
         struct icalgeotype geo = {0.0, 0.0};
   
-        if (simple_str_to_float (str, &geo.lat, &cur)) {
+        if (simple_str_to_double (str, &geo.lat, &cur)) {
             goto geo_parsing_error ;
         }
   
         /*skip white spaces*/
         while (cur && isspace (*cur)) {
             ++cur ;
         }
 
@@ -579,17 +516,17 @@ icalvalue* icalvalue_new_from_string_wit
         if (!cur)
             goto geo_parsing_error ;
 
         /*skip white spaces*/
         while (cur && isspace (*cur)) {
             ++cur ;
         }
 
-        if (simple_str_to_float (cur, &geo.lon, &cur)) {
+        if (simple_str_to_double (cur, &geo.lon, &cur)) {
             goto geo_parsing_error ;
         }
         value = icalvalue_new_geo (geo) ;
         break ;
 
 geo_parsing_error:
         if (error != 0){
             char temp[TMP_BUF_SIZE];
@@ -767,16 +704,17 @@ icalvalue_free (icalvalue* v)
 		v->data.v_attach = NULL;
 	    }
 
 	    break;
 	}
 	case ICAL_TEXT_VALUE:
 	case ICAL_CALADDRESS_VALUE:
 	case ICAL_URI_VALUE:
+	case ICAL_STRING_VALUE:
 	case ICAL_QUERY_VALUE:
 	{
 	    if (v->data.v_string != 0) { 
 		free((void*)v->data.v_string);
 		v->data.v_string = 0;
 	    }
 	    break;
 	}
@@ -827,36 +765,38 @@ static char* icalvalue_binary_as_ical_st
     return str;
 }
 
 
 #define MAX_INT_DIGITS 12 /* Enough for 2^32 + sign*/ 
     
 static char* icalvalue_int_as_ical_string_r(const icalvalue* value) {
     int data;
-    char* str = (char*)icalmemory_new_buffer(MAX_INT_DIGITS); 
+    char* str;
 
     icalerror_check_arg_rz( (value!=0),"value");
+    str = (char*)icalmemory_new_buffer(MAX_INT_DIGITS); 
 
     data = icalvalue_get_integer(value);
 	
     snprintf(str,MAX_INT_DIGITS,"%d",data);
 
     return str;
 }
 
 
 static char* icalvalue_utcoffset_as_ical_string_r(const icalvalue* value)
 {    
     int data,h,m,s;
     char sign;
-    char* str = (char*)icalmemory_new_buffer(9);
+    char* str;
 
     icalerror_check_arg_rz( (value!=0),"value");
 
+    str = (char*)icalmemory_new_buffer(9);
     data = icalvalue_get_utcoffset(value);
 
     if (abs(data) == data){
 	sign = '+';
     } else {
 	sign = '-';
     }
 
@@ -895,26 +835,76 @@ static char* icalvalue_recur_as_ical_str
 
  /* @todo This is not RFC2445 compliant.
  * The RFC only allows:
  * TSAFE-CHAR = %x20-21 / %x23-2B / %x2D-39 / %x3C-5B / %x5D-7E / NON-US-ASCII
  * As such, \t\r\b\f are not allowed, not even escaped
  */
 
 static char* icalvalue_text_as_ical_string_r(const icalvalue* value) {
-    return icalmemory_strdup_and_quote(value->data.v_string);
+    char *str;
+    char *str_p;
+    const char *p;
+    size_t buf_sz;
+
+    buf_sz = strlen(value->data.v_string)+1;
+
+    str_p = str = (char*)icalmemory_new_buffer(buf_sz);
+
+    if (str_p == 0){
+      return 0;
+    }
+
+    for(p=value->data.v_string; *p!=0; p++){
+
+	switch(*p){
+	    case '\n': {
+		icalmemory_append_string(&str,&str_p,&buf_sz,"\\n");
+		break;
+	    }
 
-}
+	    case '\t': {
+		icalmemory_append_string(&str,&str_p,&buf_sz,"\\t");
+		break;
+	    }
+	    case '\r': {
+		icalmemory_append_string(&str,&str_p,&buf_sz,"\\r");
+		break;
+	    }
+	    case '\b': {
+		icalmemory_append_string(&str,&str_p,&buf_sz,"\\b");
+		break;
+	    }
+	    case '\f': {
+		icalmemory_append_string(&str,&str_p,&buf_sz,"\\f");
+		break;
+	    }
+
+	    case ';':
+	    case ',':
+	    case '"':
+	    case '\\':{
+		icalmemory_append_char(&str,&str_p,&buf_sz,'\\');
+		icalmemory_append_char(&str,&str_p,&buf_sz,*p);
+		break;
+	    }
+
+	    default: {
+		icalmemory_append_char(&str,&str_p,&buf_sz,*p);
+	    }
+	}
+    }
+
+    /* Assume the last character is not a '\0' and add one. We could
+       check *str_p != 0, but that would be an uninitialized memory
+       read. */
 
 
-static char* icalvalue_text_as_ical_string(const icalvalue* value) {
-	char *buf;
-	buf = icalvalue_text_as_ical_string_r(value);
-	icalmemory_add_tmp_buffer(buf);
-	return buf;
+    icalmemory_append_char(&str,&str_p,&buf_sz,'\0');
+    return str;
 }
 
 
 
 static char* 
 icalvalue_attach_as_ical_string_r(const icalvalue* value) 
 {
     icalattach *a;
@@ -951,57 +941,69 @@ static char* icalvalue_duration_as_ical_
     return icaldurationtype_as_ical_string_r(data);
 }
 
 
 
 void print_time_to_string(char* str, const struct icaltimetype *data)
 {
     char temp[20];
+    str[0] = '\0';
 
-    if (icaltime_is_utc(*data)){
-    snprintf(temp,sizeof(temp),"%02d%02d%02dZ",data->hour,data->minute,data->second);
-    } else {
-    snprintf(temp,sizeof(temp),"%02d%02d%02d",data->hour,data->minute,data->second);
-    }   
-
-    strcat(str,temp);
+    if (data != 0) {
+        if (icaltime_is_utc(*data)){
+            snprintf(temp,sizeof(temp),"%02d%02d%02dZ",data->hour,data->minute,data->second);
+            strncat(str,temp,7);
+        } else {
+            snprintf(temp,sizeof(temp),"%02d%02d%02d",data->hour,data->minute,data->second);
+            strncat(str,temp,6);
+        }   
+    }
 }
 
  
 void print_date_to_string(char* str,  const struct icaltimetype *data)
 {
     char temp[20];
+    str[0] = '\0';
 
-    snprintf(temp,sizeof(temp),"%04d%02d%02d",data->year,data->month,data->day);
-
-    strcat(str,temp);
+    if (data != 0) {
+        snprintf(temp,sizeof(temp),"%04d%02d%02d",data->year,data->month,data->day);
+        strncat(str,temp,8);
+    }
 }
 
 static char* icalvalue_date_as_ical_string_r(const icalvalue* value) {
 
     struct icaltimetype data;
     char* str;
     icalerror_check_arg_rz( (value!=0),"value");
     data = icalvalue_get_date(value);
 
     str = (char*)icalmemory_new_buffer(9);
  
-    str[0] = 0;
+    str[0] = '\0';
     print_date_to_string(str,&data);
    
     return str;
 }
 
 void print_datetime_to_string(char* str,  const struct icaltimetype *data)
 {
-    print_date_to_string(str,data);
-    if ( !data->is_date ) {
-        strcat(str,"T");
-        print_time_to_string(str,data);
+    char temp[20];
+    str[0] = '\0';
+
+    if (data != 0) {
+        print_date_to_string(str,data);
+        if ( !data->is_date ) {
+            strncat(str,"T",19);
+            temp[0] = '\0';
+            print_time_to_string(temp,data);
+            strncat(str,temp,19);
+        }
     }
 }
 
 
 static char* icalvalue_datetime_as_ical_string_r(const icalvalue* value) {
     
     struct icaltimetype data;
     char* str;
@@ -1016,17 +1018,16 @@ static char* icalvalue_datetime_as_ical_
 	    return 0;
 	}
 
     data = icalvalue_get_datetime(value);
 
     str = (char*)icalmemory_new_buffer(20);
  
     str[0] = 0;
-
     print_datetime_to_string(str,&data);
    
     return str;
 
 }
 
 static char* icalvalue_float_as_ical_string_r(const icalvalue* value) {
 
@@ -1178,17 +1179,17 @@ icalvalue_as_ical_string_r(const icalval
         if(value->x_value !=0){
             return icalmemory_strdup(value->x_value);
         }
 
         return icalproperty_enum_to_string_r(value->data.v_enum);
         
     case ICAL_X_VALUE: 
 	if (value->x_value != 0)
-            return icalmemory_strdup_and_quote(value->x_value);
+            return icalmemory_strdup(value->x_value);
 
     /* FALLTHRU */
 
     case ICAL_NO_VALUE:
     default:
 	{
 	    return 0;
 	}
--- a/calendar/libical/src/libical/icalvalue.h
+++ b/calendar/libical/src/libical/icalvalue.h
@@ -58,28 +58,29 @@ icalvalue_kind icalvalue_isa(const icalv
 
 int icalvalue_isa_value(void*);
 
 icalparameter_xliccomparetype icalvalue_compare(const icalvalue* a, const icalvalue *b);
 
 
 /* Special, non autogenerated value accessors */
 
-icalvalue* icalvalue_new_recur (struct icalrecurrencetype v);
-void icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v);
-struct icalrecurrencetype icalvalue_get_recur(const icalvalue* value);
+/* Defined in icalderivedvalue.h */
+/* icalvalue* icalvalue_new_recur (struct icalrecurrencetype v); */
+/* void icalvalue_set_recur(icalvalue* value, struct icalrecurrencetype v); */
+/* struct icalrecurrencetype icalvalue_get_recur(const icalvalue* value); */
 
-icalvalue* icalvalue_new_trigger (struct icaltriggertype v);
-void icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v);
-struct icaltriggertype icalvalue_get_trigger(const icalvalue* value);
+/* icalvalue* icalvalue_new_trigger (struct icaltriggertype v); */
+/* void icalvalue_set_trigger(icalvalue* value, struct icaltriggertype v); */
+/* struct icaltriggertype icalvalue_get_trigger(const icalvalue* value); */
 
-icalvalue* icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v);
-void icalvalue_set_datetimeperiod(icalvalue* value, 
-				  struct icaldatetimeperiodtype v);
-struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(const icalvalue* value);
+/* icalvalue* icalvalue_new_datetimeperiod (struct icaldatetimeperiodtype v); */
+/* void icalvalue_set_datetimeperiod(icalvalue* value,  */
+/* 				  struct icaldatetimeperiodtype v); */
+/* struct icaldatetimeperiodtype icalvalue_get_datetimeperiod(const icalvalue* value); */
 
 /* Convert enumerations */
 
 icalvalue_kind icalvalue_string_to_kind(const char* str);
 const char* icalvalue_kind_to_string(const icalvalue_kind kind);
 
 /** Check validity of a specific icalvalue_kind **/
 int icalvalue_kind_is_valid(const icalvalue_kind kind);
new file mode 100644
--- /dev/null
+++ b/calendar/libical/src/libical/libicals_w32_vsnprintf_replacement.c
@@ -0,0 +1,173 @@
+#ifdef WIN32
+#include "config.h"
+#ifndef HAVE_SNPRINTF
+#error DO NOT USE libical version of vsnprintf.
+#endif
+/*
+ * Revision 12: http://theos.com/~deraadt/snprintf.c
+ *
+ * Copyright (c) 1997 Theo de Raadt
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WIN32
+#include <sys/param.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#endif
+#include <sys/types.h>
+#include <signal.h>
+#include <stdio.h>
+#include <string.h>
+#if __STDC__
+#include <stdarg.h>
+#include <stdlib.h>
+#else
+#include <varargs.h>
+#endif
+#include <setjmp.h>
+
+#ifndef roundup
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
+#endif
+
+static int pgsize;
+static char *curobj;
+static sigjmp_buf bail;
+
+#define EXTRABYTES	2	/* XXX: why 2? you don't want to know */
+
+static char *
+msetup(str, n)
+	char *str;
+	size_t n;
+{
+	char *e;
+
+	if (n == 0)
+		return NULL;
+	if (pgsize == 0)
+		pgsize = getpagesize();
+	curobj = (char *)malloc(n + EXTRABYTES + pgsize * 2);
+	if (curobj == NULL)
+		return NULL;
+	e = curobj + n + EXTRABYTES;
+	e = (char *)roundup((unsigned long)e, pgsize);
+	if (mprotect(e, pgsize, PROT_NONE) == -1) {
+		free(curobj);
+		curobj = NULL;
+		return NULL;
+	}
+	e = e - n - EXTRABYTES;
+	*e = '\0';
+	return (e);
+}
+
+static void
+mcatch(int i)
+{
+	siglongjmp(bail, 1);
+}
+
+static void
+mcleanup(str, n, p)
+	char *str;
+	size_t n;
+	char *p;
+{
+	strncpy(str, p, n-1);
+	str[n-1] = '\0';
+	if (mprotect((caddr_t)(p + n + EXTRABYTES), pgsize,
+	    PROT_READ|PROT_WRITE|PROT_EXEC) == -1)
+		mprotect((caddr_t)(p + n + EXTRABYTES), pgsize,
+		    PROT_READ|PROT_WRITE);
+	free(curobj);
+}
+
+int
+#if __STDC__
+vsnprintf(char *str, size_t n, char const *fmt, va_list ap)
+#else
+vsnprintf(str, n, fmt, ap)
+	char *str;
+	size_t n;
+	char *fmt;
+	char *ap;
+#endif
+{
+	struct sigaction osa, nsa;
+	char *p;
+	int ret = n + 1;	/* if we bail, indicated we overflowed */
+
+	memset(&nsa, 0, sizeof nsa);
+	nsa.sa_handler = mcatch;
+	sigemptyset(&nsa.sa_mask);
+
+	p = msetup(str, n);
+	if (p == NULL) {
+		*str = '\0';
+		return 0;
+	}
+	if (sigsetjmp(bail, 1) == 0) {
+		if (sigaction(SIGSEGV, &nsa, &osa) == -1) {
+			mcleanup(str, n, p);
+			return (0);
+		}
+		ret = vsprintf(p, fmt, ap);
+	}
+	mcleanup(str, n, p);
+	(void) sigaction(SIGSEGV, &osa, NULL);
+	return (ret);
+}
+
+int
+#if __STDC__
+snprintf(char *str, size_t n, char const *fmt, ...)
+#else
+snprintf(str, n, fmt, va_alist)
+	char *str;
+	size_t n;
+	char *fmt;
+	va_dcl
+#endif
+{
+	va_list ap;
+#if __STDC__
+	va_start(ap, fmt);
+#else
+	va_start(ap);
+#endif
+
+	return (vsnprintf(str, n, fmt, ap));
+	va_end(ap);
+}
+
+
+#else
+
+/* ANSI C forbids an empty source file... */
+
+static void vsnprintf_dummy_func() {
+   vsnprintf_dummy_func();
+}
+
+#endif
--- a/calendar/libical/src/libical/pvl.c
+++ b/calendar/libical/src/libical/pvl.c
@@ -1,15 +1,27 @@
 /*======================================================================
  FILE: pvl.c
  CREATOR: eric November, 1995
 
 
  (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
      http://www.softwarestudio.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of either:
+
+    The LGPL as published by the Free Software Foundation, version
+    2.1, available at: http://www.fsf.org/copyleft/lesser.html
+
+  Or:
+
+    The Mozilla Public License Version 1.0. You may obtain a copy of
+    the License at http://www.mozilla.org/MPL/
+
 ======================================================================*/
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #include "pvl.h"
 #include <errno.h>
--- a/calendar/libical/src/libical/pvl.h
+++ b/calendar/libical/src/libical/pvl.h
@@ -1,15 +1,27 @@
 /*======================================================================
  FILE: pvl.h
  CREATOR: eric November, 1995
 
 
  (C) COPYRIGHT 2000, Eric Busboom <eric@softwarestudio.org>
      http://www.softwarestudio.org
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of either:
+
+    The LGPL as published by the Free Software Foundation, version
+    2.1, available at: http://www.fsf.org/copyleft/lesser.html
+
+  Or:
+
+    The Mozilla Public License Version 1.0. You may obtain a copy of
+    the License at http://www.mozilla.org/MPL/
+
 ======================================================================*/
 
 
 #ifndef __PVL_H__
 #define __PVL_H__
 
 typedef struct pvl_list_t* pvl_list;
 typedef struct pvl_elem_t* pvl_elem;
--- a/calendar/libical/src/libical/sspm.c
+++ b/calendar/libical/src/libical/sspm.c
@@ -176,17 +176,18 @@ char* sspm_get_parameter(const char* lin
 
     if(q !=0){
 	p = q+1;
     }
 
     if(s != 0){
 	strncpy(name,p,(size_t)s-(size_t)p);
     } else {
-	strcpy(name,p);
+	strncpy(name,p,sizeof(name)-1);
+	name[sizeof(name)-1]='\0';
     }
 
     /* Strip off trailing quote, if it exists */
 
     q = strrchr(name,'\"');
 
     if (q != 0){
 	*q='\0';
@@ -247,17 +248,17 @@ static const char *mime_headers[] = {
     "Content-Transfer-Encoding",
     "Content-Disposition",
     "Content-Id",
     "Mime-Version",
     0 
 };
 
 
-void* sspm_default_new_part()
+void* sspm_default_new_part(void)
 {
     return 0;
 }
 void sspm_default_add_line(void *part, struct sspm_header *header, 
 			   const char* line, size_t size)
 {
     (void)part;
     (void)header;
@@ -467,16 +468,17 @@ enum sspm_major_type sspm_find_major_con
 enum sspm_minor_type sspm_find_minor_content_type(char* type)
 {
     int i;
     char* ltype = sspm_lowercase(type);
 
     char *p = strchr(ltype,'/');
 
     if (p==0){
+        free(ltype);
 	return SSPM_UNKNOWN_MINOR_TYPE; 
     }
 
     p++; /* Skip the '/' */
 
     for (i=0; minor_content_type_map[i].type !=  SSPM_UNKNOWN_MINOR_TYPE; i++){
 	if(strncmp(p, minor_content_type_map[i].str,
 		   strlen(minor_content_type_map[i].str))==0){
--- a/calendar/libical/src/libical/sspm.h
+++ b/calendar/libical/src/libical/sspm.h
@@ -106,17 +106,17 @@ struct sspm_part {
 	int level;
 	size_t data_size;
 	void *data;
 };
 
 struct sspm_action_map {
 	enum sspm_major_type major;
 	enum sspm_minor_type minor;
-	void* (*new_part)();
+	void* (*new_part)(void);
 	void (*add_line)(void *part, struct sspm_header *header, 
 			 const char* line, size_t size);
 	void* (*end_part)(void* part);
 	void (*free_part)(void *part);
 };
 
 const char* sspm_major_type_string(enum sspm_major_type type);
 const char* sspm_minor_type_string(enum sspm_minor_type type);
new file mode 100644
--- /dev/null
+++ b/calendar/libical/src/libical/vsnprintf.h
@@ -0,0 +1,33 @@
+#ifdef WIN32
+
+#ifndef roundup
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
+#endif
+
+#include <stdlib.h>
+#include <stdarg.h>
+
+int
+#if __STDC__
+vsnprintf(char *str, size_t n, char const *fmt, va_list ap);
+#else
+vsnprintf(str, n, fmt, ap);
+	char *str;
+	size_t n;
+	char *fmt;
+	char *ap;
+#endif
+
+
+int
+#if __STDC__
+snprintf(char *str, size_t n, char const *fmt, ...);
+#else
+snprintf(str, n, fmt, va_alist);
+	char *str;
+	size_t n;
+	char *fmt;
+	va_dcl
+#endif
+
+#endif