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 "NGMimeHeaderFields.h"
24 #include "NGMimeUtilities.h"
27 NGMime_DECLARE NSString *NGMimeContentDispositionInlineType = @"inline";
28 NGMime_DECLARE NSString *NGMimeContentDispositionAttachmentType = @"attachment";
29 NGMime_DECLARE NSString *NGMimeContentDispositionFormType = @"form-data";
31 @implementation NGMimeContentDispositionHeaderField
33 static int MimeLogEnabled = -1;
40 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
42 MimeLogEnabled = [ud boolForKey:@"MimeLogEnabled"] ? 1 : 0;
45 - (id)initWithString:(NSString *)_value {
46 unsigned len = [_value length];
51 @"WARNING(%s): no value for disposition header value!",
53 self = [self autorelease];
57 [_value getCharacters:buf];
60 if ((self = [super init])) {
64 // skip leading spaces
66 while (isRfc822_LWSP(buf[cnt])) cnt++;
68 if (buf[cnt] == '\0') {
70 [self logWithFormat:@"WARNING(%s): no value for disposition header"
71 @" value !", __PRETTY_FUNCTION__];
72 self = [self autorelease];
77 while ((buf[cnt] != ';') && (buf[cnt] != '\0') && !isRfc822_LWSP(buf[cnt]))
82 [self logWithFormat:@"WARNING(%s): found no type in disposition "
83 @"header value (%@) !", __PRETTY_FUNCTION__, _value];
84 self = [self autorelease];
88 self->type = [[[NSString alloc]
89 initWithCharacters:buf+start length:(cnt - start)]
92 self->type = [self->type lowercaseString];
93 self->type = [self->type retain];
95 if (self->type == nil) {
97 [self logWithFormat:@"WARNING(%s): found no type in disposition header "
98 @"value (%@) !", __PRETTY_FUNCTION__, _value];
99 self = [self autorelease];
102 self->parameters = [parseParameters(self, _value, buf+cnt) retain];
108 return [self initWithString:nil];
112 [self->type release];
113 [self->parameters release];
126 return [self->parameters objectForKey:@"name"];
128 - (NSString *)filename {
131 fn = [self->parameters objectForKey:@"filename"];
142 - (NSString *)valueOfParameterWithName:(NSString *)_name {
143 return [self->parameters objectForKey:_name];
146 - (BOOL)valueNeedsQuotes:(NSString *)_parameterValue {
147 int len = [_parameterValue length];
148 unichar cstr[len + 1];
151 [_parameterValue getCharacters:cstr];
153 for (cnt = 0; cnt < len; cnt++) {
155 if (isMime_SpecialByte(cstr[cnt]))
164 - (NSString *)parametersAsString {
167 if ((names = [self->parameters keyEnumerator])) {
168 NSMutableString *result = [NSMutableString stringWithCapacity:64];
171 while ((name = [names nextObject])) {
172 id value = [[parameters objectForKey:name] stringValue];
173 [result appendString:@"; "];
174 [result appendString:name];
175 [result appendString:@"="];
176 if ([self valueNeedsQuotes:value]) {
177 [result appendString:@"\""];
178 [result appendString:value];
179 [result appendString:@"\""];
182 [result appendString:value];
190 - (NSString *)stringValue {
191 NSMutableString *str;
193 str = [NSMutableString stringWithCapacity:20];
194 [str appendString:type];
196 NSString *paras = [self parametersAsString];
197 if (paras) [str appendString:paras];
204 - (NSString *)description {
207 d = [[NSMutableString alloc] init];
209 [d appendFormat:@"<%@[0x%08X]: type=%@",
210 NSStringFromClass([self class]), self, self->type];
212 if (self->parameters)
213 [d appendFormat:@" parameters=%@", self->parameters];
215 [d appendString:@">"];
216 return [d autorelease];
219 @end /* NGMimeContentDispositionHeaderField */