]> err.no Git - sope/blob - sope-core/samples/imap_tool.m
more code directory reorganizations
[sope] / sope-core / samples / imap_tool.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 #include "common.h"
25 #include "NGImap4.h"
26
27
28 int main(int argc, char **argv, char **env) {
29   NSAutoreleasePool *pool;
30   
31 #if LIB_FOUNDATION_LIBRARY
32   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
33 #endif
34
35   pool = [[NSAutoreleasePool alloc] init];
36
37   {
38     NSString       *login, *pwd, *host;
39     NSUserDefaults *ud;
40     NGImap4Client  *client;
41
42     ud = [NSUserDefaults standardUserDefaults];
43
44     if (!(login = [ud stringForKey:@"login"])) {
45       login = @"j";
46     }
47     if (!(pwd = [ud stringForKey:@"pwd"])) {
48       pwd = @"system";
49     }
50     if (!(host = [ud stringForKey:@"host"])) {
51       host = @"defiant";
52     }
53
54     client = [NGImap4Client clientWithHost:host];
55
56     [client login:login password:pwd];
57     NSLog(@"client %@", client);
58
59     {
60       int cnt = 0;
61       
62       while (1) {
63         NSString *action;
64         NSString *arg;
65         id       result;
66
67         action = [ud stringForKey:
68                      [NSString stringWithFormat:@"action_%d", cnt]]; 
69         arg = [ud stringForKey:
70                   [NSString stringWithFormat:@"arg_%d", cnt]];
71
72         if (![action length])
73           break;
74         
75         if ([action isEqualToString:@"select"]) {
76           result = [client select:arg];
77         }
78         else if ([action isEqualToString:@"thread"]) {
79           result = [client threadBySubject:[arg boolValue] charset:nil];
80         }
81         else if ([action isEqualToString:@"list"]) {
82           result = [client list:arg pattern:@"*"];
83         }
84         else if ([action isEqualToString:@"fetch"]) {
85           NSArray *args;
86
87           args = [arg componentsSeparatedByString:@":"];
88           result = [client fetchFrom:[[args objectAtIndex:0] intValue]
89                            to:[[args objectAtIndex:1] intValue]
90                            parts:[args subarrayWithRange:
91                                        NSMakeRange(2,[args count] - 2)]];
92         }
93         NSLog(@"action %d: %@:%@ : %@", cnt, action, arg,
94               result);
95         cnt++;
96       }
97     }
98   }
99   [pool release];
100   return 0;
101 }
102