diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 40857d39c..28fcca431 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -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] diff --git a/OpenChange/MAPIStoreMailMessage.h b/OpenChange/MAPIStoreMailMessage.h index 22d9e3320..6bae6647a 100644 --- a/OpenChange/MAPIStoreMailMessage.h +++ b/OpenChange/MAPIStoreMailMessage.h @@ -73,6 +73,7 @@ /* batch-mode helpers */ - (NSString *) bodyContentPartKey; - (void) setBodyContentFromRawData: (NSData *) rawContent; +- (BOOL) read; /* Unseen from sogoObject */ @end diff --git a/OpenChange/MAPIStoreMailMessage.m b/OpenChange/MAPIStoreMailMessage.m index 3a00796c4..c64f60c22 100644 --- a/OpenChange/MAPIStoreMailMessage.m +++ b/OpenChange/MAPIStoreMailMessage.m @@ -1598,4 +1598,12 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) } } +- (BOOL) read +{ + if (!headerSetup) + [self _fetchHeaderData]; + + return [sogoObject read]; +} + @end