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;
}
[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 {
@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[<section>]<<partial>>
+ 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;
}