]> err.no Git - scalable-opengroupware.org/commitdiff
check mailbox existance in SoObject lookup
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 25 Mar 2005 18:29:08 +0000 (18:29 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Fri, 25 Mar 2005 18:29:08 +0000 (18:29 +0000)
prepared for WebDAV move/copy operations

git-svn-id: http://svn.opengroupware.org/SOGo/trunk@639 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGo/SoObjects/Mailer/ChangeLog
SOGo/SoObjects/Mailer/SOGoMailFolder.m
SOGo/SoObjects/Mailer/SOGoMailManager.h
SOGo/SoObjects/Mailer/SOGoMailManager.m
SOGo/SoObjects/Mailer/SOGoMailObject.m
SOGo/SoObjects/Mailer/Version

index e4d5f4e35db4543d9d86797056b503f74fbe3d4f..542febe3af37701dfa21facac7f13d6e4d1ae448 100644 (file)
@@ -1,5 +1,14 @@
 2005-03-25  Helge Hess  <helge.hess@opengroupware.org>
-
+       
+       * v0.9.80
+       
+       * SOGoMailFolder.m: now ensures during lookup that mailboxes actually
+         exist, this may slow down the lookup if the hierarchy was not fetched
+         yet
+       
+       * SOGoMailObject.m, SOGoMailFolder.m: prepared for WebDAV move and copy
+         operations
+       
        * v0.9.79
        
        * SOGoMailFolder.m: ensure that mailbox exists if a DAV depth:0 query
index 459cf049a4a377818ac5598b1e8a5ae2f6983d38..9a810a93d5fed72e532b35a68226f34cd00dd658 100644 (file)
 
 - (id)lookupImap4Folder:(NSString *)_key inContext:(id)_ctx {
   // TODO: we might want to check for existence prior controller creation
+  NSURL *sf;
+
+  /* check whether URL exists */
+  
+  sf = [self imap4URL];
+  sf = [NSURL URLWithString:[[sf path] stringByAppendingPathComponent:_key]
+             relativeToURL:sf];
+  
+  if (![[self mailManager] doesMailboxExistAtURL:sf
+                          password:[self imap4Password]]) {
+    /* 
+       We may not return 404, confuses path traversal - but we still do in the
+       calling method. Probably the traversal process should be fixed to
+       support 404 exceptions (as stop traversal _and_ acquisition).
+    */
+    return nil;
+  }
+  
+  /* create object */
+  
   return [[[SOGoMailFolder alloc] initWithName:_key 
                                  inContainer:self] autorelease];
 }
                                  inContainer:self] autorelease];
 }
 
-- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_flag {
+- (id)lookupName:(NSString *)_key inContext:(id)_ctx acquire:(BOOL)_acquire {
   id obj;
   
   if ([self isMessageKey:_key inContext:_ctx])
     return obj;
   
   /* return 404 to stop acquisition */
-  return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
+  return _acquire
+    ? [NSException exceptionWithHTTPStatus:404 /* Not Found */]
+    : nil; /* hack to work with WebDAV move */
 }
 
 /* WebDAV */
                             password:[self imap4Password]];
 }
 
-- (id)davQueryOnSelf:(EOFetchSpecification *)_fs inContext:(id)_ctx {
-  NSException *error;
-  
-  /* ensure that the mailbox exists */
-  if ((error = [self primaryFetchMailboxInfo]) != nil)
-    return error;
-  
-  return [super davQueryOnSelf:_fs inContext:_ctx];
-}
-
 - (NSException *)delete {
   /* Note: overrides SOGoObject -delete */
   return [[self mailManager] deleteMailboxAtURL:[self imap4URL]
                             password:[self imap4Password]];
 }
 
