From 4b7785fcf7c8cfb1d290375b530efb1965328925 Mon Sep 17 00:00:00 2001 From: Wolfgang Sourdeau Date: Thu, 7 Feb 2008 23:09:12 +0000 Subject: [PATCH] Monotone-Parent: 998f8668c2a6175352cb3f2d659db5aa04b0fa39 Monotone-Revision: eb80137abbc0c0a426a654921250804b1c3d92ab Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2008-02-07T23:09:12 Monotone-Branch: ca.inverse.sogo --- ChangeLog | 7 +++++++ SoObjects/Mailer/SOGoMailAccount.m | 26 ++++++++++++++++++++++++-- SoObjects/Mailer/SOGoMailAccounts.m | 1 - SoObjects/SOGo/SOGoUser.h | 1 + SoObjects/SOGo/SOGoUser.m | 25 ++++++++++++++++++++----- 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 001304afe..84bb66280 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,15 @@ 2008-02-07 Wolfgang Sourdeau + * SoObjects/Mailer/SOGoMailAccount.m ([SOGoMailAccount + -imap4URLString]): compose the mail hostname part of the url by + escaping the username. This is part of the fix below. + * SoObjects/SOGo/SOGoUser.m ([SOGoUser -mailAccounts]): if the loginname for the default mail account contains an "@", it should be url-escaped to avoid confusing NSURL. + ([SOGoUser -accountWithName:accountName]): new method that wanders + the accounts list and returns the one that matches the name passed + as parameter, if found. * SoObjects/SOGo/SOGoUserFolder.m ([-login]): removed useless method. diff --git a/SoObjects/Mailer/SOGoMailAccount.m b/SoObjects/Mailer/SOGoMailAccount.m index 4a64431b4..7270874e5 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -28,8 +28,9 @@ #import #import #import -#import #import +#import +#import #import #import #import @@ -245,6 +246,27 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default return [creds objectAtIndex:0]; /* the user */ } +- (NSString *) _urlHostString +{ + NSDictionary *mailAccount; + NSString *username, *escUsername, *hostString; + + mailAccount = [[context activeUser] accountWithName: nameInContainer]; + if (mailAccount) + { + username = [mailAccount objectForKey: @"userName"]; + escUsername + = [[username stringByReplacingString: @"@" withString: @"%40"] + stringByEscapingURL]; + hostString = [NSString stringWithFormat: @"%@@%@", escUsername, + [mailAccount objectForKey: @"serverName"]]; + } + else + hostString = @"localhost"; + + return hostString; +} + - (NSMutableString *) imap4URLString { /* private, overridden by SOGoSharedMailAccount */ @@ -258,7 +280,7 @@ static NSString *otherUsersFolderName = @""; // TODO: add English default else [urlString appendString: @"imap://"]; - host = [self nameInContainer]; + host = [self _urlHostString]; if (![host rangeOfString: @"@"].length) [urlString appendFormat: @"%@@", [self imap4LoginFromHTTP]]; [urlString appendFormat: @"%@/", host]; diff --git a/SoObjects/Mailer/SOGoMailAccounts.m b/SoObjects/Mailer/SOGoMailAccounts.m index 8a2cde7be..cf498cf32 100644 --- a/SoObjects/Mailer/SOGoMailAccounts.m +++ b/SoObjects/Mailer/SOGoMailAccounts.m @@ -95,7 +95,6 @@ // return [NSException exceptionWithHTTPStatus:403 /* Forbidden */ // reason:@"Tried to access the mail of another user"]; // } - /* first check attributes directly bound to the application */ obj = [super lookupName:_key inContext:_ctx acquire:NO]; diff --git a/SoObjects/SOGo/SOGoUser.h b/SoObjects/SOGo/SOGoUser.h index 1c580e57a..03c067cea 100644 --- a/SoObjects/SOGo/SOGoUser.h +++ b/SoObjects/SOGo/SOGoUser.h @@ -118,6 +118,7 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (NSTimeZone *) serverTimeZone; - (NSArray *) mailAccounts; +- (NSDictionary *) accountWithName: (NSString *) accountName; - (NSArray *) allIdentities; - (NSDictionary *) primaryIdentity; - (NSMutableDictionary *) defaultIdentity; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index a9ec7d78a..89d6b7f0e 100644 --- a/SoObjects/SOGo/SOGoUser.m +++ b/SoObjects/SOGo/SOGoUser.m @@ -454,16 +454,14 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; { NSMutableDictionary *mailAccount, *identity; NSMutableArray *identities; - NSString *name, *fullName, *userName; + NSString *name, *fullName; NSArray *mails; unsigned int count, max; mailAccount = [NSMutableDictionary dictionary]; - userName = [[login stringByReplacingString: @"@" withString: @"%40"] - stringByEscapingURL]; name = [NSString stringWithFormat: @"%@@%@", - userName, fallbackIMAP4Server]; - [mailAccount setObject: userName forKey: @"userName"]; + login, fallbackIMAP4Server]; + [mailAccount setObject: login forKey: @"userName"]; [mailAccount setObject: fallbackIMAP4Server forKey: @"serverName"]; [mailAccount setObject: name forKey: @"name"]; @@ -509,6 +507,23 @@ NSString *SOGoWeekStartFirstFullWeek = @"FirstFullWeek"; return mailAccounts; } +- (NSDictionary *) accountWithName: (NSString *) accountName; +{ + NSEnumerator *accounts; + NSDictionary *mailAccount, *currentAccount; + + mailAccount = nil; + + accounts = [[self mailAccounts] objectEnumerator]; + while (!mailAccount + && ((currentAccount = [accounts nextObject]))) + if ([[currentAccount objectForKey: @"name"] + isEqualToString: accountName]) + mailAccount = currentAccount; + + return mailAccount; +} + /* @interface SOGoMailIdentity : NSObject {