]> err.no Git - scalable-opengroupware.org/commitdiff
added folder management methods
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Sat, 30 Oct 2004 00:04:41 +0000 (00:04 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Sat, 30 Oct 2004 00:04:41 +0000 (00:04 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@444 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGo/SoObjects/Mailer/ChangeLog
SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.h
SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m
SOGo/SoObjects/Mailer/SOGoMailFolder.m
SOGo/SoObjects/Mailer/SOGoMailManager.h
SOGo/SoObjects/Mailer/SOGoMailManager.m
SOGo/SoObjects/Mailer/SOGoMailObject.m
SOGo/SoObjects/Mailer/product.plist

index 9e437e9c6d899c5e2a251f0f2cc5cda35ef23842..76e292407fc2dbf6b7ea10e99b1737f297f257af 100644 (file)
@@ -1,5 +1,15 @@
 2004-10-30  Helge Hess  <helge.hess@skyrix.com>
 
+       * 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)
index 69970fb85117017a8b59b25b563320f587bf3c24..c8fd0f394b6168055edfe13cbe54fbeb6bb69c5c 100644 (file)
@@ -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
index bb2d486b917849afe192d12f86798d050dd95aa6..1ea7e948a26755667b4ddce18a08c5f521c12d10 100644 (file)
 - (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)
index e4149f3c442a4be100b78599cb9ab682f2bd8654..6aa2b5646c5dcf2fe439c186f0d81c21fba14c8d 100644 (file)
   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 */
index 3eb874a2baa93154563fec8caff765ccb0d48b65..8395caa22ed9345acb8c427b17b9901c56ee6adc 100644 (file)
@@ -32,6 +32,7 @@
 */
 
 @class NSString, NSData, NSURL, NSArray, NSMutableDictionary, NSTimer;
+@class NSException;
 @class NGImap4Client;
 
 @interface SOGoMailManager : NSObject
 - (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__ */
index 9ae1e556858b8ae324fae5890da62aee8a762e98..82e5ecd9217c809938c33714a541eb670aea0ec5 100644 (file)
@@ -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 {
index b7822ec78dbfd98aa5d75d71f25e07b1f3ef0a3d..34f63cafb439643c28cd83d0de4c34f773247473 100644 (file)
@@ -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];
index 26d8c0d2ea8d59c22ac00e6e1b9b1ead9f794139..16bc55b6fd2c665f2017c635e293c7528cdb33df 100644 (file)
@@ -22,6 +22,9 @@
 
     SOGoMailFolder = {
       superclass    = "SOGoMailBaseObject";
+      defaultRoles = {
+        "Add Folders" = "Owner";
+      };
     };
 
     SOGoMailObject = {