1 /* SOGoContactLDAPEntry.m - this file is part of SOGo
3 * Copyright (C) 2006 Inverse groupe conseil
5 * Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
7 * This file is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This file is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 #import <Foundation/NSArray.h>
24 #import <Foundation/NSDictionary.h>
25 #import <Foundation/NSString.h>
27 #import <NGCards/NGVCard.h>
28 #import <NGCards/CardVersitRenderer.h>
30 #import <NGLdap/NGLdapEntry.h>
31 #import <NGLdap/NGLdapAttribute.h>
33 #import "NGLdapEntry+Contact.h"
35 #import "SOGoContactLDAPEntry.h"
37 @implementation SOGoContactLDAPEntry
39 + (SOGoContactLDAPEntry *) contactEntryWithName: (NSString *) aName
40 withLDAPEntry: (NGLdapEntry *) anEntry
41 inContainer: (id) aContainer
43 SOGoContactLDAPEntry *entry;
45 entry = [[self alloc] initWithName: aName
46 withLDAPEntry: anEntry
47 inContainer: aContainer];
53 - (void) dumpEntry: (NGLdapEntry *) anEntry
56 unsigned int count, max;
58 keys = [anEntry attributeNames];
61 NSLog (@"dumping entry...");
62 for (count = 0; count < max; count++)
63 NSLog (@"%d: %@ = '%@'", count,
64 [keys objectAtIndex: count],
65 [anEntry singleAttributeWithName: [keys objectAtIndex: count]]);
66 NSLog (@"dumping finished..");
69 - (id) initWithName: (NSString *) aName
70 withLDAPEntry: (NGLdapEntry *) anEntry
71 inContainer: (id) aContainer
73 if ((self = [super initWithName: aName inContainer: aContainer]))
76 [self setLDAPEntry: anEntry];
79 [self dumpEntry: anEntry];
91 - (void) setLDAPEntry: (NGLdapEntry *) anEntry;
96 - (NSString *) contentAsString
98 return [[self vCard] versitString];
101 - (void) _setPhonesOfVCard: (NGVCard *) vCard
105 info = [ldapEntry singleAttributeWithName: @"telephoneNumber"];
108 types: [NSArray arrayWithObjects: @"work", @"voice", @"pref", nil]];
109 info = [ldapEntry singleAttributeWithName: @"homePhone"];
112 types: [NSArray arrayWithObjects: @"home", @"voice", nil]];
113 info = [ldapEntry singleAttributeWithName: @"fax"];
116 types: [NSArray arrayWithObjects: @"work", @"fax", nil]];
117 info = [ldapEntry singleAttributeWithName: @"pager"];
120 types: [NSArray arrayWithObjects: @"pager", nil]];
121 info = [ldapEntry singleAttributeWithName: @"mobile"];
124 types: [NSArray arrayWithObjects: @"cell", @"voice", nil]];
126 // telephoneNumber: work phone
127 // homePhone: home phone
130 // mobile: mobile phone
136 NSString *info, *surname, *streetAddress, *location;
137 CardElement *element;
141 vcard = [[NGVCard alloc] initWithUid: [self nameInContainer]];
142 [vcard setVClass: @"PUBLIC"];
143 [vcard setProdID: @"-//OpenGroupware.org//SOGo"];
144 [vcard setProfile: @"vCard"];
145 info = [ldapEntry singleAttributeWithName: @"displayName"];
146 if (!(info && [info length] > 0))
147 info = [ldapEntry singleAttributeWithName: @"cn"];
149 surname = [ldapEntry singleAttributeWithName: @"sn"];
151 surname = [ldapEntry singleAttributeWithName: @"surname"];
152 [vcard setNWithFamily: surname
153 given: [ldapEntry singleAttributeWithName: @"givenName"]
157 info = [ldapEntry singleAttributeWithName: @"title"];
159 [vcard setTitle: info];
160 info = [ldapEntry singleAttributeWithName: @"mozillaNickname"];
162 [vcard setNickname: info];
163 info = [ldapEntry singleAttributeWithName: @"xmozillaNickname"];
165 [vcard setNickname: info];
166 info = [ldapEntry singleAttributeWithName: @"notes"];
168 [vcard setNote: info];
169 info = [ldapEntry singleAttributeWithName: @"mail"];
171 [vcard addEmail: info
172 types: [NSArray arrayWithObjects: @"internet", @"pref", nil]];
173 [self _setPhonesOfVCard: vcard];
174 streetAddress = [ldapEntry singleAttributeWithName: @"streetAddress"];
175 location = [ldapEntry singleAttributeWithName: @"l"];
176 element = [CardElement elementWithTag: @"adr"
177 attributes: nil values: nil];
178 [element setValue: 0 ofAttribute: @"type" to: @"work"];
180 [element setValue: 2 to: streetAddress];
182 [element setValue: 3 to: location];
183 if (streetAddress || location)
184 [vcard addChild: element];
185 info = [ldapEntry singleAttributeWithName: @"calFBURL"];
187 [vcard addChildWithTag: @"FBURL"
195 - (NSString *) davEntityTag
197 return [[ldapEntry attributeWithName: @"modifyTimeStamp"]
198 stringValueAtIndex: 0];
201 - (NSString *) davContentType
203 return @"text/x-vcard";
212 - (NSString *) outlookMessageClass
214 return @"IPM.Contact";