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 "NGMimeHeaderFieldGenerator.h"
23 #include "NGMimeHeaderFields.h"
26 @implementation NGMimeContentDispositionHeaderFieldGenerator
32 - (NSData *)generateDataForHeaderFieldNamed:(NSString *)_headerField
35 NGMimeContentDispositionHeaderField *field;
41 [self logWithFormat:@"WARNING(%s): Content-Disposition field is empty",
46 if ([_value isKindOfClass:[NSString class]])
47 return [_value dataUsingEncoding:NSUTF8StringEncoding];
49 // TODO: move the stuff below to some NSString or NSData category?
51 data = [NSMutableData dataWithCapacity:64];
53 [data appendBytes:[tmp cString] length:[tmp length]];
54 tmp = [field filename];
56 [data appendBytes:"; " length:2];
57 [data appendBytes:"filename=\"" length:10];
64 len = [tmp cStringLength];
65 ctmp = malloc(len + 3);
66 [tmp getCString:(char *)ctmp]; ctmp[len] = '\0';
70 if ((unsigned char)ctmp[cnt] > 127) {
77 char iso[] = "=?iso-8859-15?q?";
80 unsigned isoEndLen = 2;
88 #if APPLE_Foundation_LIBRARY || NeXT_Foundation_LIBRARY
89 data = [tmp dataUsingEncoding:NSISOLatin1StringEncoding];
91 data = [tmp dataUsingEncoding:NSISOLatin9StringEncoding];
96 [data getBytes:ctmp]; ctmp[len] = '\0';
99 desLen = len * 3 + 20;
100 des = calloc(desLen + 10, sizeof(char));
102 memcpy(des, ctmp, cnt);
103 memcpy(des + cnt, iso, isoLen);
105 NGEncodeQuotedPrintableMime((unsigned char *)ctmp + cnt, len - cnt,
106 (unsigned char *)des + cnt + isoLen,
107 desLen - cnt - isoLen);
108 if ((int)desLen != -1) {
109 memcpy(des + cnt + isoLen + desLen, isoEnd, isoEndLen);
110 [data appendBytes:des length:(cnt + isoLen + desLen + isoEndLen)];
113 [self logWithFormat:@"WARNING(%s:%i): An error occour during "
114 @"quoted-printable decoding",
115 __PRETTY_FUNCTION__, __LINE__];
120 [data appendBytes:ctmp length:len];
123 // [data appendBytes:[tmp cString] length:[tmp length]];
124 [data appendBytes:"\"" length:1];
129 @end /* NGMimeContentDispositionHeaderFieldGenerator */