From abfda48769449cbe0a5149cf0e127296ec09dfdb Mon Sep 17 00:00:00 2001 From: wolfgang Date: Thu, 7 Feb 2008 22:21:14 +0000 Subject: [PATCH] git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1361 d1b88da0-ebda-0310-925b-ed51d893ca5b --- ChangeLog | 3 +++ SoObjects/Mailer/SOGoMailAccount.m | 23 ++++++++++++++++++++++- SoObjects/Mailer/SOGoMailAccounts.m | 1 - SoObjects/SOGo/SOGoUser.h | 1 + SoObjects/SOGo/SOGoUser.m | 25 ++++++++++++++++++++----- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 001304af..e17a8e43 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,9 @@ * 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 4a64431b..69cefa26 100644 --- a/SoObjects/Mailer/SOGoMailAccount.m +++ b/SoObjects/Mailer/SOGoMailAccount.m @@ -245,6 +245,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 +279,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 8a2cde7b..cf498cf3 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 1c580e57..6a5e89c6 100644 --- a/SoObjects/SOGo/SOGoUser.h +++ b/SoObjects/SOGo/SOGoUser.h @@ -118,6 +118,7 @@ extern NSString *SOGoWeekStartFirstFullWeek; - (NSTimeZone *) serverTimeZone; - (NSArray *) mailAccounts; +- (NSDictinary *) accountWithName: (NSString *) accountName; - (NSArray *) allIdentities; - (NSDictionary *) primaryIdentity; - (NSMutableDictionary *) defaultIdentity; diff --git a/SoObjects/SOGo/SOGoUser.m b/SoObjects/SOGo/SOGoUser.m index a9ec7d78..b94e7188 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; } +- (NSDictinary *) accountWithName: (NSString *) accountName +{ + NSEnumerator *accounts; + NSDictionary *mailAccount, *currentAccount; + + mailAccount = nil; + + accounts = [[self mailAccounts] objectEnumerator]; + while (!mailAccount + && ((currentAccount = [accounts nextObject]))) + if ([[currentAccount objectForKey: @"name"] + isEqualToString: nameInContainer]) + mailAccount = currentAccount; + + return mailAccount; +} + /* @interface SOGoMailIdentity : NSObject { -- 2.39.5