*** SOGo/SoObjects/SOGo/SOGoUserManager.m	2010-04-01 18:08:05.000000000 +0200
--- ../SOGo/SoObjects/SOGo/SOGoUserManager.m	2010-04-09 14:45:10.000000000 +0200
***************
*** 480,486 ****
  
  - (void) _fillContactMailRecords: (NSMutableDictionary *) contact
  {
!   NSString *uid, *domain, *systemEmail;
    NSMutableArray *emails;
    SOGoDomainDefaults *dd;
  
--- 480,486 ----
  
  - (void) _fillContactMailRecords: (NSMutableDictionary *) contact
  {
!   NSString *uid, *domain, *systemEmail, *mail;
    NSMutableArray *emails;
    SOGoDomainDefaults *dd;
  
***************
*** 491,501 ****
      dd = [SOGoSystemDefaults sharedSystemDefaults];
    emails = [contact objectForKey: @"emails"];
    uid = [contact objectForKey: @"c_uid"];
!   if ([uid rangeOfString: @"@"].location == NSNotFound)
      systemEmail
        = [NSString stringWithFormat: @"%@@%@", uid, [dd mailDomain]];
    else
      systemEmail = uid;
    [emails addObject: systemEmail];
    [contact setObject: [emails objectAtIndex: 0] forKey: @"c_email"];
  }
--- 491,505 ----
      dd = [SOGoSystemDefaults sharedSystemDefaults];
    emails = [contact objectForKey: @"emails"];
    uid = [contact objectForKey: @"c_uid"];
!   mail = [contact objectForKey: @"mail"];
!   if (mail != nil)
!     systemEmail = mail;
!   else if ([uid rangeOfString: @"@"].location == NSNotFound)
      systemEmail
        = [NSString stringWithFormat: @"%@@%@", uid, [dd mailDomain]];
    else
      systemEmail = uid;
+   NSLog (@"EmailForContact: %@", mail);
    [emails addObject: systemEmail];
    [contact setObject: [emails objectAtIndex: 0] forKey: @"c_email"];
  }
***************
*** 507,519 ****
    NSDictionary *userEntry;
    NSEnumerator *sogoSources;
    NSObject <SOGoDNSource> *currentSource;
!   NSString *sourceID, *cn, *c_domain, *c_uid, *c_imaphostname;
    NSArray *c_emails;
    BOOL access;
  
    emails = [NSMutableArray array];
    cn = nil;
    c_uid = nil;
    c_domain = nil;
    c_imaphostname = nil;
  
--- 511,524 ----
    NSDictionary *userEntry;
    NSEnumerator *sogoSources;
    NSObject <SOGoDNSource> *currentSource;
!   NSString *sourceID, *cn, *c_domain, *c_uid, *c_email, *c_imaphostname;
    NSArray *c_emails;
    BOOL access;
  
    emails = [NSMutableArray array];
    cn = nil;
    c_uid = nil;
+   c_email = nil;
    c_domain = nil;
    c_imaphostname = nil;
  
***************
*** 534,539 ****
--- 539,546 ----
  	    cn = [userEntry objectForKey: @"c_cn"];
  	  if (!c_uid)
  	    c_uid = [userEntry objectForKey: @"c_uid"];
+ 	  if (!c_email)
+ 	    c_email = [userEntry objectForKey: @"mail"];
            if (!c_domain)
              c_domain = [userEntry objectForKey: @"c_domain"];
  	  c_emails = [userEntry objectForKey: @"c_emails"];
***************
*** 564,569 ****
--- 571,578 ----
    [currentUser setObject: emails forKey: @"emails"];
    [currentUser setObject: cn forKey: @"cn"];
    [currentUser setObject: c_uid forKey: @"c_uid"];
+   if (c_email)
+     [currentUser setObject: c_email forKey: @"mail"];
    [currentUser setObject: c_domain forKey: @"c_domain"];
  
    // If our LDAP queries gave us nothing, we add at least one default
