From adee80529e66eea9acfef9e311a9ff3365114690 Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Thu, 23 Jan 2014 11:09:32 -0500 Subject: [PATCH] Added more event props and fixed date issues --- ActiveSync/NSDate+ActiveSync.h | 1 + ActiveSync/NSDate+ActiveSync.m | 10 ++++ ActiveSync/iCalEvent+ActiveSync.m | 76 ++++++++++++++++++++++++------- 3 files changed, 71 insertions(+), 16 deletions(-) diff --git a/ActiveSync/NSDate+ActiveSync.h b/ActiveSync/NSDate+ActiveSync.h index 172552470..dced4de94 100644 --- a/ActiveSync/NSDate+ActiveSync.h +++ b/ActiveSync/NSDate+ActiveSync.h @@ -37,6 +37,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @interface NSDate (ActiveSync) - (NSString *) activeSyncRepresentation; +- (NSString *) activeSyncRepresentationWithoutSeparators; @end diff --git a/ActiveSync/NSDate+ActiveSync.m b/ActiveSync/NSDate+ActiveSync.m index dba1a345f..05a0df1a3 100644 --- a/ActiveSync/NSDate+ActiveSync.m +++ b/ActiveSync/NSDate+ActiveSync.m @@ -39,4 +39,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. return [self descriptionWithCalendarFormat: @"%Y-%m-%d-T%H:%M:%S.%FZ" timeZone: [NSTimeZone timeZoneWithName: @"GMT"] locale: nil]; } + +// +// From [MS-ASDTYPE].pdf - section 2.3 "Dates and times in calendar items MUST NOT include punctuation separators." +// +- (NSString *) activeSyncRepresentationWithoutSeparators +{ + return [self descriptionWithCalendarFormat: @"%Y%m%dT%H%M%SZ" timeZone: [NSTimeZone timeZoneWithName: @"GMT"] locale: nil]; +} + + @end diff --git a/ActiveSync/iCalEvent+ActiveSync.m b/ActiveSync/iCalEvent+ActiveSync.m index 0db3f1cf5..b6a074e5b 100644 --- a/ActiveSync/iCalEvent+ActiveSync.m +++ b/ActiveSync/iCalEvent+ActiveSync.m @@ -54,22 +54,25 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. iCalPerson *organizer, *attendee; iCalTimeZone *tz; + id o; + + int v; s = [NSMutableString string]; // DTStamp -- http://msdn.microsoft.com/en-us/library/ee219470(v=exchg.80).aspx if ([self timeStampAsDate]) - [s appendFormat: @"%@", [[self timeStampAsDate] activeSyncRepresentation]]; + [s appendFormat: @"%@", [[self timeStampAsDate] activeSyncRepresentationWithoutSeparators]]; else if ([self created]) - [s appendFormat: @"%@", [[self created] activeSyncRepresentation]]; + [s appendFormat: @"%@", [[self created] activeSyncRepresentationWithoutSeparators]]; // StartTime -- http://msdn.microsoft.com/en-us/library/ee157132(v=exchg.80).aspx if ([self startDate]) - [s appendFormat: @"%@", [[self startDate] activeSyncRepresentation]]; + [s appendFormat: @"%@", [[self startDate] activeSyncRepresentationWithoutSeparators]]; // EndTime -- http://msdn.microsoft.com/en-us/library/ee157945(v=exchg.80).aspx if ([self endDate]) - [s appendFormat: @"%@", [[self endDate] activeSyncRepresentation]]; + [s appendFormat: @"%@", [[self endDate] activeSyncRepresentationWithoutSeparators]]; // Timezone tz = [(iCalDateTime *)[self firstChildWithTag: @"dtstart"] timeZone]; @@ -78,14 +81,20 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. tz = [iCalTimeZone timeZoneForName: @"Europe/London"]; [s appendFormat: @"%@", [[tz activeSyncRepresentation] stringByReplacingString: @"\n" withString: @""]];; - - // Organizer and attendees + + // Organizer if ((organizer = [self organizer])) { - [s appendFormat: @"%@", [organizer rfc822Email]]; - [s appendFormat: @"%@", [organizer cn]]; + o = [organizer rfc822Email]; + if ([o length]) + [s appendFormat: @"%@", o]; + + o = [organizer cn]; + if ([o length]) + [s appendFormat: @"%@", o]; } + // Attendees attendees = [self attendees]; if ([attendees count]) @@ -101,8 +110,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. attendee = [attendees objectAtIndex: i]; [s appendFormat: @"%@", [attendee rfc822Email]]; [s appendFormat: @"%@", [attendee cn]]; - - + attendee_status = 5; if ([[attendee partStat] caseInsensitiveCompare: @"ACCEPTED"] == NSOrderedSame) attendee_status = 3; @@ -119,13 +127,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. else attendee_type = 2; - [s appendFormat: @"%d", attendee_type]; - [s appendString: @""]; - } - [s appendString: @""]; } @@ -133,17 +137,57 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. if ([[self summary] length]) [s appendFormat: @"%@", [self summary]]; + // Location + if ([[self location] length]) + [s appendFormat: @"%@", [self location]]; + + // Importance - NOT SUPPORTED - DO NOT ENABLE + //o = [self priority]; + //if ([o isEqualToString: @"9"]) + // v = 0; + //else if ([o isEqualToString: @"1"]) + // v = 2; + //else + // v = 1; + //[s appendFormat: @"%d", v]; + // UID -- http://msdn.microsoft.com/en-us/library/ee159919(v=exchg.80).aspx if ([[self uid] length]) [s appendFormat: @"%@", [self uid]]; - // Sensitivity - FIXME - [s appendFormat: @"%d", 0]; + // Sensitivity + if ([[self accessClass] isEqualToString: @"PRIVATE"]) + v = 2; + if ([[self accessClass] isEqualToString: @"CONFIDENTIAL"]) + v = 3; + else + v = 0; + + [s appendFormat: @"%d", v]; // BusyStatus -- http://msdn.microsoft.com/en-us/library/ee202290(v=exchg.80).aspx [s appendFormat: @"%d", 0]; // Reminder -- http://msdn.microsoft.com/en-us/library/ee219691(v=exchg.80).aspx + // TODO + + // Location + if ([[self location] length]) + [s appendFormat: @"%@", [self location]]; + + // Comment + o = [self comment]; + if ([o length]) + { + [s appendString: @""]; + [s appendFormat: @"%d", 1]; + [s appendFormat: @"%d", [o length]]; + [s appendFormat: @"%d", 0]; + [s appendFormat: @"%@", o]; + [s appendString: @""]; + } + + [s appendFormat: @"%d", 1]; return s; }