From 2346d35d21d06730fea42dd3ac1df48b2cc05d07 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 20 Apr 2012 13:37:46 +0000 Subject: [PATCH] Monotone-Parent: 0869cb2e3bedff16fb0985d9bde1c2c2a5c80820 Monotone-Revision: ac0d12f89b420e5f1e825cebddb440417e76ce4b Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-04-20T13:37:46 --- ChangeLog | 23 ++++++++++++ SoObjects/SOGo/SOGoDomainDefaults.h | 1 + SoObjects/SOGo/SOGoDomainDefaults.m | 5 +++ SoObjects/SOGo/SOGoUser.m | 35 +++++++++++++++++-- SoObjects/SOGo/SOGoUserDefaults.h | 6 ++++ SoObjects/SOGo/SOGoUserDefaults.m | 26 ++++++++++++++ UI/PreferencesUI/UIxPreferences.h | 1 + UI/PreferencesUI/UIxPreferences.m | 30 ++++++++++++++++ UI/Templates/PreferencesUI/UIxPreferences.wox | 5 +++ UI/WebServerResources/UIxPreferences.js | 6 ++-- 10 files changed, 134 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2c9a56d94..a683825f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,24 @@ 2012-04-20 Wolfgang Sourdeau + * UI/WebServerResources/UIxPreferences.js (displayMailAccount): + disable the "fullName" and "email" input fields of the first + account only when SOGoMailCustomFromEnabled is NO. + + * UI/PreferencesUI/UIxPreferences.m (_extractMainIdentity:): the + custom values for "fullName" and "email" are now registered in the + user defaults, if "email" is different from all the values + returned by the user directory AND if SOGoMailCustomFromEnabled is + YES. + + * SoObjects/SOGo/SOGoUserDefaults.m (-setMailCustomFullName:) + (-mailCustomFullName): new accessors for the new + "SOGoMailCustomFullName" user default. + (-setMailCustomEmail:, -mailCustomEmail): new accessors for the + new "SOGoMailCustomEmail" user default. + + * SoObjects/SOGo/SOGoDomainDefaults.m (-mailCustomFromEnabled): + new getter for the "SOGoMailCustomFromEnabled" domain default. + * SoObjects/Mailer/SOGoDraftObject.m (-mimeHeaderMapWithHeaders:excluding:) take the new "replyTo" header into account. @@ -7,6 +26,10 @@ * SoObjects/SOGo/SOGoUser.m (-_appendSystemMailAccount): specify the value of "SOGoMailReplyTo" in the "replyTo" field of each identity, if present. + When "SOGoMailCustomFromEnabled" is YES and the user has set + a value for "SOGoMailCustomEmail", a first identity is created and + set at the first position in the list, based on that value and on + "SOGoMailCustomFullName". * SoObjects/SOGo/SOGoUserDefaults.m (-setMailReplyTo:) (-mailReplyTo:): accessors for the "SOGoMailReplyTo" user default. diff --git a/SoObjects/SOGo/SOGoDomainDefaults.h b/SoObjects/SOGo/SOGoDomainDefaults.h index 1175039dd..dd48e1b88 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.h +++ b/SoObjects/SOGo/SOGoDomainDefaults.h @@ -37,6 +37,7 @@ - (NSArray *) userSources; +- (BOOL) mailCustomFromEnabled; - (BOOL) mailAuxiliaryUserAccountsEnabled; - (NSString *) mailDomain; diff --git a/SoObjects/SOGo/SOGoDomainDefaults.m b/SoObjects/SOGo/SOGoDomainDefaults.m index 8cd5eebd7..a6c2520fb 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.m +++ b/SoObjects/SOGo/SOGoDomainDefaults.m @@ -98,6 +98,11 @@ return [self stringForKey: @"OCSFolderInfoURL"]; } +- (BOOL) mailCustomFromEnabled +{ + return [self boolForKey: @"SOGoMailCustomFromEnabled"]; +} + - (BOOL) mailAuxiliaryUserAccountsEnabled { return [self boolForKey: @"SOGoMailAuxiliaryUserAccountsEnabled"]; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index 6fb78c66e..75699eaae 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -577,7 +577,7 @@ - (void) _appendSystemMailAccount { NSString *fullName, *replyTo, *imapLogin, *imapServer, *signature, - *encryption, *scheme, *action, *query; + *encryption, *scheme, *action, *query, *customValue; NSMutableDictionary *mailAccount, *identity, *mailboxes, *receipts; NSNumber *port; NSMutableArray *identities; @@ -647,6 +647,37 @@ max = [mails count]; if (max > 1) max--; + + /* custom from */ + if ([[self domainDefaults] mailCustomFromEnabled]) + { + [self userDefaults]; + customValue = [_defaults mailCustomEmail]; + if ([customValue length] > 0) + { + identity = [NSMutableDictionary new]; + [identity setObject: customValue forKey: @"email"]; + + fullName = [_defaults mailCustomFullName]; + if (![fullName length]) + { + fullName = [self cn]; + if (![fullName length]) + fullName = login; + } + [identity setObject: fullName forKey: @"fullName"]; + + if ([replyTo length] > 0) + [identity setObject: replyTo forKey: @"replyTo"]; + + signature = [_defaults mailSignature]; + if (signature) + [identity setObject: signature forKey: @"signature"]; + [identities addObject: identity]; + [identity release]; + } + } + for (count = 0; count < max; count++) { identity = [NSMutableDictionary new]; @@ -749,7 +780,7 @@ NSArray *identities; identities = [[self mailAccounts] objectsForKey: @"identities" - notFoundMarker: nil]; + notFoundMarker: nil]; return [identities flattenedArray]; } diff --git a/SoObjects/SOGo/SOGoUserDefaults.h b/SoObjects/SOGo/SOGoUserDefaults.h index 2d86d3d10..0c82a6c75 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.h +++ b/SoObjects/SOGo/SOGoUserDefaults.h @@ -130,6 +130,12 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (void) setMailSignaturePlacement: (NSString *) newValue; - (NSString *) mailSignaturePlacement; +- (void) setMailCustomFullName: (NSString *) newValue; +- (NSString *) mailCustomFullName; + +- (void) setMailCustomEmail: (NSString *) newValue; +- (NSString *) mailCustomEmail; + - (void) setMailReplyTo: (NSString *) newValue; - (NSString *) mailReplyTo; diff --git a/SoObjects/SOGo/SOGoUserDefaults.m b/SoObjects/SOGo/SOGoUserDefaults.m index 34fba52f4..74ddb6e69 100644 --- a/SoObjects/SOGo/SOGoUserDefaults.m +++ b/SoObjects/SOGo/SOGoUserDefaults.m @@ -504,6 +504,8 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; - (void) setMailSignature: (NSString *) newValue { + if ([newValue length] == 0) + newValue = nil; [self setObject: newValue forKey: @"SOGoMailSignature"]; } @@ -531,6 +533,30 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return signaturePlacement; } +- (void) setMailCustomFullName: (NSString *) newValue +{ + if ([newValue length] == 0) + newValue = nil; + [self setObject: newValue forKey: @"SOGoMailCustomFullName"]; +} + +- (NSString *) mailCustomFullName +{ + return [self stringForKey: @"SOGoMailCustomFullName"]; +} + +- (void) setMailCustomEmail: (NSString *) newValue +{ + if ([newValue length] == 0) + newValue = nil; + [self setObject: newValue forKey: @"SOGoMailCustomEmail"]; +} + +- (NSString *) mailCustomEmail +{ + return [self stringForKey: @"SOGoMailCustomEmail"]; +} + - (void) setMailReplyTo: (NSString *) newValue { if ([newValue length] == 0) diff --git a/UI/PreferencesUI/UIxPreferences.h b/UI/PreferencesUI/UIxPreferences.h index 54465623b..cedb0263a 100644 --- a/UI/PreferencesUI/UIxPreferences.h +++ b/UI/PreferencesUI/UIxPreferences.h @@ -45,6 +45,7 @@ NSArray *daysOfWeek, *daysBetweenResponsesList; NSArray *sieveFilters; NSMutableDictionary *vacationOptions, *forwardOptions; + BOOL mailCustomFromEnabled; BOOL hasChanged; } diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index f49b40779..c1a3bd1ba 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -106,6 +106,8 @@ forwardOptions = [NSMutableDictionary new]; } + mailCustomFromEnabled = [dd mailCustomFromEnabled]; + hasChanged = NO; } @@ -1285,6 +1287,29 @@ if (!value) value = @""; [userDefaults setMailSignature: value]; + + if (mailCustomFromEnabled) + { + 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]) + { + [userDefaults setMailCustomEmail: nil]; + [userDefaults setMailCustomFullName: nil]; + } + else + { + [userDefaults setMailCustomEmail: value]; + value = [[identity objectForKey: @"fullName"] + stringByTrimmingSpaces]; + [userDefaults setMailCustomFullName: value]; + } + } + value = [[identity objectForKey: @"replyTo"] stringByTrimmingSpaces]; [userDefaults setMailReplyTo: value]; @@ -1528,4 +1553,9 @@ return [accounts jsonRepresentation]; } +- (NSString *) mailCustomFromEnabled +{ + return (mailCustomFromEnabled ? @"true" : @"false"); +} + @end diff --git a/UI/Templates/PreferencesUI/UIxPreferences.wox b/UI/Templates/PreferencesUI/UIxPreferences.wox index c7c863c91..ec86d3afa 100644 --- a/UI/Templates/PreferencesUI/UIxPreferences.wox +++ b/UI/Templates/PreferencesUI/UIxPreferences.wox @@ -318,6 +318,11 @@ + + +