]> err.no Git - sope/blob - sope-mime/samples/sievetool.m
added Kolab sample data
[sope] / sope-mime / samples / sievetool.m
1 /*
2   Copyright (C) 2004 Helge Hess
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 <NGImap4/NGSieveClient.h>
23 #include "common.h"
24
25 static NSURL *getDefaultsURL(void)  {
26   NSUserDefaults *ud;
27   NSString *pwd, *user, *host;
28   NSString *url;
29
30   ud = [NSUserDefaults standardUserDefaults];
31   
32   if ((url = [ud stringForKey:@"url"]) != nil)
33     return [NSURL URLWithString:url];
34   
35   user = [ud stringForKey:@"user"];
36   pwd  = [ud stringForKey:@"password"];
37   host = [ud stringForKey:@"host"];
38   
39   url = [@"http://" stringByAppendingString:user];
40   url = [url stringByAppendingString:@":"];
41   url = [url stringByAppendingString:pwd];
42   url = [url stringByAppendingString:@"@"];
43   url = [url stringByAppendingString:host];
44   url = [url stringByAppendingString:@":2000/"];
45   return [NSURL URLWithString:url];
46 }
47
48 static int test(NSArray *args) {
49   NSUserDefaults *ud;
50   NGSieveClient  *client;
51   NSURL *url;
52   id res;
53
54   ud = [NSUserDefaults standardUserDefaults];
55   
56   url = getDefaultsURL();
57   NSLog(@"check URL: %@", url);
58   
59   client = [[NGSieveClient alloc] initWithURL:url];
60   NSLog(@"  client: %@", client);
61   
62   res = [client login:[url user] password:[url password]];
63   if (![[res valueForKey:@"result"] boolValue]) {
64     NSLog(@"could not login %@: %@", [url user], client);
65     return 1;
66   }
67   
68   NSLog(@"  login %@: %@", [url user], res);
69   NSLog(@"  client: %@", client);
70   
71   res = [client listScripts];
72   NSLog(@"  list: %@", res);
73   
74   res = [client getScript:@"ogo"];
75   NSLog(@"  get 'ogo': %@", res);
76   
77   return 0;
78 }
79
80 int main(int argc, char **argv, char **env) {
81   NSAutoreleasePool *pool;
82   int res;
83   
84   pool = [NSAutoreleasePool new];
85 #if LIB_FOUNDATION_LIBRARY  
86   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
87 #endif
88   
89   res = test([[NSProcessInfo processInfo] argumentsWithoutDefaults]);
90   
91   [pool release];
92   exit(0);
93   /* static linking */
94   [NGExtensions class];
95   return 0;
96 }