From 9e3ff35354b6bcf7349899bc66f56ad57e73bd2d Mon Sep 17 00:00:00 2001 From: helge Date: Fri, 1 Jun 2007 10:38:18 +0000 Subject: [PATCH] fixed OGo bug #1856, added new NSData category git-svn-id: http://svn.opengroupware.org/SOPE/trunk@1496 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-mime/ChangeLog | 5 ++ sope-mime/NGMime/ChangeLog | 6 ++ sope-mime/NGMime/NGMimePartParser.h | 10 ++- sope-mime/NGMime/NGMimePartParser.m | 111 ++++++++++++++++------------ sope-mime/Version | 2 +- 5 files changed, 83 insertions(+), 51 deletions(-) diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index b27a3278..33e50a04 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,8 @@ +2007-06-01 Helge Hess + + * NGMime: code refactoring, fixed OGo bug #1856 (QP decoding) + (v4.7.248) + 2007-05-28 Helge Hess * NGMime: fixed compilation on gnustep-base (v4.7.247) diff --git a/sope-mime/NGMime/ChangeLog b/sope-mime/NGMime/ChangeLog index 8f6b30a7..34caa2d0 100644 --- a/sope-mime/NGMime/ChangeLog +++ b/sope-mime/NGMime/ChangeLog @@ -1,3 +1,9 @@ +2007-06-01 Helge Hess + + * NGMimePartParser.m: moved processing of content-transfer-encoding + to an NSData category, fixed OGo bug #1856 (use correct quoted + printable decoder!) + 2007-05-28 Helge Hess * NGMimeTextBodyGenerator.m: fixed compilation on gnustep-base diff --git a/sope-mime/NGMime/NGMimePartParser.h b/sope-mime/NGMime/NGMimePartParser.h index 7e852385..4ce8b96f 100644 --- a/sope-mime/NGMime/NGMimePartParser.h +++ b/sope-mime/NGMime/NGMimePartParser.h @@ -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. @@ -24,6 +25,7 @@ #import #import +#import #import #include #include @@ -282,4 +284,10 @@ typedef struct _NGMimeHeaderNames { @end +@interface NSData(MIMEContentTransferEncoding) + +- (NSData *)dataByApplyingMimeContentTransferEncoding:(NSString *)_enc; + +@end + #endif /* __NGMime_NGMimePartParser_H__ */ diff --git a/sope-mime/NGMime/NGMimePartParser.m b/sope-mime/NGMime/NGMimePartParser.m index b71681f0..f717c422 100644 --- a/sope-mime/NGMime/NGMimePartParser.m +++ b/sope-mime/NGMime/NGMimePartParser.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. @@ -29,6 +30,62 @@ /* this tunes, how big reused data cache objects may get (10MB) */ #define MAX_DATA_OBJECT_SIZE_CACHE (10*1024*1024) +@implementation NSData(MIMEContentTransferEncoding) + +- (NSData *)dataByApplyingMimeContentTransferEncoding:(NSString *)_enc { + // TODO: make this an NSData category + unsigned len; + unichar c; + + if ((len = [_enc length]) == 0) + return self; + + _enc = [_enc lowercaseString]; + + c = [_enc characterAtIndex:0]; + switch (c) { + case 'q': + if ([_enc hasPrefix:@"quoted"]) + return [self dataByDecodingQuotedPrintableTransferEncoding]; + break; + case 'b': + if ([_enc hasPrefix:@"base64"]) + return [self dataByDecodingBase64]; + if ([@"binary" isEqualToString:_enc]) + return self; + break; + case '7': + case '8': + case 'i': + if (len == 4) { + if ([@"7bit" isEqualToString:_enc]) + return self; + if ([@"8bit" isEqualToString:_enc]) + return self; + break; + } + else if (len == 8) { + if ([@"identity" isEqualToString:_enc]) + return self; + } + + case 'u': + if (len == 12) { + if ([@"unknown-8bit" isEqualToString:_enc]) + return self; + } + default: + break; + } + + [self warnWithFormat:@"%s: unknown content-transfer-encoding: '%@'", + __PRETTY_FUNCTION__, _enc]; + return nil; +} + +@end /* NSData(MIMEContentTransferEncoding) */ + + @implementation NGMimePartParser static Class StringClass = Nil; @@ -965,58 +1022,14 @@ static NSString *fieldNameForCString(id self, char *_cstring, int _len) { } - (NSData *)readBodyWithKnownLength:(unsigned)_len { - return (self->source) + return (self->source != nil) ? [self readBodyWithKnownLengthFromStream:_len] : [self readBodyWithKnownLengthFromData:_len]; } -- (NSData *)applyTransferEncoding:(NSString *)_encoding onData:(NSData *)_data{ - // TODO: make this an NSData category - unsigned len; - unichar c; - - if ((len = [_encoding length]) == 0) - return nil; - - _encoding = [_encoding lowercaseString]; - - c = [_encoding characterAtIndex:0]; - switch (c) { - case 'q': - if ([_encoding hasPrefix:@"quoted"]) - return [_data dataByDecodingQuotedPrintable]; - break; - case 'b': - if ([_encoding hasPrefix:@"base64"]) - return [_data dataByDecodingBase64]; - else if ([@"binary" isEqualToString:_encoding]) - return _data; - break; - case '7': - case '8': - case 'i': - if (len == 4) { - if ([@"7bit" isEqualToString:_encoding]) - return _data; - if ([@"8bit" isEqualToString:_encoding]) - return _data; - break; - } - else if (len == 8) { - if ([@"identity" isEqualToString:_encoding]) - return _data; - } - - case 'u': - if (len == 12) { - if ([@"unknown-8bit" isEqualToString:_encoding]) - return _data; - } - default: - break; - } - - return nil; +- (NSData *)applyTransferEncoding:(NSString *)_enc onData:(NSData *)_data{ + // Note: this method is used in WebUI + return [_data dataByApplyingMimeContentTransferEncoding:_enc]; } - (NSData *)readBody { diff --git a/sope-mime/Version b/sope-mime/Version index 83332567..0a9b81c9 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=7 -SUBMINOR_VERSION:=247 +SUBMINOR_VERSION:=248 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34 -- 2.39.5