oc-mailfolder: Get seen flag directly from message in preloading
To avoid a loop and a server-call. We are not using body.peek[text] directly because bodyContentPart message is explicitly avoiding it.pull/69/head
parent
7e0cddc06b
commit
d076e04ad4
|
@ -1274,9 +1274,8 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP)
|
|||
NSUInteger count, max;
|
||||
NSString *messageKey, *messageUid, *bodyPartKey;
|
||||
NGImap4Client *client;
|
||||
NSArray *fetch, *flags;
|
||||
NSArray *fetch;
|
||||
NSData *bodyContent;
|
||||
BOOL unseen;
|
||||
NSMutableArray *unseenUIDs;
|
||||
|
||||
if (tableType == MAPISTORE_MESSAGE_TABLE)
|
||||
|
@ -1288,6 +1287,7 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP)
|
|||
{
|
||||
bodyPartKeys = [NSMutableSet setWithCapacity: max];
|
||||
|
||||
unseenUIDs = [NSMutableArray arrayWithCapacity: max];
|
||||
keyAssoc = [NSMutableDictionary dictionaryWithCapacity: max];
|
||||
for (count = 0; count < max; count++)
|
||||
{
|
||||
|
@ -1301,6 +1301,15 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP)
|
|||
[bodyPartKeys addObject: bodyPartKey];
|
||||
messageUid = [self messageUIDFromMessageKey: messageKey];
|
||||
[keyAssoc setObject: bodyPartKey forKey: messageUid];
|
||||
/* Fetch flags to remove seen flag if required,
|
||||
as fetching a message body set the seen flag.
|
||||
We are not using body.peek[] as
|
||||
bodyContentPartKey explicitly avoids it.
|
||||
*/
|
||||
if (![message read])
|
||||
{
|
||||
[unseenUIDs addObject: messageUid];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1308,24 +1317,6 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP)
|
|||
client = [[(SOGoMailFolder *) sogoObject imap4Connection] client];
|
||||
[client select: [sogoObject absoluteImap4Name]];
|
||||
|
||||
/* Fetch flags to remove seen flag if required,
|
||||
as fetching a message body set the seen flag */
|
||||
response = [client fetchUids: [keyAssoc allKeys]
|
||||
parts: [NSArray arrayWithObjects: @"flags", nil]];
|
||||
fetch = [response objectForKey: @"fetch"];
|
||||
max = [fetch count];
|
||||
unseenUIDs = [NSMutableArray arrayWithCapacity: max];
|
||||
for (count = 0; count < max; count++)
|
||||
{
|
||||
response = [fetch objectAtIndex: count];
|
||||
messageUid = [[response objectForKey: @"uid"] stringValue];
|
||||
flags = [response objectForKey: @"flags"];
|
||||
unseen = [flags indexOfObject: @"seen"] == NSNotFound;
|
||||
if (unseen) {
|
||||
[unseenUIDs addObject: messageUid];
|
||||
}
|
||||
}
|
||||
|
||||
response = [client fetchUids: [keyAssoc allKeys]
|
||||
parts: [bodyPartKeys allObjects]];
|
||||
fetch = [response objectForKey: @"fetch"];
|
||||
|
@ -1348,7 +1339,7 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP)
|
|||
}
|
||||
}
|
||||
|
||||
// Restore unseen state once the body has been fetched
|
||||
/* Restore unseen state once the body has been fetched */
|
||||
if ([unseenUIDs count] > 0)
|
||||
{
|
||||
response = [client storeFlags: [NSArray arrayWithObjects: @"seen", nil]
|
||||
|
|
|
@ -73,6 +73,7 @@
|
|||
/* batch-mode helpers */
|
||||
- (NSString *) bodyContentPartKey;
|
||||
- (void) setBodyContentFromRawData: (NSData *) rawContent;
|
||||
- (BOOL) read; /* Unseen from sogoObject */
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1598,4 +1598,12 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data)
|
|||
}
|
||||
}
|
||||
|
||||
- (BOOL) read
|
||||
{
|
||||
if (!headerSetup)
|
||||
[self _fetchHeaderData];
|
||||
|
||||
return [sogoObject read];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
Loading…
Reference in New Issue