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 "NGMimeHeaderFieldParser.h"
24 #include "NGMimeHeaderFields.h"
25 #include "NGMimeUtilities.h"
27 #include <NGMime/NGMimePartParser.h>
29 @implementation NGMimeHeaderFieldParser
31 static int MimeLogEnabled = -1;
32 static int StripLeadingSpaces = -1;
35 NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
37 if (MimeLogEnabled == -1)
38 MimeLogEnabled = [ud boolForKey:@"MimeLogEnabled"]?1:0;
39 if (StripLeadingSpaces == -1)
40 StripLeadingSpaces = [ud boolForKey:@"StripLeadingSpaces"]?1:0;
42 + (BOOL)isMIMELogEnabled {
43 return MimeLogEnabled ? YES : NO;
45 + (BOOL)doesStripLeadingSpaces {
46 return StripLeadingSpaces ? YES : NO;
53 - (NSString *)removeCommentsFromValue:(NSString *)_rawValue {
54 unsigned int len = [_rawValue length];
55 unichar bytes[len + 1];
59 if (_rawValue == NULL) return nil;
61 [_rawValue getCharacters:bytes];
66 while ((cnt < len) && (bytes[cnt] != '(')) cnt++;
69 unichar result[len+1];
70 int resLen, commentNesting, begin;
78 for (cnt = 0; cnt < len; cnt++) {
79 if (commentNesting == 0) {
80 if (isRfc822_QUOTE(bytes[cnt])) {
82 while ((cnt < len) && !isRfc822_QUOTE(bytes[cnt]))
85 else if (bytes[cnt] == '(') {
88 if ((cnt - begin) > 0) {
91 for (c = begin; c < cnt; c++)
92 result[resLen++] = bytes[c];
98 if (bytes[cnt] == ')') {
100 if (commentNesting == 0)
103 else if (bytes[cnt] == '(')
108 if ((cnt - begin) > 0) {
111 for (c = begin; c < cnt; c++)
112 result[resLen++] = bytes[c];
114 str = [[[NSString alloc] initWithCharacters:result length:resLen]
121 if (MimeLogEnabled) {
122 if (str != _rawValue) {
123 [self logWithFormat:@"%s:%d remove comment [%@] -> [%@]",
124 __PRETTY_FUNCTION__, __LINE__, _rawValue, str];
130 - (NSData *)quotedPrintableDecoding:(NSData *)_value {
134 - (id)parseValue:(NSString *)_data ofHeaderField:(NSString *)_field {
136 NSLog(@"ERROR(%s): subclass should override this method: %@",
137 __PRETTY_FUNCTION__, self);
141 @end /* NGMimeHeaderFieldParser */