diff --git a/SOPE/NGCards/iCalCalendar.m b/SOPE/NGCards/iCalCalendar.m index 1eab53ecd..0834ed555 100644 --- a/SOPE/NGCards/iCalCalendar.m +++ b/SOPE/NGCards/iCalCalendar.m @@ -22,6 +22,8 @@ #import #import +#import + #import "iCalEvent.h" #import "iCalToDo.h" #import "iCalJournal.h" @@ -39,6 +41,30 @@ @implementation iCalCalendar ++ (NSArray *) parseFromSource: (id) source +{ + NSArray *result; + NSMutableString *content; + + result = [super parseFromSource: source]; + + // If parsing doesn't return any card, check if the opening tag is present but the ending tag + // missing. Add the ending tag and parse the source again in this case. + if ([result count] == 0 && + [source length] && + [source hasPrefix: @"BEGIN:VCALENDAR"] && + !([source hasSuffix: @"END:VCALENDAR\r\n"] || [source hasSuffix: @"END:VCALENDAR"])) + { + content = [NSMutableString stringWithString: source]; + [content appendString: @"END:VCALENDAR"]; + result = [super parseFromSource: content]; + if ([result count] > 0) + [self logWithFormat: @"Successfully repaired VCALENDAR by adding ending tag"]; + } + + return result; +} + /* class mapping */ - (Class) classForTag: (NSString *) classTag {