oc: Fix internal EntryIds properties on multidomain

PidTag*EntryId properties were not being generated (which contain
the email address and so on). Functionality on Outlook clients like
"Reply All" were not working because of this (probably a lot more
stuff related with email addresses).

With multidomain support enabled outlook clients will use full email
address (e.g. user@domain.com) as login.

This change is needed because we were performing ldap queries on samdb
using (sAMAccountName=UIDFieldName), being UIDFieldName the parameter
configured in sogo.conf for that source. In multidomain environment
this field could be `sAMAccountName` but it could not. Actually the
more logical scenario will be to use `uid` field here (which will be
just `user`, without the `@domain.com` part).

SOGoUserManager will return `sAMAccountName` if the contact has it
(in Outlook environment that means always) so it can (and must) be
used to query samdb in MAPIStoreSamDBUtils properly.

TL;DR: use sAMAccoutName instead of uid to query samdb
pull/79/head^2
Jesús García Sáez 2015-04-15 18:52:55 +02:00
parent a8e8ec535a
commit 0f432b654f
5 changed files with 49 additions and 42 deletions

View File

@ -264,7 +264,7 @@ static NSCharacterSet *hexCharacterSet = nil;
if (contactInfos) if (contactInfos)
{ {
username = [contactInfos objectForKey: @"c_uid"]; username = [contactInfos objectForKey: @"sAMAccountName"];
recipient->username = [username asUnicodeInMemCtx: msgData]; recipient->username = [username asUnicodeInMemCtx: msgData];
entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username); entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username);
} }
@ -365,7 +365,7 @@ static NSCharacterSet *hexCharacterSet = nil;
if (contactInfos) if (contactInfos)
{ {
username = [contactInfos objectForKey: @"c_uid"]; username = [contactInfos objectForKey: @"sAMAccountName"];
recipient->username = [username asUnicodeInMemCtx: msgData]; recipient->username = [username asUnicodeInMemCtx: msgData];
entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username); entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username);
} }
@ -931,7 +931,7 @@ static NSCharacterSet *hexCharacterSet = nil;
contactInfos = [mgr contactInfosForUserWithUIDorEmail: email]; contactInfos = [mgr contactInfosForUserWithUIDorEmail: email];
if (contactInfos) if (contactInfos)
{ {
username = [contactInfos objectForKey: @"c_uid"]; username = [contactInfos objectForKey: @"sAMAccountName"];
entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username); entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username);
} }
else else

View File

@ -803,7 +803,7 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data)
contactInfos = [mgr contactInfosForUserWithUIDorEmail: email]; contactInfos = [mgr contactInfosForUserWithUIDorEmail: email];
if (contactInfos) if (contactInfos)
{ {
username = [contactInfos objectForKey: @"c_uid"]; username = [contactInfos objectForKey: @"sAMAccountName"];
samCtx = [[self context] connectionInfo]->sam_ctx; samCtx = [[self context] connectionInfo]->sam_ctx;
entryId = MAPIStoreInternalEntryId (samCtx, username); entryId = MAPIStoreInternalEntryId (samCtx, username);
} }
@ -1501,10 +1501,10 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data)
if ([cn length] == 0) if ([cn length] == 0)
cn = email; cn = email;
contactInfos = [mgr contactInfosForUserWithUIDorEmail: email]; contactInfos = [mgr contactInfosForUserWithUIDorEmail: email];
if (contactInfos) if (contactInfos)
{ {
username = [contactInfos objectForKey: @"c_uid"]; username = [contactInfos objectForKey: @"sAMAccountName"];
recipient->username = [username asUnicodeInMemCtx: msgData]; recipient->username = [username asUnicodeInMemCtx: msgData];
entryId = MAPIStoreInternalEntryId (samCtx, username); entryId = MAPIStoreInternalEntryId (samCtx, username);
} }

View File

@ -386,7 +386,7 @@ static NSString *recTypes[] = { @"orig", @"to", @"cc", @"bcc" };
contactInfos = [mgr contactInfosForUserWithUIDorEmail: email]; contactInfos = [mgr contactInfosForUserWithUIDorEmail: email];
if (contactInfos) if (contactInfos)
{ {
username = [contactInfos objectForKey: @"c_uid"]; username = [contactInfos objectForKey: @"sAMAccountName"];
recipient->username = [username asUnicodeInMemCtx: msgData]; recipient->username = [username asUnicodeInMemCtx: msgData];
entryId = MAPIStoreInternalEntryId (samCtx, username); entryId = MAPIStoreInternalEntryId (samCtx, username);
} }

View File

@ -96,8 +96,11 @@ MAPIStoreInternalEntryId (struct ldb_context *samCtx, NSString *username)
[entryId appendUInt8: 0]; // end of string [entryId appendUInt8: 0]; // end of string
} }
else else
entryId = nil; {
NSLog (@"Error trying to generate EntryId for `%@`", username);
entryId = nil;
}
return entryId; return entryId;
} }

View File

