2006-06-15 21:34:10 +02:00
|
|
|
/*
|
2020-05-07 13:22:24 +02:00
|
|
|
Copyright (C) 2006-2020 Inverse inc.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2013-09-27 21:54:11 +02:00
|
|
|
This file is part of SOGo.
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2013-09-27 21:54:11 +02:00
|
|
|
SOGo is free software; you can redistribute it and/or modify it under
|
2006-06-15 21:34:10 +02:00
|
|
|
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.
|
|
|
|
|
2013-09-27 21:54:11 +02:00
|
|
|
SOGo is distributed in the hope that it will be useful, but WITHOUT ANY
|
2006-06-15 21:34:10 +02:00
|
|
|
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
|
2016-06-13 16:44:49 +02:00
|
|
|
License along with SOGo; see the file COPYING. If not, write to the
|
2006-06-15 21:34:10 +02:00
|
|
|
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
|
|
|
|
02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
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>
|
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
|
|
|
|
2010-04-20 23:30:17 +02:00
|
|
|
#import <Appointments/SOGoAppointmentFolders.h>
|
2015-03-04 02:59:32 +01:00
|
|
|
#import <Contacts/SOGoContactFolders.h>
|
2010-04-20 23:30:17 +02:00
|
|
|
|
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"
|
2007-04-17 16:34:31 +02:00
|
|
|
#import "SOGoPermissions.h"
|
2009-11-29 05:19:32 +01:00
|
|
|
#import "SOGoSystemDefaults.h"
|
2008-07-29 18:36:16 +02:00
|
|
|
#import "SOGoUserFolder.h"
|
2009-11-19 18:08:47 +01:00
|
|
|
#import "SOGoUserManager.h"
|
2009-11-29 05:19:32 +01:00
|
|
|
#import "SOGoUserSettings.h"
|
2011-02-03 17:12:22 +01:00
|
|
|
#import "WOResourceManager+SOGo.h"
|
2009-04-01 15:49:24 +02:00
|
|
|
|
2020-05-07 13:22:24 +02:00
|
|
|
#if defined(MFA_CONFIG)
|
|
|
|
#include <liboath/oath.h>
|
|
|
|
#endif
|
|
|
|
|
2007-06-01 07:10:07 +02:00
|
|
|
#import "SOGoUser.h"
|
2006-12-14 22:20:13 +01:00
|
|
|
|
2007-10-18 19:17:29 +02:00
|
|
|
@implementation SoUser (SOGoExtension)
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (SOGoDomainDefaults *) userDefaults
|
2007-10-18 19:17:29 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [SOGoSystemDefaults sharedSystemDefaults];
|
2007-10-18 19:17:29 +02:00
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (SOGoDomainDefaults *) domainDefaults
|
2008-07-18 21:25:26 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
return [SOGoSystemDefaults sharedSystemDefaults];
|
2008-07-18 21:25:26 +02:00
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
@end
|
2007-04-11 21:07:54 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
@implementation SOGoUser
|
2007-10-23 00:24:08 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
// + (NSString *) language
|
|
|
|
// {
|
|
|
|
// NSArray *bLanguages;
|
|
|
|
// WOContext *context;
|
|
|
|
// NSString *lng;
|
2007-10-23 00:24:08 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
// context = [[WOApplication application] context];
|
|
|
|
// bLanguages = [[context request] browserLanguages];
|
|
|
|
// if ([bLanguages count] > 0)
|
|
|
|
// lng = [bLanguages objectAtIndex: 0];
|
2007-10-23 00:24:08 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
// if (![lng length])
|
|
|
|
// lng = defaultLanguage;
|
2007-10-23 00:24:08 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
// return lng;
|
|
|
|
// }
|
2008-02-07 17:53:19 +01:00
|
|
|
|
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-11-29 05:19:32 +01:00
|
|
|
user = [[self alloc] initWithLogin: newLogin roles: newRoles trust: b];
|
2008-01-24 18:11:29 +01:00
|
|
|
if (user)
|
|
|
|
{
|
2009-09-11 16:38:43 +02:00
|
|
|
[cache registerUser: user withName: newLogin];
|
2010-04-19 23:30:25 +02:00
|
|
|
[user release];
|
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;
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
/**
|
|
|
|
* Return a new instance for the login name, which can be appended by a
|
2011-07-16 00:22:11 +02:00
|
|
|
* domain name. The domain is extracted only if the system defaults
|
2011-07-19 18:25:11 +02:00
|
|
|
* SOGoEnableDomainBasedUID is enabled.
|
2011-06-24 21:19:50 +02:00
|
|
|
*
|
|
|
|
* @param newLogin a login name optionally follow by @domain
|
|
|
|
* @param newRoles
|
|
|
|
* @param b is set to YES if newLogin can be trust
|
|
|
|
* @see loginInDomain
|
|
|
|
* @see [SOGoSession decodeValue:usingKey:login:domain:password:]
|
|
|
|
*/
|
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;
|
2011-06-24 21:19:50 +02:00
|
|
|
SOGoSystemDefaults *sd;
|
2011-07-19 03:21:18 +02:00
|
|
|
NSDictionary *contactInfos;
|
2011-06-24 21:19:50 +02:00
|
|
|
NSString *realUID, *uid, *domain;
|
|
|
|
NSRange r;
|
2009-08-03 17:46:02 +02:00
|
|
|
|
|
|
|
_defaults = nil;
|
|
|
|
_settings = nil;
|
2009-04-21 17:20:52 +02:00
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
uid = nil;
|
2011-07-25 16:28:15 +02:00
|
|
|
realUID = nil;
|
2011-06-24 21:19:50 +02:00
|
|
|
domain = nil;
|
|
|
|
|
2008-12-19 18:07:32 +01:00
|
|
|
if ([newLogin isEqualToString: @"anonymous"]
|
|
|
|
|| [newLogin isEqualToString: @"freebusy"])
|
|
|
|
realUID = newLogin;
|
|
|
|
else
|
|
|
|
{
|
2011-07-16 00:22:11 +02:00
|
|
|
sd = [SOGoSystemDefaults sharedSystemDefaults];
|
2011-07-27 16:53:12 +02:00
|
|
|
if ([sd enableDomainBasedUID] || [[sd loginDomains] count] > 0)
|
2011-06-24 21:19:50 +02:00
|
|
|
{
|
2011-07-16 00:22:11 +02:00
|
|
|
r = [newLogin rangeOfString: @"@" options: NSBackwardsSearch];
|
|
|
|
if (r.location != NSNotFound)
|
|
|
|
{
|
|
|
|
// The domain is probably appended to the username;
|
|
|
|
// make sure it is defined as a domain in the configuration.
|
|
|
|
domain = [newLogin substringFromIndex: (r.location + r.length)];
|
2015-12-30 15:22:08 +01:00
|
|
|
if ([[SOGoUserManager sharedUserManager] isDomainDefined: domain] &&
|
2015-05-25 19:00:08 +02:00
|
|
|
![sd enableDomainBasedUID])
|
|
|
|
newLogin = [newLogin substringToIndex: r.location];
|
2011-07-27 16:53:12 +02:00
|
|
|
|
|
|
|
if (domain != nil && ![sd enableDomainBasedUID])
|
|
|
|
// Login domains are enabled (SOGoLoginDomains) but not
|
|
|
|
// domain-based UID (SOGoEnableDomainBasedUID).
|
|
|
|
// Drop the domain from the login name.
|
|
|
|
domain = nil;
|
2011-07-16 00:22:11 +02:00
|
|
|
}
|
2011-06-24 21:19:50 +02:00
|
|
|
}
|
|
|
|
|
2010-08-20 16:07:32 +02:00
|
|
|
newLogin = [newLogin stringByReplacingString: @"%40"
|
|
|
|
withString: @"@"];
|
2009-04-21 17:20:52 +02:00
|
|
|
if (b)
|
|
|
|
realUID = newLogin;
|
|
|
|
else
|
|
|
|
{
|
2009-09-25 16:42:33 +02:00
|
|
|
um = [SOGoUserManager sharedUserManager];
|
2011-07-19 03:21:18 +02:00
|
|
|
contactInfos = [um contactInfosForUserWithUIDorEmail: newLogin
|
|
|
|
inDomain: domain];
|
|
|
|
realUID = [contactInfos objectForKey: @"c_uid"];
|
2011-07-19 18:25:11 +02:00
|
|
|
if (domain == nil && [sd enableDomainBasedUID])
|
2011-07-19 03:21:18 +02:00
|
|
|
domain = [contactInfos objectForKey: @"c_domain"];
|
2009-04-21 17:20:52 +02:00
|
|
|
}
|
2011-06-24 21:19:50 +02:00
|
|
|
|
2011-07-25 16:28:15 +02:00
|
|
|
if ([realUID length] && [domain length])
|
2011-06-24 21:19:50 +02:00
|
|
|
{
|
|
|
|
// When the user is associated to a domain, the [SOGoUser login]
|
|
|
|
// method returns the combination login@domain while
|
|
|
|
// [SOGoUser loginInDomain] only returns the login.
|
2015-05-22 20:03:49 +02:00
|
|
|
r = [realUID rangeOfString: domain options: NSBackwardsSearch|NSCaseInsensitiveSearch];
|
|
|
|
|
2015-05-25 15:19:04 +02:00
|
|
|
// Do NOT strip @domain.com if SOGoEnableDomainBasedUID is enabled since
|
|
|
|
// the real login most likely is the email address.
|
|
|
|
if (r.location != NSNotFound && ![sd enableDomainBasedUID])
|
2015-05-22 20:03:49 +02:00
|
|
|
uid = [realUID substringToIndex: r.location-1];
|
2015-06-05 18:18:27 +02:00
|
|
|
// If we don't have the domain in the UID but SOGoEnableDomainBasedUID is
|
|
|
|
// enabled, let's add it internally so so it becomes unique across
|
|
|
|
// all potential domains.
|
|
|
|
else if (r.location == NSNotFound && [sd enableDomainBasedUID])
|
|
|
|
{
|
|
|
|
uid = [NSString stringWithString: realUID];
|
|
|
|
realUID = [NSString stringWithFormat: @"%@@%@", realUID, domain];
|
|
|
|
}
|
|
|
|
// We found the domain and SOGoEnableDomainBasedUID is enabled,
|
|
|
|
// we keep realUID.. This would happen for example if the user
|
|
|
|
// authenticates with foo@bar.com and the UIDFieldName is also foo@bar.com
|
|
|
|
else if ([sd enableDomainBasedUID])
|
2015-05-22 20:03:49 +02:00
|
|
|
uid = [NSString stringWithString: realUID];
|
2011-06-24 21:19:50 +02:00
|
|
|
}
|
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;
|
2011-06-24 21:19:50 +02:00
|
|
|
ASSIGN (loginInDomain, (uid ? uid : realUID));
|
2009-11-29 05:19:32 +01:00
|
|
|
_defaults = nil;
|
|
|
|
_domainDefaults = nil;
|
|
|
|
_settings = nil;
|
|
|
|
mailAccounts = nil;
|
2008-09-02 04:52:55 +02:00
|
|
|
}
|
|
|
|
}
|
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];
|
2009-11-29 05:19:32 +01:00
|
|
|
[_domainDefaults release];
|
2009-08-03 17:46:02 +02:00
|
|
|
[_settings release];
|
2007-05-30 22:20:02 +02:00
|
|
|
[allEmails release];
|
2009-11-29 05:19:32 +01:00
|
|
|
[mailAccounts release];
|
2008-08-29 02:31:27 +02:00
|
|
|
[currentPassword release];
|
|
|
|
[cn release];
|
2011-06-24 21:19:50 +02:00
|
|
|
[loginInDomain release];
|
2006-06-15 21:34:10 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2008-01-16 19:57:58 +01:00
|
|
|
- (void) setPrimaryRoles: (NSArray *) newRoles
|
|
|
|
{
|
2009-11-29 05:19:32 +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-11-29 05:19:32 +01:00
|
|
|
ASSIGN (currentPassword, newPassword);
|
2007-06-19 20:06:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) currentPassword
|
|
|
|
{
|
|
|
|
return currentPassword;
|
|
|
|
}
|
|
|
|
|
2011-06-24 21:19:50 +02:00
|
|
|
- (NSString *) loginInDomain
|
|
|
|
{
|
|
|
|
return loginInDomain;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
{
|
2013-04-16 20:33:57 +02:00
|
|
|
cn = [[self _fetchFieldForUser: @"cn"] stringByTrimmingSpaces];
|
2007-05-09 21:23:09 +02:00
|
|
|
[cn retain];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* properties */
|
2009-11-29 05:19:32 +01:00
|
|
|
- (NSString *) domain
|
|
|
|
{
|
|
|
|
return [self _fetchFieldForUser: @"c_domain"];
|
|
|
|
}
|
|
|
|
|
2012-01-03 23:52:27 +01:00
|
|
|
- (id <SOGoSource>) authenticationSource
|
|
|
|
{
|
|
|
|
NSString *sourceID;
|
|
|
|
SOGoUserManager *um;
|
|
|
|
|
|
|
|
sourceID = [self _fetchFieldForUser: @"SOGoSource"];
|
|
|
|
um = [SOGoUserManager sharedUserManager];
|
|
|
|
|
|
|
|
return [um sourceWithID: sourceID];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-04-18 19:39:11 +02:00
|
|
|
//
|
|
|
|
// We always return the last object among our list of email addresses. This value
|
|
|
|
// is always added in SOGoUserManager: -_fillContactMailRecords:
|
|
|
|
//
|
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
|
|
|
|
2018-07-06 16:24:40 +02:00
|
|
|
return [allEmails objectAtIndex: 0];
|
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;
|
|
|
|
}
|
|
|
|
|
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;
|
2009-11-29 05:19:32 +01:00
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
NSDictionary *locale;
|
2011-02-03 17:12:22 +01:00
|
|
|
WOResourceManager *resMgr;
|
2007-06-19 20:06:18 +02:00
|
|
|
|
2009-03-03 20:08:02 +01:00
|
|
|
dateFormatter = [SOGoDateFormatter new];
|
|
|
|
[dateFormatter autorelease];
|
|
|
|
|
|
|
|
ud = [self userDefaults];
|
2011-02-03 17:12:22 +01:00
|
|
|
resMgr = [[WOApplication application] resourceManager];
|
|
|
|
locale = [resMgr localeForLanguageNamed: [ud language]];
|
2009-11-29 05:19:32 +01:00
|
|
|
[dateFormatter setLocale: locale];
|
|
|
|
format = [ud shortDateFormat];
|
2009-03-03 20:08:02 +01:00
|
|
|
if (format)
|
|
|
|
[dateFormatter setShortDateFormat: format];
|
2009-11-29 05:19:32 +01:00
|
|
|
format = [ud longDateFormat];
|
2009-03-03 20:08:02 +01:00
|
|
|
if (format)
|
|
|
|
[dateFormatter setLongDateFormat: format];
|
2009-11-29 05:19:32 +01:00
|
|
|
format = [ud timeFormat];
|
2009-03-03 20:08:02 +01:00
|
|
|
if (format)
|
|
|
|
[dateFormatter setTimeFormat: format];
|
|
|
|
|
2007-06-19 20:06:18 +02:00
|
|
|
return dateFormatter;
|
|
|
|
}
|
|
|
|
|
2015-03-26 13:52:48 +01:00
|
|
|
- (NSDictionary *) currentDay
|
|
|
|
{
|
|
|
|
NSCalendarDate *now;
|
|
|
|
NSDictionary *description, *abbr;
|
|
|
|
NSDictionary *locale;
|
|
|
|
SOGoUserDefaults *ud;
|
|
|
|
WOResourceManager *resMgr;
|
|
|
|
NSUInteger seconds;
|
|
|
|
|
|
|
|
now = [NSCalendarDate calendarDate];
|
|
|
|
ud = [self userDefaults];
|
|
|
|
resMgr = [[WOApplication application] resourceManager];
|
|
|
|
locale = [resMgr localeForLanguageNamed: [ud language]];
|
|
|
|
|
|
|
|
[now setTimeZone: [ud timeZone]];
|
|
|
|
seconds = [now hourOfDay]*3600 + [now minuteOfHour]*60 + [now secondOfMinute];
|
|
|
|
|
|
|
|
abbr = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[now descriptionWithCalendarFormat: @"%a" locale: locale], @"weekday",
|
|
|
|
[now descriptionWithCalendarFormat: @"%b" locale: locale], @"month",
|
|
|
|
nil];
|
|
|
|
description = [NSDictionary dictionaryWithObjectsAndKeys:
|
|
|
|
[now descriptionWithCalendarFormat: @"%A" locale: locale], @"weekday",
|
|
|
|
[now descriptionWithCalendarFormat: @"%B" locale: locale], @"month",
|
|
|
|
[now descriptionWithCalendarFormat: @"%d" locale: locale], @"day",
|
|
|
|
[now descriptionWithCalendarFormat: @"%Y" locale: locale], @"year",
|
|
|
|
abbr, @"abbr",
|
|
|
|
[NSNumber numberWithInt: (24*3600 - seconds)], @"secondsBeforeTomorrow",
|
|
|
|
nil];
|
|
|
|
|
|
|
|
return description;
|
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (SOGoUserDefaults *) userDefaults
|
2009-01-13 21:39:10 +01:00
|
|
|
{
|
2009-11-19 18:08:47 +01:00
|
|
|
if (!_defaults)
|
2009-01-13 16:26:35 +01:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
_defaults = [SOGoUserDefaults defaultsForUser: login
|
|
|
|
inDomain: [self domain]];
|
|
|
|
[_defaults retain];
|
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-11-29 05:19:32 +01:00
|
|
|
return _defaults;
|
2007-03-27 20:16:52 +02:00
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (SOGoDomainDefaults *) domainDefaults
|
2007-03-27 20:16:52 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
NSString *domain;
|
|
|
|
|
|
|
|
if (!_domainDefaults)
|
2009-01-13 16:26:35 +01:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
domain = [self domain];
|
|
|
|
if ([domain length])
|
|
|
|
{
|
|
|
|
_domainDefaults = [SOGoDomainDefaults defaultsForDomain: domain];
|
|
|
|
if (!_domainDefaults)
|
|
|
|
{
|
2012-02-11 08:08:02 +01:00
|
|
|
//[self errorWithFormat: @"domain '%@' does not exist!", domain];
|
2009-11-29 05:19:32 +01:00
|
|
|
_domainDefaults = [SOGoSystemDefaults sharedSystemDefaults];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_domainDefaults = [SOGoSystemDefaults sharedSystemDefaults];
|
|
|
|
[_domainDefaults retain];
|
2008-11-11 01:17:35 +01:00
|
|
|
}
|
2009-02-24 02:54:59 +01:00
|
|
|
//else
|
2009-11-29 05:19:32 +01:00
|
|
|
// NSLog(@"User defaults cache hit for %@", login);
|
2007-03-27 20:16:52 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
return _domainDefaults;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
- (SOGoUserSettings *) userSettings
|
2007-05-30 22:20:02 +02:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
if (!_settings)
|
2009-03-22 17:03:21 +01:00
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
_settings = [SOGoUserSettings settingsForUser: login];
|
|
|
|
[_settings retain];
|
2009-03-22 17:03:21 +01:00
|
|
|
}
|
2007-05-30 22:20:02 +02:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
return _settings;
|
2007-04-11 21:07:54 +02:00
|
|
|
}
|
|
|
|
|
2008-07-18 21:25:26 +02:00
|
|
|
- (NSCalendarDate *) firstDayOfWeekForDate: (NSCalendarDate *) date
|
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
NSCalendarDate *firstDay;
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
offset = [[self userDefaults] firstDayOfWeek] - [date dayOfWeek];
|
2008-07-18 21:25:26 +02:00
|
|
|
if (offset > 0)
|
|
|
|
offset -= 7;
|
|
|
|
|
|
|
|
firstDay = [date addTimeInterval: offset * 86400];
|
|
|
|
|
|
|
|
return firstDay;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int) dayOfWeekForDate: (NSCalendarDate *) date
|
|
|
|
{
|
|
|
|
unsigned int offset, baseDayOfWeek, dayOfWeek;
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
offset = [[self userDefaults] firstDayOfWeek];
|
2008-07-18 21:25:26 +02:00
|
|
|
baseDayOfWeek = [date dayOfWeek];
|
|
|
|
if (offset > baseDayOfWeek)
|
|
|
|
baseDayOfWeek += 7;
|
|
|
|
|
|
|
|
dayOfWeek = baseDayOfWeek - offset;
|
|
|
|
|
|
|
|
return dayOfWeek;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCalendarDate *) firstWeekOfYearForDate: (NSCalendarDate *) date
|
|
|
|
{
|
|
|
|
NSString *firstWeekRule;
|
|
|
|
NSCalendarDate *januaryFirst, *firstWeek;
|
|
|
|
unsigned int dayOfWeek;
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
firstWeekRule = [[self userDefaults] firstWeekOfYear];
|
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
|
|
|
|
{
|
2015-12-22 20:19:02 +01:00
|
|
|
NSCalendarDate *firstWeek, *previousWeek;
|
2008-07-18 21:25:26 +02:00
|
|
|
unsigned int weekNumber;
|
|
|
|
|
|
|
|
firstWeek = [self firstWeekOfYearForDate: date];
|
|
|
|
if ([firstWeek earlierDate: date] == firstWeek)
|
2015-12-22 20:19:02 +01:00
|
|
|
{
|
|
|
|
weekNumber = ([date timeIntervalSinceDate: firstWeek] / (86400 * 7) + 1);
|
|
|
|
}
|
2008-07-18 21:25:26 +02:00
|
|
|
else
|
2015-12-22 20:19:02 +01:00
|
|
|
{
|
|
|
|
// Date is within the last week of the previous year;
|
|
|
|
// Compute the previous week number to find the week number of the requested date.
|
|
|
|
// The number will either be 52 or 53.
|
|
|
|
previousWeek = [date dateByAddingYears: 0
|
|
|
|
months: 0
|
|
|
|
days: -7];
|
|
|
|
firstWeek = [self firstWeekOfYearForDate: previousWeek];
|
|
|
|
weekNumber = ([previousWeek timeIntervalSinceDate: firstWeek] / (86400 * 7) + 1);
|
|
|
|
weekNumber += 1;
|
|
|
|
}
|
2008-07-18 21:25:26 +02:00
|
|
|
|
|
|
|
return weekNumber;
|
|
|
|
}
|
|
|
|
|
2007-08-15 22:30:37 +02:00
|
|
|
/* mail */
|
2010-08-06 16:25:59 +02:00
|
|
|
- (BOOL) _migrateFolderWithPurpose: (NSString *) purpose
|
|
|
|
withName: (NSString *) folderName
|
|
|
|
{
|
|
|
|
NSString *methodName;
|
|
|
|
SEL methodSel;
|
|
|
|
BOOL rc;
|
|
|
|
|
|
|
|
[self userDefaults];
|
|
|
|
methodName = [NSString stringWithFormat: @"set%@FolderName:", purpose];
|
|
|
|
methodSel = NSSelectorFromString (methodName);
|
|
|
|
if ([_defaults respondsToSelector: methodSel])
|
|
|
|
{
|
|
|
|
[_defaults performSelector: methodSel withObject: folderName];
|
|
|
|
rc = YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[self errorWithFormat: @"method '%@' not available with user defaults"
|
|
|
|
@" object, folder migration fails", methodName];
|
|
|
|
rc = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _migrateFolderSettings
|
|
|
|
{
|
|
|
|
NSMutableDictionary *mailSettings;
|
|
|
|
NSString *folderName, *key;
|
|
|
|
BOOL migrated;
|
|
|
|
NSString **purpose;
|
|
|
|
NSString *purposes[] = { @"Drafts", @"Sent", @"Trash", nil };
|
|
|
|
|
|
|
|
[self userSettings];
|
|
|
|
mailSettings = [_settings objectForKey: @"Mail"];
|
|
|
|
if (mailSettings)
|
|
|
|
{
|
|
|
|
migrated = NO;
|
|
|
|
purpose = purposes;
|
|
|
|
while (*purpose)
|
|
|
|
{
|
2010-08-06 17:24:47 +02:00
|
|
|
key = [NSString stringWithFormat: @"%@Folder", *purpose];
|
2010-08-06 16:25:59 +02:00
|
|
|
folderName = [mailSettings objectForKey: key];
|
|
|
|
if ([folderName length]
|
|
|
|
&& [self _migrateFolderWithPurpose: *purpose
|
|
|
|
withName: folderName])
|
|
|
|
{
|
|
|
|
migrated = YES;
|
|
|
|
[mailSettings removeObjectForKey: key];
|
|
|
|
folderName = nil;
|
|
|
|
}
|
|
|
|
purpose++;
|
|
|
|
}
|
|
|
|
if (migrated)
|
|
|
|
{
|
|
|
|
[_settings synchronize];
|
|
|
|
[self userDefaults];
|
|
|
|
[_defaults synchronize];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-13 16:44:49 +02:00
|
|
|
- (void) _appendSystemMailAccountWithDelegatedIdentities: (BOOL) appendDeletegatedIdentities
|
2007-08-15 22:30:37 +02:00
|
|
|
{
|
2012-12-03 22:49:20 +01:00
|
|
|
NSString *fullName, *replyTo, *imapLogin, *imapServer, *cImapServer, *signature,
|
2015-03-23 19:08:31 +01:00
|
|
|
*encryption, *scheme, *action, *query, *customEmail, *defaultEmail, *sieveServer;
|
2018-01-12 20:47:31 +01:00
|
|
|
NSMutableDictionary *mailAccount, *identity, *mailboxes, *receipts, *security, *mailSettings;
|
2010-09-28 17:29:05 +02:00
|
|
|
NSNumber *port;
|
2016-10-03 16:29:30 +02:00
|
|
|
NSMutableArray *identities, *mails;
|
|
|
|
NSArray *delegators, *delegates;
|
2012-12-03 22:49:20 +01:00
|
|
|
NSURL *url, *cUrl;
|
2015-03-23 19:08:31 +01:00
|
|
|
unsigned int count, max, default_identity;
|
2010-09-28 17:29:05 +02:00
|
|
|
NSInteger defaultPort;
|
2016-10-03 16:29:30 +02:00
|
|
|
NSUInteger index;
|
2007-11-06 18:12:37 +01:00
|
|
|
|
2010-09-01 22:27:45 +02:00
|
|
|
[self userDefaults];
|
2016-10-26 21:42:50 +02:00
|
|
|
[self userSettings];
|
2010-09-01 22:27:45 +02:00
|
|
|
|
2016-10-26 21:42:50 +02:00
|
|
|
mailSettings = [_settings objectForKey: @"Mail"];
|
2010-08-03 20:54:49 +02:00
|
|
|
mailAccount = [NSMutableDictionary new];
|
|
|
|
|
2010-09-28 17:29:05 +02:00
|
|
|
// 1. login
|
2010-08-03 20:54:49 +02:00
|
|
|
imapLogin = [[SOGoUserManager sharedUserManager]
|
2013-01-11 15:55:10 +01:00
|
|
|
getExternalLoginForUID: [self loginInDomain]
|
|
|
|
inDomain: [self domain]];
|
2010-09-28 17:29:05 +02:00
|
|
|
[mailAccount setObject: imapLogin forKey: @"userName"];
|
2010-08-06 16:25:59 +02:00
|
|
|
|
2010-09-28 17:29:05 +02:00
|
|
|
// 2. server
|
2010-08-25 15:09:25 +02:00
|
|
|
// imapServer might have the following format
|
|
|
|
// localhost
|
|
|
|
// localhost:143
|
|
|
|
// imap://localhost
|
|
|
|
// imap://localhost:143
|
|
|
|
// imaps://localhost:993
|
|
|
|
// imaps://localhost:143/?tls=YES
|
|
|
|
// imaps://localhost/?tls=YES
|
2010-09-28 17:29:05 +02:00
|
|
|
|
2012-12-03 22:49:20 +01:00
|
|
|
cImapServer = [self _fetchFieldForUser: @"c_imaphostname"];
|
|
|
|
imapServer = [[self domainDefaults] imapServer];
|
|
|
|
cUrl = [NSURL URLWithString: (cImapServer ? cImapServer : @"")];
|
2010-08-25 15:09:25 +02:00
|
|
|
url = [NSURL URLWithString: imapServer];
|
2012-12-03 22:49:20 +01:00
|
|
|
if([cUrl host])
|
|
|
|
imapServer = [cUrl host];
|
|
|
|
else
|
|
|
|
if(cImapServer)
|
|
|
|
imapServer = cImapServer;
|
|
|
|
else
|
|
|
|
if([url host])
|
|
|
|
imapServer = [url host];
|
2010-09-28 17:29:05 +02:00
|
|
|
[mailAccount setObject: imapServer forKey: @"serverName"];
|
2010-08-25 15:09:25 +02:00
|
|
|
|
2010-09-28 17:29:05 +02:00
|
|
|
// 3. port & encryption
|
2012-12-03 22:49:20 +01:00
|
|
|
scheme = [cUrl scheme] ? [cUrl scheme] : [url scheme];
|
2013-09-27 21:54:11 +02:00
|
|
|
query = [cUrl query] ? [cUrl query] : [url query];
|
|
|
|
|
2010-10-06 21:47:20 +02:00
|
|
|
if (scheme
|
|
|
|
&& [scheme caseInsensitiveCompare: @"imaps"] == NSOrderedSame)
|
2010-08-25 15:09:25 +02:00
|
|
|
{
|
2013-09-27 21:54:11 +02:00
|
|
|
if (query && [query caseInsensitiveCompare: @"tls=YES"] == NSOrderedSame)
|
|
|
|
{
|
|
|
|
defaultPort = 143;
|
|
|
|
encryption = @"tls";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
encryption = @"ssl";
|
|
|
|
defaultPort = 993;
|
|
|
|
}
|
2010-08-25 15:09:25 +02:00
|
|
|
}
|
2010-09-28 17:29:05 +02:00
|
|
|
else
|
|
|
|
{
|
2010-10-06 21:47:20 +02:00
|
|
|
if (query && [query caseInsensitiveCompare: @"tls=YES"] == NSOrderedSame)
|
2010-09-28 17:29:05 +02:00
|
|
|
encryption = @"tls";
|
|
|
|
else
|
|
|
|
encryption = @"none";
|
2013-09-27 21:54:11 +02:00
|
|
|
|
2010-09-28 17:29:05 +02:00
|
|
|
defaultPort = 143;
|
|
|
|
}
|
2012-12-03 22:49:20 +01:00
|
|
|
port = [cUrl port] ? [cUrl port] : [url port];
|
2010-09-28 17:29:05 +02:00
|
|
|
if ([port intValue] == 0) /* port is nil or intValue == 0 */
|
|
|
|
port = [NSNumber numberWithInt: defaultPort];
|
2010-08-25 15:09:25 +02:00
|
|
|
[mailAccount setObject: port forKey: @"port"];
|
|
|
|
[mailAccount setObject: encryption forKey: @"encryption"];
|
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
// 4. Sieve server
|
2012-11-26 19:13:06 +01:00
|
|
|
sieveServer = [self _fetchFieldForUser: @"c_sievehostname"];
|
|
|
|
|
|
|
|
if (sieveServer)
|
|
|
|
{
|
|
|
|
[mailAccount setObject: sieveServer forKey: @"sieveServerName"];
|
|
|
|
}
|
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
// 5. Identities
|
2015-03-23 19:08:31 +01:00
|
|
|
defaultEmail = [NSString stringWithFormat: @"%@@%@", [self loginInDomain], [self domain]];
|
|
|
|
default_identity = 0;
|
2010-08-03 20:54:49 +02:00
|
|
|
identities = [NSMutableArray new];
|
2016-10-03 16:29:30 +02:00
|
|
|
mails = [NSMutableArray arrayWithArray: [self allEmails]];
|
2010-08-03 20:54:49 +02:00
|
|
|
[mailAccount setObject: [mails objectAtIndex: 0] forKey: @"name"];
|
|
|
|
|
2012-04-20 15:27:21 +02:00
|
|
|
replyTo = [_defaults mailReplyTo];
|
|
|
|
|
2010-08-03 20:54:49 +02:00
|
|
|
max = [mails count];
|
2012-04-20 15:37:46 +02:00
|
|
|
|
|
|
|
/* custom from */
|
|
|
|
if ([[self domainDefaults] mailCustomFromEnabled])
|
|
|
|
{
|
|
|
|
[self userDefaults];
|
2012-04-25 23:32:18 +02:00
|
|
|
customEmail = [_defaults mailCustomEmail];
|
|
|
|
fullName = [_defaults mailCustomFullName];
|
|
|
|
if ([customEmail length] > 0 || [fullName length] > 0)
|
2012-04-20 15:37:46 +02:00
|
|
|
{
|
2012-04-25 23:32:18 +02:00
|
|
|
if ([customEmail length] == 0)
|
|
|
|
customEmail = [mails objectAtIndex: 0];
|
2016-10-03 16:29:30 +02:00
|
|
|
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--;
|
|
|
|
}
|
|
|
|
}
|
2012-04-20 15:37:46 +02:00
|
|
|
|
2012-04-25 23:32:18 +02:00
|
|
|
if ([fullName length] == 0)
|
2012-04-20 15:37:46 +02:00
|
|
|
{
|
|
|
|
fullName = [self cn];
|
2012-04-25 23:32:18 +02:00
|
|
|
if ([fullName length] == 0)
|
2012-04-20 15:37:46 +02:00
|
|
|
fullName = login;
|
|
|
|
}
|
2012-04-25 23:32:18 +02:00
|
|
|
|
|
|
|
identity = [NSMutableDictionary new];
|
|
|
|
[identity setObject: customEmail forKey: @"email"];
|
2012-04-20 15:37:46 +02:00
|
|
|
[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];
|
2015-03-23 19:08:31 +01:00
|
|
|
|
|
|
|
if ([[identity objectForKey: @"email"] caseInsensitiveCompare: defaultEmail] == NSOrderedSame)
|
|
|
|
default_identity = [identities count]-1;
|
|
|
|
|
2012-04-20 15:37:46 +02:00
|
|
|
[identity release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 20:54:49 +02:00
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
|
|
|
identity = [NSMutableDictionary new];
|
|
|
|
fullName = [self cn];
|
|
|
|
if (![fullName length])
|
|
|
|
fullName = login;
|
|
|
|
[identity setObject: fullName forKey: @"fullName"];
|
2013-04-16 20:33:57 +02:00
|
|
|
[identity setObject: [[mails objectAtIndex: count] stringByTrimmingSpaces]
|
|
|
|
forKey: @"email"];
|
2012-04-20 15:27:21 +02:00
|
|
|
|
|
|
|
if ([replyTo length] > 0)
|
|
|
|
[identity setObject: replyTo forKey: @"replyTo"];
|
|
|
|
|
2010-09-01 22:27:45 +02:00
|
|
|
signature = [_defaults mailSignature];
|
2010-08-06 16:25:59 +02:00
|
|
|
if (signature)
|
|
|
|
[identity setObject: signature forKey: @"signature"];
|
2010-08-03 20:54:49 +02:00
|
|
|
[identities addObject: identity];
|
2015-03-23 19:08:31 +01:00
|
|
|
|
|
|
|
if ([[identity objectForKey: @"email"] caseInsensitiveCompare: defaultEmail] == NSOrderedSame)
|
2016-03-14 18:18:24 +01:00
|
|
|
default_identity = [identities count]-1;
|
2015-03-23 19:08:31 +01:00
|
|
|
|
2010-08-03 20:54:49 +02:00
|
|
|
[identity release];
|
|
|
|
}
|
2015-03-23 19:08:31 +01:00
|
|
|
[[identities objectAtIndex: default_identity] setObject: [NSNumber numberWithBool: YES]
|
|
|
|
forKey: @"isDefault"];
|
2016-06-13 16:44:49 +02:00
|
|
|
|
|
|
|
/* identities from delegators */
|
|
|
|
if (appendDeletegatedIdentities)
|
|
|
|
{
|
|
|
|
delegators = [mailSettings objectForKey: @"DelegateFrom"];
|
|
|
|
if (delegators)
|
|
|
|
{
|
2016-10-26 21:42:50 +02:00
|
|
|
BOOL dirty;
|
|
|
|
NSDictionary *delegatorAccount, *delegatorSettings;
|
|
|
|
NSMutableArray *validDelegators;
|
|
|
|
NSString *delegatorLogin;
|
|
|
|
SOGoUser *delegatorUser;
|
|
|
|
|
|
|
|
dirty = NO;
|
|
|
|
validDelegators = [NSMutableArray array];
|
2016-06-13 16:44:49 +02:00
|
|
|
max = [delegators count];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
{
|
2016-10-26 21:42:50 +02:00
|
|
|
// 1. Verify if delegator is valid
|
|
|
|
delegatorLogin = [delegators objectAtIndex: count];
|
|
|
|
delegatorUser = [SOGoUser userWithLogin: delegatorLogin];
|
|
|
|
if (delegatorUser)
|
2016-06-13 16:44:49 +02:00
|
|
|
{
|
2016-10-26 21:42:50 +02:00
|
|
|
// 2. Verify if delegator still delegates to user
|
|
|
|
delegatorSettings = [[delegatorUser userSettings] objectForKey: @"Mail"];
|
|
|
|
delegates = [delegatorSettings objectForKey: @"DelegateTo"];
|
|
|
|
if ([delegates containsObject: [self login]])
|
|
|
|
{
|
|
|
|
[validDelegators addObject: delegatorLogin];
|
|
|
|
delegatorAccount = [[delegatorUser mailAccountsWithDelegatedIdentities: NO] objectAtIndex: 0];
|
|
|
|
[identities addObjectsFromArray: [delegatorAccount objectForKey: @"identities"]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
dirty = YES;
|
2016-06-13 16:44:49 +02:00
|
|
|
}
|
2016-10-26 21:42:50 +02:00
|
|
|
else
|
|
|
|
dirty = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dirty)
|
|
|
|
{
|
|
|
|
[mailSettings setObject: validDelegators
|
|
|
|
forKey: @"DelegateFrom"];
|
|
|
|
[_settings synchronize];
|
2016-06-13 16:44:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-03 20:54:49 +02:00
|
|
|
[mailAccount setObject: identities forKey: @"identities"];
|
|
|
|
[identities release];
|
2010-08-06 16:25:59 +02:00
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
// 6. Receipts
|
2010-09-01 22:27:45 +02:00
|
|
|
if ([_defaults allowUserReceipt])
|
|
|
|
{
|
|
|
|
receipts = [NSMutableDictionary new];
|
|
|
|
|
|
|
|
[receipts setObject: @"allow" forKey: @"receiptAction"];
|
|
|
|
action = [_defaults userReceiptNonRecipientAction];
|
|
|
|
if (action)
|
|
|
|
[receipts setObject: action forKey: @"receiptNonRecipientAction"];
|
|
|
|
action = [_defaults userReceiptOutsideDomainAction];
|
|
|
|
if (action)
|
|
|
|
[receipts setObject: action forKey: @"receiptOutsideDomainAction"];
|
|
|
|
action = [_defaults userReceiptAnyAction];
|
|
|
|
if (action)
|
|
|
|
[receipts setObject: action forKey: @"receiptAnyAction"];
|
|
|
|
|
|
|
|
[mailAccount setObject: receipts forKey: @"receipts"];
|
|
|
|
[receipts release];
|
|
|
|
}
|
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
// 7. Mailboxes
|
2010-08-06 16:25:59 +02:00
|
|
|
mailboxes = [NSMutableDictionary new];
|
|
|
|
|
|
|
|
[self _migrateFolderSettings];
|
|
|
|
[mailboxes setObject: [_defaults draftsFolderName]
|
|
|
|
forKey: @"Drafts"];
|
|
|
|
[mailboxes setObject: [_defaults sentFolderName]
|
|
|
|
forKey: @"Sent"];
|
|
|
|
[mailboxes setObject: [_defaults trashFolderName]
|
|
|
|
forKey: @"Trash"];
|
2016-01-22 16:30:27 +01:00
|
|
|
[mailboxes setObject: [_defaults junkFolderName]
|
|
|
|
forKey: @"Junk"];
|
2014-11-25 22:09:55 +01:00
|
|
|
[mailAccount setObject: mailboxes forKey: @"specialMailboxes"];
|
2010-08-06 16:25:59 +02:00
|
|
|
[mailboxes release];
|
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
// 8. Delegates
|
2015-07-04 02:40:06 +02:00
|
|
|
delegates = [mailSettings objectForKey: @"DelegateTo"];
|
|
|
|
if (!delegates)
|
|
|
|
delegates = [NSArray array];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSMutableArray *allDelegates;
|
|
|
|
SOGoUser *delegate;
|
|
|
|
|
|
|
|
allDelegates = [NSMutableArray array];
|
|
|
|
for (count = 0; count < [delegates count]; count++)
|
|
|
|
{
|
|
|
|
delegate = [SOGoUser userWithLogin: [delegates objectAtIndex: count]];
|
|
|
|
[allDelegates addObject: [NSDictionary dictionaryWithObjectsAndKeys: [delegates objectAtIndex: count], @"uid",
|
|
|
|
[delegate cn], @"cn",
|
|
|
|
[delegate systemEmail], @"c_email", nil]];
|
|
|
|
}
|
|
|
|
|
|
|
|
delegates = allDelegates;
|
|
|
|
}
|
|
|
|
[mailAccount setObject: delegates forKey: @"delegates"];
|
2016-06-13 16:44:49 +02:00
|
|
|
|
2018-01-12 20:47:31 +01:00
|
|
|
// 9. Security
|
|
|
|
if ([[_defaults mailCertificate] length])
|
|
|
|
{
|
|
|
|
security = [NSMutableDictionary new];
|
|
|
|
|
|
|
|
[security setObject: [NSNumber numberWithBool: YES] forKey: @"hasCertificate"];
|
|
|
|
|
|
|
|
if ([_defaults mailCertificateAlwaysSign])
|
|
|
|
[security setObject: [NSNumber numberWithBool: YES] forKey: @"alwaysSign"];
|
|
|
|
|
|
|
|
if ([_defaults mailCertificateAlwaysEncrypt])
|
|
|
|
[security setObject: [NSNumber numberWithBool: YES] forKey: @"alwaysEncrypt"];
|
|
|
|
|
|
|
|
[mailAccount setObject: security forKey: @"security"];
|
|
|
|
[security release];
|
|
|
|
}
|
|
|
|
|
2016-06-13 16:44:49 +02:00
|
|
|
[mailAccounts addObject: mailAccount];
|
|
|
|
[mailAccount release];
|
2010-08-03 20:54:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) mailAccounts
|
2016-06-13 16:44:49 +02:00
|
|
|
{
|
|
|
|
return [self mailAccountsWithDelegatedIdentities: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *) mailAccountsWithDelegatedIdentities: (BOOL) appendDeletegatedIdentities
|
2010-08-03 20:54:49 +02:00
|
|
|
{
|
2010-08-06 16:25:59 +02:00
|
|
|
NSArray *auxAccounts;
|
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
if (!mailAccounts)
|
2007-11-06 18:12:37 +01:00
|
|
|
{
|
2010-08-03 20:54:49 +02:00
|
|
|
mailAccounts = [NSMutableArray new];
|
2016-06-13 16:44:49 +02:00
|
|
|
[self _appendSystemMailAccountWithDelegatedIdentities: appendDeletegatedIdentities];
|
2010-08-06 16:25:59 +02:00
|
|
|
if ([[self domainDefaults] mailAuxiliaryUserAccountsEnabled])
|
|
|
|
{
|
|
|
|
auxAccounts = [[self userDefaults] auxiliaryMailAccounts];
|
|
|
|
if (auxAccounts)
|
|
|
|
[mailAccounts addObjectsFromArray: auxAccounts];
|
|
|
|
}
|
2007-11-06 18:12:37 +01:00
|
|
|
}
|
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
|
|
|
- (NSArray *) allIdentities
|
|
|
|
{
|
|
|
|
NSArray *identities;
|
|
|
|
|
2008-10-23 17:35:20 +02:00
|
|
|
identities = [[self mailAccounts] objectsForKey: @"identities"
|
2012-04-20 15:37:46 +02:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-01-15 00:19:19 +01:00
|
|
|
return [SOGoUserFolder objectWithName: login
|
|
|
|
inContainer: [WOApplication application]];
|
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
|
|
|
}
|
|
|
|
|
2014-01-10 20:03:50 +01:00
|
|
|
- (SOGoAppointmentFolder *) personalCalendarFolderInContext: (WOContext *) context
|
2007-11-13 23:38:05 +01:00
|
|
|
{
|
2010-07-15 19:06:29 +02:00
|
|
|
return [[self calendarsFolderInContext: context] lookupPersonalFolder: @"personal"
|
|
|
|
ignoringRights: YES];
|
2007-11-13 23:38:05 +01:00
|
|
|
}
|
|
|
|
|
2014-01-10 20:03:50 +01:00
|
|
|
- (SOGoContactFolder *) personalContactsFolderInContext: (WOContext *) context
|
|
|
|
{
|
|
|
|
SOGoContactFolders *folders;
|
|
|
|
|
|
|
|
folders = [[self homeFolderInContext: context] lookupName: @"Contacts"
|
|
|
|
inContext: context
|
|
|
|
acquire: NO];
|
|
|
|
|
|
|
|
return [folders lookupPersonalFolder: @"personal"
|
|
|
|
ignoringRights: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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];
|
2010-06-02 18:35:59 +02:00
|
|
|
if ([login isEqualToString: @"anonymous"]
|
|
|
|
&& [(SOGoObject *) object isInPublicZone])
|
|
|
|
[rolesForObject addObject: SOGoRole_PublicUser];
|
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
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
[self domainDefaults];
|
|
|
|
|
|
|
|
return [[_domainDefaults superUsernames] containsObject: login];
|
2007-11-19 23:34:31 +01:00
|
|
|
}
|
|
|
|
|
2011-04-14 20:41:10 +02:00
|
|
|
- (BOOL) canAuthenticate
|
|
|
|
{
|
|
|
|
id authValue;
|
|
|
|
|
|
|
|
authValue = [self _fetchFieldForUser: @"canAuthenticate"];
|
|
|
|
|
|
|
|
return [authValue boolValue];
|
|
|
|
}
|
|
|
|
|
2020-05-07 13:22:24 +02:00
|
|
|
- (NSString *) googleAuthenticatorKey
|
|
|
|
{
|
|
|
|
#if defined(MFA_CONFIG)
|
|
|
|
NSString *key, *result;
|
|
|
|
const char *s;
|
|
|
|
char *secret;
|
|
|
|
|
|
|
|
size_t s_len, secret_len;
|
|
|
|
|
|
|
|
key = [[[self userSettings] userSalt] substringToIndex: 12];
|
|
|
|
s = [key UTF8String];
|
|
|
|
s_len = strlen(s);
|
|
|
|
|
|
|
|
oath_init();
|
|
|
|
oath_base32_encode(s,s_len, &secret, &secret_len);
|
|
|
|
oath_done();
|
|
|
|
|
|
|
|
result = [[NSString alloc] initWithBytesNoCopy: secret
|
|
|
|
length: secret_len
|
|
|
|
encoding: NSASCIIStringEncoding
|
|
|
|
freeWhenDone: YES];
|
|
|
|
|
|
|
|
return [result autorelease];
|
|
|
|
#else
|
|
|
|
return nil;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-25 12:31:08 +02:00
|
|
|
/* resource */
|
|
|
|
- (BOOL) isResource
|
|
|
|
{
|
|
|
|
NSNumber *v;
|
|
|
|
|
|
|
|
v = [self _fetchFieldForUser: @"isResource"];
|
|
|
|
|
|
|
|
return (v && [v intValue]);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) numberOfSimultaneousBookings
|
|
|
|
{
|
|
|
|
NSNumber *v;
|
|
|
|
|
|
|
|
v = [self _fetchFieldForUser: @"numberOfSimultaneousBookings"];
|
|
|
|
|
|
|
|
if (v)
|
|
|
|
return [v intValue];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-11-26 21:41:59 +01:00
|
|
|
/* module access */
|
|
|
|
- (BOOL) canAccessModule: (NSString *) module
|
|
|
|
{
|
2009-10-13 22:17:29 +02:00
|
|
|
id accessValue;
|
2007-11-26 21:41:59 +01:00
|
|
|
|
|
|
|
accessValue = [self _fetchFieldForUser:
|
|
|
|
[NSString stringWithFormat: @"%@Access", module]];
|
|
|
|
|
|
|
|
return [accessValue boolValue];
|
|
|
|
}
|
|
|
|
|
2006-06-15 21:34:10 +02:00
|
|
|
@end /* SOGoUser */
|