/*
- Copyright (C) 2000-2005 SKYRIX Software AG
+ Copyright (C) 2000-2007 SKYRIX Software AG
+ Copyright (C) 2007 Helge Hess
This file is part of SOPE.
@implementation NSString(Imap4)
- (NSString *)stringByEncodingImap4FolderName {
- /* doof.d& --> doof.d&- */
+ // TBD: this is restricted to Latin1, should be fixed to UTF-8
+ /* dude.d& --> dude.d&- */
unsigned char *buf = NULL;
unsigned char *res = NULL;
unsigned int len = 0;
unsigned int cnt = 0;
unsigned int cntRes = 0;
NSString *result = nil;
+ NSData *data;
len = [self cStringLength];
buf = calloc(len + 3, sizeof(char));
length = cnt - start + 1;
- _encodeToModifiedUTF7(buf+start, length, &res, &cntRes);
+ _encodeToModifiedUTF7(buf + start, length, &res, &cntRes);
- res[cntRes++] = '-';
+ res[cntRes] = '-';
+ cntRes++;
cnt++;
}
}
}
}
- result = [[NSString alloc] initWithCStringNoCopy:(char *)res
- length:cntRes
- freeWhenDone:YES];
- free(buf); buf = NULL;
+ if (buf != NULL) free(buf); buf = NULL;
+
+ data = [[NSData alloc] initWithBytesNoCopy:res length:cntRes
+ freeWhenDone:YES];
+ result = [[NSString alloc] initWithData:data
+ encoding:NSISOLatin1StringEncoding];
+ [data release]; data = nil;
+
return [result autorelease];
}
- (NSString *)stringByDecodingImap4FolderName {
- /* doof/d&- --> doof/d& */
- unsigned char *buf = NULL;
- unsigned char *res = NULL;
- unsigned int len = 0;
+ // TBD: this is restricted to Latin1, should be fixed to UTF-8
+ /* dude/d&- --> dude/d& */
+ unsigned char *buf;
+ unsigned char *res;
+ unsigned int len;
unsigned int cnt = 0;
unsigned int cntRes = 0;
NSString *result = nil;
-
+ NSData *data;
+
if ((len = [self cStringLength]) == 0)
return @"";
if (cnt < len)
res[cntRes++] = buf[cnt++];
- result = [[NSString alloc] initWithCStringNoCopy:(char *)res
- length:cntRes
- freeWhenDone:YES];
- if (buf) free(buf); buf = NULL;
+ if (buf != NULL) free(buf); buf = NULL;
+
+ data = [[NSData alloc] initWithBytesNoCopy:res length:cntRes
+ freeWhenDone:YES];
+ result = [[NSString alloc] initWithData:data
+ encoding:NSISOLatin1StringEncoding];
+ [data release]; data = nil;
+
return [result autorelease];
}