2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
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
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.
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
25 static void usage(void) {
26 fprintf(stderr, "usage: imap_tool"
33 static void runAction(NGImap4Client *client, NSString *action, NSString *arg) {
34 if ([action length] == 0)
37 if ([action isEqualToString:@"select"]) {
38 result = [client select:arg];
40 else if ([action isEqualToString:@"thread"]) {
41 result = [client threadBySubject:[arg boolValue] charset:nil];
43 else if ([action isEqualToString:@"list"]) {
44 result = [client list:arg pattern:@"*"];
46 else if ([action isEqualToString:@"fetch"]) {
49 args = [arg componentsSeparatedByString:@":"];
50 result = [client fetchFrom:[[args objectAtIndex:0] intValue]
51 to:[[args objectAtIndex:1] intValue]
52 parts:[args subarrayWithRange:
53 NSMakeRange(2,[args count] - 2)]];
56 NSLog(@"action: %@:%@ : %@", action, arg, result);
59 static void run(void) {
60 NSString *login, *pwd, *host;
62 NGImap4Client *client;
65 ud = [NSUserDefaults standardUserDefaults];
67 if ((login = [ud stringForKey:@"login"]) == nil)
69 if ((pwd = [ud stringForKey:@"pwd"]) == nil)
71 if ((host = [ud stringForKey:@"host"]) == nil)
74 client = [NGImap4Client clientWithHost:host];
76 NSLog(@"attempt login '%@' ...", login);
77 [client login:login password:pwd];
78 NSLog(@" got client: %@", client);
80 for (cnt = 0; YES; cnt++) {
85 action = [ud stringForKey:
86 [NSString stringWithFormat:@"action_%d", cnt]];
87 arg = [ud stringForKey:
88 [NSString stringWithFormat:@"arg_%d", cnt]];
89 if (!runAction(client, action, arg))
94 int main(int argc, char **argv, char **env) {
95 NSAutoreleasePool *pool;
97 #if LIB_FOUNDATION_LIBRARY
98 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
101 pool = [[NSAutoreleasePool alloc] init];