2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "NGMimeMessageParser.h"
23 #include "NGMimeMessage.h"
27 @interface NGMimeMessageParserDelegate : NSObject
30 @implementation NGMimeMessageParserDelegate
32 static Class NGMimeMessageParserClass = Nil;
35 if (NGMimeMessageParserClass == Nil)
36 NGMimeMessageParserClass = [NGMimeMessageParser class];
39 - (id)parser:(NGMimePartParser *)_p parseHeaderField:(NSString *)_field
42 NGMimeMessageParser *parser = nil;
45 if ([_p isKindOfClass:NGMimeMessageParserClass])
48 parser = [[NGMimeMessageParserClass alloc] init];
49 v = [parser valueOfHeaderField:_field data:_data];
50 [parser release]; parser = nil;
54 - (id<NGMimeBodyParser>)parser:(NGMimePartParser *)_parser
55 bodyParserForPart:(id<NGMimePart>)_part
58 NGMimeType *contentType;
60 ctype = [_part contentType];
62 contentType = ([ctype isKindOfClass:[NGMimeType class]])
64 : [NGMimeType mimeType:[ctype stringValue]];
66 if ([[contentType type] isEqualToString:@"message"] &&
67 [[contentType subType] isEqualToString:@"rfc822"]) {
68 return [[[NGMimeRfc822BodyParser alloc] init] autorelease];
74 @end /* NGMimeMessageParserDelegate */
76 @implementation NGMimeMessageParser
78 static Class NSStringClass = Nil;
84 NSAssert2([super version] == 3,
85 @"invalid superclass (%@) version %i !",
86 NSStringFromClass([self superclass]), [super version]);
87 if (NSStringClass == Nil)
88 NSStringClass = [NSString class];
92 if ((self = [super init])) {
93 [self setDelegate:[NGMimeMessageParserDelegate new]];
100 - (id<NGMimePart>)producePartWithHeader:(NGHashMap *)_header {
101 return [NGMimeMessage messageWithHeader:_header];
104 /* header field specifics */
106 - (id)valueOfHeaderField:(NSString *)_name data:(id)_data {
107 // check data for 8-bit headerfields (RFC 2047 (MIME PART III))
109 /* check whether we got passed a string ... */
110 if ([_data isKindOfClass:NSStringClass]) {
111 NSLog(@"%s: WARNING unexpected class for headerfield %@ (value %@)",
112 __PRETTY_FUNCTION__, _name, _data);
113 return [super valueOfHeaderField:_name data:_data];
115 _data = [_data decodeQuotedPrintableValueOfMIMEHeaderField:_name];
116 return [super valueOfHeaderField:_name data:_data];
119 @end /* NGMimeMessageParser */
123 @implementation NGMimeRfc822BodyParser
129 NSAssert2([super version] == 2,
130 @"invalid superclass (%@) version %i !",
131 NSStringFromClass([self superclass]), [super version]);
134 - (id)parseBodyOfPart:(id<NGMimePart>)_part data:(NSData *)_data
138 id parser; // NGMimeMessageParser
140 parser = [[NGMimeMessageParser alloc] init];
141 body = [parser parsePartFromData:_data];
142 [parser release]; parser = nil;
147 @end /* NGMimeRfc822BodyParser */