2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #include "NGMimeBodyParser.h"
24 #include "NGMimeBodyPartParser.h"
25 #include "NGMimeMultipartBody.h"
28 @implementation NGMimeBodyParser
34 - (id)parseBodyOfPart:(id<NGMimePart>)_part
41 @end /* NGMimeBodyParser */
43 @implementation NGMimeTextBodyParser
45 static int UseFoundationStringEncodingForMimeText = -1;
51 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
53 NSAssert2([super version] == 2,
54 @"invalid superclass (%@) version %i !",
55 NSStringFromClass([self superclass]), [super version]);
56 if (UseFoundationStringEncodingForMimeText == -1) {
57 UseFoundationStringEncodingForMimeText =
58 [ud boolForKey:@"UseFoundationStringEncodingForMimeText"]?1:0;
62 - (id)parseBodyOfPart:(id<NGMimePart>)_part data:(NSData *)_data
68 if (_data == nil) return nil;
70 ctype = [_part contentType];
72 if (![ctype isKindOfClass:[NGMimeType class]])
73 ctype = [NGMimeType mimeType:[ctype stringValue]];
75 charset = [[ctype valueOfParameter:NGMimeParameterTextCharset]
79 if (!UseFoundationStringEncodingForMimeText) {
83 if (![[charset lowercaseString] isEqualToString:@"us-ascii"] &&
85 body = [NSString stringWithData:_data usingEncodingNamed:charset];
89 NSStringEncoding encoding;
91 encoding = [NGMimeType stringEncodingForCharset:charset];
93 body = [[[NSString alloc]
95 encoding:encoding] autorelease];
100 @end /* NGMimeTextBodyParser */