From: helge Date: Tue, 28 Sep 2004 14:17:13 +0000 (+0000) Subject: added SOGoMailManager object X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce916fe06ecb1cc1c711148f99a03130827a2702;p=scalable-opengroupware.org added SOGoMailManager object git-svn-id: http://svn.opengroupware.org/SOGo/trunk@325 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index ee2ccf2d..87a3e750 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,4 +1,12 @@ 2004-09-28 Helge Hess + + * 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) diff --git a/SOGo/SoObjects/Mailer/GNUmakefile b/SOGo/SoObjects/Mailer/GNUmakefile index b14a2948..f033de56 100644 --- a/SOGo/SoObjects/Mailer/GNUmakefile +++ b/SOGo/SoObjects/Mailer/GNUmakefile @@ -8,7 +8,9 @@ Mailer_PRINCIPAL_CLASS = SOGoMailerProduct Mailer_OBJC_FILES += \ Product.m \ - \ + \ + SOGoMailManager.m \ + \ SOGoMailBaseObject.m \ SOGoMailAccounts.m \ SOGoMailAccount.m \ diff --git a/SOGo/SoObjects/Mailer/SOGoMailBaseObject.h b/SOGo/SoObjects/Mailer/SOGoMailBaseObject.h index e5d50070..5ca0a908 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailBaseObject.h +++ b/SOGo/SoObjects/Mailer/SOGoMailBaseObject.h @@ -33,6 +33,7 @@ @class NSURL; @class NGImap4Client; +@class SOGoMailManager; @class SOGoMailAccount; @interface SOGoMailBaseObject : SOGoObject @@ -48,7 +49,9 @@ /* IMAP4 */ +- (SOGoMailManager *)mailManager; - (NSURL *)imap4URL; +- (NSString *)imap4Password; - (NSString *)imap4FolderName; - (NGImap4Client *)imap4Client; diff --git a/SOGo/SoObjects/Mailer/SOGoMailBaseObject.m b/SOGo/SoObjects/Mailer/SOGoMailBaseObject.m index 589d063b..3eac2157 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailBaseObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailBaseObject.m @@ -21,6 +21,7 @@ // $Id$ #include "SOGoMailBaseObject.h" +#include "SOGoMailManager.h" #include "common.h" #include @@ -55,6 +56,10 @@ /* IMAP4 */ +- (SOGoMailManager *)mailManager { + return [SOGoMailManager defaultMailManager]; +} + - (NSString *)relativeImap4Name { [self logWithFormat:@"WARNING: subclass should override %@", NSStringFromSelector(_cmd)]; @@ -91,23 +96,8 @@ 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 { @@ -115,23 +105,7 @@ } - (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 { diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.m b/SOGo/SoObjects/Mailer/SOGoMailFolder.m index f26d4c89..9f8d20c2 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.m @@ -22,6 +22,7 @@ #include "SOGoMailFolder.h" #include "SOGoMailObject.h" +#include "SOGoMailManager.h" #include "common.h" @implementation SOGoMailFolder @@ -34,57 +35,9 @@ /* 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 */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.h b/SOGo/SoObjects/Mailer/SOGoMailManager.h new file mode 100644 index 00000000..4fa50e5e --- /dev/null +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.h @@ -0,0 +1,54 @@ +/* + 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 + +/* + 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__ */ diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m new file mode 100644 index 00000000..00b0cc42 --- /dev/null +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -0,0 +1,144 @@ +/* + 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 */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 28292b54..81be7eb6 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=8 +SUBMINOR_VERSION:=9 diff --git a/SOGo/UI/Mailer/Images/tbtv_account_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_account_17x17.gif new file mode 100644 index 00000000..fbbdd1e2 Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_account_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_drafts_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_drafts_17x17.gif new file mode 100644 index 00000000..c6a82e6c Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_drafts_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_inbox_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_inbox_17x17.gif new file mode 100644 index 00000000..745709d3 Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_inbox_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_junction2_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_junction2_17x17.gif new file mode 100644 index 00000000..f3c22703 Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_junction2_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_junction_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_junction_17x17.gif new file mode 100644 index 00000000..3c555529 Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_junction_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_leaf_corner_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_leaf_corner_17x17.gif new file mode 100644 index 00000000..33c9708a Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_leaf_corner_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_line_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_line_17x17.gif new file mode 100644 index 00000000..962791fe Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_line_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_minus_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_minus_17x17.gif new file mode 100644 index 00000000..ca17de65 Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_minus_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_plus_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_plus_17x17.gif new file mode 100644 index 00000000..21eb597d Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_plus_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_sent_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_sent_17x17.gif new file mode 100644 index 00000000..aabe79aa Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_sent_17x17.gif differ diff --git a/SOGo/UI/Mailer/Images/tbtv_trash_17x17.gif b/SOGo/UI/Mailer/Images/tbtv_trash_17x17.gif new file mode 100644 index 00000000..da3c01a7 Binary files /dev/null and b/SOGo/UI/Mailer/Images/tbtv_trash_17x17.gif differ