#include "SOGoUser+Mail.h"
#include "common.h"
#include <NGObjWeb/SoObject+SoDAV.h>
-#include <SOGo/WOContext+Agenor.h>
@implementation SOGoMailAccounts
static NSString *AgenorShareLoginMarker = @".-.";
-/* detect webmail being accessed from the outside */
-
-- (BOOL)isInternetRequest {
- return [[(WOApplication *)[WOApplication application] context]
- isAccessFromIntranet] ? NO : YES;
-}
-
/* listing the available mailboxes */
-- (BOOL)isInHomeFolderBranchOfLoggedInAccount:(id)_ctx {
- id user;
-
- if (_ctx == nil) _ctx = [[WOApplication application] context];
- if (_ctx == nil) {
- [self errorWithFormat:@"Missing context!"];
- return NO;
- }
-
- user = [_ctx activeUser];
- return [[[self container] nameInContainer] isEqualToString:[user login]];
+- (BOOL) isInHomeFolderBranchOfLoggedInAccount: (NSString *) userLogin
+{
+ return [[[self container] nameInContainer] isEqualToString: userLogin];
}
- (NSArray *)toManyRelationshipKeys {
- WOContext *ctx;
- id user;
+ SOGoUser *user;
id account;
NSArray *shares;
-
- if ((ctx = [[WOApplication application] context]) == nil) {
- [self logWithFormat:@"ERROR(%s): cannot procede without context!",
- __PRETTY_FUNCTION__];
- return nil;
- }
+ NSString *userLogin;
/*
Note: this is not strictly correct. The accounts being retrieved should be
functionality which isn't perfect either.
=> TODO
*/
- user = [ctx activeUser];
+ user = [context activeUser];
+ userLogin = [user login];
/* for now: return nothing if the home-folder does not belong to the login */
- if (![self isInHomeFolderBranchOfLoggedInAccount:ctx]) {
+ if (![self isInHomeFolderBranchOfLoggedInAccount: userLogin]) {
[self warnWithFormat:@"User %@ tried to access mail hierarchy of %@",
[user login], [[self container] nameInContainer]];
return nil;
}
- account = [user valueForKey:@"primaryIMAP4AccountString"];
+ account = [user primaryIMAP4AccountString];
if ([account isNotNull]) account = [NSArray arrayWithObject:account];
- if ([self isInternetRequest]) /* only show primary mailbox in Internet */
- return account;
-
shares = [user valueForKey:@"additionalIMAP4AccountStrings"];
return ([shares count] == 0)
? account
: [account arrayByAddingObjectsFromArray:shares];
}
-- (NSArray *)fetchIdentitiesWithOnlyEmitterAccess:(BOOL)_flag {
- WOContext *ctx;
-
- if ((ctx = [[WOApplication application] context]) == nil) {
- [self logWithFormat:@"ERROR(%s): cannot procede without context!",
- __PRETTY_FUNCTION__];
- return nil;
- }
-
- if ([self isInternetRequest]) { /* only show primary mailbox in Internet */
- // just return the primary identity
- id identity;
-
- identity = [[ctx activeUser] primaryMailIdentity];
- return [identity isNotNull] ? [NSArray arrayWithObject:identity] : nil;
- }
-
- return [[ctx activeUser] fetchAllMailIdentitiesWithOnlyEmitterAccess:_flag];
+- (NSArray *) fetchIdentitiesWithOnlyEmitterAccess: (BOOL) _flag
+{
+ NSString *accountString;
+
+ accountString = [[context activeUser] primaryIMAP4AccountString];
+
+ return [NSArray arrayWithObject: accountString];
}
- (NSArray *)fetchAllIdentities {
return [ct autorelease];
}
-- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
+- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag
+{
id obj;
+ NSString *userLogin;
+
+ userLogin = [[context activeUser] login];
/* first check attributes directly bound to the application */
if ((obj = [super lookupName:_key inContext:_ctx acquire:NO]))
return obj;
- if (![self isInHomeFolderBranchOfLoggedInAccount:_ctx]) {
+ if (![self isInHomeFolderBranchOfLoggedInAccount: userLogin]) {
[self warnWithFormat:@"User %@ tried to access mail hierarchy of %@",
- [[_ctx activeUser] login], [[self container] nameInContainer]];
+ userLogin, [[self container] nameInContainer]];
return [NSException exceptionWithHTTPStatus:403 /* Forbidden */
reason:@"Tried to access the mail of another user"];
}
if ([self isValidMailAccountName:_key]) {
- /* forbid shares for requests coming from the Internet */
BOOL isSharedKey;
isSharedKey = [_key rangeOfString:AgenorShareLoginMarker].length > 0;
- if ([self isInternetRequest]) {
- if (isSharedKey) {
- return [NSException exceptionWithHTTPStatus:403 /* Forbidden */
- reason:
- @"Access to shares forbidden from the Internet"];
- }
- }
-
return isSharedKey
? [self sharedMailAccountWithName:_key inContext:_ctx]
: [self mailAccountWithName:_key inContext:_ctx];
/* WebDAV */
-- (BOOL)davIsCollection {
+- (BOOL) davIsCollection
+{
return YES;
}
+- (NSString *) davContentType
+{
+ return @"httpd/unix-directory";
+}
+
+/* acls */
+
+- (NSArray *) aclsForUser: (NSString *) uid
+{
+ return nil;
+}
+
+
@end /* SOGoMailAccounts */