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 "NGMimeBodyPart.h"
24 #include "NGMimeType.h"
26 #include "NGMimeFileData.h"
27 #include <NGMime/NGMimePartParser.h>
29 @implementation NGMimeBodyPart
35 static NGMimeType *defaultType = nil;
38 static BOOL isInitialized = NO;
43 [[NGMimeType mimeType:@"text/plain; charset=us-ascii"] retain];
47 + (id)bodyPartWithHeader:(NGHashMap *)_header {
48 return [[[self alloc] initWithHeader:_header] autorelease];
51 - (id)initWithHeader:(NGHashMap *)_header {
52 if ((self = [super init])) {
53 self->header = [_header retain];
59 return [self initWithHeader:nil];
63 [self->header release];
70 - (NSEnumerator *)valuesOfHeaderFieldWithName:(NSString *)_name {
71 return [self->header objectEnumeratorForKey:_name];
73 - (NSEnumerator *)headerFieldNames {
74 return [self->header keyEnumerator];
77 - (void)setBody:(id)_body {
78 ASSIGN(self->body, _body);
86 - (NGMimeType *)contentType {
88 static NGMimeHeaderNames *Fields = NULL;
91 Fields = (NGMimeHeaderNames *)[NGMimePartParser headerFieldNames];
94 type = [self->header objectForKey:Fields->contentType];
96 if (![type isKindOfClass:[NGMimeType class]])
97 type = [NGMimeType mimeType:[type stringValue]];
99 return (type != nil ? type : defaultType);
102 - (NSString *)contentId {
103 return [[self->header objectForKey:@"content-id"] stringValue];
106 - (NSArray *)contentLanguage {
109 value = [self->header objectForKey:@"content-language"];
110 if (![value isKindOfClass:[NSArray class]])
111 value = [value componentsSeparatedByString:@","];
116 - (NSString *)contentMd5 {
117 return [[self->header objectForKey:@"content-md5"] stringValue];
120 - (NSString *)encoding {
121 return [[self->header objectForKey:@"content-transfer-encoding"]
125 - (NSString *)contentDescription {
126 return [[self->header objectForKey:@"content-description"] stringValue];
131 - (NSString *)description {
132 NSMutableString *d = [[NSMutableString alloc] init];
135 [d appendFormat:@"<%@[0x%08X]: header=%@",
136 NSStringFromClass([self class]), self, self->header];
138 if (b) [d appendFormat:@" bodyClass=%@", NSStringFromClass([b class])];
140 if ([b isKindOfClass:[NGMimeFileData class]]) {
141 [d appendFormat:@" body=%@", b];
143 else if ([b isKindOfClass:[NSString class]] ||
144 [b isKindOfClass:[NSData class]]) {
145 if ([b length] < 512) {
146 [d appendFormat:@" bodyLen=%i body=%@", [b length], b];
149 [d appendFormat:@" body[len=%i]", [b length]];
152 [d appendFormat:@" body=%@", b];
155 [d appendString:@">"];
157 return AUTORELEASE(d);
160 @end /* NGMimeBodyPart */