]> err.no Git - scalable-opengroupware.org/commitdiff
added some basic IMAP4 folder support
authorhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Sun, 26 Sep 2004 23:44:59 +0000 (23:44 +0000)
committerhelge <helge@d1b88da0-ebda-0310-925b-ed51d893ca5b>
Sun, 26 Sep 2004 23:44:59 +0000 (23:44 +0000)
git-svn-id: http://svn.opengroupware.org/SOGo/trunk@321 d1b88da0-ebda-0310-925b-ed51d893ca5b

SOGo/SoObjects/Mailer/ChangeLog
SOGo/SoObjects/Mailer/SOGoMailAccount.m
SOGo/SoObjects/Mailer/SOGoMailBaseObject.h
SOGo/SoObjects/Mailer/SOGoMailBaseObject.m
SOGo/SoObjects/Mailer/SOGoMailFolder.m
SOGo/SoObjects/Mailer/Version
SOGo/SoObjects/Mailer/common.h

index a499dfd91e33e130b029eb6aa8805379ebfa35a9..89e3cd50f4aac0694262639afa1a246f333bd27d 100644 (file)
@@ -1,3 +1,11 @@
+2004-09-27  Helge Hess  <helge.hess@opengroupware.org>
+
+       * v0.9.6
+
+       * added basic folder listing
+
+       * SOGoMailAccount.m: list "INBOX" as the sole account subfolder
+
 2004-09-26  Helge Hess  <helge.hess@opengroupware.org>
 
        * v0.9.5
index 95a857a06b56cb760fc6f7fab8cf20b89da1a64b..d0ca36a9b9b448134fdfe2607f6ba26027a145e6 100644 (file)
 
 @implementation SOGoMailAccount
 
+/* listing the available folders */
+
+- (NSArray *)toManyRelationshipKeys {
+  // TODO: hardcoded, if we want to support shared folders, need to change */
+  return [NSArray arrayWithObjects:@"INBOX", nil];
+}
+
 /* IMAP4 */
 
 - (BOOL)useSSL {
index b78c0a2c4bc18739e1fdbcf5cb976936902bb3ec..4a8221ee30944630ab7dab53c0e24ae41075a8e6 100644 (file)
@@ -32,6 +32,7 @@
 */
 
 @class NSURL;
+@class NGImap4Client;
 
 @interface SOGoMailBaseObject : SOGoObject
 {
@@ -43,6 +44,8 @@
 /* IMAP4 */
 
 - (NSURL *)imap4URL;
+- (NSString *)imap4FolderName;
+- (NGImap4Client *)imap4Client;
 
 @end
 
index 847445b048df63afbd542918bfd4a6648c272825..56e0e55db08a77f4ad22f9f694c0f6f6f9288267 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "SOGoMailBaseObject.h"
 #include "common.h"
+#include <NGExtensions/NSURL+misc.h>
 
 @implementation SOGoMailBaseObject
 
          NSStringFromSelector(_cmd)];
   return nil;
 }
+- (NSURL *)baseImap4URL {
+  if (![[self container] respondsToSelector:@selector(imap4URL)]) {
+    [self logWithFormat:@"WARNING: container does not implement -imap4URL!"];
+    return nil;
+  }
+  
+  return [[self container] imap4URL];
+}
 - (NSURL *)imap4URL {
   NSString *sn;
+  NSURL    *base;
   
   if (self->imap4URL != nil) 
     return self->imap4URL;
     return nil;
   }
   
-  self->imap4URL = [[NSURL alloc] initWithString:[self nameInContainer] 
-                                 relativeToURL:[[self container] imap4URL]];
+  base           = [self baseImap4URL];
+  sn             = [[base path] stringByAppendingPathComponent:sn];
+  self->imap4URL = [[NSURL alloc] initWithString:sn relativeToURL:base];
   return self->imap4URL;
 }
 
