diff --git a/ChangeLog b/ChangeLog index f045b5f81..730df92d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2011-01-05 Ludovic Marcotte + + * SoObjects/SOGo/SQLSource.m - we now honor the "mail" column + and we also support "MailFieldNames" in the SQL source - which + is essentially and array of column names holding additonnal email + addresses of users (beside the "mail" column). Also updated + the documentation to reflect this change. + 2011-01-05 Francis Lachapelle * UI/WebServerResources/SOGoAutoCompletion.js (onKeydown): added diff --git a/Documentation/SOGo Installation Guide.odt b/Documentation/SOGo Installation Guide.odt index 892f28eba..33dd8729b 100644 Binary files a/Documentation/SOGo Installation Guide.odt and b/Documentation/SOGo Installation Guide.odt differ diff --git a/SoObjects/SOGo/SQLSource.h b/SoObjects/SOGo/SQLSource.h index 8d08a1fdc..18900cf5b 100644 --- a/SoObjects/SOGo/SQLSource.h +++ b/SoObjects/SOGo/SQLSource.h @@ -1,6 +1,6 @@ /* SQLSource.h - this file is part of SOGo * - * Copyright (C) 2009-2010 Inverse inc. + * Copyright (C) 2009-2011 Inverse inc. * * Author: Ludovic Marcotte * diff --git a/SoObjects/SOGo/SQLSource.m b/SoObjects/SOGo/SQLSource.m index 1ddf7e63e..cf6fa785a 100644 --- a/SoObjects/SOGo/SQLSource.m +++ b/SoObjects/SOGo/SQLSource.m @@ -1,6 +1,6 @@ /* SQLSource.h - this file is part of SOGo * - * Copyright (C) 2009-2010 Inverse inc. + * Copyright (C) 2009-2011 Inverse inc. * * Author: Ludovic Marcotte * @@ -220,6 +220,26 @@ return NO; } +- (NSString *) _whereClauseFromArray: (NSArray *) theArray + value: (NSString *) theValue + exact: (BOOL) theBOOL +{ + NSMutableString *s; + int i; + + s = [NSMutableString string]; + + for (i = 0; i < [theArray count]; i++) + { + if (theBOOL) + [s appendFormat: @" OR LOWER(%@) = '%@'", [theArray objectAtIndex: i], theValue]; + else + [s appendFormat: @" OR LOWER(%@) LIKE '%%%@%%'", [theArray objectAtIndex: i], theValue]; + } + + return s; +} + - (NSDictionary *) _lookupContactEntry: (NSString *) theID considerEmail: (BOOL) b { @@ -242,15 +262,24 @@ @" WHERE c_uid = '%@'"), [_viewURL gcsTableName], theID]; else - sql = [NSString stringWithFormat: (@"SELECT *" - @" FROM %@" - @" WHERE c_uid = '%@' OR" - @" LOWER(mail) = '%@'"), - [_viewURL gcsTableName], theID, [theID lowercaseString]]; - + { + sql = [NSString stringWithFormat: (@"SELECT *" + @" FROM %@" + @" WHERE c_uid = '%@' OR" + @" LOWER(mail) = '%@'"), + [_viewURL gcsTableName], theID, [theID lowercaseString]]; + + if (_mailFields && [_mailFields count] > 0) + { + sql = [sql stringByAppendingString: [self _whereClauseFromArray: _mailFields value: [theID lowercaseString] exact: YES]]; + } + } + ex = [channel evaluateExpressionX: sql]; if (!ex) { + NSMutableArray *emails; + response = [[channel fetchAttributes: [channel describeResults: NO] withZone: NULL] mutableCopy]; [response autorelease]; @@ -260,6 +289,24 @@ // constraints right now over a SQL backend. [response setObject: [NSNumber numberWithBool: YES] forKey: @"CalendarAccess"]; [response setObject: [NSNumber numberWithBool: YES] forKey: @"MailAccess"]; + + // We populate all mail fields + emails = [NSMutableArray array]; + + if ([response objectForKey: @"mail"]) + [emails addObject: [response objectForKey: @"mail"]]; + + if (_mailFields && [_mailFields count] > 0) + { + NSString *s; + int i; + + for (i = 0; i < [_mailFields count]; i++) + if ((s = [response objectForKey: [_mailFields objectAtIndex: i]])) + [emails addObject: s]; + } + + [response setObject: emails forKey: @"c_emails"]; } else [self errorWithFormat: @"could not run SQL '%@': %@", sql, ex]; @@ -352,6 +399,11 @@ [_viewURL gcsTableName], lowerFilter, lowerFilter]; + if (_mailFields && [_mailFields count] > 0) + { + sql = [sql stringByAppendingString: [self _whereClauseFromArray: _mailFields value: lowerFilter exact: NO]]; + } + ex = [channel evaluateExpressionX: sql]; if (!ex) {