From debb2b6ffab9904983785e0c9b9c2ffef7109a75 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Fri, 17 Aug 2007 02:27:35 +0000 Subject: [PATCH] Monotone-Parent: cb5bfb62000fd7982b31d051ab2a4f4d859b9125 Monotone-Revision: 7d2a0f0461686fedc8113fa82622e1f9f934130a Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-08-17T02:27:35 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 8 ++++ SoObjects/Mailer/SOGoMailFolder.h | 1 + SoObjects/Mailer/SOGoMailFolder.m | 72 +++++++++++++++++++++++-------- 3 files changed, 62 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index e03ea2fb7..8b61239eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2007-08-16 Wolfgang Sourdeau + * SoObjects/Mailer/SOGoMailFolder.m ([SOGoMailFolder -aclUsers]): + cache the mailbox acl. + ([SOGoMailFolder -aclsForUser:uid]): cache the mailbox acl. + ([SOGoMailFolder -setRoles:rolesforUser:uid]): reset the mailbox + acl cache. + ([SOGoMailFolder -httpURLForAdvisoryToUser:uid]): modified to use + the new method of determining the users mail accounts. + * SoObjects/Mailer/SOGoMailBaseObject.m ([-imap4URLString]): no longer adds a "/" at the end of the string (the default for folders), therefore this will be overriden in SOGoMailFolder diff --git a/SoObjects/Mailer/SOGoMailFolder.h b/SoObjects/Mailer/SOGoMailFolder.h index 491734c73..89d8c68d6 100644 --- a/SoObjects/Mailer/SOGoMailFolder.h +++ b/SoObjects/Mailer/SOGoMailFolder.h @@ -40,6 +40,7 @@ { NSMutableArray *filenames; NSString *folderType; + NSDictionary *mailboxACL; } /* messages */ diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index 3232947fe..7087a1711 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -85,6 +85,7 @@ static BOOL useAltNamespace = NO; inContainer: newContainer])) { [self _adjustOwner]; + mailboxACL = nil; } return self; @@ -94,6 +95,7 @@ static BOOL useAltNamespace = NO; { [filenames release]; [folderType release]; + [mailboxACL release]; [super dealloc]; } @@ -104,6 +106,17 @@ static BOOL useAltNamespace = NO; return [nameInContainer substringFromIndex: 6]; } + +- (NSMutableString *) imap4URLString +{ + NSMutableString *urlString; + + urlString = [super imap4URLString]; + [urlString appendString: @"/"]; + + return urlString; +} + /* listing the available folders */ - (NSArray *) toManyRelationshipKeys @@ -179,22 +192,22 @@ static BOOL useAltNamespace = NO; sortOrdering: (id) _so { /* seems to return an NSArray of NSNumber's */ - return [[self imap4Connection] fetchUIDsInURL:[self imap4URL] - qualifier:_q sortOrdering:_so]; + return [[self imap4Connection] fetchUIDsInURL: [self imap4URL] + qualifier: _q sortOrdering: _so]; } - (NSArray *) fetchUIDs: (NSArray *) _uids parts: (NSArray *) _parts { - return [[self imap4Connection] fetchUIDs:_uids inURL:[self imap4URL] - parts:_parts]; + return [[self imap4Connection] fetchUIDs: _uids inURL: [self imap4URL] + parts: _parts]; } - (NSException *) postData: (NSData *) _data flags: (id) _flags { - return [[self imap4Connection] postData:_data flags:_flags - toFolderURL:[self imap4URL]]; + return [[self imap4Connection] postData: _data flags: _flags + toFolderURL: [self imap4URL]]; } - (NSException *) expunge @@ -460,14 +473,22 @@ static BOOL useAltNamespace = NO; return imapAcls; } +- (void) _readMailboxACL +{ + mailboxACL + = [[self imap4Connection] aclForMailboxAtURL: [self imap4URL]]; + [mailboxACL retain]; +} + - (NSArray *) aclUsers { NSArray *users; - NSDictionary *imapAcls; - imapAcls = [[self imap4Connection] aclForMailboxAtURL: [self imap4URL]]; - if ([imapAcls isKindOfClass: [NSDictionary class]]) - users = [imapAcls allKeys]; + if (!mailboxACL) + [self _readMailboxACL]; + + if ([mailboxACL isKindOfClass: [NSDictionary class]]) + users = [mailboxACL allKeys]; else users = nil; @@ -506,17 +527,19 @@ static BOOL useAltNamespace = NO; - (NSArray *) aclsForUser: (NSString *) uid { - NSDictionary *imapAcls; NSMutableArray *acls; NSString *userAcls; acls = [self _sharesACLs]; - imapAcls = [[self imap4Connection] aclForMailboxAtURL: [self imap4URL]]; - if ([imapAcls isKindOfClass: [NSDictionary class]]) + + if (!mailboxACL) + [self _readMailboxACL]; + + if ([mailboxACL isKindOfClass: [NSDictionary class]]) { - userAcls = [imapAcls objectForKey: uid]; + userAcls = [mailboxACL objectForKey: uid]; if (!([userAcls length] || [uid isEqualToString: defaultUserID])) - userAcls = [imapAcls objectForKey: defaultUserID]; + userAcls = [mailboxACL objectForKey: defaultUserID]; if ([userAcls length]) [acls addObjectsFromArray: [self _imapAclsToSOGoAcls: userAcls]]; } @@ -541,6 +564,8 @@ static BOOL useAltNamespace = NO; [client deleteACL: folderName uid: currentUID]; currentUID = [uids nextObject]; } + [mailboxACL release]; + mailboxACL = nil; } - (void) setRoles: (NSArray *) roles @@ -551,6 +576,9 @@ static BOOL useAltNamespace = NO; acls = [self _sogoAclsToImapAcls: roles]; folderName = [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]]; [[imap4 client] setACL: folderName rights: acls uid: uid]; + + [mailboxACL release]; + mailboxACL = nil; } - (NSString *) defaultUserID @@ -592,14 +620,20 @@ static BOOL useAltNamespace = NO; { SOGoUser *user; NSString *otherUsersPath, *url; + SOGoMailAccount *thisAccount; + NSDictionary *mailAccount; user = [SOGoUser userWithLogin: uid roles: nil]; otherUsersPath = [self otherUsersPathToFolder]; if (otherUsersPath) - url = [NSString stringWithFormat: @"%@/%@%@", - [self soURLToBaseContainerForUser: uid], - [user primaryIMAP4AccountString], - otherUsersPath]; + { + thisAccount = [self mailAccountFolder]; + mailAccount = [[user mailAccounts] objectAtIndex: 0]; + url = [NSString stringWithFormat: @"%@/%@%@", + [self soURLToBaseContainerForUser: uid], + [mailAccount objectForKey: @"name"], + otherUsersPath]; + } else url = nil;