return [NSException exceptionWithHTTPStatus:404 /* Not Found */];
}
+/* WebDAV */
+
+- (NSString *)shortTitle {
+ NSString *s, *login, *host;
+ NSRange r;
+
+ s = [self nameInContainer];
+
+ r = [s rangeOfString:@"@"];
+ if (r.length > 0) {
+ login = [s substringToIndex:r.location];
+ host = [s substringFromIndex:(r.location + r.length)];
+ }
+ else {
+ login = nil;
+ host = s;
+ }
+
+ r = [host rangeOfString:@"."];
+ if (r.length > 0)
+ host = [host substringToIndex:r.location];
+
+ if ([login length] == 0)
+ return host;
+
+ return [NSString stringWithFormat:@"%@ (%@)", host, login];
+}
+
+- (NSString *)davDisplayName {
+ return [self shortTitle];
+}
+
@end /* SOGoMailAccount */
#include "SOGoMailBaseObject.h"
#include "SOGoMailManager.h"
#include "common.h"
+#include <WebDAV/SoObject+SoDAV.h>
#include <NGExtensions/NSURL+misc.h>
@implementation SOGoMailBaseObject
return [[self container] mailAccountFolder];
}
+- (NSArray *)fetchSubfolders {
+ NSMutableArray *ma;
+ NSArray *names;
+ unsigned i, count;
+
+ if ((names = [self toManyRelationshipKeys]) == nil)
+ return nil;
+
+ count = [names count];
+ ma = [NSMutableArray arrayWithCapacity:count + 1];
+ for (i = 0; i < count; i++) {
+ id folder;
+
+ folder = [self lookupName:[names objectAtIndex:i] inContext:nil
+ acquire:NO];
+ if (folder == nil)
+ continue;
+ if ([folder isKindOfClass:[NSException class]])
+ continue;
+
+ [ma addObject:folder];
+ }
+ return ma;
+}
+
/* IMAP4 */
- (SOGoMailManager *)mailManager {
password:[self imap4Password]];
}
+/* UI navigation */
+
+- (NSString *)treeNavigationLinkAtDepth:(int)_depth {
+ NSString *link;
+ unsigned i;
+
+ link = [[self nameInContainer] stringByAppendingString:@"/"];
+ for (i = 0; i < _depth; i++)
+ link = [@"../" stringByAppendingString:link];
+ return link;
+}
+
+- (id)treeNavigationBlockForLeafNodeAtDepth:(int)_depth {
+ NSMutableDictionary *md;
+
+ md = [NSMutableDictionary dictionaryWithCapacity:4];
+ [md setObject:[self davDisplayName] forKey:@"title"];
+ [md setObject:[self treeNavigationLinkAtDepth:_depth] forKey:@"link"];
+
+ if ([[self toManyRelationshipKeys] count] > 0)
+ /* trigger plus in treeview */
+ [md setObject:[NSArray arrayWithObject:@"FAKE"] forKey:@"children"];
+ return md;
+}
+
+- (id)treeNavigationBlockForActiveNode {
+ /* this generates the block for the clientObject */
+ NSMutableDictionary *md;
+ NSMutableArray *blocks;
+ NSArray *folders;
+ unsigned i, count;
+
+ /* process child folders */
+
+ folders = [self fetchSubfolders];
+ count = [folders count];
+ blocks = [NSMutableArray arrayWithCapacity:count];
+ for (i = 0; i < count; i++) {
+ id block;
+
+ block = [[folders objectAtIndex:i]
+ treeNavigationBlockForLeafNodeAtDepth:0];
+ if ([block isNotNull]) [blocks addObject:block];
+ }
+
+ /* build block */
+
+ md = [NSMutableDictionary dictionaryWithCapacity:4];
+ [md setObject:[NSNumber numberWithBool:YES] forKey:@"isActiveNode"];
+ [md setObject:[NSNumber numberWithBool:YES] forKey:@"isPathNode"];
+ [md setObject:[self davDisplayName] forKey:@"title"];
+ [md setObject:[self nameInContainer] forKey:@"name"];
+ [md setObject:@"." forKey:@"link"];
+ if ([blocks count] > 0)
+ [md setObject:blocks forKey:@"children"];
+ return md;
+}
+
+- (id)treeNavigationBlockWithActiveChildBlock:(id)_activeChildBlock
+ depth:(int)_depth
+{
+ NSMutableDictionary *md;
+ NSMutableArray *blocks;
+ NSString *activeName;
+ NSArray *folders;
+ unsigned i, count;
+
+ activeName = [_activeChildBlock valueForKey:@"name"];
+
+ /* process child folders */
+
+ folders = [self fetchSubfolders];
+ count = [folders count];
+ blocks = [NSMutableArray arrayWithCapacity:count];
+ for (i = 0; i < count; i++) {
+ id folder;
+ id block;
+
+ folder = [folders objectAtIndex:i];
+ if ([activeName isEqualToString:[folder nameInContainer]]) {
+ block = _activeChildBlock;
+ }
+ else {
+ block = [folder treeNavigationBlockForLeafNodeAtDepth:_depth];
+ }
+ if ([block isNotNull]) [blocks addObject:block];
+ }
+
+ /* build block */
+
+ md = [NSMutableDictionary dictionaryWithCapacity:4];
+ [md setObject:[self davDisplayName] forKey:@"title"];
+ [md setObject:[self nameInContainer] forKey:@"name"];
+ [md setObject:[NSNumber numberWithBool:YES] forKey:@"isPathNode"];
+ [md setObject:[self treeNavigationLinkAtDepth:(_depth + 1)] forKey:@"link"];
+ if ([blocks count] > 0)
+ [md setObject:blocks forKey:@"children"];
+
+ /* recurse up */
+
+ return [[self container] treeNavigationBlockWithActiveChildBlock:md
+ depth:(_depth + 1)];
+}
+
+- (id)treeNavigationNodes {
+ return [[self container] treeNavigationBlockWithActiveChildBlock:
+ [self treeNavigationBlockForActiveNode]
+ depth:1];
+}
+
@end /* SOGoMailBaseObject */
@implementation SOGoMailManager
static BOOL debugOn = YES;
+static BOOL debugCache = NO;
static BOOL poolingOff = NO;
static NSTimeInterval PoolScanInterval = 5 * 60;
if ([entry isValidPassword:_pwd]) {
NSDictionary *allFolders;
- [self debugWithFormat:@"valid password, reusing folder cache .."];
+ if (debugCache)
+ [self logWithFormat:@"valid password, reusing folder cache .."];
if ((allFolders = [entry cachedHierarchyResults]) != nil)
return [self extractSubfoldersForURL:_url fromResultSet:allFolders];
entry = [self entryForURL:_url];
[entry cacheHierarchyResults:result];
- [self debugWithFormat:@"cached results in entry %@: %@", entry, result];
+ if (debugCache)
+ [self logWithFormat:@"cached results in entry %@: %@", entry, result];
}
/* extract list */