2006-08-09 23:21:40 +02:00
|
|
|
/* SOGoContactLDAPEntry.m - this file is part of SOGo
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Inverse groupe conseil
|
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
|
|
|
*
|
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
|
|
|
#import <Foundation/NSString.h>
|
|
|
|
|
2006-09-13 23:28:38 +02:00
|
|
|
#import <NGCards/NGVCard.h>
|
|
|
|
#import <NGCards/CardVersitRenderer.h>
|
2006-08-09 23:21:40 +02:00
|
|
|
|
|
|
|
#import "SOGoContactLDAPEntry.h"
|
|
|
|
|
|
|
|
@implementation SOGoContactLDAPEntry
|
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
+ (SOGoContactLDAPEntry *) contactEntryWithName: (NSString *) newName
|
|
|
|
withLDAPEntry: (NGLdapEntry *) newEntry
|
|
|
|
inContainer: (id) newContainer
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
|
|
|
SOGoContactLDAPEntry *entry;
|
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
entry = [[self alloc] initWithName: newName
|
|
|
|
withLDAPEntry: newEntry
|
|
|
|
inContainer: newContainer];
|
2006-08-09 23:21:40 +02:00
|
|
|
[entry autorelease];
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dumpEntry: (NGLdapEntry *) anEntry
|
|
|
|
{
|
|
|
|
NSArray *keys;
|
|
|
|
unsigned int count, max;
|
|
|
|
|
|
|
|
keys = [anEntry attributeNames];
|
|
|
|
max = [keys count];
|
|
|
|
|
|
|
|
NSLog (@"dumping entry...");
|
|
|
|
for (count = 0; count < max; count++)
|
|
|
|
NSLog (@"%d: %@ = '%@'", count,
|
|
|
|
[keys objectAtIndex: count],
|
|
|
|
[anEntry singleAttributeWithName: [keys objectAtIndex: count]]);
|
|
|
|
NSLog (@"dumping finished..");
|
|
|
|
}
|
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
- (id) initWithName: (NSString *) newName
|
|
|
|
withLDAPEntry: (NGLdapEntry *) newEntry
|
|
|
|
inContainer: (id) newContainer
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2007-05-08 17:10:40 +02:00
|
|
|
self = [self init];
|
|
|
|
ASSIGN (name, newName);
|
|
|
|
ASSIGN (container, newContainer);
|
|
|
|
ASSIGN (ldapEntry, newEntry);
|
|
|
|
vcard = nil;
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
// [self dumpEntry: anEntry];
|
2006-08-09 23:21:40 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
- (NSString *) nameInContainer
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2007-05-08 17:10:40 +02:00
|
|
|
return name;
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
- (void) dealloc
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2007-05-08 17:10:40 +02:00
|
|
|
[vcard release];
|
|
|
|
[ldapEntry release];
|
|
|
|
[super dealloc];
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
2006-09-13 23:28:38 +02:00
|
|
|
- (NSString *) contentAsString
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2006-09-13 23:28:38 +02:00
|
|
|
return [[self vCard] versitString];
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _setPhonesOfVCard: (NGVCard *) vCard
|
|
|
|
{
|
|
|
|
NSString *info;
|
|
|
|
|
|
|
|
info = [ldapEntry singleAttributeWithName: @"telephoneNumber"];
|
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"work", @"voice", @"pref", nil]];
|
2006-08-09 23:21:40 +02:00
|
|
|
info = [ldapEntry singleAttributeWithName: @"homePhone"];
|
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"home", @"voice", nil]];
|
2006-08-09 23:21:40 +02:00
|
|
|
info = [ldapEntry singleAttributeWithName: @"fax"];
|
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"work", @"fax", nil]];
|
2006-08-09 23:21:40 +02:00
|
|
|
info = [ldapEntry singleAttributeWithName: @"pager"];
|
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"pager", nil]];
|
2006-08-09 23:21:40 +02:00
|
|
|
info = [ldapEntry singleAttributeWithName: @"mobile"];
|
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"cell", @"voice", nil]];
|
2006-08-09 23:21:40 +02:00
|
|
|
|
|
|
|
// telephoneNumber: work phone
|
|
|
|
// homePhone: home phone
|
|
|
|
// fax: fax phone
|
|
|
|
// pager: page phone
|
|
|
|
// mobile: mobile phone
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NGVCard *) vCard
|
|
|
|
{
|
2006-09-20 23:38:15 +02:00
|
|
|
NSString *info, *surname, *streetAddress, *location;
|
|
|
|
CardElement *element;
|
2006-08-09 23:21:40 +02:00
|
|
|
|
|
|
|
if (!vcard)
|
|
|
|
{
|
2006-10-04 00:08:33 +02:00
|
|
|
vcard = [[NGVCard alloc] initWithUid: [self nameInContainer]];
|
2006-10-27 20:18:37 +02:00
|
|
|
[vcard setVClass: @"PUBLIC"];
|
2006-08-09 23:21:40 +02:00
|
|
|
[vcard setProdID: @"-//OpenGroupware.org//SOGo"];
|
|
|
|
[vcard setProfile: @"vCard"];
|
2006-09-26 20:39:04 +02:00
|
|
|
info = [ldapEntry singleAttributeWithName: @"displayName"];
|
|
|
|
if (!(info && [info length] > 0))
|
|
|
|
info = [ldapEntry singleAttributeWithName: @"cn"];
|
|
|
|
[vcard setFn: info];
|
2006-09-13 23:28:38 +02:00
|
|
|
surname = [ldapEntry singleAttributeWithName: @"sn"];
|
|
|
|
if (!surname)
|
|
|
|
surname = [ldapEntry singleAttributeWithName: @"surname"];
|
|
|
|
[vcard setNWithFamily: surname
|
|
|
|
given: [ldapEntry singleAttributeWithName: @"givenName"]
|
|
|
|
additional: nil
|
|
|
|
prefixes: nil
|
|
|
|
suffixes: nil];
|
2006-08-09 23:21:40 +02:00
|
|
|
info = [ldapEntry singleAttributeWithName: @"title"];
|
|
|
|
if (info)
|
|
|
|
[vcard setTitle: info];
|
|
|
|
info = [ldapEntry singleAttributeWithName: @"mozillaNickname"];
|
|
|
|
if (info)
|
|
|
|
[vcard setNickname: info];
|
|
|
|
info = [ldapEntry singleAttributeWithName: @"xmozillaNickname"];
|
|
|
|
if (info)
|
|
|
|
[vcard setNickname: info];
|
|
|
|
info = [ldapEntry singleAttributeWithName: @"notes"];
|
|
|
|
if (info)
|
|
|
|
[vcard setNote: info];
|
|
|
|
info = [ldapEntry singleAttributeWithName: @"mail"];
|
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vcard addEmail: info
|
|
|
|
types: [NSArray arrayWithObjects: @"internet", @"pref", nil]];
|
2006-08-09 23:21:40 +02:00
|
|
|
[self _setPhonesOfVCard: vcard];
|
2006-09-20 23:38:15 +02:00
|
|
|
streetAddress = [ldapEntry singleAttributeWithName: @"streetAddress"];
|
|
|
|
location = [ldapEntry singleAttributeWithName: @"l"];
|
|
|
|
element = [CardElement elementWithTag: @"adr"
|
|
|
|
attributes: nil values: nil];
|
2006-10-27 19:45:32 +02:00
|
|
|
[element setValue: 0 ofAttribute: @"type" to: @"work"];
|
2006-09-20 23:38:15 +02:00
|
|
|
if (streetAddress)
|
|
|
|
[element setValue: 2 to: streetAddress];
|
|
|
|
if (location)
|
|
|
|
[element setValue: 3 to: location];
|
|
|
|
if (streetAddress || location)
|
|
|
|
[vcard addChild: element];
|
2007-02-02 21:47:21 +01:00
|
|
|
info = [ldapEntry singleAttributeWithName: @"calFBURL"];
|
|
|
|
if (info)
|
|
|
|
[vcard addChildWithTag: @"FBURL"
|
|
|
|
types: nil
|
|
|
|
singleValue: info];
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
2006-10-27 19:45:32 +02:00
|
|
|
|
2006-08-09 23:21:40 +02:00
|
|
|
return vcard;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) davEntityTag
|
|
|
|
{
|
|
|
|
return [[ldapEntry attributeWithName: @"modifyTimeStamp"]
|
|
|
|
stringValueAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) davContentType
|
|
|
|
{
|
|
|
|
return @"text/x-vcard";
|
|
|
|
}
|
|
|
|
|
2007-04-27 21:01:46 +02:00
|
|
|
- (NSArray *) aclsForUser: (NSString *) uid
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2006-09-16 00:20:56 +02:00
|
|
|
- (void) save
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:21:40 +02:00
|
|
|
/* message type */
|
|
|
|
|
|
|
|
- (NSString *) outlookMessageClass
|
|
|
|
{
|
|
|
|
return @"IPM.Contact";
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|