]> err.no Git - sope/blob - sope-mime/NGMime/NGMimeStringHeaderFieldParser.m
fixed library version
[sope] / sope-mime / NGMime / NGMimeStringHeaderFieldParser.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "NGMimeHeaderFieldParser.h"
24 #include "NGMimeHeaderFields.h"
25 #include "NGMimeUtilities.h"
26 #include "common.h"
27
28 @implementation NGMimeStringHeaderFieldParser
29
30 static BOOL StripLeadingSpaces = NO;
31
32 + (int)version {
33   return 2;
34 }
35 + (void)initialize {
36   StripLeadingSpaces = [self doesStripLeadingSpaces];
37 }
38
39 - (id)initWithRemoveComments:(BOOL)_flag {
40   if ((self = [super init])) {
41     self->removeComments = _flag;
42   }
43   return self;
44 }
45 - (id)init {
46   return [self initWithRemoveComments:YES];
47 }
48
49 /* operation */
50
51 - (id)parseValue:(NSString *)_value ofHeaderField:(NSString *)_field {
52   // TODO: fixup
53   unsigned len = [_value length];
54   unsigned cnt;
55   unichar  src[len+1];
56   NSString *res;
57
58   if (_value == nil)
59     return nil;
60   
61   if (len == 0)
62     return @"";
63
64   res = self->removeComments ? [self removeCommentsFromValue:_value] : _value;
65
66   if (StripLeadingSpaces) { /* currently be done during header field parsing */
67     [res getCharacters:src];
68     // strip leading spaces
69     cnt     = 0;
70   
71     while (isRfc822_LWSP(src[cnt]) && (len > 0)) {
72       cnt++;
73       len--;
74     }
75     if (cnt > 0)
76       res = [[[NSString alloc] initWithCharacters:src+cnt length:len]
77                         autorelease];
78   }
79   return res;
80 }
81
82 /* description */
83
84 - (NSString *)description {
85   return [NSString stringWithFormat:
86                      @"<MimeStringHeaderFieldParser: id=0x%08X"
87                      @" removesComments=%s>",
88                      (unsigned)self, self->removeComments ? "YES" : "NO"];
89 }
90
91 @end /* NGMimeStringHeaderFieldParser */