2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
21 // $Id: NGMimeContentDispositionHeaderFieldGenerator.m 1 2004-08-20 10:08:27Z znek $
23 #include "NGMimeHeaderFieldGenerator.h"
24 #include "NGMimeHeaderFields.h"
27 @implementation NGMimeContentDispositionHeaderFieldGenerator
33 - (NSData *)generateDataForHeaderFieldNamed:(NSString *)_headerField
36 NGMimeContentDispositionHeaderField *field;
42 [self logWithFormat:@"WARNING(%s): Content-Disposition field is empty",
47 if ([_value isKindOfClass:[NSString class]])
48 return [_value dataUsingEncoding:NSUTF8StringEncoding];
50 // TODO: move the stuff below to some NSString or NSData category?
52 data = [NSMutableData dataWithCapacity:64];
54 [data appendBytes:[tmp cString] length:[tmp length]];
55 tmp = [field filename];
57 [data appendBytes:"; " length:2];
58 [data appendBytes:"filename=\"" length:10];
65 len = [tmp cStringLength];
66 ctmp = malloc(len + 3);
67 [tmp getCString:ctmp]; ctmp[len] = '\0';
71 if ((unsigned char)ctmp[cnt] > 127) {
78 char iso[] = "=?iso-8859-15?q?";
81 unsigned isoEndLen = 2;
89 #if APPLE_Foundation_LIBRARY || NeXT_Foundation_LIBRARY
90 data = [tmp dataUsingEncoding:NSISOLatin1StringEncoding];
92 data = [tmp dataUsingEncoding:NSISOLatin9StringEncoding];
97 [data getBytes:ctmp]; ctmp[len] = '\0';
100 desLen = len * 3 + 20;
101 des = calloc(desLen + 10, sizeof(char));
103 memcpy(des, ctmp, cnt);
104 memcpy(des + cnt, iso, isoLen);
106 NGEncodeQuotedPrintableMime(ctmp + cnt, len - cnt,
108 desLen - cnt - isoLen);
109 if ((int)desLen != -1) {
110 memcpy(des + cnt + isoLen + desLen, isoEnd, isoEndLen);
111 [data appendBytes:des length:(cnt + isoLen + desLen + isoEndLen)];
114 [self logWithFormat:@"WARNING(%s:%i): An error occour during "
115 @"quoted-printable decoding",
116 __PRETTY_FUNCTION__, __LINE__];
121 [data appendBytes:ctmp length:len];
124 // [data appendBytes:[tmp cString] length:[tmp length]];
125 [data appendBytes:"\"" length:1];
130 @end /* NGMimeContentDispositionHeaderFieldGenerator */