Skip to content

Commit

Permalink
fix(calendar): try to repair VCALENDAR when parsing versit string
Browse files Browse the repository at this point in the history
It seems that Exchange 2010 and 2016 sometimes produce calendar
invitation emails with text/calendar multipart parts in the email that
have "END:VCALENDAR" at the end of the calendar data missing.
  • Loading branch information
cgx committed Feb 8, 2021
1 parent 9dcdaed commit 9fe2de7
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions SOPE/NGCards/iCalCalendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#import <Foundation/NSArray.h>
#import <Foundation/NSString.h>

#import <NGExtensions/NSObject+Logs.h>

#import "iCalEvent.h"
#import "iCalToDo.h"
#import "iCalJournal.h"
Expand All @@ -39,6 +41,30 @@ - (void) addToFreeBusys: (iCalFreeBusy *) _obj;

@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
{
Expand Down

0 comments on commit 9fe2de7

Please sign in to comment.