2006-06-15 21:34:10 +02:00
|
|
|
/*
|
|
|
|
Copyright (C) 2004-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.
|
|
|
|
*/
|
|
|
|
|
2009-09-29 22:13:36 +02:00
|
|
|
#import <Foundation/NSDictionary.h>
|
2007-08-01 20:22:45 +02:00
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
|
|
|
#import <NGObjWeb/NSException+HTTP.h>
|
|
|
|
#import <NGObjWeb/WOContext+SoObjects.h>
|
|
|
|
#import <NGExtensions/NSNull+misc.h>
|
|
|
|
#import <NGExtensions/NSObject+Logs.h>
|
|
|
|
|
2007-08-15 22:17:16 +02:00
|
|
|
#import "../SOGo/NSArray+Utilities.h"
|
2009-09-29 22:13:36 +02:00
|
|
|
#import "../SOGo/NSString+Utilities.h"
|
2007-08-15 22:17:16 +02:00
|
|
|
#import "../SOGo/SOGoUser.h"
|
2008-02-07 21:21:13 +01:00
|
|
|
#import "SOGoMailAccount.h"
|
2007-08-01 20:22:45 +02:00
|
|
|
|
|
|
|
#import "SOGoMailAccounts.h"
|
2006-06-15 21:34:10 +02:00
|
|
|
|
|
|
|
@implementation SOGoMailAccounts
|
|
|
|
|
2010-08-03 20:52:49 +02:00
|
|
|
- (NSArray *) mailAccounts
|
2007-05-25 23:22:38 +02:00
|
|
|
{
|
2010-08-03 20:52:49 +02:00
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2010-08-03 20:52:49 +02:00
|
|
|
return [user mailAccounts];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2010-08-03 20:52:49 +02:00
|
|
|
- (NSArray *) toManyRelationshipKeys
|
2009-09-29 22:13:36 +02:00
|
|
|
{
|
2010-08-03 20:52:49 +02:00
|
|
|
NSMutableArray *keys;
|
2009-09-29 22:13:36 +02:00
|
|
|
NSArray *accounts;
|
|
|
|
int count, max;
|
2010-08-03 20:52:49 +02:00
|
|
|
SOGoUser *user;
|
|
|
|
|
|
|
|
user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
|
|
|
|
accounts = [user mailAccounts];
|
|
|
|
max = [accounts count];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2010-08-03 20:52:49 +02:00
|
|
|
keys = [NSMutableArray arrayWithCapacity: max];
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
[keys addObject: [NSString stringWithFormat: @"%d", count]];
|
2009-09-29 22:13:36 +02:00
|
|
|
|
2010-08-03 20:52:49 +02:00
|
|
|
return keys;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2009-09-29 22:13:36 +02:00
|
|
|
/* name lookup */
|
|
|
|
|
2007-08-15 22:17:16 +02:00
|
|
|
- (id) lookupName: (NSString *) _key
|
2009-09-29 22:13:36 +02:00
|
|
|
inContext: (id) _ctx
|
|
|
|
acquire: (BOOL) _flag
|
2007-04-12 02:34:43 +02:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
id obj;
|
2010-08-03 20:52:49 +02:00
|
|
|
NSArray *accounts;
|
|
|
|
SOGoUser *user;
|
|
|
|
int keyCount;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
/* first check attributes directly bound to the application */
|
|
|
|
obj = [super lookupName:_key inContext:_ctx acquire:NO];
|
|
|
|
if (!obj)
|
|
|
|
{
|
2010-08-03 20:52:49 +02:00
|
|
|
user = [SOGoUser userWithLogin: [self ownerInContext: nil]];
|
|
|
|
accounts = [user mailAccounts];
|
|
|
|
|
|
|
|
keyCount = [_key intValue];
|
|
|
|
if ([_key isEqualToString: [NSString stringWithFormat: @"%d", keyCount]]
|
|
|
|
&& keyCount > -1 && keyCount < [accounts count])
|
|
|
|
obj = [SOGoMailAccount objectWithName: _key inContainer: self];
|
2008-02-07 21:21:13 +01:00
|
|
|
else
|
2009-09-29 22:13:36 +02:00
|
|
|
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
|
2008-02-07 21:21:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end /* SOGoMailAccounts */
|