/*
- 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.
#import <Foundation/NSObject.h>
#import <Foundation/NSString.h>
+#import <Foundation/NSData.h>
#import <NGStreams/NGStreamProtocols.h>
#include <NGMime/NGPart.h>
#include <NGMime/NGMimeHeaderFieldParser.h>
@end
+@interface NSData(MIMEContentTransferEncoding)
+
+- (NSData *)dataByApplyingMimeContentTransferEncoding:(NSString *)_enc;
+
+@end
+
#endif /* __NGMime_NGMimePartParser_H__ */
/*
- 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.
/* 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;
}
- (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 {