From 208ee08960910e9f708e8bcfa0f8a22f508b47de Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 10 Jul 2020 17:01:26 -0400 Subject: [PATCH] feat(mail): handle multiple mail identities Create read-only identities for email addresses for which no identity has been defined. This way, when visiting the message editor, the user will have access to all of her known email addresses. Fixes #768, fixes #4602 --- SoObjects/SOGo/SOGoUser.m | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 03a366c2a..2d7f473f5 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -784,26 +784,41 @@ [identities replaceObjectAtIndex: count withObject: identity]; } - if (![identities count]) + // Create an identity for each missing email address + max = [mails count]; + for (count = 0; count < max; count++) { - // Create an identity for each email address - max = [mails count]; - for (count = 0; count < max; count++) + BOOL noIdentityForEmail; + NSString *identityEmail; + + noIdentityForEmail = YES; + customEmail = [mails objectAtIndex: count]; + for (index = 0; noIdentityForEmail && index < [identities count]; index++) + { + identity = [identities objectAtIndex: index]; + identityEmail = [identity objectForKey: @"email"]; + if ([customEmail caseInsensitiveCompare: identityEmail] == NSOrderedSame) + { + noIdentityForEmail = NO; + } + } + + if (noIdentityForEmail) { identity = [NSMutableDictionary dictionaryWithObjectsAndKeys: fullName, @"fullName", - [mails objectAtIndex: count], @"email", nil]; - if (appendDeletegatedIdentities) + customEmail, @"email", nil]; + if (appendDeletegatedIdentities && + count == 0 && + [identities count] == 0) { - if (count == 0) - { - // First identity uses the system email -- mark it as the default - [identity setObject: [NSNumber numberWithBool: YES] forKey: @"isDefault"]; - hasDefaultIdentity = YES; - } + // First identity uses the system email -- mark it as the default and keep it editable + [identity setObject: [NSNumber numberWithBool: YES] forKey: @"isDefault"]; + hasDefaultIdentity = YES; } else { + // This additional identity should not appear in the identity manager of the Preferences [identity setObject: [NSNumber numberWithBool: YES] forKey: @"isReadOnly"]; } [identities addObject: identity];