+- (NSException *)davMoveToTargetObject:(id)_target newName:(NSString *)_name
+  inContext:(id)_ctx
+{
+  [self logWithFormat:@"TODO: should move collection as '%@' to: %@",
+       _name, _target];
+  return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */
+                     reason:@"not implemented"];
+}
+- (NSException *)davCopyToTargetObject:(id)_target newName:(NSString *)_name
+  inContext:(id)_ctx
+{
+  [self logWithFormat:@"TODO: should copy collection as '%@' to: %@",
+       _name, _target];
+  return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */
+                     reason:@"not implemented"];
+}
+
 /* folder type */
 
 - (NSString *)outlookFolderClass {
index c46371288ebeef758d38f4c8103ea99e3192332f..9ca2ff4424129ed51265a9388a0269e23b0c453c 100644 (file)
@@ -80,7 +80,8 @@
 
 /* managing folders */
 
-- (id)infoForMailboxAtURL:(NSURL *)_url password:(NSString *)_pwd;
+- (BOOL)doesMailboxExistAtURL:(NSURL *)_url password:(NSString *)_pwd;
+- (id)infoForMailboxAtURL:(NSURL *)_url     password:(NSString *)_pwd;
 
 - (NSException *)createMailbox:(NSString *)_mailbox atURL:(NSURL *)_url
   password:(NSString *)_pwd;
index 21b7e02e5910e14c82862aa8f115186ea07ad013..0486e4ee37940f8b825c33cf374c9c25fea090bf 100644 (file)
@@ -724,6 +724,32 @@ static NSString       *imap4Separator  = nil;
                   isEqualToString:@"Permission denied"];
 }
 
+- (BOOL)doesMailboxExistAtURL:(NSURL *)_url password:(NSString *)_pwd {
+  SOGoMailConnectionEntry *entry;
+  NSString        *folderName;
+  id result;
+  
+  if ((entry = [self entryForURL:_url password:_pwd]) == nil)
+    return NO;
+  
+  /* check in hierarchy cache */
+  
+  if ((result = [entry cachedHierarchyResults]) != nil) {
+    result = [result objectForKey:@"list"];
+    return ([result objectForKey:[_url path]] != nil) ? YES : NO;
+  }
+  
+  /* check using IMAP4 select */
+  // TODO: we should probably just fetch the whole hierarchy?
+  
+  folderName = [self imap4FolderNameForURL:_url];
+  result = [[entry client] select:folderName];
+  if (![[result valueForKey:@"result"] boolValue])
+    return NO;
+  
+  return YES;
+}
+
 - (id)infoForMailboxAtURL:(NSURL *)_url password:(NSString *)_pwd {
   SOGoMailConnectionEntry *entry;
   SOGoMailboxInfo *info;
index 37040bd98b0f7b747a8fd251f2040532971cedfa..4e55f4664b049289178a35336560099cb95a29da 100644 (file)
@@ -549,6 +549,23 @@ static BOOL debugBodyStructure = NO;
   return [self davCreationDate];
 }
 
+- (NSException *)davMoveToTargetObject:(id)_target newName:(NSString *)_name
+  inContext:(id)_ctx
+{
+  [self logWithFormat:@"TODO: should move mail as '%@' to: %@",
+       _name, _target];
+  return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */
+                     reason:@"not implemented"];
+}
+- (NSException *)davCopyToTargetObject:(id)_target newName:(NSString *)_name
+  inContext:(id)_ctx
+{
+  [self logWithFormat:@"TODO: should copy mail as '%@' to: %@",
+       _name, _target];
+  return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */
+                     reason:@"not implemented"];
+}
+
 /* actions */
 
 - (id)GETAction:(WOContext *)_ctx {
index 2d796d6994045aac9b3a9b3f0f270ecb80e73efb..4d7aec2ae6587789df81f9701c4ff4784e364556 100644 (file)
@@ -1,6 +1,6 @@
 # Version file
 
-SUBMINOR_VERSION:=79
+SUBMINOR_VERSION:=80
 
 # v0.9.69 requires libNGMime       v4.5.210
 # v0.9.55 requires libNGExtensions v4.5.136