fix(addressbook): handle vCard with multiple title values

pull/283/head
Francis Lachapelle 2020-07-07 14:11:04 -04:00
parent 747ba75503
commit 96c22b6b96
4 changed files with 51 additions and 8 deletions

View File

@ -244,8 +244,7 @@
NSMutableString *flattenedValues;
NSString *encoding, *realValue, *value;
encoding = [[self value: 0 ofAttribute: @"encoding"]
lowercaseString];
encoding = [[self value: 0 ofAttribute: @"encoding"] lowercaseString];
flattenedValues = [NSMutableString string];

View File

@ -1,6 +1,6 @@
/* NGVCard+SOGo.h - this file is part of SOGo
*
* Copyright (C) 2009-2017 Inverse inc.
* Copyright (C) 2009-2020 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
@ -56,6 +56,9 @@
- (void) setNotes: (NSArray *) newNotes;
- (NSArray *) notes;
- (void) setTitles;
- (NSArray *) titles;
@end
#endif /* NGVCARD_SOGO_H */

View File

@ -1,6 +1,6 @@
/* NGVCard+SOGo.m - this file is part of SOGo
*
* Copyright (C) 2009-2017 Inverse inc.
* Copyright (C) 2009-2020 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
@ -310,7 +310,12 @@ convention:
given: [ldifRecord objectForKey: @"givenname"]
additional: nil prefixes: nil suffixes: nil];
[self setNickname: [ldifRecord objectForKey: @"mozillanickname"]];
[self setTitle: [ldifRecord objectForKey: @"title"]];
o = [ldifRecord objectForKey: @"title"];
if ([o isKindOfClass: [NSArray class]])
[self setTitles: o];
else
[self setTitle: o];
fn = [ldifRecord objectForKey: @"displayname"];
if (!fn)
@ -1001,6 +1006,42 @@ convention:
return flattenedNotes;
}
- (void) setTitles: (NSArray *) newTitles
{
NSArray *elements;
NSUInteger count, max;
elements = [self childrenWithTag: @"title"];
[self removeChildren: elements];
max = [newTitles count];
for (count = 0; count < max; count++)
{
[self addChildWithTag: @"title"
types: nil
singleValue: [newTitles objectAtIndex: count]];
}
}
- (NSArray *) titles
{
NSArray *titles;
NSMutableArray *flattenedTitles;
NSString *title;
NSUInteger count, max;
titles = [self childrenWithTag: @"title"];
max = [titles count];
flattenedTitles = [NSMutableArray arrayWithCapacity: max];
for (count = 0; count < max; count++)
{
title = [[titles objectAtIndex: count] flattenedValuesForKey: @""];
[flattenedTitles addObject: title];
}
return flattenedTitles;
}
- (NSMutableDictionary *) quickRecordFromContent: (NSString *) theContent
container: (id) theContainer
nameInContainer: (NSString *) nameInContainer

View File

@ -320,9 +320,9 @@
o = [card nickname];
if (o) [data setObject: o forKey: @"nickname"];
o = [card title];
if ([o length] > 0)
[data setObject: o forKey: @"title"];
o = [card titles];
if ([o count])
[data setObject: [o componentsJoinedByString: @" / "] forKey: @"title"];
o = [card role];
if ([o length] > 0)
[data setObject: o forKey: @"role"];