}
- (NSDictionary *)login {
+ /*
+ On failure returns a dictionary with those keys:
+ 'result' - a boolean => false
+ 'reason' - reason why login failed
+ 'RawResponse' - the raw IMAP4 response
+ On success:
+ 'result' - a boolean => true
+ 'expunge' - an array (containing what?)
+ 'RawResponse' - the raw IMAP4 response
+ */
NGHashMap *map;
NSString *s, *log;
return nil;
self->isLogin = YES;
-
+
s = [NSString stringWithFormat:@"login \"%@\" \"%@\"",
self->login, self->password];
log = [NSString stringWithFormat:@"login %@ <%@>",
(self->password != nil) ? @"PASSWORD" : @"NO PASSWORD"];
map = [self processCommand:s logText:log];
- if (self->selectedFolder)
+ if (self->selectedFolder != nil)
[self select:self->selectedFolder];
self->isLogin = NO;
Instead of you should use the pattern to get the expected result.
If folder is NIL it would be set to empty string ''.
If pattern is NIL it would be set to ''.
+
+ The result dict contains the following keys:
+ 'result' - a boolean
+ 'list' - a dictionary (key is folder name, value is flags)
+ 'RawResponse' - the raw IMAP4 response
*/
NSAutoreleasePool *pool;
NGHashMap *map;
02111-1307, USA.
*/
+#include <NGImap4/NGImap4.h>
#include "common.h"
-#include "NGImap4.h"
static void usage(void) {
fprintf(stderr, "usage: imap_tool"
" -login <login>"
" -pwd <pwd>"
- " [-host <host>]\n");
+ " [-host <host>]\n"
+ " (-action0 select|thread|list|fetch [-arg0 <arg>])*"
+ "\n"
+ " select arg: <string>\n"
+ " thread arg: <bool> (threadBySubject?)\n"
+ " list arg: <string>\n"
+ " fetch arg: <from>:<to>(:<parts>)+\n"
+ );
exit(1);
}
-static void runAction(NGImap4Client *client, NSString *action, NSString *arg) {
+static BOOL runAction(NGImap4Client *client, NSString *action, NSString *arg) {
+ id result;
+
if ([action length] == 0)
- return;
-
+ return NO;
+
if ([action isEqualToString:@"select"]) {
result = [client select:arg];
}
}
else if ([action isEqualToString:@"fetch"]) {
NSArray *args;
-
- args = [arg componentsSeparatedByString:@":"];
- result = [client fetchFrom:[[args objectAtIndex:0] intValue]
- to:[[args objectAtIndex:1] intValue]
- parts:[args subarrayWithRange:
- NSMakeRange(2,[args count] - 2)]];
+ NSArray *parts;
+ int from, to;
+
+ args = [arg componentsSeparatedByString:@":"];
+ parts = [args subarrayWithRange:NSMakeRange(2,[args count] - 2)];
+ from = [[args objectAtIndex:0] intValue];
+ to = [[args objectAtIndex:1] intValue];
+
+ result = [client fetchFrom:from to:to parts:parts];
}
NSLog(@"action: %@:%@ : %@", action, arg, result);
+ return YES;
}
static void run(void) {
NSString *login, *pwd, *host;
NSUserDefaults *ud;
NGImap4Client *client;
+ NSDictionary *res;
int cnt;
ud = [NSUserDefaults standardUserDefaults];
host = @"localhost";
client = [NGImap4Client clientWithHost:host];
+ NSLog(@"got client: %@", client);
NSLog(@"attempt login '%@' ...", login);
- [client login:login password:pwd];
- NSLog(@" got client: %@", client);
+ res = [client login:login password:pwd];
+ if (![[res valueForKey:@"result"] boolValue]) {
+ NSLog(@" login failed: %@", res);
+ exit(2);
+ }
for (cnt = 0; YES; cnt++) {
- NSString *action;
- NSString *arg;
- id result;
-
- action = [ud stringForKey:
- [NSString stringWithFormat:@"action_%d", cnt]];
- arg = [ud stringForKey:
- [NSString stringWithFormat:@"arg_%d", cnt]];
- if (!runAction(client, action, arg))
- break;
+ NSString *action;
+ NSString *arg;
+
+ action = [ud stringForKey:[NSString stringWithFormat:@"action%d", cnt]];
+ arg = [ud stringForKey:[NSString stringWithFormat:@"arg%d", cnt]];
+ if (!runAction(client, action, arg))
+ break;
}
}