2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "SOGoMailAccounts.h"
24 #include <NGObjWeb/SoObject+SoDAV.h>
25 #include <SOGo/WOContext+Agenor.h>
27 @implementation SOGoMailAccounts
29 static NSString *AgenorShareLoginMarker = @".-.";
31 /* detect webmail being accessed from the outside */
33 - (BOOL)isInternetRequest {
34 return [[(WOApplication *)[WOApplication application] context]
35 isAccessFromIntranet] ? NO : YES;
38 /* listing the available mailboxes */
40 - (NSArray *)toManyRelationshipKeys {
46 if ((ctx = [[WOApplication application] context]) == nil) {
47 [self logWithFormat:@"ERROR(%s): cannot procede without context!",
51 user = [ctx activeUser];
52 account = [user valueForKey:@"primaryIMAP4AccountString"];
53 if ([account isNotNull]) account = [NSArray arrayWithObject:account];
55 if ([self isInternetRequest]) /* only show primary mailbox in Internet */
58 shares = [user valueForKey:@"additionalIMAP4AccountStrings"];
59 return ([shares count] == 0)
61 : [account arrayByAddingObjectsFromArray:shares];
66 - (BOOL)isValidMailAccountName:(NSString *)_key {
67 if ([_key length] == 0)
73 - (id)mailAccountWithName:(NSString *)_key inContext:(id)_ctx {
74 static Class ctClass = Nil;
78 ctClass = NSClassFromString(@"SOGoMailAccount");
80 [self errorWithFormat:@"missing SOGoMailAccount class!"];
84 ct = [[ctClass alloc] initWithName:_key inContainer:self];
85 return [ct autorelease];
87 - (id)sharedMailAccountWithName:(NSString *)_key inContext:(id)_ctx {
88 static Class ctClass = Nil;
92 ctClass = NSClassFromString(@"SOGoSharedMailAccount");
94 [self errorWithFormat:@"missing SOGoSharedMailAccount class!"];
98 ct = [[ctClass alloc] initWithName:_key inContainer:self];
99 return [ct autorelease];
102 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
105 /* first check attributes directly bound to the application */
106 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
109 if ([self isValidMailAccountName:_key]) {
110 /* forbid shares for requests coming from the Internet */
113 isSharedKey = [_key rangeOfString:AgenorShareLoginMarker].length > 0;
115 if ([self isInternetRequest]) {
117 return [NSException exceptionWithHTTPStatus:403 /* Forbidden */
119 @"Access to shares forbidden from the Internet"];
124 ? [self sharedMailAccountWithName:_key inContext:_ctx]
125 : [self mailAccountWithName:_key inContext:_ctx];
128 /* return 404 to stop acquisition */
129 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
134 - (BOOL)davIsCollection {
138 @end /* SOGoMailAccounts */