]> err.no Git - sope/blob - sope-mime/NGMime/NGMimeHeaderFieldGenerator.m
minor code cleanups
[sope] / sope-mime / NGMime / NGMimeHeaderFieldGenerator.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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 "NGMimeHeaderFieldGenerator.h"
24 #include "NGMimeHeaderFields.h"
25 #include "common.h"
26
27 @implementation NGMimeHeaderFieldGenerator
28
29 + (int)version {
30   return 2;
31 }
32
33 + (id)headerFieldGenerator {
34   return [[[self alloc] init] autorelease];
35 }
36
37 - (NSData *)generateDataForHeaderFieldNamed:(NSString *)_headerField
38   value:(id)_value
39 {
40   [self subclassResponsibility:_cmd];
41   return nil;
42 }
43
44 @end /* NGMimeHeaderFieldGenerator */
45
46 #if 1
47 int NGEncodeQuotedPrintableMime
48 (const unsigned char *_src, unsigned _srcLen,
49  unsigned char *_dest, unsigned _destLen) 
50 {
51   /* decode also spaces*/
52   unsigned cnt      = 0;
53   unsigned destCnt  = 0;
54   unsigned char
55     hexT[16] = {'0','1','2','3','4','5','6','7','8',
56                 '9','A','B','C','D','E','F'};
57   
58   if (_srcLen > _destLen)
59     return -1;
60   
61   for (cnt = 0; (cnt < _srcLen) && (destCnt < _destLen); cnt++) {
62     register unsigned char c = _src[cnt];
63     
64     if (((c > 47) && (c < 58)) ||
65         ((c > 64) && (c < 91)) ||
66         ((c > 96) && (c < 123))) {
67       // no quoting
68       _dest[destCnt] = c;
69       destCnt++;
70     }
71     else { // need to be quoted
72       if (_destLen - destCnt > 2) {
73         _dest[destCnt] = '='; destCnt++;
74         _dest[destCnt] = hexT[(c >> 4) & 15]; destCnt++;
75         _dest[destCnt] = hexT[c & 15]; destCnt++;
76       }
77       else 
78         break;
79     }
80   }
81   if (cnt < _srcLen)
82     return -1;
83   return destCnt;
84 }
85
86 #else /* TODO: this one was declared in NGMimeMessageGenerator, any diff? */
87
88 static int NGEncodeQuotedPrintableMime(const char *_src, unsigned _srcLen,
89                                        char *_dest, unsigned _destLen) {
90   /* decode also spaces*/
91   unsigned cnt      = 0;
92   unsigned destCnt  = 0;
93   char     hexT[16] = {'0','1','2','3','4','5','6','7','8',
94                        '9','A','B','C','D','E','F'};
95   
96   if (_srcLen > _destLen)
97     return -1;
98   
99   for (cnt = 0; (cnt < _srcLen) && (destCnt < _destLen); cnt++) {
100     char c = _src[cnt];
101
102     if (((c > 47) && (c < 58)) ||
103         ((c > 64) && (c < 91)) ||
104         ((c > 96) && (c < 123))) { // no quoting
105       _dest[destCnt++] = c;
106     }
107     else { // need to be quoted
108       if (_destLen - destCnt > 2) {
109         _dest[destCnt++] = '=';
110         _dest[destCnt++] = hexT[(c >> 4) & 15];
111         _dest[destCnt++] = hexT[c & 15];
112       }
113       else 
114         break;
115     }
116   }
117   if (cnt < _srcLen)
118     return -1;
119   return destCnt;
120 }
121
122 #endif