+- (NSString *)imap4Separator {
+  return @".";
+}
+
+- (NSString *)imap4FolderName {
+  /* a bit hackish, but should be OK */
+  NSString *folderName;
+  
+  folderName = [[self imap4URL] path];
+  if ([folderName length] == 0)
+    return nil;
+  if ([folderName characterAtIndex:0] == '/')
+    folderName = [folderName substringFromIndex:1];
+  
+  [self logWithFormat:@"FOLDER: %@", folderName];
+  return [[folderName pathComponents] componentsJoinedByString:
+                                       [self imap4Separator]];
+}
+
+- (NSString *)imap4Password {
+  return @"";
+}
+
+- (NGImap4Client *)imap4ClientForURL:(NSURL *)_url password:(NSString *)_pwd {
+  // TODO: move to some global IMAP4 connection pool manager
+  NGImap4Client *client;
+  NSDictionary  *result;
+  
+  if (_url == nil)
+    return nil;
+  
+  if ((client = [NGImap4Client clientWithURL:_url]) == nil)
+    return nil;
+  
+  result = [client login:[_url user] password:_pwd];
+  if (![[result valueForKey:@"result"] boolValue]) {
+    [self logWithFormat:@"ERROR: IMAP4 login failed!"];
+    return nil;
+  }
+  
+  return client;
+}
+
+- (NGImap4Client *)imap4Client {
+  return [self imap4ClientForURL:[self imap4URL]
+              password:[self imap4Password]];
+}
+
 @end /* SOGoMailBaseObject */
index fd993a6264c511daf4cac602eba05e0352f87467..f26d4c892d02428dd58b7a519616b4795f962b21 100644 (file)
   return [self nameInContainer];
 }
 
+/* listing the available folders */
+
+- (NSArray *)_getDirectChildren:(NSArray *)_array folderName:(NSString *)_fn {
+  // TODO: we should get the full list of folders _once_ and work on that
+  //       (we could cache it in the context)
+  NSMutableArray *ma;
+  unsigned i, count, prefixlen;
+  
+  if ((count = [_array count]) < 2)
+    /* one entry is the folder itself, so we need at least two */
+    return [NSArray array];
+  
+  prefixlen = [_fn length] + 1;
+  ma = [NSMutableArray arrayWithCapacity:count];
+  for (i = 0; i < count; i++) {
+    NSString *p;
+    
+    p = [_array objectAtIndex:i];
+    if ([p length] <= prefixlen)
+      continue;
+    p = [p substringFromIndex:prefixlen];
+    
+    if ([p rangeOfString:@"/"].length > 0)
+      continue;
+    
+    [ma addObject:p];
+  }
+  
+  [ma sortUsingSelector:@selector(compare:)];
+  return ma;
+}
+
+- (NSArray *)toManyRelationshipKeys {
+  // TODO
+  NGImap4Client *client;
+  NSDictionary  *result;
+  NSString      *folderName;
+  
+  if ((client = [self imap4Client]) == nil)
+    return nil;
+  
+  folderName = [self imap4FolderName];
+  
+  /* maybe we want to use a cache over here */
+  result = [client list:folderName pattern:@"*"];
+  if (![[result valueForKey:@"result"] boolValue]) {
+    [self logWithFormat:@"ERROR: listing of folder failed!"];
+    return nil;
+  }
+  
+  /* extract list */
+  result = [result valueForKey:@"list"];
+  return [self _getDirectChildren:[result allKeys] folderName:folderName];
+}
+
 /* name lookup */
 
 - (BOOL)isMessageKey:(NSString *)_key inContext:(id)_ctx {
index 6b227f7e3b266ef9cc7a5dc1fd384537da8702c7..0eb47da345be1d4c8ac5a363234ca3f2c77473cb 100644 (file)
@@ -1,3 +1,3 @@
 # $Id$
 
-SUBMINOR_VERSION:=5
+SUBMINOR_VERSION:=6
index 88fc5806e8924504f4cddb160a32fecb5c01d802..a03b8b0d186bca6a72c9c2d47db8d2f68a110dea 100644 (file)
@@ -33,3 +33,4 @@
 
 #include <SOGoLogic/SOGoAppointment.h>
 
+#include <NGImap4/NGImap4Client.h>