From 31485fdb4811b31420b6dfe189b5d03bf4cddd7d Mon Sep 17 00:00:00 2001 From: helge Date: Thu, 3 Mar 2005 00:43:11 +0000 Subject: [PATCH] some debugging in NGImap4 git-svn-id: http://svn.opengroupware.org/SOPE/trunk@610 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-mime/ChangeLog | 4 ++ sope-mime/NGImap4/ChangeLog | 10 +++ sope-mime/NGImap4/NGImap4Context.m | 26 ++++---- sope-mime/NGImap4/NGImap4FileManager.m | 86 ++++++++++++++++++-------- sope-mime/NGImap4/NGImap4Folder.m | 3 +- sope-mime/NGImap4/NGImap4Functions.m | 19 ++++-- sope-mime/Version | 2 +- sope-mime/samples/ChangeLog | 4 ++ sope-mime/samples/ImapListTool.m | 22 +++---- 9 files changed, 122 insertions(+), 54 deletions(-) diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index 0bf8627f..3e7e5e5a 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,7 @@ +2005-03-03 Helge Hess + + * NGImap4: added some debugging facilities (v4.5.215) + 2005-02-14 Helge Hess * NGImap4: changed base64 encoding in Sieve client to fix OGo bug #1228 diff --git a/sope-mime/NGImap4/ChangeLog b/sope-mime/NGImap4/ChangeLog index 05ae3f40..60bb5a77 100644 --- a/sope-mime/NGImap4/ChangeLog +++ b/sope-mime/NGImap4/ChangeLog @@ -1,3 +1,13 @@ +2005-03-03 Helge Hess + + * NGImap4FileManager.m: added debug logs which can be enabled using + the 'NGImap4FileManagerDebugEnabled' default, improved handling of + root folder in -fileExists method + + * NGImap4Context.m: improved -description + + * NGImap4Functions.m: added some debugging facilities + 2005-02-14 Helge Hess * NGSieveClient.m: encode base64 with a large line break to fix OGo diff --git a/sope-mime/NGImap4/NGImap4Context.m b/sope-mime/NGImap4/NGImap4Context.m index 357f1257..645f8c3b 100644 --- a/sope-mime/NGImap4/NGImap4Context.m +++ b/sope-mime/NGImap4/NGImap4Context.m @@ -929,20 +929,18 @@ static int ImapLogEnabled = -1; /* description */ -- (NSString *)description { - NSMutableString *ms; +- (void)appendAttributesToDescription:(NSMutableString *)ms { NSString *tmp; - - ms = [NSMutableString stringWithCapacity:64]; - - [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; - - if ((tmp = [self host])) + + if ((tmp = [self host]) != nil) [ms appendFormat:@" host=%@", tmp]; - if ((tmp = [self login])) + if ((tmp = [self login]) != nil) [ms appendFormat:@" login=%@", tmp]; - [ms appendFormat:@" server='%@'/%@/%@.%@/%@", + if ((tmp = [self serverName]) != nil) + [ms appendFormat:@" server='%@'", tmp]; + + [ms appendFormat:@" kind=%@/v%@.%@/tag=%@", [self serverName], [self serverKind], [self serverVersion], @@ -951,9 +949,15 @@ static int ImapLogEnabled = -1; if (self->syncMode) [ms appendString:@" syncmode"]; +} + +- (NSString *)description { + NSMutableString *ms; + ms = [NSMutableString stringWithCapacity:64]; + [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; + [self appendAttributesToDescription:ms]; [ms appendString:@">"]; - return ms; } diff --git a/sope-mime/NGImap4/NGImap4FileManager.m b/sope-mime/NGImap4/NGImap4FileManager.m index 6e411bae..fbfacb12 100644 --- a/sope-mime/NGImap4/NGImap4FileManager.m +++ b/sope-mime/NGImap4/NGImap4FileManager.m @@ -42,13 +42,20 @@ @implementation NGImap4FileManager +static BOOL debugOn = NO; + + (int)version { return [super version] + 0 /* v0 */; } + (void)initialize { + NSUserDefaults *ud = [NSUserDefaults standardUserDefaults]; + NSAssert2([super version] == 0, @"invalid superclass (%@) version %i !", NSStringFromClass([self superclass]), [super version]); + + if ((debugOn = [ud boolForKey:@"NGImap4FileManagerDebugEnabled"])) + NSLog(@"NGImap4FileManager debugging is enabled."); } - (id)initWithUser:(NSString *)_user @@ -268,20 +275,25 @@ NSEnumerator *e; NGImap4Folder *tmp; NGImap4Message *msg; - + if (![_path isAbsolutePath]) _path = [[self currentDirectoryPath] stringByAppendingPathComponent:_path]; - if ((folder = [self _lookupFolderAtPath:[_path pathComponents]]) == nil) + if ((folder = [self _lookupFolderAtPath:[_path pathComponents]]) == nil) { /* folder does not exist */ + if (debugOn) [self debugWithFormat:@"did not find folder."]; return nil; - + } + results = [NSMutableArray arrayWithCapacity:64]; - + /* add folders */ if (_dirs) { + if (debugOn) + [self debugWithFormat:@" add subfolders: %@", [folder subFolders]]; + e = [[folder subFolders] objectEnumerator]; - while ((tmp = [e nextObject])) + while ((tmp = [e nextObject]) != nil) [results addObject:[tmp name]]; } @@ -292,6 +304,8 @@ [results addObject:[NSString stringWithFormat:@"%d", [msg uid]]]; } + if (debugOn) + [self debugWithFormat:@" dir contents: %@", results]; return results; } @@ -358,14 +372,22 @@ if (![_path isAbsolutePath]) _path = [[self currentDirectoryPath] stringByAppendingPathComponent:_path]; + + if ([_path isEqualToString:@"/"]) { + if (_isDir) *_isDir = YES; + return self->rootFolder != nil ? YES : NO; + } fileName = [_path lastPathComponent]; _path = [_path stringByDeletingLastPathComponent]; paths = [_path pathComponents]; - - folder = [self _lookupFolderAtPath:paths]; - - // NSLog(@"paths: %@, file %@, folder %@", paths, fileName, folder); + folder = [self _lookupFolderAtPath:paths]; + + if (debugOn) { + [self debugWithFormat: + @"base '%@' file '%@' paths: %@, file %@, folder %@", + _path, fileName, paths, fileName, folder]; + } if (folder == nil) return NO; @@ -379,11 +401,13 @@ return YES; } - if ([folder subFolderWithName:fileName caseInsensitive:NO]) { + // TODO: what is the caseInsensitive good for? + if (debugOn) [self debugWithFormat:@" lookup '%@' in %@", fileName, folder]; + if ([folder subFolderWithName:fileName caseInsensitive:NO] != nil) { *_isDir = YES; return YES; } - + *_isDir = NO; /* check for message 'file' */ @@ -588,21 +612,6 @@ return dict; } -/* description */ - -- (NSString *)description { - NSMutableString *ms; - - ms = [NSMutableString stringWithCapacity:64]; - - [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; - [ms appendFormat:@" ctx=%@", self->imapContext]; - [ms appendFormat:@" root=%@", self->rootFolder]; - [ms appendFormat:@" wd=%@", self->currentFolder]; - [ms appendString:@">"]; - - return ms; -} - (EODataSource *)dataSourceAtPath:(NSString *)_path { NGImap4Folder *f; @@ -624,4 +633,29 @@ [self->imapContext leaveSyncMode]; } +/* debugging */ + +- (BOOL)isDebuggingEnabled { + return debugOn; +} + +/* description */ + +- (void)appendAttributesToDescription:(NSMutableString *)ms { + [ms appendFormat:@" ctx=%@", self->imapContext]; + [ms appendFormat:@" root=%@", self->rootFolder]; + [ms appendFormat:@" wd=%@", self->currentFolder]; +} + +- (NSString *)description { + NSMutableString *ms; + + ms = [NSMutableString stringWithCapacity:64]; + + [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; + [self appendAttributesToDescription:ms]; + [ms appendString:@">"]; + return ms; +} + @end /* NGImap4FileManager */ diff --git a/sope-mime/NGImap4/NGImap4Folder.m b/sope-mime/NGImap4/NGImap4Folder.m index 4c6af2c1..2d90dd9c 100644 --- a/sope-mime/NGImap4/NGImap4Folder.m +++ b/sope-mime/NGImap4/NGImap4Folder.m @@ -368,7 +368,8 @@ static int FetchNewUnseenMessagesInSubFoldersOnDemand = -1; } - (NGImap4Folder *)subFolderWithName:(NSString *)_name - caseInsensitive:(BOOL)_caseIns { + caseInsensitive:(BOOL)_caseIns +{ return _subFolderWithName(self, _name, _caseIns); } diff --git a/sope-mime/NGImap4/NGImap4Functions.m b/sope-mime/NGImap4/NGImap4Functions.m index c0e6e5c4..9d881724 100644 --- a/sope-mime/NGImap4/NGImap4Functions.m +++ b/sope-mime/NGImap4/NGImap4Functions.m @@ -34,6 +34,7 @@ static int LogImapEnabled = -1; static NGImap4FolderHandler *sharedHandler = nil; // THREAD +static BOOL debugFolderLookup = NO; + (id)sharedImap4FolderHandler { if (sharedHandler == nil) @@ -106,21 +107,31 @@ NGImap4Folder *_subFolderWithName if (_caseIns) _name = [_name lowercaseString]; - + + if (debugFolderLookup) + NSLog(@"LOOKUP %@ IN %@", _name, [_parent subFolders]); + enumerator = [[_parent subFolders] objectEnumerator]; - while ((f = [enumerator nextObject])) { + while ((f = [enumerator nextObject]) != nil) { NSString *n; n = [f name]; if (_caseIns) n = [n lowercaseString]; - if ([n isEqualToString:_name]) + if ([n isEqualToString:_name]) { + if (debugFolderLookup) NSLog(@" FOUND: %@", f); return f; + } - if ([[_parent context] lastException]) + if ([[_parent context] lastException] != nil) { + if (debugFolderLookup) { + NSLog(@" FAILED: %@", [[_parent context] lastException]); + } return NO; + } } + if (debugFolderLookup) NSLog(@" NOT FOUND."); return nil; } diff --git a/sope-mime/Version b/sope-mime/Version index 8f5d80cb..c61276a2 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=5 -SUBMINOR_VERSION:=214 +SUBMINOR_VERSION:=215 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34 diff --git a/sope-mime/samples/ChangeLog b/sope-mime/samples/ChangeLog index dcd9fe64..024ae5bd 100644 --- a/sope-mime/samples/ChangeLog +++ b/sope-mime/samples/ChangeLog @@ -1,3 +1,7 @@ +2005-03-03 Helge Hess + + * ImapListTool.m: improved output with directories + 2004-09-26 Helge Hess * GNUmakefile: added imap_tool to compilation diff --git a/sope-mime/samples/ImapListTool.m b/sope-mime/samples/ImapListTool.m index 02bfbc74..9256b42f 100644 --- a/sope-mime/samples/ImapListTool.m +++ b/sope-mime/samples/ImapListTool.m @@ -40,6 +40,7 @@ NSString *cpath, *apath; NSDictionary *info; NSString *mid; + const unsigned char *datestr; if (!self->useDataSource) { cpath = [dirContents objectAtIndex:i]; @@ -61,19 +62,22 @@ mid = [mid substringToIndex:37]; mid = [mid stringByAppendingString:@"..."]; } - + /* id uid date name */ if (_part) { printf("%10d ", [[fm contentsAtPath:[info valueForKey:@"NSFilePath"] part:_part] length]); } + + datestr = [[[info valueForKey:NSFileModificationDate] + description] cString]; + printf("%-40s %8s %8i %-32s %s", - [mid cString], + (mid ? [mid cString] : ""), [[info valueForKey:NSFileOwnerAccountName] cString], [[info valueForKey:NSFileSize] intValue], - [[[info valueForKey:NSFileModificationDate] - description] cString], + (datestr ? (char *)datestr : ""), [apath cString]); if ([[info valueForKey:NSFileType] @@ -81,8 +85,6 @@ printf("/\n"); else printf("\n"); - - } return YES; } @@ -174,7 +176,7 @@ if (![fm changeCurrentDirectoryPath:path]) { NSLog(@"%s: could not change to directory: '%@'", path); } - + ds = self->useDataSource ? [(id)fm dataSourceAtPath:path] : nil; @@ -282,12 +284,10 @@ return; } - if (isDir) { + if (isDir) [self processFolder:path fileManager:fm part:part]; - } - else { + else [self processFile:path fileManager:fm part:part]; - } } /* tool operation */ -- 2.39.5