From 6be64211f5e9efea67cfbb102c09e19e9442e515 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Tue, 5 Jun 2007 14:59:30 +0000 Subject: [PATCH] Monotone-Parent: e4a4a2d80e8cd1af24e0b3ca0dbfbb60f72d55f1 Monotone-Revision: 5f3c62eeb6192df923fff5368021fbf700189341 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2007-06-05T14:59:30 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 11 +++++ SoObjects/Mailer/SOGoMailFolder.m | 76 ++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0a9ea4df2..571e4010b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-06-05 Wolfgang Sourdeau + + * SoObjects/Mailer/SOGoMailFolder.m ([SOGoMailFolder + -_adjustOwner]): sharedFolderName and otherUsersFolderName may be + nil, in which case a crash happens when calling hasPrefix:. + ([SOGoMailFolder -_sharesACLs]): same as above. + ([SOGoMailFolder -otherUsersPathToFolder]): same as above. If + otherUsersFolderName is nil, we return nil. + ([SOGoMailFolder -httpURLForAdvisoryToUser:uid]): if we receive + nil from [self otherUsersPathToFolder], we return nil too. + 2007-06-01 Wolfgang Sourdeau * SoObjects/SOGo/SOGoObject.m ([SOGoObject diff --git a/SoObjects/Mailer/SOGoMailFolder.m b/SoObjects/Mailer/SOGoMailFolder.m index d79cb68d6..bfc6e747c 100644 --- a/SoObjects/Mailer/SOGoMailFolder.m +++ b/SoObjects/Mailer/SOGoMailFolder.m @@ -65,21 +65,26 @@ static BOOL useAltNamespace = NO; - (void) _adjustOwner { SOGoMailAccount *mailAccount; - NSString *path; + NSString *path, *folder; NSArray *names; mailAccount = [self mailAccountFolder]; path = [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]]; - if ([path hasPrefix: [mailAccount sharedFolderName]]) - owner = @"anyone"; - else if ([path hasPrefix: [mailAccount otherUsersFolderName]]) + folder = [mailAccount sharedFolderName]; + if (folder && [path hasPrefix: folder]) + [self setOwner: @"anyone"]; + else { - names = [path componentsSeparatedByString: @"/"]; - if ([names count] > 1) - owner = [names objectAtIndex: 1]; - else - owner = @"anyone"; + folder = [mailAccount otherUsersFolderName]; + if (folder && [path hasPrefix: folder]) + { + names = [path componentsSeparatedByString: @"/"]; + if ([names count] > 1) + [self setOwner: [names objectAtIndex: 1]]; + else + [self setOwner: @"anyone"]; + } } } @@ -525,23 +530,28 @@ static BOOL useAltNamespace = NO; { NSMutableArray *acls; SOGoMailAccount *mailAccount; - NSString *path; - NSArray *names; + NSString *path, *folder; +// NSArray *names; unsigned int count; acls = [NSMutableArray array]; mailAccount = [self mailAccountFolder]; path = [[self imap4Connection] imap4FolderNameForURL: [self imap4URL]]; - names = [path componentsSeparatedByString: @"/"]; +// names = [path componentsSeparatedByString: @"/"]; count = [names count]; - if ([path hasPrefix: [mailAccount sharedFolderName]]) - [acls addObject: SOGoRole_ObjectViewer]; - else if ([path hasPrefix: [mailAccount otherUsersFolderName]]) + folder = [mailAccount sharedFolderName]; + if (folder && [path hasPrefix: folder]) [acls addObject: SOGoRole_ObjectViewer]; else - [acls addObject: SoRole_Owner]; + { + folder = [mailAccount otherUsersFolderName]; + if (folder && [path hasPrefix: folder]) + [acls addObject: SOGoRole_ObjectViewer]; + else + [acls addObject: SoRole_Owner]; + } return acls; } @@ -610,14 +620,22 @@ static BOOL useAltNamespace = NO; sharedFolders = [account sharedFolderName]; selfPath = [[self imap4URL] path]; - if ([selfPath hasPrefix: [NSString stringWithFormat: @"/%@", otherUsers]] - || [selfPath hasPrefix: - [NSString stringWithFormat: @"/%@", sharedFolders]]) + if ((otherUsers + && [selfPath hasPrefix: + [NSString stringWithFormat: @"/%@", otherUsers]]) + || (sharedFolders + && [selfPath hasPrefix: + [NSString stringWithFormat: @"/%@", sharedFolders]])) userPath = selfPath; else - userPath = [NSString stringWithFormat: @"/%@/%@%@", - [otherUsers stringByEscapingURL], - owner, selfPath]; + { + if (otherUsers) + userPath = [NSString stringWithFormat: @"/%@/%@%@", + [otherUsers stringByEscapingURL], + owner, selfPath]; + else + userPath = nil; + } return userPath; } @@ -625,13 +643,19 @@ static BOOL useAltNamespace = NO; - (NSString *) httpURLForAdvisoryToUser: (NSString *) uid; { SOGoUser *user; + NSString *otherUsersPath, *url; user = [SOGoUser userWithLogin: uid roles: nil]; + otherUsersPath = [self otherUsersPathToFolder]; + if (otherUsersPath) + url = [NSString stringWithFormat: @"%@/%@%@", + [self soURLToBaseContainerForUser: uid], + [user primaryIMAP4AccountString], + otherUsersPath]; + else + url = nil; - return [NSString stringWithFormat: @"%@/%@%@", - [self soURLToBaseContainerForUser: uid], - [user primaryIMAP4AccountString], - [self otherUsersPathToFolder]]; + return url; } - (NSString *) resourceURLForAdvisoryToUser: (NSString *) uid;