2007-05-09 21:09:50 +02:00
|
|
|
/* SOGoContactLDIFEntry.m - this file is part of SOGo
|
2006-08-09 23:21:40 +02:00
|
|
|
*
|
2011-07-29 15:26:14 +02:00
|
|
|
* Copyright (C) 2006-2011 Inverse inc.
|
2006-08-09 23:21:40 +02:00
|
|
|
*
|
|
|
|
* Author: Wolfgang Sourdeau <wsourdeau@inverse.ca>
|
2009-02-17 20:52:11 +01:00
|
|
|
* Ludovic Marcotte <lmarcotte@inverse.ca>
|
2006-08-09 23:21:40 +02:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
2011-03-30 17:01:55 +02:00
|
|
|
#import <SOGo/SOGoBuild.h>
|
|
|
|
|
2008-08-10 23:44:25 +02:00
|
|
|
#import "SOGoContactGCSEntry.h"
|
2007-05-09 21:09:50 +02:00
|
|
|
#import "SOGoContactLDIFEntry.h"
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2007-05-09 21:09:50 +02:00
|
|
|
@implementation SOGoContactLDIFEntry
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2007-05-09 21:09:50 +02:00
|
|
|
+ (SOGoContactLDIFEntry *) contactEntryWithName: (NSString *) newName
|
|
|
|
withLDIFEntry: (NSDictionary *) newEntry
|
2007-05-08 17:10:40 +02:00
|
|
|
inContainer: (id) newContainer
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2007-05-09 21:09:50 +02:00
|
|
|
SOGoContactLDIFEntry *entry;
|
2006-08-09 23:21:40 +02:00
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
entry = [[self alloc] initWithName: newName
|
2007-05-09 21:09:50 +02:00
|
|
|
withLDIFEntry: newEntry
|
2007-05-08 17:10:40 +02:00
|
|
|
inContainer: newContainer];
|
2006-08-09 23:21:40 +02:00
|
|
|
[entry autorelease];
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2007-05-08 17:10:40 +02:00
|
|
|
- (id) initWithName: (NSString *) newName
|
2007-05-09 21:09:50 +02:00
|
|
|
withLDIFEntry: (NSDictionary *) newEntry
|
2007-05-08 17:10:40 +02:00
|
|
|
inContainer: (id) newContainer
|
2006-08-09 23:21:40 +02:00
|
|
|
{
|
2010-02-03 01:32:26 +01:00
|
|
|
if ((self = [self initWithName: newName inContainer: newContainer]))
|
|
|
|
{
|
|
|
|
ASSIGN (ldifEntry, newEntry);
|
|
|
|
vcard = nil;
|
|
|
|
}
|
2006-08-09 23:21:40 +02:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
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];
|
2007-05-09 21:09:50 +02:00
|
|
|
[ldifEntry release];
|
2007-05-08 17:10:40 +02:00
|
|
|
[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;
|
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
info = [ldifEntry objectForKey: @"telephonenumber"];
|
2006-08-09 23:21:40 +02:00
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"work", @"voice", @"pref", nil]];
|
2009-09-25 16:42:33 +02:00
|
|
|
info = [ldifEntry objectForKey: @"homephone"];
|
2006-08-09 23:21:40 +02:00
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"home", @"voice", nil]];
|
2007-05-09 21:30:06 +02:00
|
|
|
info = [ldifEntry objectForKey: @"fax"];
|
2006-08-09 23:21:40 +02:00
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"work", @"fax", nil]];
|
2007-05-09 21:30:06 +02:00
|
|
|
info = [ldifEntry objectForKey: @"pager"];
|
2006-08-09 23:21:40 +02:00
|
|
|
if (info)
|
2006-09-13 23:28:38 +02:00
|
|
|
[vCard addTel: info
|
|
|
|
types: [NSArray arrayWithObjects: @"pager", nil]];
|
2007-05-09 21:30:06 +02:00
|
|
|
info = [ldifEntry objectForKey: @"mobile"];
|
2006-08-09 23:21:40 +02:00
|
|
|
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
|
|
|
|
{
|
2009-11-29 05:19:32 +01:00
|
|
|
NSString *info, *surname, *streetAddress, *location, *region, *postalCode, *country, *org, *orgunit;
|
2006-09-20 23:38:15 +02:00
|
|
|
CardElement *element;
|
2008-08-22 21:57:18 +02:00
|
|
|
unsigned int count;
|
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"];
|
2011-03-30 17:01:55 +02:00
|
|
|
[vcard setProdID: [NSString
|
|
|
|
stringWithFormat: @"-//Inverse inc./SOGo %@//EN",
|
|
|
|
SOGoVersion]];
|
2009-10-09 00:34:52 +02:00
|
|
|
[vcard setProfile: @"VCARD"];
|
|
|
|
info = [ldifEntry objectForKey: @"c_cn"];
|
|
|
|
if (![info length])
|
|
|
|
{
|
|
|
|
info = [ldifEntry objectForKey: @"displayname"];
|
|
|
|
if (![info length])
|
|
|
|
info = [ldifEntry objectForKey: @"cn"];
|
|
|
|
}
|
2006-09-26 20:39:04 +02:00
|
|
|
[vcard setFn: info];
|
2007-05-09 21:30:06 +02:00
|
|
|
surname = [ldifEntry objectForKey: @"sn"];
|
2006-09-13 23:28:38 +02:00
|
|
|
if (!surname)
|
2007-05-09 21:30:06 +02:00
|
|
|
surname = [ldifEntry objectForKey: @"surname"];
|
2006-09-13 23:28:38 +02:00
|
|
|
[vcard setNWithFamily: surname
|
2009-10-09 00:34:52 +02:00
|
|
|
given: [ldifEntry objectForKey: @"givenname"]
|
|
|
|
additional: nil
|
|
|
|
prefixes: nil
|
|
|
|
suffixes: nil];
|
2007-05-09 21:30:06 +02:00
|
|
|
info = [ldifEntry objectForKey: @"title"];
|
2006-08-09 23:21:40 +02:00
|
|
|
if (info)
|
|
|
|
[vcard setTitle: info];
|
2009-09-25 16:42:33 +02:00
|
|
|
info = [ldifEntry objectForKey: @"mozillanickname"];
|
2006-08-09 23:21:40 +02:00
|
|
|
if (info)
|
|
|
|
[vcard setNickname: info];
|
2008-12-15 22:32:32 +01:00
|
|
|
|
2009-11-29 05:19:32 +01:00
|
|
|
/* If "c_info" is defined, we set as the NOTE value in order for
|
|
|
|
Thunderbird (or any other CardDAV client) to display it. */
|
|
|
|
info = [ldifEntry objectForKey: @"c_info"];
|
|
|
|
if (![info length])
|
|
|
|
info = [ldifEntry objectForKey: @"description"];
|
|
|
|
if ([info length])
|
2006-08-09 23:21:40 +02:00
|
|
|
[vcard setNote: info];
|
2008-12-15 22:32:32 +01:00
|
|
|
|
2007-05-09 21:30:06 +02:00
|
|
|
info = [ldifEntry objectForKey: @"mail"];
|
2006-08-09 23:21:40 +02:00
|
|
|
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];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
|
|
|
streetAddress = [ldifEntry objectForKey: @"street"];
|
2009-10-09 00:34:52 +02:00
|
|
|
if (!streetAddress)
|
|
|
|
streetAddress = [ldifEntry objectForKey: @"streetaddress"];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
2007-05-09 21:30:06 +02:00
|
|
|
location = [ldifEntry objectForKey: @"l"];
|
2009-10-09 00:34:52 +02:00
|
|
|
if (!location)
|
|
|
|
location = [ldifEntry objectForKey: @"locality"];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
|
|
|
region = [ldifEntry objectForKey: @"st"];
|
2009-10-09 00:34:52 +02:00
|
|
|
if (!region)
|
|
|
|
region = [ldifEntry objectForKey: @"region"];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
2009-09-25 16:42:33 +02:00
|
|
|
postalCode = [ldifEntry objectForKey: @"postalcode"];
|
2009-10-09 00:34:52 +02:00
|
|
|
if (!postalCode)
|
|
|
|
postalCode = [ldifEntry objectForKey: @"zip"];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
|
|
|
country = [ldifEntry objectForKey: @"c"];
|
2009-10-09 00:34:52 +02:00
|
|
|
if (!country)
|
|
|
|
country = [ldifEntry objectForKey: @"countryname"];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
2006-09-20 23:38:15 +02:00
|
|
|
element = [CardElement elementWithTag: @"adr"
|
2009-10-09 00:34:52 +02:00
|
|
|
attributes: nil values: nil];
|
2006-10-27 19:45:32 +02:00
|
|
|
[element setValue: 0 ofAttribute: @"type" to: @"work"];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
2006-09-20 23:38:15 +02:00
|
|
|
if (streetAddress)
|
|
|
|
[element setValue: 2 to: streetAddress];
|
|
|
|
if (location)
|
|
|
|
[element setValue: 3 to: location];
|
2009-02-17 20:52:11 +01:00
|
|
|
if (region)
|
|
|
|
[element setValue: 4 to: region];
|
|
|
|
if (postalCode)
|
|
|
|
[element setValue: 5 to: postalCode];
|
|
|
|
if (country)
|
|
|
|
[element setValue: 6 to: country];
|
|
|
|
|
|
|
|
if (streetAddress || location || region || postalCode || country)
|
2006-09-20 23:38:15 +02:00
|
|
|
[vcard addChild: element];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
|
|
|
// We handle the org/orgunit stuff
|
|
|
|
element = [CardElement elementWithTag: @"org"
|
|
|
|
attributes: nil values: nil];
|
|
|
|
org = [ldifEntry objectForKey: @"o"];
|
|
|
|
orgunit = [ldifEntry objectForKey: @"ou"];
|
2009-10-09 00:34:52 +02:00
|
|
|
if (!orgunit)
|
|
|
|
orgunit = [ldifEntry objectForKey: @"orgunit"];
|
2009-02-17 20:52:11 +01:00
|
|
|
|
|
|
|
if (org)
|
|
|
|
[element setValue: 0 to: org];
|
|
|
|
if (orgunit)
|
|
|
|
[element setValue: 1 to: orgunit];
|
|
|
|
|
|
|
|
if (org || orgunit)
|
|
|
|
[vcard addChild: element];
|
|
|
|
|
2007-05-09 21:30:06 +02:00
|
|
|
info = [ldifEntry objectForKey: @"calFBURL"];
|
2007-02-02 21:47:21 +01:00
|
|
|
if (info)
|
|
|
|
[vcard addChildWithTag: @"FBURL"
|
|
|
|
types: nil
|
|
|
|
singleValue: info];
|
2008-08-22 21:57:18 +02:00
|
|
|
for (count = 1; count < 5; count++)
|
|
|
|
{
|
|
|
|
info = [ldifEntry objectForKey:
|
2009-09-25 16:42:33 +02:00
|
|
|
[NSString stringWithFormat: @"mozillacustom%d",
|
2008-08-22 21:57:18 +02:00
|
|
|
count]];
|
|
|
|
if (info)
|
|
|
|
[vcard addChildWithTag: [NSString stringWithFormat: @"CUSTOM%d",
|
|
|
|
count]
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-03-28 15:47:33 +01:00
|
|
|
- (BOOL) isFolderish
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:21:40 +02:00
|
|
|
- (NSString *) davEntityTag
|
|
|
|
{
|
2007-10-23 00:18:07 +02:00
|
|
|
unsigned int hash;
|
|
|
|
// return [ldifEntry objectForKey: @"modifyTimeStamp"];
|
|
|
|
|
|
|
|
hash = [[self contentAsString] hash];
|
|
|
|
|
|
|
|
return [NSString stringWithFormat: @"hash%u", hash];
|
2006-08-09 23:21:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (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
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-08-10 23:44:25 +02:00
|
|
|
/* DAV */
|
|
|
|
- (NSException *) copyToFolder: (SOGoGCSFolder *) newFolder
|
|
|
|
{
|
|
|
|
NGVCard *newCard;
|
|
|
|
NSString *newUID;
|
|
|
|
SOGoContactGCSEntry *newContact;
|
|
|
|
|
|
|
|
// Change the contact UID
|
|
|
|
newUID = [self globallyUniqueObjectId];
|
|
|
|
newCard = [self vCard];
|
|
|
|
|
|
|
|
[newCard setUid: newUID];
|
|
|
|
|
|
|
|
newContact = [SOGoContactGCSEntry objectWithName:
|
|
|
|
[NSString stringWithFormat: @"%@.vcf", newUID]
|
|
|
|
inContainer: newFolder];
|
|
|
|
|
|
|
|
return [newContact saveContentString: [newCard versitString]];
|
|
|
|
}
|
|
|
|
|
2006-08-09 23:21:40 +02:00
|
|
|
@end
|