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/AgenorUserManager.h>
26 #include <SOGo/WOContext+Agenor.h>
28 @implementation SOGoMailAccounts
30 static NSString *AgenorShareLoginMarker = @".-.";
32 /* detect webmail being accessed from the outside */
34 - (BOOL)isInternetRequest {
35 return [[(WOApplication *)[WOApplication application] context]
36 isAccessFromIntranet] ? NO : YES;
39 /* listing the available mailboxes */
41 - (NSArray *)toManyRelationshipKeys {
42 static AgenorUserManager *um = nil;
48 um = [[AgenorUserManager sharedUserManager] retain];
50 uid = [[self container] davDisplayName]; /* the uid part of the URL */
51 account = [um getIMAPAccountStringForUID:uid];
52 if (account != nil) account = [NSArray arrayWithObject:account];
54 if ([self isInternetRequest]) /* only show primary mailbox in Internet */
57 shares = [um getSharedMailboxAccountStringsForUID:uid];
58 return ([shares count] == 0)
60 : [account arrayByAddingObjectsFromArray:shares];
65 - (BOOL)isValidMailAccountName:(NSString *)_key {
66 if ([_key length] == 0)
72 - (id)mailAccountWithName:(NSString *)_key inContext:(id)_ctx {
73 static Class ctClass = Nil;
77 ctClass = NSClassFromString(@"SOGoMailAccount");
79 [self errorWithFormat:@"missing SOGoMailAccount class!"];
83 ct = [[ctClass alloc] initWithName:_key inContainer:self];
84 return [ct autorelease];
87 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
90 /* first check attributes directly bound to the application */
91 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
94 if ([self isValidMailAccountName:_key]) {
95 /* forbid shares for requests coming from the Internet */
96 if ([self isInternetRequest]) {
97 if ([_key rangeOfString:AgenorShareLoginMarker].length > 0) {
98 return [NSException exceptionWithHTTPStatus:403 /* Forbidden */
100 @"Access to shares forbidden from the Internet"];
104 return [self mailAccountWithName:_key inContext:_ctx];
107 /* return 404 to stop acquisition */
108 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
113 - (BOOL)davIsCollection {
117 @end /* SOGoMailAccounts */