From 3796009eca93b2a5c8db706aa75bedc944d67bbe Mon Sep 17 00:00:00 2001 From: Ludovic Marcotte Date: Tue, 3 Nov 2020 07:47:53 -0500 Subject: [PATCH] fix(eas): handle SENT-BY in delegated calendars --- ActiveSync/SOGoActiveSyncDispatcher+Sync.m | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m index b32e45360..48da086be 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher+Sync.m +++ b/ActiveSync/SOGoActiveSyncDispatcher+Sync.m @@ -54,6 +54,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import +#import #import #import @@ -297,6 +298,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NSMutableDictionary *folderMetadata, *dateCache, *syncCache, *uidCache, *allValues; NSString *clientId, *serverId, *easId; NSArray *additions, *roles; + SOGoUser *ownerUser; id anAddition, sogoObject, o; BOOL is_new; @@ -456,6 +458,16 @@ FIXME else { [o takeActiveSyncValues: allValues inContext: context]; + // Handle situation were Alice creates an event in Bob's calendar. + // Bob should be the organizer, and Alice the SENT-BY. + ownerUser = [SOGoUser userWithLogin: [sogoObject ownerInContext: context]]; + if (theFolderType == ActiveSyncEventFolder && ![o userIsOrganizer: ownerUser] && [[context activeUser] hasEmail: [[o organizer] rfc822Email]]) + { + [[o organizer] setCn: [ownerUser cn]]; + [[o organizer] setEmail: [[ownerUser allEmails] objectAtIndex: 0]]; + [[o organizer] setSentBy: [NSString stringWithFormat: @"\"MAILTO:%@\"", [[[context activeUser] allEmails] objectAtIndex: 0]]]; + } + [sogoObject setIsNew: is_new]; if (theFolderType == ActiveSyncEventFolder) @@ -570,6 +582,7 @@ FIXME NSArray *changes, *a, *roles; id aChange, o, sogoObject; NSMutableDictionary *folderMetadata, *syncCache, *uidCache; + SOGoUser *ownerUser; int i; @@ -690,6 +703,16 @@ FIXME if (theFolderType == ActiveSyncEventFolder) { + // Handle situation were Alice creates an event in Bob's calendar. + // Bob should be the organizer, and Alice the SENT-BY. + ownerUser = [SOGoUser userWithLogin: [sogoObject ownerInContext: context]]; + if (theFolderType == ActiveSyncEventFolder && ![o userIsOrganizer: ownerUser] && [[context activeUser] hasEmail: [[o organizer] rfc822Email]]) + { + [[o organizer] setCn: [ownerUser cn]]; + [[o organizer] setEmail: [[ownerUser allEmails] objectAtIndex: 0]]; + [[o organizer] setSentBy: [NSString stringWithFormat: @"\"MAILTO:%@\"", [[[context activeUser] allEmails] objectAtIndex: 0]]]; + } + [sogoObject saveComponent: o force: YES]; if ([sogoObject resourceHasAutoAccepted]) [objectsToTouch addObject: sogoObject];