diff --git a/ChangeLog b/ChangeLog index 1f0ab2025..9410748b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2011-11-17 Wolfgang Sourdeau + + * OpenChange/MAPIStoreMessage.m (MAPIStoreInternalEntryId): now + takes a ldb_context * parameter pointing to the samdb, which + enables us: 1) to return the real legacyExchangeDN 2) to make use + of sAMAccountName as search parameter for the username. + 2011-11-16 Ludovic Marcotte * SoObjects/SOGo/SOGoSieveManager.m (-updateFiltersForLogin:...) diff --git a/OpenChange/MAPIStoreAppointmentWrapper.h b/OpenChange/MAPIStoreAppointmentWrapper.h index 4fcf2b4d8..fa1cb8f20 100644 --- a/OpenChange/MAPIStoreAppointmentWrapper.h +++ b/OpenChange/MAPIStoreAppointmentWrapper.h @@ -39,6 +39,7 @@ extern NSTimeZone *utcTZ; @interface MAPIStoreAppointmentWrapper : NSObject { + struct mapistore_connection_info *connInfo; iCalCalendar *calendar; iCalEvent *event; NSTimeZone *timeZone; @@ -56,11 +57,13 @@ extern NSTimeZone *utcTZ; + (id) wrapperWithICalEvent: (iCalEvent *) newEvent andUser: (SOGoUser *) newUser andSenderEmail: (NSString *) newSenderEmail - inTimeZone: (NSTimeZone *) newTimeZone; + inTimeZone: (NSTimeZone *) newTimeZone + withConnectionInfo: (struct mapistore_connection_info *) newConnInfo; - (id) initWithICalEvent: (iCalEvent *) newEvent andUser: (SOGoUser *) newUser andSenderEmail: (NSString *) newSenderEmail - inTimeZone: (NSTimeZone *) newTimeZone; + inTimeZone: (NSTimeZone *) newTimeZone + withConnectionInfo: (struct mapistore_connection_info *) newConnInfo; /* getters */ - (void) fillMessageData: (struct mapistore_message *) dataPtr diff --git a/OpenChange/MAPIStoreAppointmentWrapper.m b/OpenChange/MAPIStoreAppointmentWrapper.m index 82753c076..493c5b527 100644 --- a/OpenChange/MAPIStoreAppointmentWrapper.m +++ b/OpenChange/MAPIStoreAppointmentWrapper.m @@ -80,13 +80,15 @@ static NSCharacterSet *hexCharacterSet = nil; andUser: (SOGoUser *) newUser andSenderEmail: (NSString *) newSenderEmail inTimeZone: (NSTimeZone *) newTimeZone + withConnectionInfo: (struct mapistore_connection_info *) newConnInfo { MAPIStoreAppointmentWrapper *wrapper; wrapper = [[self alloc] initWithICalEvent: newEvent andUser: newUser andSenderEmail: newSenderEmail - inTimeZone: newTimeZone]; + inTimeZone: newTimeZone + withConnectionInfo: newConnInfo]; [wrapper autorelease]; return wrapper; @@ -96,6 +98,7 @@ static NSCharacterSet *hexCharacterSet = nil; { if ((self = [super init])) { + connInfo = NULL; calendar = nil; event = nil; timeZone = nil; @@ -178,9 +181,11 @@ static NSCharacterSet *hexCharacterSet = nil; andUser: (SOGoUser *) newUser andSenderEmail: (NSString *) newSenderEmail inTimeZone: (NSTimeZone *) newTimeZone + withConnectionInfo: (struct mapistore_connection_info *) newConnInfo { if ((self = [self init])) { + connInfo = newConnInfo; ASSIGN (event, newEvent); ASSIGN (calendar, [event parent]); ASSIGN (timeZone, newTimeZone); @@ -256,7 +261,7 @@ static NSCharacterSet *hexCharacterSet = nil; { username = [contactInfos objectForKey: @"c_uid"]; recipient->username = [username asUnicodeInMemCtx: msgData]; - entryId = MAPIStoreInternalEntryId (username); + entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username); } else { @@ -357,7 +362,7 @@ static NSCharacterSet *hexCharacterSet = nil; { username = [contactInfos objectForKey: @"c_uid"]; recipient->username = [username asUnicodeInMemCtx: msgData]; - entryId = MAPIStoreInternalEntryId (username); + entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username); } else { @@ -727,7 +732,7 @@ static NSCharacterSet *hexCharacterSet = nil; if (contactInfos) { username = [contactInfos objectForKey: @"c_uid"]; - entryId = MAPIStoreInternalEntryId (username); + entryId = MAPIStoreInternalEntryId (connInfo->sam_ctx, username); } else entryId = MAPIStoreExternalEntryId (cn, email); diff --git a/OpenChange/MAPIStoreCalendarMessage.m b/OpenChange/MAPIStoreCalendarMessage.m index 33b7ffe9d..73729cc66 100644 --- a/OpenChange/MAPIStoreCalendarMessage.m +++ b/OpenChange/MAPIStoreCalendarMessage.m @@ -104,15 +104,18 @@ - (MAPIStoreAppointmentWrapper *) appointmentWrapper { iCalEvent *event; + MAPIStoreContext *context; if (!appointmentWrapper) { event = [sogoObject component: NO secure: NO]; + context = [self context]; ASSIGN (appointmentWrapper, [MAPIStoreAppointmentWrapper wrapperWithICalEvent: event - andUser: [[self context] activeUser] + andUser: [context activeUser] andSenderEmail: nil - inTimeZone: [self ownerTimeZone]]); + inTimeZone: [self ownerTimeZone] + withConnectionInfo: [context connectionInfo]]); } return appointmentWrapper; diff --git a/OpenChange/MAPIStoreMailMessage.m b/OpenChange/MAPIStoreMailMessage.m index 7ab44bd2b..6c148f5b1 100644 --- a/OpenChange/MAPIStoreMailMessage.m +++ b/OpenChange/MAPIStoreMailMessage.m @@ -263,6 +263,7 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) iCalCalendar *calendar; iCalEvent *event; NSString *stringValue, *senderEmail; + MAPIStoreContext *context; if (!appointmentWrapper) { @@ -280,11 +281,13 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) senderEmail = [[from objectAtIndex: 0] email]; else senderEmail = nil; + context = [self context]; appointmentWrapper = [MAPIStoreAppointmentWrapper wrapperWithICalEvent: event - andUser: [[self context] activeUser] + andUser: [context activeUser] andSenderEmail: senderEmail - inTimeZone: [self ownerTimeZone]]; + inTimeZone: [self ownerTimeZone] + withConnectionInfo: [context connectionInfo]]; [appointmentWrapper retain]; } } @@ -721,6 +724,7 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) NSDictionary *contactInfos; NGMailAddress *ngAddress; NSData *entryId; + struct ldb_context *samCtx; int rc; if (fullMail) @@ -743,7 +747,8 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) if (contactInfos) { username = [contactInfos objectForKey: @"c_uid"]; - entryId = MAPIStoreInternalEntryId (username); + samCtx = [[self context] connectionInfo]->sam_ctx; + entryId = MAPIStoreInternalEntryId (samCtx, username); } else entryId = MAPIStoreExternalEntryId (cn, email); @@ -1349,9 +1354,11 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) NSData *entryId; NSDictionary *contactInfos; SOGoUserManager *mgr; + struct ldb_context *samCtx; struct mapistore_message *msgData; struct mapistore_message_recipient *recipient; + samCtx = [[self context] connectionInfo]->sam_ctx; [super getMessageData: &msgData inMemCtx: memCtx]; if (!headerSetup) @@ -1397,7 +1404,7 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) { username = [contactInfos objectForKey: @"c_uid"]; recipient->username = [username asUnicodeInMemCtx: msgData]; - entryId = MAPIStoreInternalEntryId (username); + entryId = MAPIStoreInternalEntryId (samCtx, username); } else { diff --git a/OpenChange/MAPIStoreMailVolatileMessage.m b/OpenChange/MAPIStoreMailVolatileMessage.m index bc62b181a..b23eefd6d 100644 --- a/OpenChange/MAPIStoreMailVolatileMessage.m +++ b/OpenChange/MAPIStoreMailVolatileMessage.m @@ -249,10 +249,13 @@ static NSString *recTypes[] = { @"orig", @"to", @"cc", @"bcc" }; NSData *entryId; NSDictionary *allRecipients, *dict, *contactInfos; SOGoUserManager *mgr; + struct ldb_context *samCtx; struct mapistore_message *msgData; struct mapistore_message_recipient *recipient; enum ulRecipClass type; + samCtx = [[self context] connectionInfo]->sam_ctx; + [super getMessageData: &msgData inMemCtx: memCtx]; allRecipients = [[sogoObject properties] objectForKey: @"recipients"]; @@ -295,7 +298,7 @@ static NSString *recTypes[] = { @"orig", @"to", @"cc", @"bcc" }; { username = [contactInfos objectForKey: @"c_uid"]; recipient->username = [username asUnicodeInMemCtx: msgData]; - entryId = MAPIStoreInternalEntryId (username); + entryId = MAPIStoreInternalEntryId (samCtx, username); } else { diff --git a/OpenChange/MAPIStoreMessage.h b/OpenChange/MAPIStoreMessage.h index 85c3d2d9b..9270fb973 100644 --- a/OpenChange/MAPIStoreMessage.h +++ b/OpenChange/MAPIStoreMessage.h @@ -35,9 +35,11 @@ @class MAPIStoreAttachmentTable; @class MAPIStoreFolder; +struct ldb_context; + #import "MAPIStoreObject.h" -extern NSData *MAPIStoreInternalEntryId (NSString *username); +extern NSData *MAPIStoreInternalEntryId (struct ldb_context *, NSString *username); extern NSData *MAPIStoreExternalEntryId (NSString *cn, NSString *email); @interface MAPIStoreMessage : MAPIStoreObject diff --git a/OpenChange/MAPIStoreMessage.m b/OpenChange/MAPIStoreMessage.m index 6c912c6e3..b5c9d3fe7 100644 --- a/OpenChange/MAPIStoreMessage.m +++ b/OpenChange/MAPIStoreMessage.m @@ -55,14 +55,18 @@ static NSString *resourcesDir = nil; NSData * -MAPIStoreInternalEntryId (NSString *username) +MAPIStoreInternalEntryId (struct ldb_context *samCtx, NSString *username) { - NSMutableData *entryId; - static uint8_t providerUid[] = { 0xdc, 0xa7, 0x40, 0xc8, - 0xc0, 0x42, 0x10, 0x1a, - 0xb4, 0xb9, 0x08, 0x00, - 0x2b, 0x2f, 0xe1, 0x82 }; - NSString *x500dn; + NSMutableData *entryId = nil; + TALLOC_CTX *memCtx; + struct ldb_result *res = NULL; + const char * const attrs[] = { "legacyExchangeDN", NULL }; + const char *legacyDn; + int ret; + static const uint8_t const providerUid[] = { 0xdc, 0xa7, 0x40, 0xc8, + 0xc0, 0x42, 0x10, 0x1a, + 0xb4, 0xb9, 0x08, 0x00, + 0x2b, 0x2f, 0xe1, 0x82 }; /* structure: flags: 32 @@ -71,20 +75,28 @@ MAPIStoreInternalEntryId (NSString *username) type: 32 X500DN: variable */ - entryId = [NSMutableData dataWithCapacity: 256]; - [entryId appendUInt32: 0]; // flags - [entryId appendBytes: providerUid length: 16]; // provideruid - [entryId appendUInt32: 1]; // version - [entryId appendUInt32: 0]; // type (local mail user) + memCtx = talloc_zero(NULL, TALLOC_CTX); - /* X500DN */ - /* FIXME: the DN will likely work on DEMO installations for now but we - really should get the dn prefix from the server */ - x500dn = [NSString stringWithFormat: @"/O=FIRST ORGANIZATION" - @"/OU=FIRST ADMINISTRATIVE GROUP" - @"/CN=RECIPIENTS/CN=%@", username]; - [entryId appendData: [x500dn dataUsingEncoding: NSISOLatin1StringEncoding]]; - [entryId appendUInt8: 0]; + /* Search mapistoreURI given partial URI */ + ret = ldb_search (samCtx, memCtx, &res, ldb_get_default_basedn(samCtx), + LDB_SCOPE_SUBTREE, attrs, + "(&(objectClass=user)(sAMAccountName=%s))", + [username UTF8String]); + if (ret == LDB_SUCCESS && res->count == 1) + { + legacyDn = ldb_msg_find_attr_as_string (res->msgs[0], attrs[0], NULL); + if (legacyDn) + { + entryId = [NSMutableData dataWithCapacity: 256]; + [entryId appendUInt32: 0]; // flags + [entryId appendBytes: providerUid length: 16]; // provideruid + [entryId appendUInt32: 1]; // version + [entryId appendUInt32: 0]; // type (local mail user) + [entryId appendBytes: legacyDn length: strlen (legacyDn) + 1]; // x500dn + } + } + + talloc_free(memCtx); return entryId; }