]> err.no Git - sope/blob - sope-core/samples/test_qpdecode.m
deleted moved files (not sure what went wrong before ...)
[sope] / sope-core / samples / test_qpdecode.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 /*
24   check whether the quoted printable MIME decoding works ...
25 */
26
27 #include "common.h"
28
29 static void test(void) {
30   static unsigned char *fields[] = {
31     "attachment; filename=\"Mappe langerp=?iso-8859-15?q?=FC=E4=F6=20Name=F6=F6=F6=201234456=2Exls?=\"",
32     "Umlaute: =?iso-8859-15?q?=FC=E4=F6?=",
33     "keine Umlaute: =?iso-8859-15?q?keine Umlaute?=",
34     "=?iso-8859-15?q?keine Umlaute?=",
35     "=?iso-8859-15?q?=FC=E4=F6?=",
36     "",
37     "hello world !",
38     "??doit??",
39     NULL
40   };
41   unsigned char *field;
42   int i;
43   
44   for (i = 0; (field = fields[i]); i++) {
45     NSData *fieldData;
46     id result;
47     
48     NSLog(@"decoding field: '%s'", field);
49     fieldData = [NSData dataWithBytes:field length:strlen(field)];
50     NSLog(@"  length: %i", [fieldData length]);
51     
52     result = [fieldData decodeQuotedPrintableValueOfMIMEHeaderField:
53                           @"content-disposition"];
54     
55     if (result == nil) {
56       NSLog(@"  got no result for field data %@ !!!", fieldData);
57     }
58     else if ([result isKindOfClass:[NSData class]]) {
59       NSLog(@"  got a data, length %i: %@", [result length], result);
60     }
61     else if ([result isKindOfClass:[NSString class]]) {
62       NSLog(@"  got a string, length %i: '%@'", [result length], result);
63     }
64     else {
65       NSLog(@"  got an unexpected object, class %@: %@",
66             NSStringFromClass([result class]), result);
67     }
68   }
69 }
70
71 int main(int argc, char **argv, char **env) {
72   NSAutoreleasePool *pool;
73   
74   pool = [NSAutoreleasePool new];
75   
76 #if LIB_FOUNDATION_LIBRARY  
77   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
78 #endif
79   
80   test();
81   
82   [pool release];
83   exit(0);
84   /* static linking */
85   [NGExtensions class];
86   return 0;
87 }