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"
23 #include "SOGoUser+Mail.h"
25 #include <NGObjWeb/SoObject+SoDAV.h>
27 @implementation SOGoMailAccounts
29 static NSString *AgenorShareLoginMarker = @".-.";
31 /* listing the available mailboxes */
33 - (BOOL) isInHomeFolderBranchOfLoggedInAccount: (NSString *) userLogin
35 return [[[self container] nameInContainer] isEqualToString: userLogin];
38 - (NSArray *)toManyRelationshipKeys {
45 Note: this is not strictly correct. The accounts being retrieved should be
46 the accounts based on the container object of this folder. Given
47 sufficient rights (eg delegation rights!), this would allow you to
48 browse the hierarchies of other users.
50 But then, the home-folder would need to know about mail
51 functionality which isn't perfect either.
54 user = [context activeUser];
55 userLogin = [user login];
57 /* for now: return nothing if the home-folder does not belong to the login */
58 if (![self isInHomeFolderBranchOfLoggedInAccount: userLogin]) {
59 [self warnWithFormat:@"User %@ tried to access mail hierarchy of %@",
60 [user login], [[self container] nameInContainer]];
64 account = [user primaryIMAP4AccountString];
65 if ([account isNotNull]) account = [NSArray arrayWithObject:account];
67 shares = [user valueForKey:@"additionalIMAP4AccountStrings"];
68 return ([shares count] == 0)
70 : [account arrayByAddingObjectsFromArray:shares];
73 - (NSArray *) fetchIdentitiesWithOnlyEmitterAccess: (BOOL) _flag
75 NSString *accountString;
77 accountString = [[context activeUser] primaryIMAP4AccountString];
79 return [NSArray arrayWithObject: accountString];
82 - (NSArray *)fetchAllIdentities {
83 return [self fetchIdentitiesWithOnlyEmitterAccess:NO];
86 - (NSArray *)fetchIdentitiesWithEmitterPermissions {
87 return [self fetchIdentitiesWithOnlyEmitterAccess:YES];
92 - (BOOL)isValidMailAccountName:(NSString *)_key {
93 if ([_key length] == 0)
99 - (id)mailAccountWithName:(NSString *)_key inContext:(id)_ctx {
100 static Class ctClass = Nil;
104 ctClass = NSClassFromString(@"SOGoMailAccount");
105 if (ctClass == Nil) {
106 [self errorWithFormat:@"missing SOGoMailAccount class!"];
110 ct = [[ctClass alloc] initWithName:_key inContainer:self];
111 return [ct autorelease];
114 - (id)sharedMailAccountWithName:(NSString *)_key inContext:(id)_ctx {
115 static Class ctClass = Nil;
119 ctClass = NSClassFromString(@"SOGoSharedMailAccount");
120 if (ctClass == Nil) {
121 [self errorWithFormat:@"missing SOGoSharedMailAccount class!"];
125 ct = [[ctClass alloc] initWithName:_key inContainer:self];
126 return [ct autorelease];
129 - (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag
134 userLogin = [[context activeUser] login];
136 /* first check attributes directly bound to the application */
137 if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
140 if (![self isInHomeFolderBranchOfLoggedInAccount: userLogin]) {
141 [self warnWithFormat:@"User %@ tried to access mail hierarchy of %@",
142 userLogin, [[self container] nameInContainer]];
144 return [NSException exceptionWithHTTPStatus:403 /* Forbidden */
145 reason:@"Tried to access the mail of another user"];
148 if ([self isValidMailAccountName:_key]) {
151 isSharedKey = [_key rangeOfString:AgenorShareLoginMarker].length > 0;
154 ? [self sharedMailAccountWithName:_key inContext:_ctx]
155 : [self mailAccountWithName:_key inContext:_ctx];
158 /* return 404 to stop acquisition */
159 return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
164 - (BOOL) davIsCollection
169 - (NSString *) davContentType
171 return @"httpd/unix-directory";
176 - (NSArray *) aclsForUser: (NSString *) uid
182 @end /* SOGoMailAccounts */