From f4288c16de8ec35a225db5e3adb4ebb4aa738962 Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 25 Mar 2005 18:29:08 +0000 Subject: [PATCH] check mailbox existance in SoObject lookup 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 | 11 ++++- SOGo/SoObjects/Mailer/SOGoMailFolder.m | 53 +++++++++++++++++++------ SOGo/SoObjects/Mailer/SOGoMailManager.h | 3 +- SOGo/SoObjects/Mailer/SOGoMailManager.m | 26 ++++++++++++ SOGo/SoObjects/Mailer/SOGoMailObject.m | 17 ++++++++ SOGo/SoObjects/Mailer/Version | 2 +- 6 files changed, 97 insertions(+), 15 deletions(-) diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index e4d5f4e3..542febe3 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,14 @@ 2005-03-25 Helge Hess - + + * 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 diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.m b/SOGo/SoObjects/Mailer/SOGoMailFolder.m index 459cf049..9a810a93 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.m @@ -146,6 +146,26 @@ - (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]; } @@ -155,7 +175,7 @@ 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]) @@ -175,7 +195,9 @@ 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 */ @@ -189,22 +211,29 @@ 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 { diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.h b/SOGo/SoObjects/Mailer/SOGoMailManager.h index c4637128..9ca2ff44 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.h +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.h @@ -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; diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m index 21b7e02e..0486e4ee 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.m +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -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; diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index 37040bd9..4e55f466 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -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 { diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 2d796d69..4d7aec2a 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -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 -- 2.39.2