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.
|
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
#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
|
|
|
|
|
|
|
|
/* listing the available mailboxes */
|
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
// - (BOOL) isInHomeFolderBranchOfLoggedInAccount: (NSString *) userLogin
|
|
|
|
// {
|
|
|
|
// return [[container nameInContainer] isEqualToString: userLogin];
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-08-15 22:17:16 +02:00
|
|
|
- (NSArray *) toManyRelationshipKeys
|
2007-05-25 23:22:38 +02:00
|
|
|
{
|
2007-08-15 22:17:16 +02:00
|
|
|
NSArray *accounts;
|
2007-05-25 23:22:38 +02:00
|
|
|
|
2007-08-15 22:17:16 +02:00
|
|
|
accounts = [[context activeUser] mailAccounts];
|
2006-07-29 00:59:11 +02:00
|
|
|
|
2007-08-15 22:17:16 +02:00
|
|
|
return [accounts objectsForKey: @"name"];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* name lookup */
|
|
|
|
|
2007-08-15 22:17:16 +02:00
|
|
|
- (BOOL) isValidMailAccountName: (NSString *) _key
|
|
|
|
{
|
2007-08-20 23:49:28 +02:00
|
|
|
NSArray *accounts;
|
|
|
|
|
|
|
|
accounts = [[context activeUser] mailAccounts];
|
|
|
|
|
|
|
|
return [[accounts objectsForKey: @"name"] containsObject: _key];
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
// - (id) mailAccountWithName: (NSString *) _key
|
|
|
|
// inContext: (id) _ctx
|
|
|
|
// {
|
|
|
|
// static Class ctClass = Nil;
|
|
|
|
// id ct;
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
// if (ctClass == Nil)
|
|
|
|
// ctClass = NSClassFromString(@"SOGoMailAccount");
|
|
|
|
// if (ctClass == Nil) {
|
|
|
|
// [self errorWithFormat:@"missing SOGoMailAccount class!"];
|
|
|
|
// return nil;
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
// ct = [[ctClass alloc] initWithName:_key inContainer:self];
|
2007-08-15 22:17:16 +02:00
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
// return [ct autorelease];
|
|
|
|
// }
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2007-08-15 22:17:16 +02:00
|
|
|
- (id) lookupName: (NSString *) _key
|
|
|
|
inContext: (id) _ctx
|
|
|
|
acquire: (BOOL) _flag
|
2007-04-12 02:34:43 +02:00
|
|
|
{
|
2006-06-15 21:34:10 +02:00
|
|
|
id obj;
|
2008-02-07 21:21:13 +01:00
|
|
|
// NSString *userLogin;
|
2008-01-16 19:59:58 +01:00
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
// userLogin = [[context activeUser] login];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
// if (![self isInHomeFolderBranchOfLoggedInAccount: userLogin]) {
|
|
|
|
// [self warnWithFormat:@ "User %@ tried to access mail hierarchy of %@",
|
|
|
|
// userLogin, [container nameInContainer]];
|
2006-06-15 21:34:10 +02:00
|
|
|
|
2008-02-07 21:21:13 +01:00
|
|
|
// return [NSException exceptionWithHTTPStatus:403 /* Forbidden */
|
|
|
|
// reason:@"Tried to access the mail of another user"];
|
|
|
|
// }
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if ([self isValidMailAccountName: _key])
|
|
|
|
obj = [SOGoMailAccount objectWithName: _key inContainer: self];
|
|
|
|
else
|
|
|
|
obj = [NSException exceptionWithHTTPStatus: 404 /* Not Found */];
|
|
|
|
}
|
|
|
|
|
|
|
|
return obj;
|
2006-06-15 21:34:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@end /* SOGoMailAccounts */
|