2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2005 SKYRIX Software AG
|
|
|
|
|
|
|
|
This file is part of OpenGroupware.org.
|
|
|
|
|
|
|
|
OGo is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License as published by the
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
later version.
|
|
|
|
|
|
|
|
OGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with OGo; see the file COPYING. If not, write to the
|
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2007-04-17 16:34:31 +02:00
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSNull.h>
|
|
|
|
#import <Foundation/NSTimeZone.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-08-15 22:30:37 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2007-04-17 16:34:31 +02:00
|
|
|
#import <NGObjWeb/WOApplication.h>
|
2007-08-22 17:16:35 +02:00
|
|
|
#import <NGObjWeb/WOContext.h>
|
|
|
|
#import <NGObjWeb/WORequest.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
#import <NGObjWeb/SoObject.h>
|
2007-04-17 16:34:31 +02:00
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
2008-02-07 17:53:19 +01:00
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
#import "AgenorUserDefaults.h"
|
|
|
|
#import "LDAPUserManager.h"
|
2008-01-16 19:57:58 +01:00
|
|
|
#import "NSArray+Utilities.h"
|
|
|
|
#import "SOGoCache.h"
|
2007-06-19 20:06:18 +02:00
|
|
|
#import "SOGoDateFormatter.h"
|
|
|
|
#import "SOGoObject.h"
|
2007-04-17 16:34:31 +02:00
|
|
|
#import "SOGoPermissions.h"
|
2007-06-01 07:10:07 +02:00
|
|
|
|
|
|
|
#import "SOGoUser.h"
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
static NSTimeZone *serverTimeZone = nil;
|
2007-05-09 21:23:09 +02:00
|
|
|
static NSString *fallbackIMAP4Server = nil;
|
2008-02-07 17:53:19 +01:00
|
|
|
static BOOL fallbackIsConfigured = NO;
|
2007-05-30 22:20:02 +02:00
|
|
|
static NSString *defaultLanguage = nil;
|
2007-10-19 21:03:21 +02:00
|
|
|
static NSArray *superUsernames = nil;
|
2007-05-09 21:23:09 +02:00
|
|
|
static NSURL *AgenorProfileURL = nil;
|
2007-06-22 21:58:31 +02:00
|
|
|
static BOOL acceptAnyUser = NO;
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2007-06-19 20:06:18 +02:00
|
|
|
NSString *SOGoWeekStartHideWeekNumbers = @"HideWeekNumbers";
|
|
|
|
NSString *SOGoWeekStartJanuary1 = @"January1";
|
|
|
|
NSString *SOGoWeekStartFirst4DayWeek = @"First4DayWeek";
|
|
|
|
NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek";
|
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
@interface NSObject (SOGoRoles)
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSArray *) rolesOfUser: (NSString *) uid;
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
@end
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-10-18 19:17:29 +02:00
|
|
|
@implementation SoUser (SOGoExtension)
|
|
|
|
|
|
|
|
- (NSString *) language
|
|
|
|
{
|
2007-10-23 00:24:08 +02:00
|
|
|
return [SOGoUser language];
|
2007-10-18 19:17:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@implementation SOGoUser
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
2007-10-19 21:03:21 +02:00
|
|
|
NSString *tzName;
|
2007-05-09 21:23:09 +02:00
|
|
|
NSUserDefaults *ud;
|
|
|
|
NSString *profileURL;
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
ud = [NSUserDefaults standardUserDefaults];
|
2007-04-11 21:07:54 +02:00
|
|
|
if (!serverTimeZone)
|
|
|
|
{
|
2007-05-09 21:23:09 +02:00
|
|
|
tzName = [ud stringForKey: @"SOGoServerTimeZone"];
|
2007-04-11 21:07:54 +02:00
|
|
|
if (!tzName)
|
2007-06-01 07:10:07 +02:00
|
|
|
tzName = @"UTC";
|
2007-04-11 21:07:54 +02:00
|
|
|
serverTimeZone = [NSTimeZone timeZoneWithName: tzName];
|
|
|
|
[serverTimeZone retain];
|
|
|
|
}
|
2007-05-09 21:23:09 +02:00
|
|
|
if (!AgenorProfileURL)
|
|
|
|
{
|
|
|
|
profileURL = [ud stringForKey: @"AgenorProfileURL"];
|
|
|
|
AgenorProfileURL = [[NSURL alloc] initWithString: profileURL];
|
|
|
|
}
|
|
|
|
if (!fallbackIMAP4Server)
|
2007-05-30 22:20:02 +02:00
|
|
|
ASSIGN (fallbackIMAP4Server,
|
|
|
|
[ud stringForKey: @"SOGoFallbackIMAP4Server"]);
|
2008-02-07 17:53:19 +01:00
|
|
|
if (fallbackIMAP4Server)
|
|
|
|
fallbackIsConfigured = YES;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self warnWithFormat:
|
|
|
|
@"no server specified for SOGoFallbackIMAP4Server,"
|
|
|
|
@" value set to 'localhost'"];
|
|
|
|
fallbackIMAP4Server = @"localhost";
|
|
|
|
}
|
|
|
|
|
2007-05-30 22:20:02 +02:00
|
|
|
if (!defaultLanguage)
|
|
|
|
{
|
|
|
|
ASSIGN (defaultLanguage, [ud stringForKey: @"SOGoDefaultLanguage"]);
|
|
|
|
if (!defaultLanguage)
|
|
|
|
ASSIGN (defaultLanguage, @"English");
|
|
|
|
}
|
2007-10-19 21:03:21 +02:00
|
|
|
if (!superUsernames)
|
2007-10-31 15:18:17 +01:00
|
|
|
ASSIGN (superUsernames, [ud arrayForKey: @"SOGoSuperUsernames"]);
|
2007-06-22 21:58:31 +02:00
|
|
|
|
2007-07-13 16:03:18 +02:00
|
|
|
acceptAnyUser = ([[ud stringForKey: @"SOGoAuthentificationMethod"]
|
|
|
|
isEqualToString: @"bypass"]);
|
2007-04-11 21:07:54 +02:00
|
|
|
}
|
|
|
|
|
2007-10-23 00:24:08 +02:00
|
|
|
+ (NSString *) language
|
|
|
|
{
|
|
|
|
NSArray *bLanguages;
|
|
|
|
WOContext *context;
|
2007-11-08 21:35:09 +01:00
|
|
|
NSString *lng;
|
2007-10-23 00:24:08 +02:00
|
|
|
|
|
|
|
context = [[WOApplication application] context];
|
|
|
|
bLanguages = [[context request] browserLanguages];
|
|
|
|
if ([bLanguages count] > 0)
|
2007-11-08 21:35:09 +01:00
|
|
|
lng = [bLanguages objectAtIndex: 0];
|
2007-10-23 00:24:08 +02:00
|
|
|
|
2007-11-08 21:35:09 +01:00
|
|
|
if (![lng length])
|
|
|
|
lng = defaultLanguage;
|
2007-10-23 00:24:08 +02:00
|
|
|
|
2007-11-08 21:35:09 +01:00
|
|
|
return lng;
|
2007-10-23 00:24:08 +02:00
|
|
|
}
|
|
|
|
|
2008-02-07 17:53:19 +01:00
|
|
|
+ (NSString *) fallbackIMAP4Server
|
|
|
|
{
|
|
|
|
return fallbackIMAP4Server;
|
|
|
|
}
|
|
|
|
|
2007-05-11 23:44:47 +02:00
|
|
|
+ (SOGoUser *) userWithLogin: (NSString *) newLogin
|
|
|
|
roles: (NSArray *) newRoles
|
2007-04-11 21:07:54 +02:00
|
|
|
{
|
2008-01-16 19:57:58 +01:00
|
|
|
SOGoCache *cache;
|
2007-04-11 21:07:54 +02:00
|
|
|
SOGoUser *user;
|
|
|
|
|
2008-01-16 19:57:58 +01:00
|
|
|
cache = [SOGoCache sharedCache];
|
|
|
|
user = [cache userNamed: newLogin];
|
|
|
|
if (!user)
|
|
|
|
{
|
|
|
|
user = [[self alloc] initWithLogin: newLogin roles: newRoles];
|
2008-01-24 18:11:29 +01:00
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
[user autorelease];
|
|
|
|
[cache registerUser: user];
|
|
|
|
}
|
2008-01-16 19:57:58 +01:00
|
|
|
}
|
|
|
|
[user setPrimaryRoles: newRoles];
|
2007-04-11 21:07:54 +02:00
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
2007-03-27 20:16:52 +02:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
if ((self = [super init]))
|
|
|
|
{
|
|
|
|
userDefaults = nil;
|
|
|
|
userSettings = nil;
|
2007-05-09 21:23:09 +02:00
|
|
|
allEmails = nil;
|
2007-05-30 22:20:02 +02:00
|
|
|
language = nil;
|
2007-06-19 20:06:18 +02:00
|
|
|
currentPassword = nil;
|
|
|
|
dateFormatter = nil;
|
2007-11-18 11:16:25 +01:00
|
|
|
homeFolder = nil;
|
2007-05-09 21:23:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithLogin: (NSString *) newLogin
|
|
|
|
roles: (NSArray *) newRoles
|
|
|
|
{
|
|
|
|
LDAPUserManager *um;
|
2007-06-22 21:58:31 +02:00
|
|
|
NSString *realUID;
|
2007-05-09 21:23:09 +02:00
|
|
|
|
2007-07-04 22:15:42 +02:00
|
|
|
if (acceptAnyUser
|
|
|
|
|| [newLogin isEqualToString: @"anonymous"]
|
2007-05-09 21:23:09 +02:00
|
|
|
|| [newLogin isEqualToString: @"freebusy"])
|
2007-07-04 22:15:42 +02:00
|
|
|
realUID = newLogin;
|
2007-05-09 21:23:09 +02:00
|
|
|
else
|
|
|
|
{
|
2007-07-04 22:15:42 +02:00
|
|
|
um = [LDAPUserManager sharedUserManager];
|
|
|
|
realUID = [[um contactInfosForUserWithUIDorEmail: newLogin]
|
|
|
|
objectForKey: @"c_uid"];
|
2007-03-27 20:16:52 +02:00
|
|
|
}
|
2008-02-07 17:53:19 +01:00
|
|
|
|
2008-01-24 18:11:29 +01:00
|
|
|
if (realUID)
|
|
|
|
self = [super initWithLogin: realUID roles: newRoles];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self release];
|
|
|
|
self = nil;
|
|
|
|
}
|
2007-03-27 20:16:52 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
2007-06-19 20:06:18 +02:00
|
|
|
[currentPassword release];
|
2007-04-11 21:07:54 +02:00
|
|
|
[userDefaults release];
|
|
|
|
[userSettings release];
|
2007-05-30 22:20:02 +02:00
|
|
|
[allEmails release];
|
|
|
|
[language release];
|
2007-06-19 20:06:18 +02:00
|
|
|
[dateFormatter release];
|
2007-11-18 11:16:25 +01:00
|
|
|
[homeFolder release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2008-01-16 19:57:58 +01:00
|
|
|
- (void) setPrimaryRoles: (NSArray *) newRoles
|
|
|
|
{
|
|
|
|
ASSIGN (roles, newRoles);
|
|
|
|
}
|
|
|
|
|
2007-06-19 20:06:18 +02:00
|
|
|
- (void) setCurrentPassword: (NSString *) newPassword
|
|
|
|
{
|
|
|
|
ASSIGN (currentPassword, newPassword);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentPassword
|
|
|
|
{
|
|
|
|
return currentPassword;
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
- (id) _fetchFieldForUser: (NSString *) field
|
|
|
|
{
|
|
|
|
NSDictionary *contactInfos;
|
|
|
|
LDAPUserManager *um;
|
|
|
|
|
|
|
|
um = [LDAPUserManager sharedUserManager];
|
|
|
|
contactInfos = [um contactInfosForUserWithUIDorEmail: login];
|
|
|
|
|
|
|
|
return [contactInfos objectForKey: field];
|
|
|
|
}
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
- (void) _fetchAllEmails
|
2007-04-11 21:07:54 +02:00
|
|
|
{
|
2007-05-09 21:23:09 +02:00
|
|
|
allEmails = [self _fetchFieldForUser: @"emails"];
|
|
|
|
[allEmails retain];
|
|
|
|
}
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
- (void) _fetchCN
|
|
|
|
{
|
|
|
|
cn = [self _fetchFieldForUser: @"cn"];
|
|
|
|
[cn retain];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
// - (NSString *) fullEmail
|
|
|
|
// {
|
|
|
|
// return [[LDAPUserManager sharedUserManager] getFullEmailForUID: login];
|
|
|
|
// }
|
2007-05-30 22:20:02 +02:00
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
// - (NSString *) primaryEmail
|
|
|
|
// {
|
|
|
|
// if (!allEmails)
|
|
|
|
// [self _fetchAllEmails];
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
// return [allEmails objectAtIndex: 0];
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
- (NSArray *) allEmails
|
2007-05-03 20:39:03 +02:00
|
|
|
{
|
2007-05-09 21:23:09 +02:00
|
|
|
if (!allEmails)
|
|
|
|
[self _fetchAllEmails];
|
2007-05-03 20:39:03 +02:00
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
return allEmails;
|
2007-05-03 20:39:03 +02:00
|
|
|
}
|
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
- (NSString *) systemEmail
|
2007-04-11 21:07:54 +02:00
|
|
|
{
|
2007-05-09 21:23:09 +02:00
|
|
|
if (!allEmails)
|
|
|
|
[self _fetchAllEmails];
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
return [allEmails lastObject];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
- (BOOL) hasEmail: (NSString *) email
|
2007-04-11 21:07:54 +02:00
|
|
|
{
|
2007-05-09 21:23:09 +02:00
|
|
|
if (!allEmails)
|
|
|
|
[self _fetchAllEmails];
|
2007-06-01 07:10:07 +02:00
|
|
|
|
|
|
|
return [allEmails containsCaseInsensitiveString: email];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
- (NSString *) cn
|
2007-04-11 21:07:54 +02:00
|
|
|
{
|
2007-05-09 21:23:09 +02:00
|
|
|
if (!cn)
|
|
|
|
[self _fetchCN];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
return cn;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2008-02-07 17:53:19 +01:00
|
|
|
- (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"];
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
// - (NSString *) primaryMailServer
|
|
|
|
// {
|
|
|
|
// return [[self userManager] getServerForUID: [self login]];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSArray *) additionalIMAP4AccountStrings
|
|
|
|
// {
|
|
|
|
// return [[self userManager]getSharedMailboxAccountStringsForUID: [self login]];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSArray *) additionalEMailAddresses
|
|
|
|
// {
|
|
|
|
// return [[self userManager] getSharedMailboxEMailsForUID: [self login]];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// - (NSDictionary *) additionalIMAP4AccountsAndEMails
|
|
|
|
// {
|
|
|
|
// return [[self userManager] getSharedMailboxesAndEMailsForUID: [self login]];
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSURL *) freeBusyURL
|
|
|
|
{
|
2007-05-09 21:23:09 +02:00
|
|
|
return nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-06-19 20:06:18 +02:00
|
|
|
- (SOGoDateFormatter *) dateFormatterInContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSString *format;
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
|
|
|
if (!dateFormatter)
|
|
|
|
{
|
|
|
|
dateFormatter = [SOGoDateFormatter new];
|
|
|
|
[dateFormatter setLocale: [context valueForKey: @"locale"]];
|
|
|
|
ud = [self userDefaults];
|
|
|
|
format = [ud stringForKey: @"ShortDateFormat"];
|
|
|
|
if (format)
|
|
|
|
[dateFormatter setShortDateFormat: format];
|
|
|
|
format = [ud stringForKey: @"LongDateFormat"];
|
|
|
|
if (format)
|
|
|
|
[dateFormatter setLongDateFormat: format];
|
|
|
|
format = [ud stringForKey: @"TimeFormat"];
|
|
|
|
if (format)
|
|
|
|
[dateFormatter setTimeFormat: format];
|
|
|
|
}
|
|
|
|
|
|
|
|
return dateFormatter;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* defaults */
|
|
|
|
|
2007-03-27 20:16:52 +02:00
|
|
|
- (NSUserDefaults *) userDefaults
|
|
|
|
{
|
|
|
|
if (!userDefaults)
|
2007-07-04 22:15:42 +02:00
|
|
|
userDefaults
|
|
|
|
= [[AgenorUserDefaults alloc] initWithTableURL: AgenorProfileURL
|
|
|
|
uid: login
|
2007-07-24 20:45:52 +02:00
|
|
|
fieldName: @"c_defaults"];
|
2007-03-27 20:16:52 +02:00
|
|
|
|
|
|
|
return userDefaults;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUserDefaults *) userSettings
|
|
|
|
{
|
|
|
|
if (!userSettings)
|
2007-07-04 22:15:42 +02:00
|
|
|
userSettings
|
|
|
|
= [[AgenorUserDefaults alloc] initWithTableURL: AgenorProfileURL
|
|
|
|
uid: login
|
2007-07-24 20:45:52 +02:00
|
|
|
fieldName: @"c_settings"];
|
2007-03-27 20:16:52 +02:00
|
|
|
|
|
|
|
return userSettings;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-05-30 22:20:02 +02:00
|
|
|
- (NSString *) language
|
|
|
|
{
|
|
|
|
if (!language)
|
|
|
|
{
|
|
|
|
language = [[self userDefaults] stringForKey: @"Language"];
|
2007-08-22 17:16:35 +02:00
|
|
|
if (![language length])
|
2007-10-23 00:24:08 +02:00
|
|
|
language = [SOGoUser language];
|
2007-05-30 22:20:02 +02:00
|
|
|
[language retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSTimeZone *) timeZone
|
|
|
|
{
|
|
|
|
NSString *timeZoneName;
|
|
|
|
|
|
|
|
if (!userTimeZone)
|
|
|
|
{
|
|
|
|
timeZoneName = [[self userDefaults] stringForKey: @"TimeZone"];
|
|
|
|
if ([timeZoneName length] > 0)
|
|
|
|
userTimeZone = [NSTimeZone timeZoneWithName: timeZoneName];
|
|
|
|
if (!userTimeZone)
|
2007-04-27 21:02:01 +02:00
|
|
|
userTimeZone = serverTimeZone;
|
2007-04-11 21:07:54 +02:00
|
|
|
[userTimeZone retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return userTimeZone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTimeZone *) serverTimeZone
|
|
|
|
{
|
|
|
|
return serverTimeZone;
|
|
|
|
}
|
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
/* mail */
|
2007-11-06 18:12:37 +01:00
|
|
|
- (void) _prepareDefaultMailAccounts
|
2007-08-15 22:30:37 +02:00
|
|
|
{
|
|
|
|
NSMutableDictionary *mailAccount, *identity;
|
|
|
|
NSMutableArray *identities;
|
2008-02-08 00:09:12 +01:00
|
|
|
NSString *name, *fullName;
|
2007-11-06 18:12:37 +01:00
|
|
|
NSArray *mails;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
mailAccount = [NSMutableDictionary dictionary];
|
|
|
|
name = [NSString stringWithFormat: @"%@@%@",
|
2008-02-08 00:09:12 +01:00
|
|
|
login, fallbackIMAP4Server];
|
|
|
|
[mailAccount setObject: login forKey: @"userName"];
|
2007-11-06 18:12:37 +01:00
|
|
|
[mailAccount setObject: fallbackIMAP4Server forKey: @"serverName"];
|
|
|
|
[mailAccount setObject: name forKey: @"name"];
|
|
|
|
|
|
|
|
identities = [NSMutableArray array];
|
|
|
|
mails = [self allEmails];
|
|
|
|
|
|
|
|
max = [mails count];
|
|
|
|
if (max > 1)
|
|
|
|
max--;
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
identity = [NSMutableDictionary dictionary];
|
|
|
|
fullName = [self cn];
|
|
|
|
if (![fullName length])
|
|
|
|
fullName = login;
|
|
|
|
[identity setObject: fullName forKey: @"fullName"];
|
|
|
|
[identity setObject: [mails objectAtIndex: count] forKey: @"email"];
|
|
|
|
[identities addObject: identity];
|
|
|
|
}
|
|
|
|
[[identities objectAtIndex: 0] setObject: [NSNumber numberWithBool: YES]
|
|
|
|
forKey: @"isDefault"];
|
|
|
|
|
|
|
|
[mailAccount setObject: identities forKey: @"identities"];
|
|
|
|
|
|
|
|
mailAccounts = [NSMutableArray new];
|
|
|
|
[mailAccounts addObject: mailAccount];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) mailAccounts
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
2007-08-15 22:30:37 +02:00
|
|
|
|
|
|
|
if (!mailAccounts)
|
|
|
|
{
|
2007-11-06 18:12:37 +01:00
|
|
|
ud = [self userDefaults];
|
|
|
|
mailAccounts = [ud objectForKey: @"MailAccounts"];
|
|
|
|
if (mailAccounts)
|
|
|
|
[mailAccounts retain];
|
|
|
|
else
|
|
|
|
[self _prepareDefaultMailAccounts];
|
2007-08-15 22:30:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return mailAccounts;
|
|
|
|
}
|
|
|
|
|
2008-02-08 00:09:12 +01:00
|
|
|
- (NSDictionary *) accountWithName: (NSString *) accountName;
|
|
|
|
{
|
|
|
|
NSEnumerator *accounts;
|
|
|
|
NSDictionary *mailAccount, *currentAccount;
|
|
|
|
|
|
|
|
mailAccount = nil;
|
|
|
|
|
|
|
|
accounts = [[self mailAccounts] objectEnumerator];
|
|
|
|
while (!mailAccount
|
|
|
|
&& ((currentAccount = [accounts nextObject])))
|
|
|
|
if ([[currentAccount objectForKey: @"name"]
|
|
|
|
isEqualToString: accountName])
|
|
|
|
mailAccount = currentAccount;
|
|
|
|
|
|
|
|
return mailAccount;
|
|
|
|
}
|
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
/*
|
|
|
|
@interface SOGoMailIdentity : NSObject
|
|
|
|
{
|
|
|
|
NSString *name;
|
|
|
|
NSString *email;
|
|
|
|
NSString *replyTo;
|
|
|
|
NSString *organization;
|
|
|
|
NSString *signature;
|
|
|
|
NSString *vCard;
|
|
|
|
NSString *sentFolderName;
|
|
|
|
NSString *sentBCC;
|
|
|
|
NSString *draftsFolderName;
|
|
|
|
NSString *templatesFolderName;
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int composeHTML:1;
|
|
|
|
int reserved:31;
|
|
|
|
} idFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setName: (NSString *) _value;
|
|
|
|
- (NSString *) name;
|
|
|
|
|
|
|
|
- (void) setEmail: (NSString *) _value;
|
|
|
|
- (NSString *) email;
|
|
|
|
|
|
|
|
- (void) setReplyTo: (NSString *) _value;
|
|
|
|
- (NSString *) replyTo;
|
|
|
|
|
|
|
|
- (void) setOrganization: (NSString *) _value;
|
|
|
|
- (NSString *) organization;
|
|
|
|
|
|
|
|
- (void) setSignature: (NSString *) _value;
|
|
|
|
- (NSString *) signature;
|
|
|
|
- (BOOL) hasSignature;
|
|
|
|
|
|
|
|
- (void) setVCard: (NSString *) _value;
|
|
|
|
- (NSString *) vCard;
|
|
|
|
- (BOOL) hasVCard;
|
|
|
|
|
|
|
|
- (void) setSentFolderName: (NSString *) _value;
|
|
|
|
- (NSString *) sentFolderName;
|
|
|
|
|
|
|
|
- (void) setSentBCC: (NSString *) _value;
|
|
|
|
- (NSString *) sentBCC;
|
|
|
|
|
|
|
|
- (void) setDraftsFolderName: (NSString *) _value;
|
|
|
|
- (NSString *) draftsFolderName;
|
|
|
|
|
|
|
|
- (void) setTemplatesFolderName: (NSString *) _value;
|
|
|
|
- (NSString *) templatesFolderName;
|
|
|
|
|
|
|
|
@end */
|
|
|
|
|
|
|
|
- (NSArray *) allIdentities
|
|
|
|
{
|
|
|
|
NSArray *identities;
|
|
|
|
|
|
|
|
[self mailAccounts];
|
|
|
|
identities = [mailAccounts objectsForKey: @"identities"];
|
|
|
|
|
|
|
|
return [identities flattenedArray];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) primaryIdentity
|
|
|
|
{
|
|
|
|
NSDictionary *defaultAccount;
|
|
|
|
|
|
|
|
[self mailAccounts];
|
|
|
|
defaultAccount = [mailAccounts objectAtIndex: 0];
|
|
|
|
|
|
|
|
return [[defaultAccount objectForKey: @"identities"] objectAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
2007-11-19 23:34:31 +01:00
|
|
|
- (NSString *) signature
|
|
|
|
{
|
|
|
|
return [[self primaryIdentity] objectForKey: @"signature"];
|
|
|
|
}
|
|
|
|
|
2007-08-22 17:16:35 +02:00
|
|
|
- (NSString *) messageForwarding
|
|
|
|
{
|
|
|
|
NSString *messageForwarding;
|
|
|
|
|
|
|
|
messageForwarding
|
|
|
|
= [[self userDefaults] stringForKey: @"MessageForwarding"];
|
|
|
|
if (![messageForwarding length])
|
2007-11-15 23:39:17 +01:00
|
|
|
messageForwarding = @"inline";
|
2007-08-22 17:16:35 +02:00
|
|
|
|
|
|
|
return messageForwarding;
|
|
|
|
}
|
|
|
|
|
2007-10-26 17:35:51 +02:00
|
|
|
- (NSString *) messageCheck
|
|
|
|
{
|
|
|
|
NSString *messageCheck;
|
|
|
|
|
|
|
|
messageCheck
|
|
|
|
= [[self userDefaults] stringForKey: @"MessageCheck"];
|
|
|
|
if (![messageCheck length])
|
|
|
|
messageCheck = @"manually";
|
|
|
|
|
|
|
|
return messageCheck;
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
/* folders */
|
|
|
|
|
|
|
|
// TODO: those methods should check whether the traversal stack in the context
|
|
|
|
// already contains proper folders to improve caching behaviour
|
|
|
|
|
2007-11-18 11:16:25 +01:00
|
|
|
- (SOGoUserFolder *) homeFolderInContext: (id) context
|
2007-04-11 21:07:54 +02:00
|
|
|
{
|
2007-11-18 11:16:25 +01:00
|
|
|
if (!homeFolder)
|
|
|
|
{
|
|
|
|
homeFolder = [[WOApplication application] lookupName: [self login]
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
[homeFolder retain];
|
|
|
|
}
|
|
|
|
|
|
|
|
return homeFolder;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2007-11-13 23:38:05 +01:00
|
|
|
- (SOGoAppointmentFolders *) calendarsFolderInContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
return [[self homeFolderInContext: context] lookupName: @"Calendar"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SOGoAppointmentFolder *)
|
|
|
|
personalCalendarFolderInContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
return [[self calendarsFolderInContext: context] lookupName: @"personal"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
// - (id) schedulingCalendarInContext: (id) _ctx
|
|
|
|
// {
|
|
|
|
// /* Note: watch out for cyclic references */
|
|
|
|
// id folder;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
// folder = [(WOContext *)_ctx objectForKey:@"ActiveUserCalendar"];
|
|
|
|
// if (folder != nil)
|
|
|
|
// return [folder isNotNull] ? folder : nil;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
// folder = [self homeFolderInContext:_ctx];
|
|
|
|
// if ([folder isKindOfClass:[NSException class]])
|
|
|
|
// return folder;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
// folder = [folder lookupName:@"Calendar" inContext:_ctx acquire:NO];
|
|
|
|
// if ([folder isKindOfClass:[NSException class]])
|
|
|
|
// return folder;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
// [(WOContext *)_ctx setObject:folder ? folder : [NSNull null]
|
|
|
|
// forKey:@"ActiveUserCalendar"];
|
|
|
|
// return folder;
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2006-12-14 22:20:13 +01:00
|
|
|
- (NSArray *) rolesForObject: (NSObject *) object
|
|
|
|
inContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
NSMutableArray *rolesForObject;
|
|
|
|
NSArray *sogoRoles;
|
|
|
|
|
2007-02-21 22:13:33 +01:00
|
|
|
rolesForObject = [NSMutableArray new];
|
|
|
|
[rolesForObject autorelease];
|
|
|
|
|
|
|
|
sogoRoles = [super rolesForObject: object inContext: context];
|
|
|
|
if (sogoRoles)
|
|
|
|
[rolesForObject addObjectsFromArray: sogoRoles];
|
|
|
|
|
2007-10-19 21:03:21 +02:00
|
|
|
if ((superUsernames && [superUsernames containsObject: login])
|
2007-07-04 22:15:42 +02:00
|
|
|
|| [[object ownerInContext: context] isEqualToString: login])
|
2006-12-14 22:20:13 +01:00
|
|
|
[rolesForObject addObject: SoRole_Owner];
|
|
|
|
if ([object isKindOfClass: [SOGoObject class]])
|
|
|
|
{
|
2007-04-17 16:34:31 +02:00
|
|
|
sogoRoles = [(SOGoObject *) object aclsForUser: login];
|
2007-11-29 17:14:11 +01:00
|
|
|
if ([sogoRoles count])
|
2007-02-16 17:55:48 +01:00
|
|
|
[rolesForObject addObjectsFromArray: sogoRoles];
|
2007-11-29 17:14:11 +01:00
|
|
|
sogoRoles = [(SOGoObject *) object subscriptionRoles];
|
|
|
|
if ([sogoRoles firstObjectCommonWithArray: rolesForObject])
|
|
|
|
[rolesForObject addObject: SOGoRole_AuthorizedSubscriber];
|
2007-02-16 17:55:48 +01:00
|
|
|
}
|
2006-12-14 22:20:13 +01:00
|
|
|
|
|
|
|
return rolesForObject;
|
|
|
|
}
|
|
|
|
|
2007-11-19 17:37:20 +01:00
|
|
|
- (BOOL) isEqual: (id) otherUser
|
|
|
|
{
|
|
|
|
return ([otherUser isKindOfClass: [SoUser class]]
|
|
|
|
&& [login isEqualToString: [otherUser login]]);
|
|
|
|
}
|
|
|
|
|
2007-11-19 23:34:31 +01:00
|
|
|
- (BOOL) isSuperUser
|
|
|
|
{
|
|
|
|
return [superUsernames containsObject: login];
|
|
|
|
}
|
|
|
|
|
2007-11-26 21:41:59 +01:00
|
|
|
/* module access */
|
|
|
|
- (BOOL) canAccessModule: (NSString *) module
|
|
|
|
{
|
|
|
|
NSString *accessValue;
|
|
|
|
|
|
|
|
accessValue = [self _fetchFieldForUser:
|
|
|
|
[NSString stringWithFormat: @"%@Access", module]];
|
|
|
|
|
|
|
|
return [accessValue boolValue];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* SOGoUser */
|