2004-09-28 Helge Hess <helge.hess@opengroupware.org>
+
+ * v0.9.9
+
+ * SOGoMailBaseObject.m: added -mailManager method to retrieve the
+ mail manager object for a folder/mail/account
+
+ * added SOGoMailManager class, will probably be moved to SOGoLogic
+ in the long run
* SOGoMailBaseObject.m, SOGoMailAccount.m: added -mailAccountFolder
method to find the active root folder along the SOPE chain (v0.9.8)
Mailer_OBJC_FILES += \
Product.m \
- \
+ \
+ SOGoMailManager.m \
+ \
SOGoMailBaseObject.m \
SOGoMailAccounts.m \
SOGoMailAccount.m \
@class NSURL;
@class NGImap4Client;
+@class SOGoMailManager;
@class SOGoMailAccount;
@interface SOGoMailBaseObject : SOGoObject
/* IMAP4 */
+- (SOGoMailManager *)mailManager;
- (NSURL *)imap4URL;
+- (NSString *)imap4Password;
- (NSString *)imap4FolderName;
- (NGImap4Client *)imap4Client;
// $Id$
#include "SOGoMailBaseObject.h"
+#include "SOGoMailManager.h"
#include "common.h"
#include <NGExtensions/NSURL+misc.h>
/* IMAP4 */
+- (SOGoMailManager *)mailManager {
+ return [SOGoMailManager defaultMailManager];
+}
+
- (NSString *)relativeImap4Name {
[self logWithFormat:@"WARNING: subclass should override %@",
NSStringFromSelector(_cmd)];
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]];
+ return [[self mailManager] imap4FolderNameForURL:[self imap4URL]];
}
- (NSString *)imap4Password {
}
- (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;
+ return [[self mailManager] imap4ClientForURL:_url password:_pwd];
}
- (NGImap4Client *)imap4Client {
#include "SOGoMailFolder.h"
#include "SOGoMailObject.h"
+#include "SOGoMailManager.h"
#include "common.h"
@implementation SOGoMailFolder
/* 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];
+ return [[self mailManager] subfoldersForURL:[self imap4URL]
+ password:[self imap4Password]];
}
/* name lookup */
--- /dev/null
+/*
+ Copyright (C) 2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#ifndef __Mailer_SOGoMailManager_H__
+#define __Mailer_SOGoMailManager_H__
+
+#import <Foundation/NSObject.h>
+
+/*
+ SOGoMailManager
+
+ Coordinates access to IMAP4 mailboxes, caches folder hierarchies, etc.
+*/
+
+@class NSString, NSURL, NSArray;
+@class NGImap4Client;
+
+@interface SOGoMailManager : NSObject
+{
+}
+
++ (id)defaultMailManager;
+
+/* client object */
+
+- (NGImap4Client *)imap4ClientForURL:(NSURL *)_url password:(NSString *)_pwd;
+
+/* folder hierarchy */
+
+- (NSString *)imap4Separator;
+- (NSString *)imap4FolderNameForURL:(NSURL *)_url;
+- (NSArray *)subfoldersForURL:(NSURL *)_url password:(NSString *)_pwd;
+
+@end
+
+#endif /* __Mailer_SOGoMailManager_H__ */
--- /dev/null
+/*
+ Copyright (C) 2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo is free software; you can redistribute it and/or modify it under
+ the terms of the GNU Lesser General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with OGo; see the file COPYING. If not, write to the
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include "SOGoMailManager.h"
+#include "common.h"
+
+@implementation SOGoMailManager
+
+static BOOL debugOn = YES;
+
++ (id)defaultMailManager {
+ static SOGoMailManager *manager = nil; // THREAD
+ if (manager == nil)
+ manager = [[self alloc] init];
+ return manager;
+}
+
+- (void)dealloc {
+ [super dealloc];
+}
+
+/* client object */
+
+- (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;
+}
+
+/* folder hierarchy */
+
+- (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;
+}
+
+- (NSString *)imap4Separator {
+ return @".";
+}
+
+- (NSString *)imap4FolderNameForURL:(NSURL *)_url {
+ /* a bit hackish, but should be OK */
+ NSString *folderName;
+
+ if (_url == nil)
+ return nil;
+
+ folderName = [_url path];
+ if ([folderName length] == 0)
+ return nil;
+ if ([folderName characterAtIndex:0] == '/')
+ folderName = [folderName substringFromIndex:1];
+
+ return [[folderName pathComponents] componentsJoinedByString:
+ [self imap4Separator]];
+}
+
+- (NSArray *)subfoldersForURL:(NSURL *)_url password:(NSString *)_pwd {
+ // TODO: add caching
+ NGImap4Client *client;
+ NSDictionary *result;
+ NSString *folderName;
+
+ if ((client = [self imap4ClientForURL:_url password:_pwd]) == nil)
+ return nil;
+
+ folderName = [self imap4FolderNameForURL:_url];
+
+ /* 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];
+}
+
+/* debugging */
+
+- (BOOL)isDebuggingEnabled {
+ return debugOn;
+}
+
+@end /* SOGoMailManager */
# $Id$
-SUBMINOR_VERSION:=8
+SUBMINOR_VERSION:=9