2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2008-12-30 20:48:33 +01:00
|
|
|
Copyright (C) 2006-2009 Inverse inc.
|
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>
|
2008-07-18 21:25:26 +02:00
|
|
|
#import <Foundation/NSCalendarDate.h>
|
2008-07-04 18:06:09 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSEnumerator.h>
|
2007-04-17 16:34:31 +02:00
|
|
|
#import <Foundation/NSNull.h>
|
|
|
|
#import <Foundation/NSTimeZone.h>
|
|
|
|
#import <Foundation/NSUserDefaults.h>
|
2007-08-15 22:30:37 +02:00
|
|
|
#import <Foundation/NSValue.h>
|
2009-02-24 02:54:59 +01:00
|
|
|
#import <Foundation/NSURL.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>
|
2008-07-18 21:25:26 +02:00
|
|
|
#import <NGExtensions/NSCalendarDate+misc.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
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
#import "SOGoUserManager.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"
|
2008-07-29 18:36:16 +02:00
|
|
|
#import "SOGoUserDefaults.h"
|
|
|
|
#import "SOGoUserFolder.h"
|
2007-06-01 07:10:07 +02:00
|
|
|
|
2009-04-01 15:49:24 +02:00
|
|
|
#import "../../Main/SOGo.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;
|
2008-10-29 20:23:31 +01:00
|
|
|
static NSString *defaultReplyPlacement = nil;
|
|
|
|
static NSString *defaultSignaturePlacement = nil;
|
|
|
|
static NSString *defaultMessageForwarding = nil;
|
|
|
|
static NSString *defaultMessageCheck = nil;
|
2007-10-19 21:03:21 +02:00
|
|
|
static NSArray *superUsernames = nil;
|
2008-07-25 19:52:49 +02:00
|
|
|
static NSURL *SOGoProfileURL = nil;
|
2008-07-24 20:00:21 +02:00
|
|
|
// static BOOL acceptAnyUser = NO;
|
2008-07-18 21:25:26 +02:00
|
|
|
static int sogoFirstDayOfWeek = -1;
|
|
|
|
static int defaultDayStartTime = -1;
|
|
|
|
static int defaultDayEndTime = -1;
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2007-06-19 20:06:18 +02:00
|
|
|
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
|
|
|
|
|
2008-07-18 21:25:26 +02:00
|
|
|
static int
|
|
|
|
_timeValue (NSString *key)
|
|
|
|
{
|
|
|
|
int time;
|
|
|
|
|
|
|
|
if (key && [key length] > 1)
|
|
|
|
time = [[key substringToIndex: 2] intValue];
|
|
|
|
else
|
|
|
|
time = -1;
|
|
|
|
|
|
|
|
return time;
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
}
|
2008-07-18 21:25:26 +02:00
|
|
|
if (sogoFirstDayOfWeek == -1)
|
|
|
|
sogoFirstDayOfWeek = [ud integerForKey: @"SOGoFirstDayOfWeek"];
|
|
|
|
if (defaultDayStartTime == -1)
|
|
|
|
{
|
|
|
|
defaultDayStartTime
|
|
|
|
= _timeValue ([ud stringForKey: @"SOGoDayStartTime"]);
|
|
|
|
if (defaultDayStartTime == -1)
|
|
|
|
defaultDayStartTime = 8;
|
|
|
|
}
|
|
|
|
if (defaultDayEndTime == -1)
|
|
|
|
{
|
|
|
|
defaultDayEndTime
|
|
|
|
= _timeValue ([ud stringForKey: @"SOGoDayEndTime"]);
|
|
|
|
if (defaultDayEndTime == -1)
|
|
|
|
defaultDayEndTime = 18;
|
|
|
|
}
|
|
|
|
|
2008-07-25 19:52:49 +02:00
|
|
|
if (!SOGoProfileURL)
|
2007-05-09 21:23:09 +02:00
|
|
|
{
|
2008-07-25 19:52:49 +02:00
|
|
|
profileURL = [ud stringForKey: @"SOGoProfileURL"];
|
|
|
|
if (!profileURL)
|
2008-08-05 02:32:26 +02:00
|
|
|
{
|
|
|
|
profileURL = [ud stringForKey: @"AgenorProfileURL"];
|
|
|
|
if (profileURL)
|
|
|
|
{
|
|
|
|
[ud setObject: profileURL forKey: @"SOGoProfileURL"];
|
|
|
|
[ud removeObjectForKey: @"AgenorProfileURL"];
|
|
|
|
[ud synchronize];
|
|
|
|
[self warnWithFormat: @"the user defaults key 'AgenorProfileURL'"
|
|
|
|
@" was renamed to 'SOGoProfileURL'"];
|
|
|
|
}
|
|
|
|
}
|
2008-07-25 19:52:49 +02:00
|
|
|
SOGoProfileURL = [[NSURL alloc] initWithString: profileURL];
|
2007-05-09 21:23:09 +02:00
|
|
|
}
|
|
|
|
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");
|
|
|
|
}
|
2008-10-29 20:23:31 +01:00
|
|
|
if (!defaultReplyPlacement)
|
|
|
|
{
|
|
|
|
ASSIGN (defaultReplyPlacement, [ud stringForKey: @"SOGoMailReplyPlacement"]);
|
|
|
|
if (!defaultReplyPlacement)
|
|
|
|
ASSIGN (defaultReplyPlacement, @"below");
|
|
|
|
}
|
|
|
|
if (!defaultSignaturePlacement)
|
|
|
|
{
|
|
|
|
ASSIGN (defaultSignaturePlacement, [ud stringForKey: @"SOGoMailSignaturePlacement"]);
|
|
|
|
if (!defaultSignaturePlacement)
|
|
|
|
ASSIGN (defaultSignaturePlacement, @"below");
|
|
|
|
}
|
|
|
|
if (!defaultMessageForwarding)
|
|
|
|
{
|
|
|
|
ASSIGN (defaultMessageForwarding, [ud stringForKey: @"SOGoMailMessageForwarding"]);
|
|
|
|
if (!defaultMessageForwarding)
|
|
|
|
ASSIGN (defaultMessageForwarding, @"inline");
|
|
|
|
}
|
|
|
|
if (!defaultMessageCheck)
|
|
|
|
{
|
|
|
|
ASSIGN (defaultMessageCheck, [ud stringForKey: @"SOGoMailMessageCheck"]);
|
|
|
|
if (!defaultMessageCheck)
|
|
|
|
ASSIGN (defaultMessageCheck, @"manually");
|
|
|
|
}
|
2009-01-13 16:26:35 +01:00
|
|
|
|
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
|
|
|
|
2008-07-24 20:00:21 +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;
|
|
|
|
}
|
|
|
|
|
2009-08-25 23:28:24 +02:00
|
|
|
+ (SOGoUser *) userWithLogin: (NSString *) newLogin
|
|
|
|
{
|
|
|
|
return [self userWithLogin: newLogin roles: nil];
|
|
|
|
}
|
|
|
|
|
2007-05-11 23:44:47 +02:00
|
|
|
+ (SOGoUser *) userWithLogin: (NSString *) newLogin
|
|
|
|
roles: (NSArray *) newRoles
|
2009-04-21 17:20:52 +02:00
|
|
|
{
|
|
|
|
return [self userWithLogin: newLogin roles: newRoles trust: NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (SOGoUser *) userWithLogin: (NSString *) newLogin
|
|
|
|
roles: (NSArray *) newRoles
|
|
|
|
trust: (BOOL) b
|
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)
|
|
|
|
{
|
2009-05-05 21:58:33 +02:00
|
|
|
user = [[self alloc] initWithLogin: newLogin roles: newRoles trust: b];
|
2008-01-24 18:11:29 +01:00
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
[user autorelease];
|
2009-09-11 16:38:43 +02:00
|
|
|
[cache registerUser: user withName: newLogin];
|
2008-01-24 18:11:29 +01:00
|
|
|
}
|
2008-01-16 19:57:58 +01:00
|
|
|
}
|
2009-05-05 21:58:33 +02:00
|
|
|
if (newRoles)
|
|
|
|
[user setPrimaryRoles: newRoles];
|
2007-04-11 21:07:54 +02:00
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
- (id) initWithLogin: (NSString *) newLogin
|
|
|
|
roles: (NSArray *) newRoles
|
2009-04-21 17:20:52 +02:00
|
|
|
trust: (BOOL) b
|
2007-05-09 21:23:09 +02:00
|
|
|
{
|
2009-09-25 16:42:33 +02:00
|
|
|
SOGoUserManager *um;
|
2007-06-22 21:58:31 +02:00
|
|
|
NSString *realUID;
|
2009-08-03 17:46:02 +02:00
|
|
|
|
|
|
|
_defaults = nil;
|
|
|
|
_settings = nil;
|
2009-04-21 17:20:52 +02:00
|
|
|
|
2008-12-19 18:07:32 +01:00
|
|
|
if ([newLogin isEqualToString: @"anonymous"]
|
|
|
|
|| [newLogin isEqualToString: @"freebusy"])
|
|
|
|
realUID = newLogin;
|
|
|
|
else
|
|
|
|
{
|
2009-04-21 17:20:52 +02:00
|
|
|
if (b)
|
|
|
|
realUID = newLogin;
|
|
|
|
else
|
|
|
|
{
|
2009-09-25 16:42:33 +02:00
|
|
|
um = [SOGoUserManager sharedUserManager];
|
2009-04-21 17:20:52 +02:00
|
|
|
realUID = [[um contactInfosForUserWithUIDorEmail: newLogin]
|
|
|
|
objectForKey: @"c_uid"];
|
|
|
|
}
|
2008-12-19 18:07:32 +01:00
|
|
|
}
|
2008-02-07 17:53:19 +01:00
|
|
|
|
2008-04-24 03:09:08 +02:00
|
|
|
if ([realUID length])
|
2008-09-02 04:52:55 +02:00
|
|
|
{
|
|
|
|
if ((self = [super initWithLogin: realUID roles: newRoles]))
|
|
|
|
{
|
|
|
|
allEmails = nil;
|
|
|
|
currentPassword = nil;
|
|
|
|
cn = nil;
|
|
|
|
}
|
|
|
|
}
|
2008-01-24 18:11:29 +01:00
|
|
|
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
|
|
|
|
{
|
2009-08-03 17:46:02 +02:00
|
|
|
[_defaults release];
|
|
|
|
[_settings release];
|
2007-05-30 22:20:02 +02:00
|
|
|
[allEmails release];
|
2008-08-29 02:31:27 +02:00
|
|
|
[currentPassword release];
|
|
|
|
[cn release];
|
2009-03-25 15:38:19 +01:00
|
|
|
[language release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2008-01-16 19:57:58 +01:00
|
|
|
- (void) setPrimaryRoles: (NSArray *) newRoles
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
ASSIGN(roles, newRoles);
|
2008-01-16 19:57:58 +01:00
|
|
|
}
|
|
|
|
|
2007-06-19 20:06:18 +02:00
|
|
|
- (void) setCurrentPassword: (NSString *) newPassword
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
ASSIGN(currentPassword, newPassword);
|
2007-06-19 20:06:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentPassword
|
|
|
|
{
|
|
|
|
return currentPassword;
|
|
|
|
}
|
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
- (id) _fetchFieldForUser: (NSString *) field
|
|
|
|
{
|
|
|
|
NSDictionary *contactInfos;
|
2009-09-25 16:42:33 +02:00
|
|
|
SOGoUserManager *um;
|
2007-05-09 21:23:09 +02:00
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
um = [SOGoUserManager sharedUserManager];
|
2007-05-09 21:23:09 +02:00
|
|
|
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
|
|
|
- (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
|
|
|
|
2009-01-13 16:26:35 +01: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];
|
2009-01-13 16:26:35 +01:00
|
|
|
|
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;
|
|
|
|
}
|
2009-09-25 16:42:33 +02:00
|
|
|
if (![SOGoUserManager defaultMailDomainIsConfigured])
|
2008-02-07 17:53:19 +01:00
|
|
|
{
|
|
|
|
[self logWithFormat: @"'SOGoDefaultMailDomain' is not set"];
|
|
|
|
doSave = NO;
|
|
|
|
}
|
2009-08-20 22:33:57 +02:00
|
|
|
doSave = NO;
|
2008-02-07 17:53:19 +01:00
|
|
|
if (doSave)
|
2008-11-11 01:17:35 +01:00
|
|
|
[[self userDefaults] setObject: [self mailAccounts]
|
|
|
|
forKey: @"MailAccounts"];
|
2008-02-07 17:53:19 +01:00
|
|
|
else
|
|
|
|
[self logWithFormat: @"saving mail accounts is disabled until the"
|
|
|
|
@" variable(s) mentionned above are configured"];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
SOGoDateFormatter *dateFormatter;
|
2007-06-19 20:06:18 +02:00
|
|
|
NSString *format;
|
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
2009-03-03 20:08:02 +01:00
|
|
|
dateFormatter = [SOGoDateFormatter new];
|
|
|
|
[dateFormatter autorelease];
|
|
|
|
|
|
|
|
[dateFormatter setLocale: [[WOApplication application] localeForLanguageNamed: [self language]]];
|
|
|
|
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];
|
|
|
|
|
2007-06-19 20:06:18 +02:00
|
|
|
return dateFormatter;
|
|
|
|
}
|
|
|
|
|
2009-01-13 21:39:10 +01:00
|
|
|
- (SOGoUserDefaults *) primaryUserDefaults
|
2007-03-27 20:16:52 +02:00
|
|
|
{
|
2009-01-13 21:39:10 +01:00
|
|
|
SOGoUserDefaults *o;
|
|
|
|
|
|
|
|
o = [[SOGoUserDefaults alloc] initWithTableURL: SOGoProfileURL
|
2009-09-19 22:07:31 +02:00
|
|
|
uid: login
|
|
|
|
fieldName: @"c_defaults"];
|
2009-01-13 16:26:35 +01:00
|
|
|
|
2009-01-13 21:39:10 +01:00
|
|
|
return o;
|
|
|
|
}
|
2008-11-12 04:30:13 +01:00
|
|
|
|
2009-01-13 21:39:10 +01:00
|
|
|
- (SOGoUserDefaults *) primaryUserSettings
|
|
|
|
{
|
|
|
|
SOGoUserDefaults *o;
|
|
|
|
|
|
|
|
o = [[SOGoUserDefaults alloc] initWithTableURL: SOGoProfileURL
|
2009-09-19 22:07:31 +02:00
|
|
|
uid: login
|
|
|
|
fieldName: @"c_settings"];
|
2009-01-13 21:39:10 +01:00
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUserDefaults *) userDefaults
|
|
|
|
{
|
2009-03-20 18:35:49 +01:00
|
|
|
NSDictionary *values;
|
2009-02-24 02:54:59 +01:00
|
|
|
|
2009-08-03 17:46:02 +02:00
|
|
|
if (!_defaults)
|
2009-01-13 16:26:35 +01:00
|
|
|
{
|
2009-08-03 17:46:02 +02:00
|
|
|
_defaults = [self primaryUserDefaults];
|
|
|
|
if (_defaults)
|
2009-03-20 18:35:49 +01:00
|
|
|
{
|
2009-08-03 17:46:02 +02:00
|
|
|
values = [[SOGoCache sharedCache] userDefaultsForLogin: login];
|
|
|
|
|
2009-03-20 18:35:49 +01:00
|
|
|
if (values)
|
|
|
|
{
|
2009-08-03 17:46:02 +02:00
|
|
|
[_defaults setValues: values];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[_defaults fetchProfile];
|
|
|
|
values = [_defaults values];
|
2009-04-21 17:20:52 +02:00
|
|
|
|
2009-08-03 17:46:02 +02:00
|
|
|
if (values)
|
|
|
|
{
|
|
|
|
// Required parameters for the Web interface. This will trigger the
|
|
|
|
// preferences to load so it's important to leave those calls here.
|
|
|
|
if (![[_defaults stringForKey: @"ReplyPlacement"] length])
|
|
|
|
[_defaults setObject: defaultReplyPlacement forKey: @"ReplyPlacement"];
|
|
|
|
if (![[_defaults stringForKey: @"SignaturePlacement"] length])
|
|
|
|
[_defaults setObject: defaultSignaturePlacement forKey: @"SignaturePlacement"];
|
|
|
|
if (![[_defaults stringForKey: @"MessageForwarding"] length])
|
|
|
|
[_defaults setObject: defaultMessageForwarding forKey: @"MessageForwarding"];
|
|
|
|
if (![[_defaults stringForKey: @"MessageCheck"] length])
|
|
|
|
[_defaults setObject: defaultMessageCheck forKey: @"MessageCheck"];
|
|
|
|
|
|
|
|
[[SOGoCache sharedCache] cacheValues: [_defaults values] ofType: @"defaults" forLogin: login];
|
|
|
|
}
|
2009-03-20 18:35:49 +01:00
|
|
|
}
|
2009-08-03 17:46:02 +02:00
|
|
|
|
|
|
|
// See explanation in -language
|
|
|
|
[self invalidateLanguage];
|
2009-03-20 18:35:49 +01:00
|
|
|
}
|
2008-10-29 20:23:31 +01:00
|
|
|
}
|
2009-02-24 02:54:59 +01:00
|
|
|
//else
|
|
|
|
// NSLog(@"User defaults cache hit for %@", login);
|
2007-03-27 20:16:52 +02:00
|
|
|
|
2009-08-03 17:46:02 +02:00
|
|
|
return (NSUserDefaults *) _defaults;
|
2007-03-27 20:16:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSUserDefaults *) userSettings
|
|
|
|
{
|
2009-03-20 18:35:49 +01:00
|
|
|
NSDictionary *values;
|
2008-11-11 01:17:35 +01:00
|
|
|
|
2009-08-03 17:46:02 +02:00
|
|
|
if (!_settings)
|
2009-01-13 16:26:35 +01:00
|
|
|
{
|
2009-08-03 17:46:02 +02:00
|
|
|
_settings = [self primaryUserSettings];
|
|
|
|
if (_settings)
|
2009-03-20 18:35:49 +01:00
|
|
|
{
|
2009-08-03 17:46:02 +02:00
|
|
|
values = [[SOGoCache sharedCache] userSettingsForLogin: login];
|
|
|
|
|
2009-03-20 18:35:49 +01:00
|
|
|
if (values)
|
|
|
|
{
|
2009-08-03 17:46:02 +02:00
|
|
|
[_settings setValues: values];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[_settings fetchProfile];
|
|
|
|
values = [_settings values];
|
2009-04-21 17:20:52 +02:00
|
|
|
|
2009-08-03 17:46:02 +02:00
|
|
|
if (values)
|
|
|
|
{
|
|
|
|
[[SOGoCache sharedCache] cacheValues: values ofType: @"settings" forLogin: login];
|
|
|
|
}
|
2009-03-20 18:35:49 +01:00
|
|
|
}
|
2009-08-03 17:46:02 +02:00
|
|
|
|
|
|
|
// See explanation in -language
|
|
|
|
[self invalidateLanguage];
|
2009-03-20 18:35:49 +01:00
|
|
|
}
|
2008-11-11 01:17:35 +01:00
|
|
|
}
|
2009-02-24 02:54:59 +01:00
|
|
|
//else
|
|
|
|
// NSLog(@"User settings cache hit for %@", login);
|
2007-03-27 20:16:52 +02:00
|
|
|
|
2009-08-03 17:46:02 +02:00
|
|
|
return (NSUserDefaults *) _settings;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2009-03-24 20:50:33 +01:00
|
|
|
- (void) invalidateLanguage
|
|
|
|
{
|
2009-03-25 15:38:19 +01:00
|
|
|
DESTROY(language);
|
2009-03-24 20:50:33 +01:00
|
|
|
}
|
|
|
|
|
2007-05-30 22:20:02 +02:00
|
|
|
- (NSString *) language
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
if (![language length])
|
2009-03-22 17:03:21 +01:00
|
|
|
{
|
|
|
|
language = [[self userDefaults] stringForKey: @"Language"];
|
2009-08-03 17:46:02 +02:00
|
|
|
// This is a workaround until we handle the connection errors to the db in a
|
2009-03-23 13:51:16 +01:00
|
|
|
// better way. It enables us to avoid retrieving the userDefaults too
|
|
|
|
// many times when the DB is down, causing a huge delay.
|
2009-03-22 17:03:21 +01:00
|
|
|
if (![language length])
|
|
|
|
language = [SOGoUser language];
|
2009-03-25 15:38:19 +01:00
|
|
|
|
|
|
|
[language retain];
|
2009-03-22 17:03:21 +01:00
|
|
|
}
|
2007-05-30 22:20:02 +02:00
|
|
|
|
|
|
|
return language;
|
|
|
|
}
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
- (NSTimeZone *) timeZone
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
NSTimeZone *userTimeZone;
|
2007-04-11 21:07:54 +02:00
|
|
|
NSString *timeZoneName;
|
2009-03-03 20:08:02 +01:00
|
|
|
|
|
|
|
timeZoneName = [[self userDefaults] stringForKey: @"TimeZone"];
|
|
|
|
userTimeZone = nil;
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2009-03-03 20:08:02 +01:00
|
|
|
if ([timeZoneName length] > 0)
|
|
|
|
userTimeZone = [NSTimeZone timeZoneWithName: timeZoneName];
|
2007-04-11 21:07:54 +02:00
|
|
|
if (!userTimeZone)
|
2009-03-03 20:08:02 +01:00
|
|
|
userTimeZone = serverTimeZone;
|
|
|
|
|
2007-04-11 21:07:54 +02:00
|
|
|
return userTimeZone;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSTimeZone *) serverTimeZone
|
|
|
|
{
|
|
|
|
return serverTimeZone;
|
|
|
|
}
|
|
|
|
|
2008-07-18 21:25:26 +02:00
|
|
|
- (unsigned int) firstDayOfWeek
|
|
|
|
{
|
|
|
|
unsigned int firstDayOfWeek;
|
|
|
|
NSNumber *value;
|
|
|
|
|
|
|
|
value = [[self userDefaults] objectForKey: @"WeekStartDay"];
|
|
|
|
if (value)
|
|
|
|
firstDayOfWeek = [value unsignedIntValue];
|
|
|
|
else
|
|
|
|
firstDayOfWeek = sogoFirstDayOfWeek;
|
|
|
|
|
|
|
|
return firstDayOfWeek;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) firstDayOfWeekForDate: (NSCalendarDate *) date
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
NSCalendarDate *firstDay;
|
|
|
|
|
|
|
|
offset = ([self firstDayOfWeek] - [date dayOfWeek]);
|
|
|
|
if (offset > 0)
|
|
|
|
offset -= 7;
|
|
|
|
|
|
|
|
firstDay = [date addTimeInterval: offset * 86400];
|
|
|
|
|
|
|
|
return firstDay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) dayOfWeekForDate: (NSCalendarDate *) date
|
|
|
|
{
|
|
|
|
unsigned int offset, baseDayOfWeek, dayOfWeek;
|
|
|
|
|
|
|
|
offset = [self firstDayOfWeek];
|
|
|
|
baseDayOfWeek = [date dayOfWeek];
|
|
|
|
if (offset > baseDayOfWeek)
|
|
|
|
baseDayOfWeek += 7;
|
|
|
|
|
|
|
|
dayOfWeek = baseDayOfWeek - offset;
|
|
|
|
|
|
|
|
return dayOfWeek;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) dayStartHour
|
|
|
|
{
|
|
|
|
int limit;
|
|
|
|
|
|
|
|
limit = _timeValue ([[self userDefaults] stringForKey: @"DayStartTime"]);
|
|
|
|
if (limit == -1)
|
|
|
|
limit = defaultDayStartTime;
|
|
|
|
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) dayEndHour
|
|
|
|
{
|
|
|
|
int limit;
|
|
|
|
|
|
|
|
limit = _timeValue ([[self userDefaults] stringForKey: @"DayEndTime"]);
|
|
|
|
if (limit == -1)
|
|
|
|
limit = defaultDayEndTime;
|
|
|
|
|
|
|
|
return limit;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) firstWeekOfYearForDate: (NSCalendarDate *) date
|
|
|
|
{
|
|
|
|
NSString *firstWeekRule;
|
|
|
|
NSCalendarDate *januaryFirst, *firstWeek;
|
|
|
|
unsigned int dayOfWeek;
|
|
|
|
|
2008-11-11 01:17:35 +01:00
|
|
|
firstWeekRule = [[self userDefaults] objectForKey: @"FirstWeek"];
|
2008-07-18 21:25:26 +02:00
|
|
|
|
|
|
|
januaryFirst = [NSCalendarDate dateWithYear: [date yearOfCommonEra]
|
|
|
|
month: 1 day: 1 hour: 0 minute: 0 second: 0
|
|
|
|
timeZone: [date timeZone]];
|
|
|
|
if ([firstWeekRule isEqualToString: SOGoWeekStartFirst4DayWeek])
|
|
|
|
{
|
|
|
|
dayOfWeek = [self dayOfWeekForDate: januaryFirst];
|
|
|
|
if (dayOfWeek < 4)
|
|
|
|
firstWeek = [self firstDayOfWeekForDate: januaryFirst];
|
|
|
|
else
|
|
|
|
firstWeek = [self firstDayOfWeekForDate: [januaryFirst
|
|
|
|
dateByAddingYears: 0
|
|
|
|
months: 0
|
|
|
|
days: 7]];
|
|
|
|
}
|
|
|
|
else if ([firstWeekRule isEqualToString: SOGoWeekStartFirstFullWeek])
|
|
|
|
{
|
|
|
|
dayOfWeek = [self dayOfWeekForDate: januaryFirst];
|
|
|
|
if (dayOfWeek == 0)
|
|
|
|
firstWeek = [self firstDayOfWeekForDate: januaryFirst];
|
|
|
|
else
|
|
|
|
firstWeek = [self firstDayOfWeekForDate: [januaryFirst
|
|
|
|
dateByAddingYears: 0
|
|
|
|
months: 0
|
|
|
|
days: 7]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
firstWeek = [self firstDayOfWeekForDate: januaryFirst];
|
|
|
|
|
|
|
|
return firstWeek;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) weekNumberForDate: (NSCalendarDate *) date
|
|
|
|
{
|
|
|
|
NSCalendarDate *firstWeek;
|
|
|
|
unsigned int weekNumber;
|
|
|
|
|
|
|
|
firstWeek = [self firstWeekOfYearForDate: date];
|
|
|
|
if ([firstWeek earlierDate: date] == firstWeek)
|
|
|
|
weekNumber = ([date timeIntervalSinceDate: firstWeek]
|
|
|
|
/ (86400 * 7) + 1);
|
|
|
|
else
|
|
|
|
weekNumber = 0;
|
|
|
|
|
|
|
|
return weekNumber;
|
|
|
|
}
|
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
/* mail */
|
2009-03-21 15:43:13 +01:00
|
|
|
- (NSArray *) _prepareDefaultMailAccounts
|
2007-08-15 22:30:37 +02:00
|
|
|
{
|
|
|
|
NSMutableDictionary *mailAccount, *identity;
|
2009-03-21 15:43:13 +01:00
|
|
|
NSMutableArray *identities, *mailAccounts;
|
2009-05-12 21:56:39 +02:00
|
|
|
NSString *name, *fullName, *imapLogin, *imapServer;
|
2007-11-06 18:12:37 +01:00
|
|
|
NSArray *mails;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
imapLogin = [[SOGoUserManager sharedUserManager] getImapLoginForUID: login];
|
2009-05-12 21:56:39 +02:00
|
|
|
imapServer = [self _fetchFieldForUser: @"c_imaphostname"];
|
|
|
|
if (!imapServer)
|
|
|
|
imapServer = fallbackIMAP4Server;
|
2007-11-06 18:12:37 +01:00
|
|
|
mailAccount = [NSMutableDictionary dictionary];
|
|
|
|
name = [NSString stringWithFormat: @"%@@%@",
|
2009-05-12 21:56:39 +02:00
|
|
|
imapLogin, imapServer];
|
2008-05-22 17:52:25 +02:00
|
|
|
[mailAccount setObject: imapLogin forKey: @"userName"];
|
2009-05-12 21:56:39 +02:00
|
|
|
[mailAccount setObject: imapServer forKey: @"serverName"];
|
2007-11-06 18:12:37 +01:00
|
|
|
[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"];
|
|
|
|
|
2009-03-24 15:25:44 +01:00
|
|
|
mailAccounts = [NSMutableArray array];
|
2007-11-06 18:12:37 +01:00
|
|
|
[mailAccounts addObject: mailAccount];
|
2009-03-21 15:43:13 +01:00
|
|
|
|
|
|
|
return mailAccounts;
|
2007-11-06 18:12:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) mailAccounts
|
|
|
|
{
|
|
|
|
NSUserDefaults *ud;
|
2009-03-21 15:43:13 +01:00
|
|
|
NSArray *mailAccounts;
|
2007-08-15 22:30:37 +02:00
|
|
|
|
2009-03-21 15:43:13 +01:00
|
|
|
ud = [self userDefaults];
|
|
|
|
mailAccounts = [ud objectForKey: @"MailAccounts"];
|
2007-08-15 22:30:37 +02:00
|
|
|
if (!mailAccounts)
|
2009-03-21 15:43:13 +01:00
|
|
|
mailAccounts = [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;
|
|
|
|
|
2008-10-23 17:35:20 +02:00
|
|
|
identities = [[self mailAccounts] objectsForKey: @"identities"
|
|
|
|
notFoundMarker: nil];
|
2007-08-15 22:30:37 +02:00
|
|
|
|
|
|
|
return [identities flattenedArray];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) primaryIdentity
|
|
|
|
{
|
|
|
|
NSDictionary *defaultAccount;
|
|
|
|
|
2009-03-21 15:43:13 +01:00
|
|
|
defaultAccount = [[self mailAccounts] objectAtIndex: 0];
|
2007-08-15 22:30:37 +02:00
|
|
|
|
|
|
|
return [[defaultAccount objectForKey: @"identities"] objectAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
2009-08-20 22:51:01 +02:00
|
|
|
- (void) migrateSignature
|
2007-11-19 23:34:31 +01:00
|
|
|
{
|
2009-08-20 22:33:57 +02:00
|
|
|
NSString *signature;
|
2009-08-20 22:51:01 +02:00
|
|
|
NSUserDefaults *ud;
|
|
|
|
|
|
|
|
signature = [[self primaryIdentity] objectForKey: @"signature"];
|
2009-08-20 22:33:57 +02:00
|
|
|
|
2009-08-20 22:51:01 +02:00
|
|
|
if ([signature length])
|
|
|
|
{
|
|
|
|
ud = [self userDefaults];
|
|
|
|
[ud setObject: signature forKey: @"MailSignature"];
|
|
|
|
[ud removeObjectForKey: @"MailAccounts"];
|
|
|
|
[ud synchronize];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) signature
|
|
|
|
{
|
|
|
|
[self migrateSignature];
|
2009-08-20 22:33:57 +02:00
|
|
|
|
2009-08-20 22:51:01 +02:00
|
|
|
return [[self userDefaults] stringForKey: @"MailSignature"];
|
2007-11-19 23:34:31 +01:00
|
|
|
}
|
|
|
|
|
2008-09-28 21:49:17 +02:00
|
|
|
- (NSString *) replyPlacement
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
return [[self userDefaults] stringForKey: @"ReplyPlacement"];
|
2008-09-28 21:49:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) signaturePlacement
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
return [[self userDefaults] stringForKey: @"SignaturePlacement"];
|
2008-09-28 21:49:17 +02:00
|
|
|
}
|
|
|
|
|
2007-08-22 17:16:35 +02:00
|
|
|
- (NSString *) messageForwarding
|
|
|
|
{
|
2009-03-03 20:08:02 +01:00
|
|
|
return [[self userDefaults] stringForKey: @"MessageForwarding"];
|
2007-08-22 17:16:35 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2009-03-19 16:42:58 +01:00
|
|
|
return [[WOApplication application] lookupName: [self login]
|
2009-06-02 19:59:06 +02:00
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
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"
|
2009-06-02 19:59:06 +02:00
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
2007-11-13 23:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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;
|
2009-01-13 16:26:35 +01:00
|
|
|
|
2007-05-09 21:23:09 +02:00
|
|
|
// folder = [folder lookupName:@"Calendar" inContext:_ctx acquire:NO];
|
|
|
|
// if ([folder isKindOfClass:[NSException class]])
|
|
|
|
// return folder;
|
2009-01-13 16:26:35 +01:00
|
|
|
|
|
|
|
// [(WOContext *)_ctx setObject:folder ? folder : [NSNull null]
|
2007-05-09 21:23:09 +02:00
|
|
|
// 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;
|
2008-04-22 17:56:51 +02:00
|
|
|
NSString *rqMethod;
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2008-07-17 23:12:43 +02:00
|
|
|
rolesForObject = [NSMutableArray array];
|
2007-02-21 22:13:33 +01:00
|
|
|
|
|
|
|
sogoRoles = [super rolesForObject: object inContext: context];
|
|
|
|
if (sogoRoles)
|
|
|
|
[rolesForObject addObjectsFromArray: sogoRoles];
|
|
|
|
|
2009-09-09 19:35:03 +02:00
|
|
|
if ([self isSuperUser]
|
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];
|
2009-06-17 15:32:31 +02:00
|
|
|
else if ([object isKindOfClass: [SOGoObject class]])
|
2006-12-14 22:20:13 +01:00
|
|
|
{
|
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
|
|
|
|
2008-04-22 17:56:51 +02:00
|
|
|
#warning this is a hack to work-around the poor implementation of PROPPATCH in SOPE
|
|
|
|
rqMethod = [[context request] method];
|
|
|
|
if ([rqMethod isEqualToString: @"PROPPATCH"])
|
|
|
|
[rolesForObject addObject: @"PROPPATCHer"];
|
|
|
|
|
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 */
|