From 63c787e7590549f2d8a73067d544961ec6271c9b Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Wed, 6 Jan 2010 13:45:55 +0000 Subject: [PATCH] Monotone-Parent: 6075106624ecdc149d0393a0796a4e87b74a1bea Monotone-Revision: c611aac3a435306dc4b8733414bd22f705466261 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2010-01-06T13:45:55 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 12 +++++ SoObjects/Mailer/SOGoMailAccount.h | 7 +-- SoObjects/Mailer/SOGoMailAccount.m | 51 +++++++++++------- SoObjects/Mailer/SOGoMailFolder.m | 82 ++++++++++++++++------------- SoObjects/SOGo/SOGoDomainDefaults.h | 2 - SoObjects/SOGo/SOGoDomainDefaults.m | 10 ---- 6 files changed, 95 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2ff4b4388..e30c6e076 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2010-01-06 Wolfgang Sourdeau + + * SoObjects/Mailer/SOGoMailAccount.m + (-otherUsersFolderNamespaces): new method that returns all the + namespace "folders" in the "other user" namespace. Replaces the + old "otherUsersFolderName" method. + (-sharedFolderNamespaces): same as above for the "shared" + namespace. + + * SoObjects/SOGo/SOGoDomainDefaults.m (-otherUsersFolderName) + (-sharedFolderName): removed obsolete methods. + 2010-01-05 Wolfgang Sourdeau * UI/WebServerResources/MailerUI.js (Mailbox): "this.name" is now diff --git a/SoObjects/Mailer/SOGoMailAccount.h b/SoObjects/Mailer/SOGoMailAccount.h index 6c138459a..b442e1a20 100644 --- a/SoObjects/Mailer/SOGoMailAccount.h +++ b/SoObjects/Mailer/SOGoMailAccount.h @@ -83,9 +83,10 @@ typedef enum { - (SOGoSentFolder *) sentFolderInContext: (id)_ctx; - (SOGoTrashFolder *) trashFolderInContext: (id)_ctx; -/* user defaults */ -- (NSString *) sharedFolderName; -- (NSString *) otherUsersFolderName; +/* namespaces */ + +- (NSArray *) otherUsersFolderNamespaces; +- (NSArray *) sharedFolderNamespaces; @end diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 416291c09..d20b4adbb 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -114,6 +114,8 @@ static NSString *sieveScriptName = @"sogo"; } } +/* namespaces */ + - (void) _appendNamespaces: (NSMutableArray *) folders { NSDictionary *namespaceDict; @@ -133,6 +135,37 @@ static NSString *sieveScriptName = @"sogo"; [self _appendNamespace: namespace toFolders: folders]; } +- (NSArray *) _namespacesWithKey: (NSString *) nsKey +{ + NSDictionary *namespaceDict; + NSArray *namespace; + NGImap4Client *client; + NSMutableArray *folders; + + client = [[self imap4Connection] client]; + namespaceDict = [client namespace]; + namespace = [namespaceDict objectForKey: nsKey]; + if (namespace) + { + folders = [NSMutableArray array]; + [self _appendNamespace: namespace toFolders: folders]; + } + else + folders = nil; + + return folders; +} + +- (NSArray *) otherUsersFolderNamespaces +{ + return [self _namespacesWithKey: @"other users"]; +} + +- (NSArray *) sharedFolderNamespaces +{ + return [self _namespacesWithKey: @"shared"]; +} + - (NSArray *) toManyRelationshipKeys { NSMutableArray *folders; @@ -755,22 +788,4 @@ static NSString *sieveScriptName = @"sogo"; return [self shortTitle]; } -- (NSString *) sharedFolderName -{ - SOGoDomainDefaults *dd; - - dd = [[context activeUser] domainDefaults]; - - return [dd sharedFolderName]; -} - -- (NSString *) otherUsersFolderName -{ - SOGoDomainDefaults *dd; - - dd = [[context activeUser] domainDefaults]; - - return [dd otherUsersFolderName]; -} - @end /* SOGoMailAccount */ diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 402e398fb..22d933938 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -74,29 +74,41 @@ static NSString *defaultUserID = @"anyone"; @implementation SOGoMailFolder +- (BOOL) _path: (NSString *) path + isInNamespaces: (NSArray *) namespaces +{ + int count, max; + BOOL rc; + + rc = NO; + + max = [namespaces count]; + for (count = 0; !rc && count < max; count++) + rc = [path hasPrefix: [namespaces objectAtIndex: count]]; + + return rc; +} + - (void) _adjustOwner { SOGoMailAccount *mailAccount; - NSString *path, *folder; + NSString *path; NSArray *names; mailAccount = [self mailAccountFolder]; path = [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]]; - folder = [mailAccount sharedFolderName]; - if (folder && [path hasPrefix: folder]) + if ([self _path: path + isInNamespaces: [mailAccount sharedFolderNamespaces]]) [self setOwner: @"nobody"]; - else + else if ([self _path: path + isInNamespaces: [mailAccount otherUsersFolderNamespaces]]) { - folder = [mailAccount otherUsersFolderName]; - if (folder && [path hasPrefix: folder]) - { - names = [path componentsSeparatedByString: @"/"]; - if ([names count] > 1) - [self setOwner: [names objectAtIndex: 1]]; - else - [self setOwner: @"nobody"]; - } + names = [path componentsSeparatedByString: @"/"]; + if ([names count] > 1) + [self setOwner: [names objectAtIndex: 1]]; + else + [self setOwner: @"nobody"]; } } @@ -893,7 +905,7 @@ static NSString *defaultUserID = @"anyone"; { NSMutableArray *acls; SOGoMailAccount *mailAccount; - NSString *path, *folder; + NSString *path; // NSArray *names; // unsigned int count; @@ -904,17 +916,13 @@ static NSString *defaultUserID = @"anyone"; // names = [path componentsSeparatedByString: @"/"]; // count = [names count]; - folder = [mailAccount sharedFolderName]; - if (folder && [path hasPrefix: folder]) + if ([self _path: path + isInNamespaces: [mailAccount sharedFolderNamespaces]] + || [self _path: path + isInNamespaces: [mailAccount sharedFolderNamespaces]]) [acls addObject: SOGoRole_ObjectViewer]; else - { - folder = [mailAccount otherUsersFolderName]; - if (folder && [path hasPrefix: folder]) - [acls addObject: SOGoRole_ObjectViewer]; - else - [acls addObject: SoRole_Owner]; - } + [acls addObject: SoRole_Owner]; return acls; } @@ -977,27 +985,29 @@ static NSString *defaultUserID = @"anyone"; - (NSString *) otherUsersPathToFolder { - NSString *userPath, *selfPath, *otherUsers, *sharedFolders; + NSString *userPath, *selfPath, *otherUsers; SOGoMailAccount *account; + NSArray *otherUsersFolderNamespaces; +#warning this method should be checked account = [self mailAccountFolder]; - otherUsers = [account otherUsersFolderName]; - sharedFolders = [account sharedFolderName]; + otherUsersFolderNamespaces = [account otherUsersFolderNamespaces]; selfPath = [[self imap4URL] path]; - if ((otherUsers - && [selfPath hasPrefix: - [NSString stringWithFormat: @"/%@", otherUsers]]) - || (sharedFolders - && [selfPath hasPrefix: - [NSString stringWithFormat: @"/%@", sharedFolders]])) + if ([self _path: selfPath isInNamespaces: otherUsersFolderNamespaces] + || [self _path: selfPath + isInNamespaces: [account sharedFolderNamespaces]]) userPath = selfPath; else { - if (otherUsers) - userPath = [NSString stringWithFormat: @"/%@/%@%@", - [otherUsers stringByEscapingURL], - owner, selfPath]; + if ([otherUsersFolderNamespaces count]) + { + /* can we really have more than one "other users" namespace? */ + otherUsers = [[otherUsersFolderNamespaces objectAtIndex: 0] + stringByEscapingURL]; + userPath = [NSString stringWithFormat: @"/%@/%@%@", + otherUsers, owner, selfPath]; + } else userPath = nil; } diff --git a/SoObjects/SOGo/SOGoDomainDefaults.h b/SoObjects/SOGo/SOGoDomainDefaults.h index 14a0191ac..4a304098c 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.h +++ b/SoObjects/SOGo/SOGoDomainDefaults.h @@ -44,8 +44,6 @@ - (BOOL) forceIMAPLoginWithEmail; - (BOOL) forwardEnabled; - (BOOL) vacationEnabled; -- (NSString *) otherUsersFolderName; -- (NSString *) sharedFolderName; - (NSString *) mailingMechanism; - (NSString *) smtpServer; - (NSString *) mailSpoolPath; diff --git a/SoObjects/SOGo/SOGoDomainDefaults.m b/SoObjects/SOGo/SOGoDomainDefaults.m index a4ab1bab4..30eea0b1f 100644 --- a/SoObjects/SOGo/SOGoDomainDefaults.m +++ b/SoObjects/SOGo/SOGoDomainDefaults.m @@ -182,16 +182,6 @@ return [self arrayForKey: @"SOGoMailPollingIntervals"]; } -- (NSString *) otherUsersFolderName -{ - return [self stringForKey: @"SOGoOtherUsersFolderName"]; -} - -- (NSString *) sharedFolderName -{ - return [self stringForKey: @"SOGoSharedFolderName"]; -} - - (NSString *) smtpServer { return [self stringForKey: @"SOGoSMTPServer"];