From: helge Date: Sun, 26 Sep 2004 18:15:48 +0000 (+0000) Subject: some minor improvements to imap_tool X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b6cd3903effe584b37ca0751da99574f9fb4a6d;p=sope some minor improvements to imap_tool git-svn-id: http://svn.opengroupware.org/SOPE/trunk@173 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- diff --git a/sope-mime/NGImap4/NGImap4Client.h b/sope-mime/NGImap4/NGImap4Client.h index a0b86667..0d7f0120 100644 --- a/sope-mime/NGImap4/NGImap4Client.h +++ b/sope-mime/NGImap4/NGImap4Client.h @@ -33,6 +33,10 @@ An IMAP4 client object. This object is a thin wrapper around the TCP/IP socket (id object) connecting to the IMAP4 server. + While it is pretty near to the IMAP4 raw protocol, it already does some + normalization of responses. We might want to have something which is even + lower level in the future. + Responses are send to all registered response receivers. TODO: explain notification system. */ diff --git a/sope-mime/NGImap4/NGImap4Client.m b/sope-mime/NGImap4/NGImap4Client.m index 9594e274..3c7da2d7 100644 --- a/sope-mime/NGImap4/NGImap4Client.m +++ b/sope-mime/NGImap4/NGImap4Client.m @@ -458,6 +458,16 @@ static BOOL ImapDebugEnabled = NO; } - (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; @@ -465,7 +475,7 @@ static BOOL ImapDebugEnabled = NO; return nil; self->isLogin = YES; - + s = [NSString stringWithFormat:@"login \"%@\" \"%@\"", self->login, self->password]; log = [NSString stringWithFormat:@"login %@ <%@>", @@ -473,7 +483,7 @@ static BOOL ImapDebugEnabled = NO; (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; @@ -500,6 +510,11 @@ static BOOL ImapDebugEnabled = 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; diff --git a/sope-mime/samples/ChangeLog b/sope-mime/samples/ChangeLog index 7585aaf0..dcd9fe64 100644 --- a/sope-mime/samples/ChangeLog +++ b/sope-mime/samples/ChangeLog @@ -1,5 +1,7 @@ 2004-09-26 Helge Hess + * GNUmakefile: added imap_tool to compilation + * imap_tool.m: code cleanups 2004-08-29 Helge Hess diff --git a/sope-mime/samples/GNUmakefile b/sope-mime/samples/GNUmakefile index 76d510cd..b27c33f2 100644 --- a/sope-mime/samples/GNUmakefile +++ b/sope-mime/samples/GNUmakefile @@ -7,9 +7,11 @@ TOOL_NAME = \ imapls \ test_qpdecode \ imapquota \ + imap_tool -imapquota_OBJC_FILES = ImapQuotaTool.m ImapTool.m imapquota.m +imapquota_OBJC_FILES = ImapQuotaTool.m ImapTool.m imapquota.m imapget_OBJC_FILES = ImapTool.m imapget.m +imap_tool_OBJC_FILES = imap_tool.m mime2xml_OBJC_FILES = Mime2XmlTool.m mime2xml.m imapls_OBJC_FILES = ImapTool.m ImapListTool.m imapls.m test_qpdecode_OBJC_FILES = test_qpdecode.m diff --git a/sope-mime/samples/imap_tool.m b/sope-mime/samples/imap_tool.m index 151140cd..b8717ea6 100644 --- a/sope-mime/samples/imap_tool.m +++ b/sope-mime/samples/imap_tool.m @@ -19,21 +19,30 @@ 02111-1307, USA. */ +#include #include "common.h" -#include "NGImap4.h" static void usage(void) { fprintf(stderr, "usage: imap_tool" " -login " " -pwd " - " [-host ]\n"); + " [-host ]\n" + " (-action0 select|thread|list|fetch [-arg0 ])*" + "\n" + " select arg: \n" + " thread arg: (threadBySubject?)\n" + " list arg: \n" + " fetch arg: :(:)+\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]; } @@ -45,21 +54,26 @@ static void runAction(NGImap4Client *client, NSString *action, NSString *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]; @@ -72,22 +86,23 @@ static void run(void) { 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; } }