From f73b138d682c937a860251f46046910eef0b1abd Mon Sep 17 00:00:00 2001 From: helge Date: Sun, 15 Jul 2007 10:05:18 +0000 Subject: [PATCH] fixed OGo bug #1885 git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1507 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-mime/ChangeLog | 5 ++++ sope-mime/NGImap4/ChangeLog | 6 ++++ sope-mime/NGImap4/NSString+Imap4.m | 48 +++++++++++++++++++----------- sope-mime/Version | 2 +- 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index 33e50a04..800c7b89 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,8 @@ +2007-07-15 Helge Hess + + * NGImap4: fixed an encoding issue on gstep-base/Cocoa (OGo bug #1885) + (v4.7.249) + 2007-06-01 Helge Hess * NGMime: code refactoring, fixed OGo bug #1856 (QP decoding) diff --git a/sope-mime/NGImap4/ChangeLog b/sope-mime/NGImap4/ChangeLog index cf1a60b5..68ac3230 100644 --- a/sope-mime/NGImap4/ChangeLog +++ b/sope-mime/NGImap4/ChangeLog @@ -1,3 +1,9 @@ +2007-07-15 Helge Hess + + * NSString+Imap4.m: changed code to use -initWithData: as suggested in + bug report (OGo bug #1885). Note that the methods still support + Latin1 only and should be changed to decode/encode unichar buffers + 2007-05-28 Helge Hess * NGImap4ResponseNormalizer.m: changed not to throw an exception in the diff --git a/sope-mime/NGImap4/NSString+Imap4.m b/sope-mime/NGImap4/NSString+Imap4.m index 76594791..76f5486f 100644 --- a/sope-mime/NGImap4/NSString+Imap4.m +++ b/sope-mime/NGImap4/NSString+Imap4.m @@ -1,5 +1,6 @@ /* - 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. @@ -35,13 +36,15 @@ static int _decodeOfModifiedUTF7(unsigned char *_target, unsigned _targetLen, @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)); @@ -86,30 +89,37 @@ static int _decodeOfModifiedUTF7(unsigned char *_target, unsigned _targetLen, 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 @""; @@ -164,10 +174,14 @@ static int _decodeOfModifiedUTF7(unsigned char *_target, unsigned _targetLen, 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]; } diff --git a/sope-mime/Version b/sope-mime/Version index 0a9b81c9..fbc4ca5b 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=7 -SUBMINOR_VERSION:=248 +SUBMINOR_VERSION:=249 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34 -- 2.39.5