From 0fc3791f378b6dd4e298364a9924f9a0bb413c33 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Mon, 3 Oct 2016 10:29:30 -0400 Subject: [PATCH] Allow custom email to be one of the user's profile Fixes #3551 --- NEWS | 2 +- SoObjects/SOGo/SOGoUser.m | 17 ++++++++++++++--- UI/PreferencesUI/UIxPreferences.m | 7 +++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 4a5796d50b..52d04f778d 100644 --- a/NEWS +++ b/NEWS @@ -5,7 +5,7 @@ New features - Enhancements - - + - [web] allow custom email address to be one of the user's profile (#3551) Bug fixes - [eas] make sure we don't sleep for too long when EAS processes need interruption diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index aa6b3c5c1b..345a503478 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -607,11 +607,11 @@ - (void) _appendSystemMailAccount *encryption, *scheme, *action, *query, *customEmail, *defaultEmail, *sieveServer; NSMutableDictionary *mailAccount, *identity, *mailboxes, *receipts; NSNumber *port; - NSMutableArray *identities; - NSArray *mails; + NSMutableArray *identities, *mails; NSURL *url, *cUrl; unsigned int count, max, default_identity; NSInteger defaultPort; + NSUInteger index; [self userDefaults]; @@ -692,7 +692,7 @@ - (void) _appendSystemMailAccount defaultEmail = [NSString stringWithFormat: @"%@@%@", [self loginInDomain], [self domain]]; default_identity = 0; identities = [NSMutableArray new]; - mails = [self allEmails]; + mails = [NSMutableArray arrayWithArray: [self allEmails]]; [mailAccount setObject: [mails objectAtIndex: 0] forKey: @"name"]; replyTo = [_defaults mailReplyTo]; @@ -709,6 +709,17 @@ - (void) _appendSystemMailAccount { if ([customEmail length] == 0) customEmail = [mails objectAtIndex: 0]; + else if ([fullName length] == 0) + { + // Custom email but default fullname; if the custom email is + // one of the user's emails, remove the duplicated entry + index = [mails indexOfObject: customEmail]; + if (index != NSNotFound) + { + [mails removeObjectAtIndex: index]; + max--; + } + } if ([fullName length] == 0) { diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index 9082ddb729..b5a684626f 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -1670,10 +1670,9 @@ - (void) _extractMainIdentity: (NSDictionary *) identity value = [[identity objectForKey: @"email"] stringByTrimmingSpaces]; - /* We make sure that the "custom" value is different from the values - returned by the user directory service. */ - if ([value length] == 0 - || [[user allEmails] containsObject: value]) + /* We make sure that the "custom" value is different from the system email */ + if ([value length] == 0) + || [[user systemEmail] isEqualToString: value]) value = nil; [userDefaults setMailCustomEmail: value];