@ -664,7 +664,7 @@ static Class NSNullK;
// //
// //
- (void) _fillContactInfosForUser: (NSMutableDictionary *) currentUser - (void) _fillContactInfosForUser: (NSMutableDictionary *) currentUser
withUIDorEmail: (NSString *) uid withUIDorEmail: (NSString *) uid
inDomain: (NSString *) domain inDomain: (NSString *) domain
{ {
NSString *sourceID, *cn, *c_domain, *c_uid, *c_imaphostname, *c_imaplogin, *c_sievehostname; NSString *sourceID, *cn, *c_domain, *c_uid, *c_imaphostname, *c_imaplogin, *c_sievehostname;
@ -685,12 +685,11 @@ static Class NSNullK;
c_sievehostname = nil; c_sievehostname = nil;
[currentUser setObject: [NSNumber numberWithBool: YES] [currentUser setObject: [NSNumber numberWithBool: YES]
forKey: @"CalendarAccess"]; forKey: @"CalendarAccess"];
[currentUser setObject: [NSNumber numberWithBool: YES] [currentUser setObject: [NSNumber numberWithBool: YES]
forKey: @"MailAccess"]; forKey: @"MailAccess"];
sogoSources = [[self authenticationSourceIDsInDomain: domain] sogoSources = [[self authenticationSourceIDsInDomain: domain] objectEnumerator];
objectEnumerator];
userEntry = nil; userEntry = nil;
while (!userEntry && (sourceID = [sogoSources nextObject])) while (!userEntry && (sourceID = [sogoSources nextObject]))
{ {
@ -698,44 +697,49 @@ static Class NSNullK;
userEntry = [currentSource lookupContactEntryWithUIDorEmail: uid userEntry = [currentSource lookupContactEntryWithUIDorEmail: uid
inDomain: domain]; inDomain: domain];
if (userEntry) if (userEntry)
{ {
[currentUser setObject: sourceID forKey: @"SOGoSource"]; [currentUser setObject: sourceID forKey: @"SOGoSource"];
if (!cn) if (!cn)
cn = [userEntry objectForKey: @"c_cn"]; cn = [userEntry objectForKey: @"c_cn"];
if (!c_uid) if (!c_uid)
c_uid = [userEntry objectForKey: @"c_uid"]; c_uid = [userEntry objectForKey: @"c_uid"];
if (!c_domain) if (!c_domain)
c_domain = [userEntry objectForKey: @"c_domain"]; c_domain = [userEntry objectForKey: @"c_domain"];
c_emails = [userEntry objectForKey: @"c_emails"]; c_emails = [userEntry objectForKey: @"c_emails"];
if ([c_emails count]) if ([c_emails count])
[emails addObjectsFromArray: c_emails]; [emails addObjectsFromArray: c_emails];
if (!c_imaphostname) if (!c_imaphostname)
c_imaphostname = [userEntry objectForKey: @"c_imaphostname"]; c_imaphostname = [userEntry objectForKey: @"c_imaphostname"];
if (!c_imaplogin) if (!c_imaplogin)
c_imaplogin = [userEntry objectForKey: @"c_imaplogin"]; c_imaplogin = [userEntry objectForKey: @"c_imaplogin"];
if (!c_sievehostname) if (!c_sievehostname)
c_sievehostname = [userEntry objectForKey: @"c_sievehostname"]; c_sievehostname = [userEntry objectForKey: @"c_sievehostname"];
access = [[userEntry objectForKey: @"CalendarAccess"] boolValue]; access = [[userEntry objectForKey: @"CalendarAccess"] boolValue];
if (!access) if (!access)
[currentUser setObject: [NSNumber numberWithBool: NO] [currentUser setObject: [NSNumber numberWithBool: NO]
forKey: @"CalendarAccess"]; forKey: @"CalendarAccess"];
access = [[userEntry objectForKey: @"MailAccess"] boolValue]; access = [[userEntry objectForKey: @"MailAccess"] boolValue];
if (!access) if (!access)
[currentUser setObject: [NSNumber numberWithBool: NO] [currentUser setObject: [NSNumber numberWithBool: NO]
forKey: @"MailAccess"]; forKey: @"MailAccess"];
// We check if it's a group // We check if it's a group
isGroup = [userEntry objectForKey: @"isGroup"]; isGroup = [userEntry objectForKey: @"isGroup"];
if (isGroup) if (isGroup)
[currentUser setObject: isGroup forKey: @"isGroup"]; [currentUser setObject: isGroup forKey: @"isGroup"];
// We also fill the resource attributes, if any // We also fill the resource attributes, if any
if ([userEntry objectForKey: @"isResource"]) if ([userEntry objectForKey: @"isResource"])
[currentUser setObject: [userEntry objectForKey: @"isResource"] [currentUser setObject: [userEntry objectForKey: @"isResource"]
forKey: @"isResource"]; forKey: @"isResource"];
if ([userEntry objectForKey: @"numberOfSimultaneousBookings"]) if ([userEntry objectForKey: @"numberOfSimultaneousBookings"])
[currentUser setObject: [userEntry objectForKey: @"numberOfSimultaneousBookings"] [currentUser setObject: [userEntry objectForKey: @"numberOfSimultaneousBookings"]
forKey: @"numberOfSimultaneousBookings"]; forKey: @"numberOfSimultaneousBookings"];
// This is Active Directory specific attribute (needed on OpenChange/* layer)
if ([userEntry objectForKey: @"samaccountname"])
[currentUser setObject: [userEntry objectForKey: @"samaccountname"]
forKey: @"sAMAccountName"];
} }
} }
@ -745,7 +749,7 @@ static Class NSNullK;
c_uid = @""; c_uid = @"";
if (!c_domain) if (!c_domain)
c_domain = @""; c_domain = @"";
if (c_imaphostname) if (c_imaphostname)
[currentUser setObject: c_imaphostname forKey: @"c_imaphostname"]; [currentUser setObject: c_imaphostname forKey: @"c_imaphostname"];
if (c_imaplogin) if (c_imaplogin)