Skip to content

Commit

Permalink
feat(addressbook(web)): import vList from versit file
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed May 18, 2022
1 parent e020a51 commit 51dc929
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 18 deletions.
6 changes: 4 additions & 2 deletions UI/Contacts/UIxContactFolderActions.h
@@ -1,5 +1,5 @@
/*
Copyright (C) 2006-2021 Inverse inc.
Copyright (C) 2006-2022 Inverse inc.
This file is part of SOGo
Expand All @@ -25,6 +25,7 @@
#import <SOGoUI/UIxComponent.h>

@class NSDictionary;
@class NSMutableArray;
@class NSString;

@protocol SOGoContactObject;
Expand All @@ -35,7 +36,8 @@
- (int) importVcardData: (NSString *) vcardData;
- (BOOL) importVcard: (NGVCard *) card;
- (BOOL) importVlist: (NGVList *) list;

- (BOOL) importVcard: (NGVCard *) card
andLists: (NSMutableArray *) lists;
@end

#endif /* __UIxContactFolderActions_H__ */
65 changes: 49 additions & 16 deletions UI/Contacts/UIxContactFolderActions.m
Expand Up @@ -338,29 +338,39 @@ - (int) importLdifData: (NSString *) ldifData

- (int) importVcardData: (NSString *) vcardData
{
NGVList *vList;
NSAutoreleasePool *pool;
NSArray *allCards;
int rc, count;
NSMutableArray *allLists;
int rc, count, i;

rc = 0;

pool = [[NSAutoreleasePool alloc] init];
allCards = [NGVCard parseFromSource: vcardData];
allLists = [NSMutableArray array];

count = [allCards count];
if (allCards && count)
{
int i;
for (i = 0; i < count; i++)
{
// Postpone importation of lists
if ([self importVcard: [allCards objectAtIndex: i]
andLists: allLists])
rc++;
}
}

// Import vLists
count = [allLists count];
if (count)
{
for (i = 0; i < count; i++)
{
if (![self importVcard: [allCards objectAtIndex: i]])
{
rc = 0;
break;
}
else
rc++;
vList = [allLists objectAtIndex: i];
if ([self importVlist: vList])
rc++;
}
}

Expand All @@ -371,31 +381,49 @@ - (int) importVcardData: (NSString *) vcardData

- (BOOL) importVcard: (NGVCard *) card
{
return [self importVcard: card
andLists: nil];
}

- (BOOL) importVcard: (NGVCard *) card
andLists: (NSMutableArray *) lists
{
BOOL rc;
SOGoContactGCSFolder *folder;
SOGoContactGCSEntry *contact;
NGVList *list;
NSAutoreleasePool *pool;
NSString *uid;

BOOL rc = NO;
rc = NO;

if (card)
{
pool = [[NSAutoreleasePool alloc] init];
folder = [self clientObject];

// TODO: shall we add .vcf as in [SOGoContactGCSEntry copyToFolder:]
uid = [card uid];
if (![uid length])
{
// TODO: shall we add .vcf as in [SOGoContactGCSEntry copyToFolder:]
uid = [folder globallyUniqueObjectId];
[card setUid: uid];
}
contact = [SOGoContactGCSEntry objectWithName: uid

if ([[card tag] isEqualToString: @"VLIST"])
{
list = [NGVList parseSingleFromSource: [card versitString]];
[lists addObject: list];
}
else
{
contact = [SOGoContactGCSEntry objectWithName: uid
inContainer: folder];
[contact setIsNew: YES];
[contact saveComponent: card];
[contact setIsNew: YES];
[contact saveComponent: card];
rc = YES;
}

rc = YES;
RELEASE(pool);
}

Expand All @@ -416,8 +444,13 @@ - (BOOL) importVlist: (NGVList *) list
pool = [[NSAutoreleasePool alloc] init];
folder = [self clientObject];

// TODO: shall we add .vcf as in [SOGoContactGCSEntry copyToFolder:]
uid = [list uid];
if (![uid length])
{
// TODO: shall we add .vcf as in [SOGoContactGCSEntry copyToFolder:]
uid = [folder globallyUniqueObjectId];
[list setUid: uid];
}
contact = [SOGoContactGCSList objectWithName: uid
inContainer: folder];
[contact setIsNew: YES];
Expand Down

0 comments on commit 51dc929

Please sign in to comment.