From: helge Date: Sat, 30 Oct 2004 00:04:41 +0000 (+0000) Subject: added folder management methods X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9de6c640bada43c25ab91ced9132fbb650b59bf6;p=scalable-opengroupware.org added folder management methods git-svn-id: http://svn.opengroupware.org/SOGo/trunk@444 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 9e437e9c..76e29240 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,15 @@ 2004-10-30 Helge Hess + * v0.9.47 + + * SOGoMailFolder.m: added ability to create and delete subfolders using + WebDAV + + * SOGoMailConnectionEntry.m: added method to flush folder hierarchy + cache + + * product.plist: added default role for adding folders (owner) + * SOGoMailObject.m: added -content and -contentAsString method to retrieve raw IMAP4 message content, added GETAction to query a message (v0.9.46) diff --git a/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h b/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h index 69970fb8..c8fd0f39 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h +++ b/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h @@ -58,6 +58,7 @@ - (void)cacheHierarchyResults:(NSDictionary *)_hierarchy; - (NSDictionary *)cachedHierarchyResults; +- (void)flushFolderHierarchyCache; - (id)cachedUIDsForURL:(NSURL *)_url qualifier:(id)_q sortOrdering:(id)_so; - (void)cacheUIDs:(NSArray *)_uids forURL:(NSURL *)_url diff --git a/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m b/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m index bb2d486b..1ea7e948 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m +++ b/SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m @@ -72,6 +72,10 @@ - (NSDictionary *)cachedHierarchyResults { return self->subfolders; } +- (void)flushFolderHierarchyCache { + [self->subfolders release]; + self->subfolders = nil; +} - (id)cachedUIDsForURL:(NSURL *)_url qualifier:(id)_q sortOrdering:(id)_so { if (_q != nil) diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.m b/SOGo/SoObjects/Mailer/SOGoMailFolder.m index e4149f3c..6aa2b564 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.m @@ -146,4 +146,20 @@ return YES; } +- (NSException *)davCreateCollection:(NSString *)_name inContext:(id)_ctx { + return [[self mailManager] createMailbox:_name atURL:[self imap4URL] + password:[self imap4Password]]; +} + +- (id)DELETEAction:(id)_ctx { + id result; + + result = [[self mailManager] deleteMailboxAtURL:[self imap4URL] + password:[self imap4Password]]; + if (result != nil) + return result; + + return [NSNumber numberWithBool:YES]; +} + @end /* SOGoMailFolder */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.h b/SOGo/SoObjects/Mailer/SOGoMailManager.h index 3eb874a2..8395caa2 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.h +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.h @@ -32,6 +32,7 @@ */ @class NSString, NSData, NSURL, NSArray, NSMutableDictionary, NSTimer; +@class NSException; @class NGImap4Client; @interface SOGoMailManager : NSObject @@ -66,6 +67,12 @@ - (NSData *)fetchContentOfBodyPart:(NSString *)_partId atURL:(NSURL *)_url password:(NSString *)_pwd; +/* managing folders */ + +- (NSException *)createMailbox:(NSString *)_mailbox atURL:(NSURL *)_url + password:(NSString *)_pwd; +- (NSException *)deleteMailboxAtURL:(NSURL *)_url password:(NSString *)_pwd; + @end #endif /* __Mailer_SOGoMailManager_H__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m index 9ae1e556..82e5ecd9 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.m +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -27,7 +27,7 @@ @implementation SOGoMailManager -static BOOL debugOn = YES; +static BOOL debugOn = NO; static BOOL debugCache = NO; static BOOL debugKeys = NO; static BOOL poolingOff = NO; @@ -523,6 +523,86 @@ static NSString *imap4Separator = nil; return result; } +/* managing folders */ + +- (BOOL)isPermissionDeniedResult:(id)_result { + if ([[_result valueForKey:@"result"] intValue] != 0) + return NO; + + return [[_result valueForKey:@"reason"] + isEqualToString:@"Permission denied"]; +} + +- (NSException *)createMailbox:(NSString *)_mailbox atURL:(NSURL *)_url + password:(NSString *)_pwd +{ + SOGoMailConnectionEntry *entry; + NSString *newPath; + id result; + + /* check connection cache */ + + if ((entry = [self entryForURL:_url password:_pwd]) == nil) { + return [NSException exceptionWithHTTPStatus:404 /* Not Found */ + reason:@"did not find IMAP4 folder"]; + } + + /* construct path */ + + newPath = [self imap4FolderNameForURL:_url]; + newPath = [newPath stringByAppendingString:[self imap4Separator]]; + newPath = [newPath stringByAppendingString:_mailbox]; + + /* create */ + + result = [[entry client] create:newPath]; + 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]; + // [self debugWithFormat:@"created mailbox: %@: %@", newPath, result]; + return nil; +} + +- (NSException *)deleteMailboxAtURL:(NSURL *)_url password:(NSString *)_pwd { + SOGoMailConnectionEntry *entry; + NSString *path; + id result; + + /* check connection cache */ + + if ((entry = [self entryForURL:_url password:_pwd]) == nil) { + return [NSException exceptionWithHTTPStatus:404 /* Not Found */ + reason:@"did not find IMAP4 folder"]; + } + + /* delete */ + + path = [self imap4FolderNameForURL:_url]; + result = [[entry client] delete:path]; + + 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:@"delete mailbox %@: %@", _url, result]; +#endif + return nil; +} + /* debugging */ - (BOOL)isDebuggingEnabled { diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index b7822ec7..34f63caf 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -246,7 +246,7 @@ static BOOL heavyDebug = NO; if ((content = [self content]) == nil) return nil; if ([content isKindOfClass:[NSException class]]) - return content; + return (id)content; s = [[NSString alloc] initWithData:content encoding:NSISOLatin1StringEncoding]; diff --git a/SOGo/SoObjects/Mailer/product.plist b/SOGo/SoObjects/Mailer/product.plist index 26d8c0d2..16bc55b6 100644 --- a/SOGo/SoObjects/Mailer/product.plist +++ b/SOGo/SoObjects/Mailer/product.plist @@ -22,6 +22,9 @@ SOGoMailFolder = { superclass = "SOGoMailBaseObject"; + defaultRoles = { + "Add Folders" = "Owner"; + }; }; SOGoMailObject = {