From b44bf86164894df3f07e1dc7c11ba7fdad081a0f Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 26 Oct 2016 15:42:50 -0400 Subject: [PATCH] Improve validation of mail account delegators --- NEWS | 1 + SoObjects/Mailer/SOGoMailAccount.m | 6 ++--- SoObjects/SOGo/SOGoUser.m | 40 ++++++++++++++++++++++++------ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/NEWS b/NEWS index f9aa9db55..dce80ac36 100644 --- a/NEWS +++ b/NEWS @@ -16,6 +16,7 @@ Bug fixes - [web] only show the organizer field of an IMIP REPLY if one is defined - [web] fixed saving the note of a card (#3849) - [web] fixed support for recurrent tasks + - [web] improved validation of mail account delegators - [eas] improve handling of email folders without a parent - [eas] never send IMIP reply when the "initiator" is Outlook 2013/2016 - [core] only consider SMTP addresses for AD's proxyAddresses (#3842) diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 7b3b426c3..16464f291 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -1134,11 +1134,9 @@ static NSString *inboxFolderName = @"INBOX"; { currentDelegate = [oldDelegates objectAtIndex: count]; delegateUser = [SOGoUser userWithLogin: currentDelegate]; + [delegates removeObject: currentDelegate]; if (delegateUser) - { - [delegates removeObject: currentDelegate]; - [delegateUser removeMailDelegator: owner]; - } + [delegateUser removeMailDelegator: owner]; } [self _setDelegates: delegates]; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 0c0bc0ae3..72ffa1744 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -634,8 +634,9 @@ NSUInteger index; [self userDefaults]; + [self userSettings]; - mailSettings = [[self userSettings] objectForKey: @"Mail"]; + mailSettings = [_settings objectForKey: @"Mail"]; mailAccount = [NSMutableDictionary new]; // 1. login @@ -800,18 +801,43 @@ delegators = [mailSettings objectForKey: @"DelegateFrom"]; if (delegators) { - NSDictionary *delegatorAccount; - SOGoUser *delegator; + BOOL dirty; + NSDictionary *delegatorAccount, *delegatorSettings; + NSMutableArray *validDelegators; + NSString *delegatorLogin; + SOGoUser *delegatorUser; + dirty = NO; + validDelegators = [NSMutableArray array]; max = [delegators count]; for (count = 0; count < max; count++) { - delegator = [SOGoUser userWithLogin: [delegators objectAtIndex: count]]; - if (delegator) + // 1. Verify if delegator is valid + delegatorLogin = [delegators objectAtIndex: count]; + delegatorUser = [SOGoUser userWithLogin: delegatorLogin]; + if (delegatorUser) { - delegatorAccount = [[delegator mailAccountsWithDelegatedIdentities: NO] objectAtIndex: 0]; - [identities addObjectsFromArray: [delegatorAccount objectForKey: @"identities"]]; + // 2. Verify if delegator still delegates to user + delegatorSettings = [[delegatorUser userSettings] objectForKey: @"Mail"]; + delegates = [delegatorSettings objectForKey: @"DelegateTo"]; + if ([delegates containsObject: [self login]]) + { + [validDelegators addObject: delegatorLogin]; + delegatorAccount = [[delegatorUser mailAccountsWithDelegatedIdentities: NO] objectAtIndex: 0]; + [identities addObjectsFromArray: [delegatorAccount objectForKey: @"identities"]]; + } + else + dirty = YES; } + else + dirty = YES; + } + + if (dirty) + { + [mailSettings setObject: validDelegators + forKey: @"DelegateFrom"]; + [_settings synchronize]; } } }