diff --git a/ChangeLog b/ChangeLog index 7b1fda531..95af587ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2008-02-07 Wolfgang Sourdeau + + * UI/PreferencesUI/UIxPreferences.m ([UIxPreferences + -setSignature:newSignature]): invoke -[SOGoUser saveMailAccounts] + + * SoObjects/SOGo/SOGoUser.m ([SOGoUser -defaultIdentity]): method + moved from UIxPreferences.m. + ([SOGoUser -saveMailAccounts]): new methods that save the + "MailAccounts" preference in the user settings. + + * SoObjects/SOGo/LDAPUserManager.m ([LDAPUserManager + +initialize]): issue a warning whenever "SOGoDefaultMailDomain" + is not configured in the user defaults, setting it to "localhost" + by default. + ([LDAPUserManager +defaultMailDomainIsConfigured]): new method + that returns whether "SOGoDefaultMailDomain" is configured. + 2008-02-06 Wolfgang Sourdeau * SoObjects/SOGo/SOGoGCSFolder.m ([SOGoGCSFolder -ocsFolder]): diff --git a/SoObjects/SOGo/LDAPUserManager.h b/SoObjects/SOGo/LDAPUserManager.h index 5ab95c923..319f6ca12 100644 --- a/SoObjects/SOGo/LDAPUserManager.h +++ b/SoObjects/SOGo/LDAPUserManager.h @@ -43,6 +43,8 @@ + (id) sharedUserManager; ++ (BOOL) defaultMailDomainIsConfigured; + - (NSArray *) sourceIDs; - (NSDictionary *) metadataForSourceID: (NSString *) sourceID; - (NSArray *) authenticationSourceIDs; diff --git a/SoObjects/SOGo/LDAPUserManager.m b/SoObjects/SOGo/LDAPUserManager.m index 0e1168852..c71619908 100644 --- a/SoObjects/SOGo/LDAPUserManager.m +++ b/SoObjects/SOGo/LDAPUserManager.m @@ -26,12 +26,14 @@ #import #import #import +#import #import "NSArray+Utilities.h" #import "LDAPSource.h" #import "LDAPUserManager.h" static NSString *defaultMailDomain = nil; +static BOOL defaultMailDomainIsConfigured = NO; @implementation LDAPUserManager @@ -44,7 +46,20 @@ static NSString *defaultMailDomain = nil; { defaultMailDomain = [ud stringForKey: @"SOGoDefaultMailDomain"]; [defaultMailDomain retain]; + defaultMailDomainIsConfigured = YES; } + if (!defaultMailDomain) + { + [self warnWithFormat: + @"no domain specified for SOGoDefaultMailDomain," + @" value set to 'localhost'"]; + defaultMailDomain = @"localhost"; + } +} + ++ (BOOL) defaultMailDomainIsConfigured +{ + return defaultMailDomainIsConfigured; } + (id) sharedUserManager diff --git a/SoObjects/SOGo/SOGoUser.h b/SoObjects/SOGo/SOGoUser.h index bc0513988..1c580e57a 100644 --- a/SoObjects/SOGo/SOGoUser.h +++ b/SoObjects/SOGo/SOGoUser.h @@ -77,6 +77,9 @@ extern NSString *SOGoWeekStartFirstFullWeek; + (SOGoUser *) userWithLogin: (NSString *) login roles: (NSArray *) roles; + +- (void) setPrimaryRoles: (NSArray *) newRoles; + - (void) setCurrentPassword: (NSString *) newPassword; - (NSString *) currentPassword; @@ -117,11 +120,14 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (NSArray *) mailAccounts; - (NSArray *) allIdentities; - (NSDictionary *) primaryIdentity; +- (NSMutableDictionary *) defaultIdentity; - (NSString *) messageForwarding; - (NSString *) messageCheck; - (NSString *) signature; +- (void) saveMailAccounts; + - (BOOL) isSuperUser; /* module access */ diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index b0f1c6b71..81187c6d1 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -29,6 +29,7 @@ #import #import #import +#import #import "AgenorUserDefaults.h" #import "LDAPUserManager.h" @@ -42,6 +43,7 @@ static NSTimeZone *serverTimeZone = nil; static NSString *fallbackIMAP4Server = nil; +static BOOL fallbackIsConfigured = NO; static NSString *defaultLanguage = nil; static NSArray *superUsernames = nil; static NSURL *AgenorProfileURL = nil; @@ -92,6 +94,16 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; if (!fallbackIMAP4Server) ASSIGN (fallbackIMAP4Server, [ud stringForKey: @"SOGoFallbackIMAP4Server"]); + if (fallbackIMAP4Server) + fallbackIsConfigured = YES; + else + { + [self warnWithFormat: + @"no server specified for SOGoFallbackIMAP4Server," + @" value set to 'localhost'"]; + fallbackIMAP4Server = @"localhost"; + } + if (!defaultLanguage) { ASSIGN (defaultLanguage, [ud stringForKey: @"SOGoDefaultLanguage"]); @@ -122,6 +134,11 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return lng; } ++ (NSString *) fallbackIMAP4Server +{ + return fallbackIMAP4Server; +} + + (SOGoUser *) userWithLogin: (NSString *) newLogin roles: (NSArray *) newRoles { @@ -176,6 +193,7 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; realUID = [[um contactInfosForUserWithUIDorEmail: newLogin] objectForKey: @"c_uid"]; } + if (realUID) self = [super initWithLogin: realUID roles: newRoles]; else @@ -284,6 +302,45 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return cn; } +- (NSMutableDictionary *) defaultIdentity +{ + NSMutableDictionary *currentIdentity, *defaultIdentity; + NSEnumerator *identities; + + defaultIdentity = nil; + + identities = [[self allIdentities] objectEnumerator]; + while (!defaultIdentity + && (currentIdentity = [identities nextObject])) + if ([[currentIdentity objectForKey: @"isDefault"] boolValue]) + defaultIdentity = currentIdentity; + + return defaultIdentity; +} + +- (void) saveMailAccounts +{ + BOOL doSave; + + doSave = YES; + if (!fallbackIsConfigured) + { + [self logWithFormat: @"'SOGoFallbackIMAP4Server' is not set"]; + doSave = NO; + } + if (![LDAPUserManager defaultMailDomainIsConfigured]) + { + [self logWithFormat: @"'SOGoDefaultMailDomain' is not set"]; + doSave = NO; + } + if (doSave) + [userDefaults setObject: [self mailAccounts] + forKey: @"MailAccounts"]; + else + [self logWithFormat: @"saving mail accounts is disabled until the" + @" variable(s) mentionned above are configured"]; +} + // - (NSString *) primaryMailServer // { // return [[self userManager] getServerForUID: [self login]]; diff --git a/UI/PreferencesUI/UIxPreferences.m b/UI/PreferencesUI/UIxPreferences.m index c5f5bac42..37af5acb6 100644 --- a/UI/PreferencesUI/UIxPreferences.m +++ b/UI/PreferencesUI/UIxPreferences.m @@ -486,33 +486,16 @@ static BOOL shouldDisplayPasswordChange = NO; return [(NSDictionary *) item keysWithFormat: @"%{fullName} <%{email}>"]; } -- (NSMutableDictionary *) defaultIdentity -{ - NSMutableDictionary *currentIdentity, *defaultIdentity; - NSEnumerator *identities; - - defaultIdentity = nil; - - identities = [[user allIdentities] objectEnumerator]; - while (!defaultIdentity - && (currentIdentity = [identities nextObject])) - if ([[currentIdentity objectForKey: @"isDefault"] boolValue]) - defaultIdentity = currentIdentity; - - return defaultIdentity; -} - - (NSString *) signature { - return [[self defaultIdentity] objectForKey: @"signature"]; + return [[user defaultIdentity] objectForKey: @"signature"]; } - (void) setSignature: (NSString *) newSignature { - [[self defaultIdentity] setObject: newSignature + [[user defaultIdentity] setObject: newSignature forKey: @"signature"]; - [userDefaults setObject: [user mailAccounts] - forKey: @"MailAccounts"]; + [user saveMailAccounts]; } - (id ) defaultAction