From 067c53e223e4fe9e775db16be8714c2dc6a9fb1d Mon Sep 17 00:00:00 2001 From: helge Date: Sat, 2 Oct 2004 00:57:24 +0000 Subject: [PATCH] more mailer work git-svn-id: http://svn.opengroupware.org/SOGo/trunk@337 d1b88da0-ebda-0310-925b-ed51d893ca5b --- SOGo/SoObjects/Mailer/ChangeLog | 2 ++ SOGo/SoObjects/Mailer/SOGoMailFolder.h | 1 + SOGo/SoObjects/Mailer/SOGoMailFolder.m | 6 ++++ SOGo/SoObjects/Mailer/SOGoMailManager.h | 2 ++ SOGo/SoObjects/Mailer/SOGoMailManager.m | 41 +++++++++++++++++++++++-- SOGo/SoObjects/Mailer/Version | 2 +- SOGo/UI/Mailer/UIxMailListView.m | 35 ++++++++++++++++++--- 7 files changed, 81 insertions(+), 8 deletions(-) diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index 6d95d2ea..793d2f22 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,5 +1,7 @@ 2004-10-01 Helge Hess + * more work on fetching mails (v0.9.18) + * v0.9.17 * SOGoMailFolder.m: -fetchUIDsMatchingQualifier:sortOrdering:range: was diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.h b/SOGo/SoObjects/Mailer/SOGoMailFolder.h index 9febee95..82ac0d5d 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.h +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.h @@ -44,6 +44,7 @@ - (NSArray *)fetchUIDsMatchingQualifier:(id)_q sortOrdering:(id)_so range:(NSRange)_r; +- (NSArray *)fetchUIDs:(NSArray *)_uids parts:(NSArray *)_parts; @end diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.m b/SOGo/SoObjects/Mailer/SOGoMailFolder.m index aae4b257..2d1c9dab 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.m @@ -50,6 +50,12 @@ password:[self imap4Password]]; } +- (NSArray *)fetchUIDs:(NSArray *)_uids parts:(NSArray *)_parts { + return [[self mailManager] fetchUIDs:_uids inURL:[self imap4URL] + parts:_parts + password:[self imap4Password]]; +} + /* name lookup */ - (BOOL)isMessageKey:(NSString *)_key inContext:(id)_ctx { diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.h b/SOGo/SoObjects/Mailer/SOGoMailManager.h index f8ac7580..b431d0f1 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.h +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.h @@ -56,6 +56,8 @@ - (NSArray *)fetchUIDsInURL:(NSURL *)_url qualifier:(id)_q sortOrdering:(id)_so range:(NSRange)_range password:(NSString *)_pwd; +- (NSArray *)fetchUIDs:(NSArray *)_uids inURL:(NSURL *)_url + parts:(NSArray *)_parts password:(NSString *)_pwd; @end diff --git a/SOGo/SoObjects/Mailer/SOGoMailManager.m b/SOGo/SoObjects/Mailer/SOGoMailManager.m index 2912ea7f..39efa976 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailManager.m +++ b/SOGo/SoObjects/Mailer/SOGoMailManager.m @@ -345,7 +345,7 @@ static NSTimeInterval PoolScanInterval = 5 * 60; result = [client select:[self imap4FolderNameForURL:_url]]; if (![[result valueForKey:@"result"] boolValue]) { - [self logWithFormat:@"ERROR: could not select URL: %@", _url]; + [self logWithFormat:@"ERROR: could not select URL: %@: %@", _url, result]; return nil; } @@ -360,12 +360,47 @@ static NSTimeInterval PoolScanInterval = 5 * 60; [self logWithFormat:@"ERROR: got no UIDs for URL: %@: %@", _url, result]; return nil; } - - // TODO: range + + // TODO: improve to use a single range call? + if (_range.location > 0) { + uids = [uids subarrayWithRange:NSMakeRange(_range.location, + [uids count]-_range.location)]; + } + if ([uids count] > _range.length && _range.length != 0) + uids = [uids subarrayWithRange:NSMakeRange(0, _range.length)]; return uids; } +- (NSArray *)fetchUIDs:(NSArray *)_uids inURL:(NSURL *)_url + parts:(NSArray *)_parts password:(NSString *)_pwd +{ + NGImap4Client *client; + NSDictionary *result; + + if (_uids == nil) + return nil; + if ([_uids count] == 0) + return [NSArray array]; + + if ((client = [self imap4ClientForURL:_url password:_pwd]) == nil) + return nil; + +#warning TODO: split uids into batches, otherwise Cyrus will complain + // not really important because we batch before (in the sort) + // if the list is too long, we get a: + // "* BYE Fatal error: word too long" + + result = [client fetchUids:_uids parts:_parts]; + if (![[result valueForKey:@"result"] boolValue]) { + [self logWithFormat:@"ERROR: could not fetch %d uids for url: %@", + [_uids count],_url]; + return nil; + } + //[self logWithFormat:@"RESULT: %@", result]; + return (id)result; +} + /* debugging */ - (BOOL)isDebuggingEnabled { diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index 33dfbe1b..cd35ad0f 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,3 +1,3 @@ # $Id$ -SUBMINOR_VERSION:=17 +SUBMINOR_VERSION:=18 diff --git a/SOGo/UI/Mailer/UIxMailListView.m b/SOGo/UI/Mailer/UIxMailListView.m index 7893672e..f94e21d8 100644 --- a/SOGo/UI/Mailer/UIxMailListView.m +++ b/SOGo/UI/Mailer/UIxMailListView.m @@ -37,12 +37,39 @@ @implementation UIxMailListView - (id)defaultAction { + NSArray *uids; + NSArray *msgs; + [self logWithFormat:@"default action ..."]; + + uids = [[self clientObject] fetchUIDsMatchingQualifier:nil + sortOrdering:@"SUBJECT" + range:NSMakeRange(0, 50)]; + + [self logWithFormat:@"UIDs: %@", [uids componentsJoinedByString:@", "]]; - [self logWithFormat:@"UIDs: %@", - [[self clientObject] fetchUIDsMatchingQualifier:nil - sortOrdering:@"SUBJECT" - range:NSMakeRange(0, 1000000)]]; + /* + Allowed fetch keys: + UID + BODY.PEEK[
]<> + BODYSTRUCTURE + ENVELOPE [this is a parsed header, but does not include type] + FLAGS + INTERNALDATE + RFC822 + RFC822.HEADER + RFC822.SIZE + RFC822.TEXT + */ + + msgs = [[self clientObject] fetchUIDs:uids + parts:[NSArray arrayWithObjects: + @"FLAGS", + @"ENVELOPE", + nil]]; + [self logWithFormat:@" msg #%d", [[msgs valueForKey:@"fetch"] count]]; + // keys: envelope + return self; } -- 2.39.5