+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
@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 {
*/
@class NSURL;
+@class NGImap4Client;
@interface SOGoMailBaseObject : SOGoObject
{
/* IMAP4 */
- (NSURL *)imap4URL;
+- (NSString *)imap4FolderName;
+- (NGImap4Client *)imap4Client;
@end
#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 */
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 {
# $Id$
-SUBMINOR_VERSION:=5
+SUBMINOR_VERSION:=6
#include <SOGoLogic/SOGoAppointment.h>
+#include <NGImap4/NGImap4Client.h>