mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-05 20:10:33 +00:00
@@ -1,6 +1,6 @@
|
||||
/* NGVCard+SOGo.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009-2014 Inverse inc.
|
||||
* Copyright (C) 2009-2021 Inverse inc.
|
||||
*
|
||||
* 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
|
||||
@@ -25,7 +25,16 @@
|
||||
|
||||
@interface NGVList (SOGoExtensions)
|
||||
|
||||
- (CardElement *) elementWithTag: (NSString *) elementTag
|
||||
ofType: (NSString *) type;
|
||||
|
||||
- (NSString *) ldifString;
|
||||
- (void) updateFromLDIFRecord: (NSDictionary *) ldifRecord
|
||||
inContainer: (id) container;
|
||||
- (void) setCardReference: (NSString *) newCardReference
|
||||
inContainer: (id) container;
|
||||
- (void) setCardReferences: (NSArray *) newCardReferences
|
||||
inContainer: (id) container;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* NGVCard+SOGo.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2009-2016 Inverse inc.
|
||||
* Copyright (C) 2009-2021 Inverse inc.
|
||||
*
|
||||
* 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
|
||||
@@ -22,13 +22,37 @@
|
||||
#import <Foundation/NSString.h>
|
||||
|
||||
#import <NGCards/NGVCardReference.h>
|
||||
#import <NGExtensions/NSNull+misc.h>
|
||||
#import <NGExtensions/NSObject+Logs.h>
|
||||
|
||||
#import "SOGoContactFolder.h"
|
||||
#import "NSDictionary+LDIF.h"
|
||||
|
||||
#import "NGVList+SOGo.h"
|
||||
|
||||
@implementation NGVList (SOGoExtensions)
|
||||
|
||||
/* LDIF -> VCARD */
|
||||
- (CardElement *) elementWithTag: (NSString *) elementTag
|
||||
ofType: (NSString *) type
|
||||
{
|
||||
NSArray *elements;
|
||||
CardElement *element;
|
||||
|
||||
elements = [self childrenWithTag: elementTag
|
||||
andAttribute: @"type" havingValue: type];
|
||||
if ([elements count] > 0)
|
||||
element = [elements objectAtIndex: 0];
|
||||
else
|
||||
{
|
||||
element = [CardElement elementWithTag: elementTag];
|
||||
[element addType: type];
|
||||
[self addChild: element];
|
||||
}
|
||||
|
||||
return element;
|
||||
}
|
||||
|
||||
- (NSString *) ldifString
|
||||
{
|
||||
NSMutableString *rc;
|
||||
@@ -56,7 +80,7 @@
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
tmp = [array objectAtIndex: i];
|
||||
[members addObject: [NSString stringWithFormat:
|
||||
[members addObject: [NSString stringWithFormat:
|
||||
@"cn=%@,mail=%@", [tmp fn], [tmp email]]];
|
||||
}
|
||||
[entry setObject: members forKey: @"member"];
|
||||
@@ -69,14 +93,14 @@
|
||||
|
||||
- (NSMutableDictionary *) quickRecordFromContent: (NSString *) theContent
|
||||
container: (id) theContainer
|
||||
nameInContainer: (NSString *) nameInContainer
|
||||
nameInContainer: (NSString *) nameInContainer
|
||||
|
||||
{
|
||||
NSMutableDictionary *fields;
|
||||
NSString *value;
|
||||
|
||||
|
||||
fields = [NSMutableDictionary dictionaryWithCapacity: 1];
|
||||
|
||||
|
||||
value = [self fn];
|
||||
if (value)
|
||||
[fields setObject: value forKey: @"c_cn"];
|
||||
@@ -85,4 +109,102 @@
|
||||
return fields;
|
||||
}
|
||||
|
||||
- (void) updateFromLDIFRecord: (NSDictionary *) ldifRecord
|
||||
inContainer: (id) container
|
||||
{
|
||||
NSString *fn;
|
||||
id o;
|
||||
|
||||
fn = [ldifRecord objectForKey: @"displayname"];
|
||||
if (!fn)
|
||||
fn = [ldifRecord objectForKey: @"cn"];
|
||||
[self setFn: fn];
|
||||
|
||||
o = [ldifRecord objectForKey: @"description"];
|
||||
if ([o isNotNull])
|
||||
[self setDescription: o];
|
||||
|
||||
o = [ldifRecord objectForKey: @"member"];
|
||||
if ([o isKindOfClass: [NSArray class]])
|
||||
[self setCardReferences: o
|
||||
inContainer: container];
|
||||
else if ([o isNotNull])
|
||||
[self setCardReference: o
|
||||
inContainer: container];
|
||||
|
||||
[self cleanupEmptyChildren];
|
||||
}
|
||||
|
||||
- (void) setCardReference: (NSString *) newCardReference
|
||||
inContainer: (id) container
|
||||
{
|
||||
NGVCardReference *cardReference;
|
||||
NSDictionary *record;
|
||||
NSEnumerator *attrsList;
|
||||
NSMutableDictionary *attrs;
|
||||
NSArray *pair, *records;
|
||||
NSString *value;
|
||||
|
||||
attrs = [NSMutableDictionary dictionary];
|
||||
attrsList = [[newCardReference componentsSeparatedByString: @","] objectEnumerator];
|
||||
while ((value = [attrsList nextObject]))
|
||||
{
|
||||
pair = [value componentsSeparatedByString: @"="];
|
||||
if ([pair count] == 2 && [[pair objectAtIndex: 1] length])
|
||||
{
|
||||
[attrs setObject: [pair objectAtIndex: 1]
|
||||
forKey: [[pair objectAtIndex: 0] lowercaseString]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self warnWithFormat: @"Unexpected LDAP member: %@", value];
|
||||
}
|
||||
}
|
||||
|
||||
records = nil;
|
||||
if ((value = [attrs objectForKey: @"mail"]))
|
||||
{
|
||||
records = [container lookupContactsWithFilter: value
|
||||
onCriteria: [NSArray arrayWithObject: @"c_mail"]
|
||||
sortBy: nil
|
||||
ordering: NSOrderedAscending
|
||||
inDomain: nil];
|
||||
}
|
||||
else if ((value = [attrs objectForKey: @"cn"]))
|
||||
{
|
||||
records = [container lookupContactsWithFilter: value
|
||||
onCriteria: [NSArray arrayWithObject: @"c_cn"]
|
||||
sortBy: nil
|
||||
ordering: NSOrderedAscending
|
||||
inDomain: nil];
|
||||
}
|
||||
if (records && [records count] > 0)
|
||||
{
|
||||
record = [records objectAtIndex: 0];
|
||||
cardReference = [NGVCardReference elementWithTag: @"card"];
|
||||
[cardReference setReference: [record objectForKey: @"c_name"]];
|
||||
if ((value = [attrs objectForKey: @"mail"]) && [value length])
|
||||
[cardReference setEmail: value];
|
||||
if ((value = [attrs objectForKey: @"cn"]) && [value length])
|
||||
[cardReference setFn: value];
|
||||
[self addCardReference: cardReference];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setCardReferences: (NSArray *) newCardReferences
|
||||
inContainer: (id) container
|
||||
{
|
||||
NSEnumerator *referencesList;
|
||||
NSString *cardReference;
|
||||
|
||||
referencesList = [newCardReferences objectEnumerator];
|
||||
while ((cardReference = [referencesList nextObject]))
|
||||
{
|
||||
[self setCardReference: cardReference
|
||||
inContainer: container];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end /* NGVList */
|
||||
|
||||
@@ -205,7 +205,7 @@
|
||||
[card release];
|
||||
card = nil;
|
||||
|
||||
// We now check if we must update lisst where this contact is present
|
||||
// We now check if we must update lists where this contact is present
|
||||
qualifier = [EOQualifier qualifierWithQualifierFormat: @"c_component = 'vlist'"];
|
||||
lists = [[self container] lookupContactsWithQualifier: qualifier];
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* SOGoContactLDIFEntry.h - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2006-2017 Inverse inc.
|
||||
* Copyright (C) 2006-2021 Inverse inc.
|
||||
*
|
||||
* 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
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
@class NSDictionary;
|
||||
@class NSString;
|
||||
@class NGVList;
|
||||
|
||||
@interface SOGoContactLDIFEntry : SOGoObject <SOGoContactObject>
|
||||
{
|
||||
@@ -42,6 +43,9 @@
|
||||
|
||||
- (BOOL) isNew;
|
||||
- (void) setIsNew: (BOOL) newIsNew;
|
||||
- (BOOL) isList;
|
||||
|
||||
- (NGVList *) vList;
|
||||
|
||||
- (NSString *) davEntityTag;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* SOGoContactLDIFEntry.m - this file is part of SOGo
|
||||
*
|
||||
* Copyright (C) 2006-2017 Inverse inc.
|
||||
* Copyright (C) 2006-2021 Inverse inc.
|
||||
*
|
||||
* 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
|
||||
@@ -26,6 +26,7 @@
|
||||
#import <SOGo/SOGoPermissions.h>
|
||||
|
||||
#import "NGVCard+SOGo.h"
|
||||
#import "NGVList+SOGo.h"
|
||||
#import "SOGoContactEntryPhoto.h"
|
||||
#import "SOGoContactGCSEntry.h"
|
||||
#import "SOGoContactLDIFEntry.h"
|
||||
@@ -76,6 +77,11 @@
|
||||
isNew = newIsNew;
|
||||
}
|
||||
|
||||
- (BOOL) isList
|
||||
{
|
||||
return [ldifEntry objectForKey: @"member"] != nil;
|
||||
}
|
||||
|
||||
- (NSString *) contentAsString
|
||||
{
|
||||
return [[self vCard] versitString];
|
||||
@@ -94,6 +100,20 @@
|
||||
return vcard;
|
||||
}
|
||||
|
||||
- (NGVList *) vList
|
||||
{
|
||||
NGVList *vlist;
|
||||
|
||||
vlist = [NGVList listWithUid: [self nameInContainer]];
|
||||
[vlist setProdID: [NSString
|
||||
stringWithFormat: @"-//Inverse inc./SOGo %@//EN",
|
||||
SOGoVersion]];
|
||||
[vlist updateFromLDIFRecord: [self ldifRecord]
|
||||
inContainer: container];
|
||||
|
||||
return vlist;
|
||||
}
|
||||
|
||||
- (BOOL) isFolderish
|
||||
{
|
||||
return NO;
|
||||
|
||||
Reference in New Issue
Block a user