]> err.no Git - sope/blob - sope-mime/NGMime/NGMimeRFC822DateHeaderFieldGenerator.m
fixed copyrights for 2005
[sope] / sope-mime / NGMime / NGMimeRFC822DateHeaderFieldGenerator.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "NGMimeHeaderFieldGenerator.h"
23 #include "NGMimeHeaderFields.h"
24 #include "common.h"
25
26 @implementation NGMimeRFC822DateHeaderFieldGenerator
27
28 + (int)version {
29   return 2;
30 }
31
32 - (NSData *)generateDataForHeaderFieldNamed:(NSString *)_headerField
33   value:(id)_value
34 {
35   NSCalendarDate *date       = nil;
36   NSString       *dateString = nil;
37   
38   if ([_value isKindOfClass:[NSString class]])
39     return [_value dataUsingEncoding:NSUTF8StringEncoding];
40   
41   date = _value;
42
43   if (date == nil)
44     return [NSData data];
45   
46   if ([date respondsToSelector:@selector(descriptionWithCalendarFormat:)]) {
47     // TODO: do not use -descriptionWithCalendarFormat: !
48     //       - slow
49     //       - does not necessarily encode an English dayname!
50     dateString = [date descriptionWithCalendarFormat:
51                          @" %a, %d %b %Y %H:%M:%S %z"];
52   }
53   else
54     dateString = [date stringValue];
55   
56   return [dateString dataUsingEncoding:NSUTF8StringEncoding];
57 }
58
59 @end /* NGMimeRFC822DateHeaderFieldGenerator */