]> err.no Git - scalable-opengroupware.org/blobdiff - SoObjects/Mailer/SOGoMailAccounts.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1101 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SoObjects / Mailer / SOGoMailAccounts.m
index d88bb9d5b08e08d29c32d449a0979dcc8be8af8d..bb3ac3ba4687fc2a987b89eef1cc4f9e0fc738c2 100644 (file)
 #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
@@ -73,45 +51,32 @@ static NSString *AgenorShareLoginMarker  = @".-.";
           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 {
@@ -161,35 +126,30 @@ static NSString *AgenorShareLoginMarker  = @".-.";
   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];
@@ -201,8 +161,22 @@ static NSString *AgenorShareLoginMarker  = @".-.";
 
 /* WebDAV */
 
-- (BOOL)davIsCollection {
+- (BOOL) davIsCollection
+{
   return YES;
 }
 
+- (NSString *) davContentType
+{
+  return @"httpd/unix-directory";
+}
+
+/* acls */
+
+- (NSArray *) aclsForUser: (NSString *) uid
+{
+  return nil;
+}
+
+
 @end /* SOGoMailAccounts */