From 0fffe85b9b985d63519fd6dc30d757fd4e537169 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 13 Jan 2012 17:20:58 +0000 Subject: [PATCH] See ChangeLog. Monotone-Parent: ef272f61d0caedee9632010cd4b3ce928a2da43e Monotone-Revision: 6ed6359462b26ed18e75361bf078fb93cda23519 Monotone-Author: flachapelle@inverse.ca Monotone-Date: 2012-01-13T17:20:58 --- ChangeLog | 21 ++++++++++ .../Appointments/SOGoAppointmentFolder.m | 21 ++++++++-- SoObjects/Appointments/SOGoFreeBusyObject.h | 3 +- SoObjects/Appointments/SOGoFreeBusyObject.m | 40 ++++++++++++++----- SoObjects/Appointments/iCalPerson+SOGo.h | 1 + SoObjects/Appointments/iCalPerson+SOGo.m | 22 ++++++++++ 6 files changed, 92 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31b1f9ec3..f2807b41c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2012-01-13 Francis Lachapelle + + * SoObjects/Appointments/SOGoAppointmentFolder.m + (-caldavFreeBusyRequestOnRecipient:withUID:andOrganizer:from:to:): + if the recipient is not associated to a user (from an + authentication source), verify if it is a contact (from an + addressbook source). If it is, SOGoFreeBusyObject will take care + of fetching the freebusy information if the contact is associated + to a MS Exchange server. + + * SoObjects/Appointments/SOGoFreeBusyObject.m + (-iCalPersonWithUID:): if no user is found from an authentication + source, verify if it matches a contact from an addressbook + source. + (-contentAsStringWithMethod:andUID:andOrganizer:andContact:from:to:): + added new parameter "contactID". + + * SoObjects/Appointments/iCalPerson+SOGo.m (-contactIDInContext:): + new method that tries to associated the person's email address to + a contact ID. + 2012-01-12 Francis Lachapelle * SoObjects/SOGo/SOGoSource.h (-bindDN, -bindPassword) diff --git a/SoObjects/Appointments/SOGoAppointmentFolder.m b/SoObjects/Appointments/SOGoAppointmentFolder.m index c171bc3d6..b9a3f8700 100644 --- a/SoObjects/Appointments/SOGoAppointmentFolder.m +++ b/SoObjects/Appointments/SOGoAppointmentFolder.m @@ -1,5 +1,5 @@ /* - Copyright (C) 2007-2011 Inverse inc. + Copyright (C) 2007-2012 Inverse inc. Copyright (C) 2004-2005 SKYRIX Software AG This file is part of SOGo. @@ -1820,7 +1820,7 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir to: (NSCalendarDate *) to { SOGoUser *user; - NSString *login, *calendarData; + NSString *login, *contactId, *calendarData; SOGoFreeBusyObject *freebusy; login = [recipient uid]; @@ -1833,8 +1833,21 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir calendarData = [freebusy contentAsStringWithMethod: @"REPLY" andUID: uid andOrganizer: organizer + andContact: nil from: start to: to]; } + else if ((contactId = [recipient contactIDInContext: context])) + { + user = [context activeUser]; + freebusy = [[user homeFolderInContext: context] + freeBusyObject: @"freebusy.ifb" + inContext: context]; + calendarData = [freebusy contentAsStringWithMethod: @"REPLY" + andUID: uid + andOrganizer: organizer + andContact: contactId + from: start to: to]; + } else { user = nil; @@ -1947,8 +1960,8 @@ firstInstanceCalendarDateRange: (NGCalendarDateRange *) fir tags = [self caldavFreeBusyRequest: (iCalFreeBusy *) element]; else if ([tag isEqualToString: @"VEVENT"]) tags = [self caldavEventRequest: (iCalEvent *) element - withContent: iCalString - from: originator to: recipients]; + withContent: iCalString + from: originator to: recipients]; else tags = nil; diff --git a/SoObjects/Appointments/SOGoFreeBusyObject.h b/SoObjects/Appointments/SOGoFreeBusyObject.h index e3644a54c..77b2f53ec 100644 --- a/SoObjects/Appointments/SOGoFreeBusyObject.h +++ b/SoObjects/Appointments/SOGoFreeBusyObject.h @@ -48,6 +48,7 @@ - (NSString *) contentAsStringWithMethod: (NSString *) method andUID: (NSString *) uid andOrganizer: (iCalPerson *) organizer + andContact: (NSString *) contactID from: (NSCalendarDate *) _startDate to: (NSCalendarDate *) _endDate; @@ -55,7 +56,7 @@ to: (NSCalendarDate *) _endDate; - (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) startDate to: (NSCalendarDate *) endDate - forUser: (NSString *) uid; + forContact: (NSString *) uid; @end #endif /* __Appointments_SOGoFreeBusyObject_H_ */ diff --git a/SoObjects/Appointments/SOGoFreeBusyObject.m b/SoObjects/Appointments/SOGoFreeBusyObject.m index af02c2ea1..87bd989ae 100644 --- a/SoObjects/Appointments/SOGoFreeBusyObject.m +++ b/SoObjects/Appointments/SOGoFreeBusyObject.m @@ -61,10 +61,20 @@ { iCalPerson *person; SOGoUserManager *um; + NSString *domain; NSDictionary *contactInfos; + NSArray *contacts; um = [SOGoUserManager sharedUserManager]; contactInfos = [um contactInfosForUserWithUIDorEmail: uid]; + if (contactInfos == nil) + { + domain = [[context activeUser] domain]; + [um fetchContactsMatching: uid inDomain: domain]; + contacts = [um fetchContactsMatching: uid inDomain: domain]; + if ([contacts count] == 1) + contactInfos = [contacts lastObject]; + } /* iCal.app compatibility: - don't add "cn"; */ @@ -96,6 +106,7 @@ withMethod: (NSString *) method andUID: (NSString *) uid andOrganizer: (iCalPerson *) organizer + andContact: (NSString *) contactID from: (NSCalendarDate *) _startDate to: (NSCalendarDate *) _endDate { @@ -125,7 +136,10 @@ [freebusy setUid: uid]; if (organizer) [freebusy setOrganizer: organizer]; - [freebusy addToAttendees: [self iCalPersonWithUID: login]]; + if (contactID) + [freebusy addToAttendees: [self iCalPersonWithUID: contactID]]; + else + [freebusy addToAttendees: [self iCalPersonWithUID: login]]; [freebusy setTimeStampAsDate: [NSCalendarDate calendarDate]]; [freebusy setStartDate: _startDate]; [freebusy setEndDate: _endDate]; @@ -223,16 +237,19 @@ - (NSString *) contentAsStringWithMethod: (NSString *) method andUID: (NSString *) UID andOrganizer: (iCalPerson *) organizer + andContact: (NSString *) contactID from: (NSCalendarDate *) _startDate to: (NSCalendarDate *) _endDate { NSArray *infos; - infos = [self fetchFreeBusyInfosFrom: _startDate to: _endDate]; + infos = [self fetchFreeBusyInfosFrom: _startDate to: _endDate + forContact: contactID]; return [self iCalStringForFreeBusyInfos: infos withMethod: method andUID: UID andOrganizer: organizer + andContact: contactID from: _startDate to: _endDate]; } @@ -241,6 +258,7 @@ { return [self contentAsStringWithMethod: nil andUID: nil andOrganizer: nil + andContact: nil from: _startDate to: _endDate]; } @@ -251,31 +269,31 @@ * (currently limited to a Microsoft Exchange server with Web Services enabled). * @param startDate the beginning of the covered period * @param endDate the ending of the covered period - * @param uid the ID of the user within the current domain + * @param uid the ID of the contact within the current domain * @return an array of dictionaries containing the start and end dates of each busy period * @see MSExchangeFreeBusy.m */ - (NSArray *) fetchFreeBusyInfosFrom: (NSCalendarDate *) startDate to: (NSCalendarDate *) endDate - forUser: (NSString *) uid + forContact: (NSString *) uid { if ([uid length]) { SOGoUserManager *um; - NSArray *users; + NSArray *contacts; NSString *domain, *email; - NSDictionary *user; + NSDictionary *contact; MSExchangeFreeBusy *exchangeFreeBusy; NSObject *source; um = [SOGoUserManager sharedUserManager]; domain = [[context activeUser] domain]; - users = [um fetchContactsMatching: uid inDomain: domain]; - if ([users count] == 1) + contacts = [um fetchContactsMatching: uid inDomain: domain]; + if ([contacts count] == 1) { - user = [users lastObject]; - email = [user valueForKey: @"c_email"]; - source = [user objectForKey: @"source"]; + contact = [contacts lastObject]; + email = [contact valueForKey: @"c_email"]; + source = [contact objectForKey: @"source"]; if ([email length]) { exchangeFreeBusy = [[MSExchangeFreeBusy alloc] init]; diff --git a/SoObjects/Appointments/iCalPerson+SOGo.h b/SoObjects/Appointments/iCalPerson+SOGo.h index 0d5c5be4d..184e67542 100644 --- a/SoObjects/Appointments/iCalPerson+SOGo.h +++ b/SoObjects/Appointments/iCalPerson+SOGo.h @@ -31,6 +31,7 @@ - (NSString *) mailAddress; - (NSString *) uid; +- (NSString *) contactIDInContext: (WOContext *) context; - (BOOL) hasSentBy; - (NSString *) sentBy; diff --git a/SoObjects/Appointments/iCalPerson+SOGo.m b/SoObjects/Appointments/iCalPerson+SOGo.m index 724b9df70..e0d07e956 100644 --- a/SoObjects/Appointments/iCalPerson+SOGo.m +++ b/SoObjects/Appointments/iCalPerson+SOGo.m @@ -22,6 +22,7 @@ #import #import +#import #import "iCalPerson+SOGo.h" @@ -51,6 +52,27 @@ static SOGoUserManager *um = nil; return [um getUIDForEmail: [self rfc822Email]]; } +- (NSString *) contactIDInContext: (WOContext *) context +{ + NSString *domain, *uid; + NSArray *contacts; + NSDictionary *contact; + + if (!um) + um = [SOGoUserManager sharedUserManager]; + + uid = nil; + domain = [[context activeUser] domain]; + contacts = [um fetchContactsMatching: [self rfc822Email] inDomain: domain]; + if ([contacts count] == 1) + { + contact = [contacts lastObject]; + uid = [contact valueForKey: @"c_uid"]; + } + + return uid; +} + - (BOOL) hasSentBy { NSString *mail;