mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-08 21:37:15 +00:00
Fixes for import/export
Monotone-Parent: 3e7ac334a4ea19aa4ec2dcbc525628005ca75fb7 Monotone-Revision: d124c012f70febcfcbb9a2b5d4f3a20a7a001d7a Monotone-Author: crobert@inverse.ca Monotone-Date: 2009-09-09T13:31:45 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
1 parent
cb888a11ff
commit
c543b9e9a7
24 files changed
+687
-547
No files matched your search
@@ -35,6 +35,9 @@
|
||||
- (NSString *) jsonRepresentation;
|
||||
- (NSString *) keysWithFormat: (NSString *) keyFormat;
|
||||
|
||||
// LDIF methods
|
||||
- (NSString *) userRecordAsLDIFEntry;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSMutableDictionary (SOGoDictionaryUtilities)
|
||||
|
||||
@@ -26,6 +26,10 @@
|
||||
#import <Foundation/NSException.h>
|
||||
#import <Foundation/NSNull.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSCharacterSet.h>
|
||||
|
||||
#import <NGExtensions/NGBase64Coding.h>
|
||||
#import <SoObjects/SOGo/NSString+Utilities.h>
|
||||
|
||||
#import "NSArray+Utilities.h"
|
||||
#import "NSObject+Utilities.h"
|
||||
@@ -108,6 +112,76 @@
|
||||
return [[self objectForKey: @"cn"] caseInsensitiveCompare: [theDictionary objectForKey: @"cn"]];
|
||||
}
|
||||
|
||||
// LDIF Methods
|
||||
- (void) _appendLDIFKey: (NSString *) key
|
||||
value: (NSString *) value
|
||||
toString: (NSMutableString *) ldifString
|
||||
{
|
||||
if ([value _isLDIFSafe])
|
||||
[ldifString appendFormat: @"%@: %@\n", key, value];
|
||||
else
|
||||
[ldifString appendFormat: @"%@:: %@\n",
|
||||
key, [value stringByEncodingBase64]];
|
||||
}
|
||||
|
||||
- (void) _appendLDIFKey: (NSString *) key
|
||||
toString: (NSMutableString *) ldifString
|
||||
{
|
||||
id value;
|
||||
int count, max;
|
||||
|
||||
value = [self objectForKey: key];
|
||||
if ([value isKindOfClass: [NSArray class]])
|
||||
{
|
||||
max = [value count];
|
||||
for (count = 0; count < max; count++)
|
||||
[self _appendLDIFKey: key value: [value objectAtIndex: count]
|
||||
toString: ldifString];
|
||||
}
|
||||
else
|
||||
[self _appendLDIFKey: key value: [self objectForKey: key]
|
||||
toString: ldifString];
|
||||
}
|
||||
|
||||
- (void) _appendObjectClassesToString: (NSMutableString *) ldifString
|
||||
{
|
||||
NSEnumerator *classes;
|
||||
NSString *currentClass;
|
||||
|
||||
classes = [[self objectForKey: @"objectClasses"] objectEnumerator];
|
||||
while ((currentClass = [classes nextObject]))
|
||||
[self _appendLDIFKey: @"objectClass" value: currentClass
|
||||
toString: ldifString];
|
||||
}
|
||||
|
||||
- (NSString *) userRecordAsLDIFEntry
|
||||
{
|
||||
NSMutableString *ldifString;
|
||||
NSEnumerator *keys;
|
||||
NSString *currentKey;
|
||||
|
||||
// {CalendarAccess = YES; MailAccess = YES; c_cn = "Wolfgang Sourdeau"; c_emails = ("wolfgang@test.com"); c_name = "wolfgang@test.com"; c_uid = "wolfgang@test.com"; cn = "wolfgang@test.com"; displayName = "Wolfgang Sourdeau"; dn = "cn=wolfgang@test.com,ou=evariste,o=inverse.ca"; givenName = Wolfgang; mail = "wolfgang@test.com"; objectClass = organizationalPerson; sn = Sourdeau; }
|
||||
|
||||
ldifString = [NSMutableString string];
|
||||
[self _appendLDIFKey: @"dn" toString: ldifString];
|
||||
[self _appendObjectClassesToString: ldifString];
|
||||
|
||||
keys = [[self allKeys] objectEnumerator];
|
||||
while ((currentKey = [keys nextObject]))
|
||||
{
|
||||
if (!([currentKey isEqualToString: @"CalendarAccess"]
|
||||
|| [currentKey isEqualToString: @"MailAccess"]
|
||||
|| [currentKey isEqualToString: @"ContactAccess"]
|
||||
|| [currentKey hasPrefix: @"objectClass"]
|
||||
|| [currentKey hasPrefix: @"c_"]
|
||||
|| [currentKey isEqualToString: @"dn"]))
|
||||
[self _appendLDIFKey: currentKey toString: ldifString];
|
||||
}
|
||||
|
||||
return ldifString;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSMutableDictionary (SOGoDictionaryUtilities)
|
||||
@@ -128,4 +202,6 @@
|
||||
@" the number of keys."];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@@ -62,6 +62,9 @@
|
||||
- (BOOL) boolValue;
|
||||
#endif
|
||||
|
||||
// LDIF
|
||||
- (BOOL) _isLDIFSafe;
|
||||
|
||||
@end
|
||||
|
||||
#endif /* NSSTRING_URL_H */
|
||||
@@ -384,4 +384,42 @@ static NSMutableCharacterSet *urlStartChars = nil;
|
||||
}
|
||||
#endif
|
||||
|
||||
static NSMutableCharacterSet *safeLDIFChars = nil;
|
||||
static NSMutableCharacterSet *safeLDIFStartChars = nil;
|
||||
|
||||
- (void) _initSafeLDIFChars
|
||||
{
|
||||
safeLDIFChars = [NSMutableCharacterSet new];
|
||||
[safeLDIFChars addCharactersInRange: NSMakeRange (0x01, 9)];
|
||||
[safeLDIFChars addCharactersInRange: NSMakeRange (0x0b, 2)];
|
||||
[safeLDIFChars addCharactersInRange: NSMakeRange (0x0e, 114)];
|
||||
|
||||
safeLDIFStartChars = [safeLDIFChars mutableCopy];
|
||||
[safeLDIFStartChars removeCharactersInString: @" :<"];
|
||||
}
|
||||
|
||||
- (BOOL) _isLDIFSafe
|
||||
{
|
||||
int count, max;
|
||||
BOOL rc;
|
||||
|
||||
if (!safeLDIFChars)
|
||||
[self _initSafeLDIFChars];
|
||||
|
||||
rc = YES;
|
||||
|
||||
max = [self length];
|
||||
if (max > 0)
|
||||
{
|
||||
if ([safeLDIFStartChars characterIsMember: [self characterAtIndex: 0]])
|
||||
for (count = 1; rc && count < max; count++)
|
||||
rc = [safeLDIFChars
|
||||
characterIsMember: [self characterAtIndex: count]];
|
||||
else
|
||||
rc = NO;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user