From 20a8a4f4dfd4a31879b449fb4a74751625416a19 Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 14 Jul 2005 10:04:59 +0000 Subject: [PATCH] work on NGImap4Connection git-svn-id: http://svn.opengroupware.org/SOPE/trunk@899 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-mime/ChangeLog | 5 ++ sope-mime/NGImap4/ChangeLog | 6 ++ sope-mime/NGImap4/NGImap4Connection.h | 1 + sope-mime/NGImap4/NGImap4Connection.m | 114 +++++++++++--------------- sope-mime/Version | 2 +- 5 files changed, 63 insertions(+), 65 deletions(-) diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index ad9e33a7..c9bd1915 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,8 @@ +2005-07-14 Helge Hess + + * NGImap4: fixed default names of NGImap4Connection, some code reorgs + (v.4.5.227) + 2005-07-13 Helge Hess * NGImap4: added -description to imap4-connection (v4.5.226) diff --git a/sope-mime/NGImap4/ChangeLog b/sope-mime/NGImap4/ChangeLog index 154ddd11..a241bf14 100644 --- a/sope-mime/NGImap4/ChangeLog +++ b/sope-mime/NGImap4/ChangeLog @@ -1,3 +1,9 @@ +2005-07-14 Helge Hess + + * NGImap4Connection.m: updated defaults to use NGImap4Connection* + names, made the IMAP4 folder separator an ivar, consolidated the + fetching of the mailbox hierarchy + 2005-07-13 Helge Hess * NGImap4Connection.m: added a -description diff --git a/sope-mime/NGImap4/NGImap4Connection.h b/sope-mime/NGImap4/NGImap4Connection.h index 4d86fc95..c1b8a339 100644 --- a/sope-mime/NGImap4/NGImap4Connection.h +++ b/sope-mime/NGImap4/NGImap4Connection.h @@ -49,6 +49,7 @@ NGImap4Client *client; NSString *password; NSDate *creationTime; + NSString *separator; /* hierarchy cache */ NSDictionary *subfolders; diff --git a/sope-mime/NGImap4/NGImap4Connection.m b/sope-mime/NGImap4/NGImap4Connection.m index 3b77e65c..1b7078a6 100644 --- a/sope-mime/NGImap4/NGImap4Connection.m +++ b/sope-mime/NGImap4/NGImap4Connection.m @@ -26,27 +26,30 @@ @implementation NGImap4Connection -static BOOL debugOn = NO; -static BOOL debugCache = NO; -static BOOL debugKeys = NO; -static BOOL alwaysSelect = NO; -static BOOL onlyFetchInbox = NO; -static NSString *imap4Separator = nil; +static BOOL debugOn = NO; +static BOOL debugCache = NO; +static BOOL debugKeys = NO; +static BOOL alwaysSelect = NO; +static BOOL onlyFetchInbox = NO; +static NSString *imap4Separator = nil; + (void)initialize { NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; - debugOn = [ud boolForKey:@"SOGoEnableIMAP4Debug"]; - debugCache = [ud boolForKey:@"SOGoEnableIMAP4CacheDebug"]; - alwaysSelect = [ud boolForKey:@"SOGoAlwaysSelectIMAP4Folder"]; - if (debugOn) NSLog(@"Note: SOGoEnableIMAP4Debug is enabled!"); + debugOn = [ud boolForKey:@"NGImap4ConnectionDebugEnabled"]; + debugCache = [ud boolForKey:@"NGImap4ConnectionCacheDebugEnabled"]; + debugKeys = [ud boolForKey:@"NGImap4ConnectionFolderDebugEnabled"]; + alwaysSelect = [ud boolForKey:@"NGImap4ConnectionAlwaysSelect"]; + + if (debugOn) NSLog(@"Note: NGImap4ConnectionDebugEnabled is enabled!"); if (alwaysSelect) - NSLog(@"WARNING: 'SOGoAlwaysSelectIMAP4Folder' enabled (slow down)"); + NSLog(@"WARNING: 'NGImap4ConnectionAlwaysSelect' enabled (slow down)"); - imap4Separator = [[ud stringForKey:@"SOGoIMAP4StringSeparator"] copy]; + imap4Separator = + [[ud stringForKey:@"NGImap4ConnectionStringSeparator"] copy]; if ([imap4Separator length] == 0) imap4Separator = @"/"; - NSLog(@"Note(SOGoMailManager): using '%@' as the IMAP4 folder separator.", + NSLog(@"Note(NGImap4Connection): using '%@' as the IMAP4 folder separator.", imap4Separator); } @@ -61,6 +64,9 @@ static NSString *imap4Separator = nil; self->password = [_pwd copy]; self->creationTime = [[NSDate alloc] init]; + + // TODO: retrieve from IMAP4 instead of using a default + self->separator = imap4Separator; } return self; } @@ -69,6 +75,7 @@ static NSString *imap4Separator = nil; } - (void)dealloc { + [self->separator release]; [self->urlToRights release]; [self->cachedUIDs release]; [self->uidFolderURL release]; @@ -239,7 +246,9 @@ NSArray *SOGoMailGetDirectChildren(NSArray *_array, NSString *_fn) { return ma; } -NSArray *SOGoMailExtractSubfolders(NSURL *_url, NSDictionary *_result) { +- (NSArray *)extractSubfoldersForURL:(NSURL *)_url + fromResultSet:(NSDictionary *)_result +{ NSString *folderName; NSDictionary *result; NSArray *names; @@ -262,7 +271,7 @@ NSArray *SOGoMailExtractSubfolders(NSURL *_url, NSDictionary *_result) { NSLog(@"%s: folder %@ has no children.", __PRETTY_FUNCTION__,folderName); return nil; } - + if (debugKeys) { NSLog(@"%s: all keys %@: %@", __PRETTY_FUNCTION__, folderName, [[result allKeys] componentsJoinedByString:@", "]); @@ -276,18 +285,8 @@ NSArray *SOGoMailExtractSubfolders(NSURL *_url, NSDictionary *_result) { return names; } -- (NSArray *)_getDirectChildren:(NSArray *)_array folderName:(NSString *)_fn { - return SOGoMailGetDirectChildren(_array, _fn); -} -- (NSArray *)extractSubfoldersForURL:(NSURL *)_url - fromResultSet:(NSDictionary *)_result -{ - return SOGoMailExtractSubfolders(_url, _result); -} - - (NSString *)imap4Separator { - // TODO: make server specific ivar! - return imap4Separator; + return self->separator; } - (NSString *)imap4FolderNameForURL:(NSURL *)_url removeFileName:(BOOL)_delfn { @@ -355,69 +354,56 @@ NSArray *SOGoMailExtractSubfolders(NSURL *_url, NSDictionary *_result) { /* folder operations */ -- (NSArray *)subfoldersForURL:(NSURL *)_url { - NSDictionary *result; - - /* check hierarchy cache */ +- (NSDictionary *)primaryFetchMailboxHierarchyForURL:(NSURL *)_url { + NSDictionary *result; if ((result = [self cachedHierarchyResults]) != nil) - return [self extractSubfoldersForURL:_url fromResultSet:result]; - - [self debugWithFormat:@" no folders cached yet .."]; + return [result isNotNull] ? result : nil; - /* fetch _all_ folders */ + if (debugCache) [self logWithFormat:@" no folders cached yet .."]; result = [[self client] list:(onlyFetchInbox ? @"INBOX" : @"*") pattern:@"*"]; if (![[result valueForKey:@"result"] boolValue]) { - [self errorWithFormat:@"listing of folder failed!"]; + [self errorWithFormat:@"Could not list mailbox hierarchy!"]; return nil; } - + /* cache results */ if ([result isNotNull]) { [self cacheHierarchyResults:result]; if (debugCache) { - [self logWithFormat:@"cached results in entry %@: 0x%08X(%d)", - self, result, [result count]]; + [self logWithFormat:@"cached results: 0x%08X(%d)", + result, [result count]]; } } - - /* extract list */ + return result; +} + +- (NSArray *)subfoldersForURL:(NSURL *)_url { + NSDictionary *result; + + if ((result = [self primaryFetchMailboxHierarchyForURL:_url]) == nil) + return nil; + if ([result isKindOfClass:[NSException class]]) { + [self errorWithFormat:@"failed to retrieve hierarchy: %@", result]; + return nil; + } return [self extractSubfoldersForURL:_url fromResultSet:result]; } - (NSArray *)allFoldersForURL:(NSURL *)_url { NSDictionary *result; - - /* check hierarchy cache */ - - if ((result = [self cachedHierarchyResults]) != nil) - return [self extractFoldersFromResultSet:result]; - - [self debugWithFormat:@" no folders cached yet .."]; - - /* fetch _all_ folders */ - - result = [[self client] list:@"INBOX" pattern:@"*"]; - if (![[result valueForKey:@"result"] boolValue]) { - [self logWithFormat:@"ERROR: listing of folder failed!"]; + + if ((result = [self primaryFetchMailboxHierarchyForURL:_url]) == nil) + return nil; + if ([result isKindOfClass:[NSException class]]) { + [self errorWithFormat:@"failed to retrieve hierarchy: %@", result]; return nil; } - /* cache results */ - - if ([result isNotNull]) { - [self cacheHierarchyResults:result]; - if (debugCache) { - [self logWithFormat:@"cached results in entry %@: 0x%08X(%d)", - self, result, [result count]]; - } - } - - /* extract list */ return [self extractFoldersFromResultSet:result]; } diff --git a/sope-mime/Version b/sope-mime/Version index 6a95f499..70d1e694 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=5 -SUBMINOR_VERSION:=226 +SUBMINOR_VERSION:=227 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34 -- 2.39.5