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 "NGMimeMultipartBody.h"
24 #include "NGMimeBodyParser.h"
27 @implementation NGMimeMultipartBody
33 - (id)initWithPart:(id<NGMimePart>)_part {
35 NSLog(@"ERROR(%s): no part provided for multipart body !",
40 if ((self = [super init])) {
41 self->flags.isParsed = YES;
45 - (id)initWithPart:(id<NGMimePart>)_part data:(NSData *)_data
48 if ((self = [self initWithPart:_part])) {
49 self->flags.isParsed = NO;
50 self->rawData = [_data retain];
51 self->delegate = _del;
56 return [self initWithPart:nil];
60 [self->rawData release];
61 [self->prefix release];
62 [self->suffix release];
63 [self->bodyParts release];
70 NGMimeMultipartBodyParser *parser = [[NGMimeMultipartBodyParser alloc] init];
72 self->flags.isParsed = YES;
74 if (![parser parseBody: self
75 ofMultipart:self->part
77 delegate: self->delegate])
78 NSLog(@"%@: error during parsing of multipart body (ignored)", self);
82 [parser release]; parser = nil;
85 static inline void _checkParse(NGMimeMultipartBody *self) {
86 if (!self->flags.isParsed) [self parse];
88 static inline void _checkArray(NGMimeMultipartBody *self) {
89 if (!self->flags.isParsed) [self parse];
90 if (self->bodyParts == nil)
91 self->bodyParts = [[NSMutableArray alloc] init];
96 - (id<NGMimePart>)part { // the part the body belongs to
101 return self->bodyParts;
104 - (void)addBodyPart:(id<NGPart>)_part {
106 [self->bodyParts addObject:_part];
108 - (void)addBodyPart:(id<NGPart>)_part atIndex:(int)_idx {
110 [self->bodyParts insertObject:_part atIndex:_idx];
113 - (void)removeBodyPart:(id<NGPart>)_part {
115 [self->bodyParts removeObject:_part];
117 - (void)removeBodyPartAtIndex:(int)_idx {
119 [self->bodyParts removeObjectAtIndex:_idx];
122 - (void)setPrefix:(NSString *)_prefix {
123 if (self->prefix != _prefix) {
124 [self->prefix release];
125 self->prefix = [_prefix copy];
128 - (NSString *)prefix {
132 - (void)setSuffix:(NSString *)_suffix {
133 if (self->suffix != _suffix) {
134 [self->suffix release];
135 self->suffix = [_suffix copy];
138 - (NSString *)suffix {
144 - (NSString *)description {
145 NSMutableString *d = [NSMutableString stringWithCapacity:64];
147 [d appendFormat:@"<%@[0x%08X]:", NSStringFromClass([self class]), self];
149 if (self->flags.isParsed) {
150 if (self->prefix) [d appendFormat:@" prefix=%@", self->prefix];
151 if (self->suffix) [d appendFormat:@" suffix=%@", self->suffix];
152 if (self->bodyParts) [d appendFormat:@" parts=%@", self->bodyParts];
154 if (self->rawData) [d appendFormat:@" data=%@", self->rawData];
156 [d appendString:@">"];
160 @end /* NGMimeMultipartBody */