]> err.no Git - sope/blob - sope-mime/samples/sievetool.m
improved Sieve client
[sope] / sope-mime / samples / sievetool.m
1 /*
2   Copyright (C) 2004 Helge Hess
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
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   if ((res = [client login:[url user] password:[url password]]) == nil) {
63     NSLog(@"could not login %@: %@", [url user], client);
64     return 1;
65   }
66   
67   NSLog(@"  login %@: %@", [url user], res);
68   NSLog(@"  client: %@", client);
69   
70   res = [client listScripts];
71   NSLog(@"  list: %@", res);
72   
73   res = [client getScript:@"ogo"];
74   NSLog(@"  get 'ogo': %@", res);
75   
76   return 0;
77 }
78
79 int main(int argc, char **argv, char **env) {
80   NSAutoreleasePool *pool;
81   int res;
82   
83   pool = [NSAutoreleasePool new];
84 #if LIB_FOUNDATION_LIBRARY  
85   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
86 #endif
87   
88   res = test([[NSProcessInfo processInfo] argumentsWithoutDefaults]);
89   
90   [pool release];
91   exit(0);
92   /* static linking */
93   [NGExtensions class];
94   return 0;
95 }