diff --git a/ActiveSync/iCalEvent+ActiveSync.m b/ActiveSync/iCalEvent+ActiveSync.m index 68ce307e6..3bfa99b9d 100644 --- a/ActiveSync/iCalEvent+ActiveSync.m +++ b/ActiveSync/iCalEvent+ActiveSync.m @@ -48,6 +48,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import +#import + #include "iCalRecurrenceRule+ActiveSync.h" #include "iCalTimeZone+ActiveSync.h" #include "NSDate+ActiveSync.h" @@ -55,6 +57,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. @implementation iCalEvent (ActiveSync) +- (int) _attendeeStatus: (iCalPerson *) attendee +{ + int attendee_status; + + attendee_status = 5; + if ([[attendee partStat] caseInsensitiveCompare: @"ACCEPTED"] == NSOrderedSame) + attendee_status = 3; + else if ([[attendee partStat] caseInsensitiveCompare: @"DECLINED"] == NSOrderedSame) + attendee_status = 4; + else if ([[attendee partStat] caseInsensitiveCompare: @"TENTATIVE"] == NSOrderedSame) + attendee_status = 2; + + return attendee_status; +} + - (NSString *) activeSyncRepresentationInContext: (WOContext *) context { NSMutableString *s; @@ -103,17 +120,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. o = [organizer cn]; if ([o length]) [s appendFormat: @"%@", o]; - - - // This depends on the 'NEEDS-ACTION' parameter. - // This will trigger the SendMail command - [s appendFormat: @"%d", 1]; - [s appendFormat: @"%d", 5]; - [s appendFormat: @"%d", 3]; - [s appendFormat: @"%d", 1]; - - // BusyStatus -- http://msdn.microsoft.com/en-us/library/ee202290(v=exchg.80).aspx - [s appendFormat: @"%d", 2]; } } @@ -122,7 +128,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. if ([attendees count]) { - int i, attendee_type, attendee_status; + int i, attendee_status, attendee_type; [s appendString: @""]; @@ -134,13 +140,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [s appendFormat: @"%@", [attendee rfc822Email]]; [s appendFormat: @"%@", [attendee cn]]; - attendee_status = 5; - if ([[attendee partStat] caseInsensitiveCompare: @"ACCEPTED"] == NSOrderedSame) - attendee_status = 3; - else if ([[attendee partStat] caseInsensitiveCompare: @"DECLINED"] == NSOrderedSame) - attendee_status = 4; - else if ([[attendee partStat] caseInsensitiveCompare: @"TENTATIVE"] == NSOrderedSame) - attendee_status = 2; + attendee_status = [self _attendeeStatus: attendee]; [s appendFormat: @"%d", attendee_status]; @@ -155,6 +155,26 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. } [s appendString: @""]; } + + // This depends on the 'NEEDS-ACTION' parameter. + // This will trigger the SendMail command + if ([self userIsAttendee: [context activeUser]]) + { + iCalPerson *attendee; + + int attendee_status; + + attendee = [self userAsAttendee: [context activeUser]]; + attendee_status = [self _attendeeStatus: attendee]; + + [s appendFormat: @"%d", 1]; + [s appendFormat: @"%d", attendee_status]; + [s appendFormat: @"%d", 3]; + [s appendFormat: @"%d", 1]; + + // BusyStatus -- http://msdn.microsoft.com/en-us/library/ee202290(v=exchg.80).aspx + [s appendFormat: @"%d", 2]; + } // Subject -- http://msdn.microsoft.com/en-us/library/ee157192(v=exchg.80).aspx if ([[self summary] length]) @@ -382,64 +402,71 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. [rule takeActiveSyncValues: o inContext: context]; } - // Organizer - if ((o = [theValues objectForKey: @"Organizer_Email"])) + // Organizer - we don't touch the value unless we're the organizer + if ([self userIsOrganizer: [context activeUser]]) { - iCalPerson *person; - - person = [iCalPerson elementWithTag: @"organizer"]; - [person setEmail: o]; - [person setCn: [theValues objectForKey: @"Organizer_Name"]]; - [person setPartStat: @"ACCEPTED"]; - [self setOrganizer: person]; + if ((o = [theValues objectForKey: @"Organizer_Email"])) + { + iCalPerson *person; + + person = [iCalPerson elementWithTag: @"organizer"]; + [person setEmail: o]; + [person setCn: [theValues objectForKey: @"Organizer_Name"]]; + [person setPartStat: @"ACCEPTED"]; + [self setOrganizer: person]; + } } - // Attendees - if ((o = [theValues objectForKey: @"Attendees"])) + // Attendees - we don't touch the values if we're an attendee. This is gonna + // be done automatically by the ActiveSync client when invoking MeetingResponse. + if ([self userIsAttendee: [context activeUser]]) { - NSMutableArray *attendees; - NSDictionary *attendee; - iCalPerson *person; - int status, i; - - attendees = [NSMutableArray array]; - - for (i = 0; i < [o count]; i++) + if ((o = [theValues objectForKey: @"Attendees"])) { - // Each attendee has is a dictionary similar to this: - // { "Attendee_Email" = "sogo3@example.com"; "Attendee_Name" = "Wolfgang Fritz"; "Attendee_Status" = 5; "Attendee_Type" = 1; } - attendee = [o objectAtIndex: i]; - - person = [iCalPerson elementWithTag: @"attendee"]; - [person setCn: [attendee objectForKey: @"Attendee_Name"]]; - [person setEmail: [attendee objectForKey: @"Attendee_Email"]]; + NSMutableArray *attendees; + NSDictionary *attendee; + iCalPerson *person; + int status, i; - status = [[attendee objectForKey: @"Attendee_Status"] intValue]; - - switch (status) + attendees = [NSMutableArray array]; + + for (i = 0; i < [o count]; i++) { - case 2: - [person setPartStat: @"TENTATIVE"]; - break; - case 3: - [person setPartStat: @"ACCEPTED"]; - break; - case 4: - [person setPartStat: @"DECLINED"]; - break; - case 0: - case 5: - default: - [person setPartStat: @"NEEDS-ACTION"]; - break; + // Each attendee has is a dictionary similar to this: + // { "Attendee_Email" = "sogo3@example.com"; "Attendee_Name" = "Wolfgang Fritz"; "Attendee_Status" = 5; "Attendee_Type" = 1; } + attendee = [o objectAtIndex: i]; + + person = [iCalPerson elementWithTag: @"attendee"]; + [person setCn: [attendee objectForKey: @"Attendee_Name"]]; + [person setEmail: [attendee objectForKey: @"Attendee_Email"]]; + + status = [[attendee objectForKey: @"Attendee_Status"] intValue]; + + switch (status) + { + case 2: + [person setPartStat: @"TENTATIVE"]; + break; + case 3: + [person setPartStat: @"ACCEPTED"]; + break; + case 4: + [person setPartStat: @"DECLINED"]; + break; + case 0: + case 5: + default: + [person setPartStat: @"NEEDS-ACTION"]; + break; + } + + // FIXME: handle Attendee_Type + + [attendees addObject: person]; } - // FIXME: handle Attendee_Type - - [attendees addObject: person]; + [self setAttendees: attendees]; } - - [self setAttendees: attendees]; } }