From 6d6053865f970f40e6dc4e6ac37df8c4d5bf29d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrique=20J=2E=20Hern=C3=A1ndez=20Blasco?= Date: Fri, 13 Mar 2015 00:00:29 +0100 Subject: [PATCH] Revert "oc-mailfolder: Get seen flag directly from message in preloading" This reverts commit d076e04ad47c8938531450af9f002552328f8fa1. --- OpenChange/MAPIStoreMailFolder.m | 33 ++++++++++++++++++++----------- OpenChange/MAPIStoreMailMessage.h | 1 - OpenChange/MAPIStoreMailMessage.m | 8 -------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/OpenChange/MAPIStoreMailFolder.m b/OpenChange/MAPIStoreMailFolder.m index 0a439e29e..e4c4b8a9b 100644 --- a/OpenChange/MAPIStoreMailFolder.m +++ b/OpenChange/MAPIStoreMailFolder.m @@ -1476,8 +1476,9 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) NSUInteger count, max; NSString *messageKey, *messageUid, *bodyPartKey; NGImap4Client *client; - NSArray *fetch; + NSArray *fetch, *flags; NSData *bodyContent; + BOOL unseen; NSMutableArray *unseenUIDs; if (tableType == MAPISTORE_MESSAGE_TABLE) @@ -1489,7 +1490,6 @@ _parseCOPYUID (NSString *line, NSArray **destUIDsP) { bodyPartKeys = [NSMutableSet setWithCapacity: max]; - unseenUIDs = [NSMutableArray arrayWithCapacity: max]; keyAssoc = [NSMutableDictionary dictionaryWithCapacity: max]; for (count = 0; count < max; count++) { @@ -1503,15 +1503,6 @@ _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]; - } } } } @@ -1519,6 +1510,24 @@ _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"]; @@ -1541,7 +1550,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 2f6192c16..fffd0c422 100644 --- a/OpenChange/MAPIStoreMailMessage.h +++ b/OpenChange/MAPIStoreMailMessage.h @@ -74,7 +74,6 @@ /* 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 4c6fba488..b5caf3355 100644 --- a/OpenChange/MAPIStoreMailMessage.m +++ b/OpenChange/MAPIStoreMailMessage.m @@ -1660,12 +1660,4 @@ _compareBodyKeysByPriority (id entry1, id entry2, void *data) } } -- (BOOL) read -{ - if (!headerSetup) - [self _fetchHeaderData]; - - return [sogoObject read]; -} - @end