From f6e04ef8bf8465d773730d1c37fbbecfd703d6c5 Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 25 Mar 2005 19:00:55 +0000 Subject: [PATCH] implemented mailbox move using WebDAV git-svn-id: http://svn.opengroupware.org/SOGo/trunk@640 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 6 ++++ SOGo/SoObjects/Mailer/SOGoMailFolder.m | 27 ++++++++++++-- SOGo/SoObjects/Mailer/SOGoMailManager.h | 3 ++ SOGo/SoObjects/Mailer/SOGoMailManager.m | 48 ++++++++++++++++++++++++- SOGo/SoObjects/Mailer/Version | 2 +- 5 files changed, 81 insertions(+), 5 deletions(-) diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 542febe3..4911223e 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,11 @@ 2005-03-25 Helge Hess + + * v0.9.81 + + * SOGoMailFolder.m: implemented mailbox renaming using WebDAV MOVE + * SOGoMailManager.m: added support for renaming mailboxes + * v0.9.80 * SOGoMailFolder.m: now ensures during lookup that mailboxes actually diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.m b/SOGo/SoObjects/Mailer/SOGoMailFolder.m index 9a810a93..4cdcd78f 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.m @@ -220,10 +220,31 @@ - (NSException *)davMoveToTargetObject:(id)_target newName:(NSString *)_name inContext:(id)_ctx { + NSURL *destImapURL; + + if ([_name length] == 0) { /* target already exists! */ + // TODO: check the overwrite request field (should be done by dispatcher) + return [NSException exceptionWithHTTPStatus:412 /* Precondition Failed */ + reason:@"target already exists"]; + } + if (![_target respondsToSelector:@selector(imap4URL)]) { + return [NSException exceptionWithHTTPStatus:502 /* Bad Gateway */ + reason:@"target is not an IMAP4 folder"]; + } + + /* build IMAP4 URL for target */ + + destImapURL = [_target imap4URL]; + destImapURL = [NSURL URLWithString:[[destImapURL path] + stringByAppendingPathComponent:_name] + relativeToURL:destImapURL]; + [self logWithFormat:@"TODO: should move collection as '%@' to: %@", - _name, _target]; - return [NSException exceptionWithHTTPStatus:501 /* Not Implemented */ - reason:@"not implemented"]; + [[self imap4URL] absoluteString], + [destImapURL absoluteString]]; + + return [[self mailManager] moveMailboxAtURL:[self imap4URL] toURL:destImapURL + password:[self imap4Password]]; } - (NSException *)davCopyToTargetObject:(id)_target newName:(NSString *)_name inContext:(id)_ctx diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.h b/SOGo/SoObjects/Mailer/SOGoMailManager.h index 9ca2ff44..51d5eb9f 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.h +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.h @@ -87,6 +87,9 @@ password:(NSString *)_pwd; - (NSException *)deleteMailboxAtURL:(NSURL *)_url password:(NSString *)_pwd; +- (NSException *)moveMailboxAtURL:(NSURL *)_srcurl toURL:(NSURL *)_desturl + password:(NSString *)_pwd; + @end #endif /* __Mailer_SOGoMailManager_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m index 0486e4ee..c430a6aa 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.m +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -838,7 +838,7 @@ static NSString *imap4Separator = nil; return [NSException exceptionWithHTTPStatus:500 /* server error */ reason:[result valueForKey:@"reason"]]; } - + [entry flushFolderHierarchyCache]; #if 0 [self debugWithFormat:@"delete mailbox %@: %@", _url, result]; @@ -846,6 +846,52 @@ static NSString *imap4Separator = nil; return nil; } +- (NSException *)moveMailboxAtURL:(NSURL *)_srcurl toURL:(NSURL *)_desturl + password:(NSString *)_pwd +{ + SOGoMailConnectionEntry *entry; + NSString *srcname, *destname; + id result; + + /* check connection cache */ + + if ((entry = [self entryForURL:_srcurl password:_pwd]) == nil) { + // TODO: better to use an auth exception? + return [NSException exceptionWithHTTPStatus:404 /* Not Found */ + reason:@"did not find IMAP4 folder (no entry)"]; + } + + /* check whether URLs are on different servers */ + + if ([self entryForURL:_desturl password:_pwd] != entry) { + // TODO: find a better error code + return [NSException exceptionWithHTTPStatus:502 /* Bad Gateway */ + reason:@"source and destination on different servers"]; + } + + /* rename */ + + srcname = [self imap4FolderNameForURL:_srcurl]; + destname = [self imap4FolderNameForURL:_desturl]; + + result = [[entry client] rename:srcname to:destname]; + + if ([self isPermissionDeniedResult:result]) { + return [NSException exceptionWithHTTPStatus:403 /* forbidden */ + reason:@"creation of folders not allowed"]; + } + else if ([[result valueForKey:@"result"] intValue] == 0) { + return [NSException exceptionWithHTTPStatus:500 /* server error */ + reason:[result valueForKey:@"reason"]]; + } + + [entry flushFolderHierarchyCache]; +#if 0 + [self debugWithFormat:@"renamed mailbox %@: %@", _srcurl, result]; +#endif + return nil; +} + /* debugging */ - (BOOL)isDebuggingEnabled { diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 4d7aec2a..9550b82f 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=80 +SUBMINOR_VERSION:=81 # v0.9.69 requires libNGMime v4.5.210 # v0.9.55 requires libNGExtensions v4.5.136 -- 2.39.5